@devries-cameron20 / t3code Mirror · read-only / commits / fb7f08782b
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 19:30 UTC

fix(server): pushes the remote refuses say why instead of a generic failure (#22904)

Co-authored-by: fixfon <12512757+fixfon@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Theo Browne committed Oct 21, 2026 at 15:08 UTC fb7f08782b964b4137eef597052c99efc9039043
3 files changed +119 -4
apps/server/src/vcs/GitVcsDriverCore.test.ts
+91 -2
@@ -80,6 +80,13 @@ const makeSuccessfulHandle = (stdout: string) =>
80 getOutputFd: () => Stream.empty,
81 });
82
83 +const makeFailedHandle = (stderr: string) =>
84 + ChildProcessSpawner.makeHandle({
85 + ...makeNonRepositoryHandle(),
86 + exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(1)),
87 + stderr: Stream.encodeText(Stream.make(stderr)),
88 + });
89 +
90 const makeTmpDir = (
91 prefix = "git-vcs-driver-test-",
92 ): Effect.Effect<string, PlatformError.PlatformError, FileSystem.FileSystem | Scope.Scope> =>
@@ -803,6 +810,88 @@ it.effect("retries a fetch that lost a ref update to another Git process", () =>
810 }).pipe(Effect.provide(layerServerConfig.pipe(Layer.provideMerge(NodeServices.layer)))),
811 );
812
813 +describe("rejected git refs", () => {
814 + const remoteUrl = "https://user:token-123@git.example.invalid/org/secret-repo.git";
815 + const failedPush = `error: failed to push some refs to '${remoteUrl}'`;
816 + const leakedText = [
817 + "token-123",
818 + "secret-repo",
819 + "git.example.invalid",
820 + "private-branch",
821 + "workflow scope",
822 + ];
823 +
824 + const failWith = (stderr: string) => {
825 + const spawner = ChildProcessSpawner.make(() => Effect.succeed(makeFailedHandle(stderr)));
826 + const layer = GitVcsDriver.layer.pipe(
827 + Layer.provide(layerServerConfig),
828 + Layer.provideMerge(
829 + Layer.merge(
830 + NodeServices.layer,
831 + Layer.succeed(ChildProcessSpawner.ChildProcessSpawner, spawner),
832 + ),
833 + ),
834 + );
835 + return Effect.gen(function* () {
836 + const driver = yield* GitVcsDriver.GitVcsDriver;
837 + return yield* driver
838 + .execute({
839 + operation: "GitVcsDriver.test.rejectedRef",
840 + cwd: "/repo",
841 + args: ["push", "origin", "HEAD"],
842 + })
843 + .pipe(Effect.flip);
844 + }).pipe(Effect.provide(layer));
845 + };
846 +
847 + it.effect.each([
848 + {
849 + label: "a ref the remote refused",
850 + stderr: [
851 + "remote: Unable to determine if workflow can be created; workflow scope may be required.",
852 + `To ${remoteUrl}`,
853 + " ! [remote rejected] private-branch -> private-branch (workflow scope may be required.)",
854 + failedPush,
855 + ],
856 + reason: "push_rejected_by_remote" as const,
857 + detail: "The remote rejected the push.",
858 + },
859 + {
860 + label: "a non-fast-forward push",
861 + stderr: [
862 + `To ${remoteUrl}`,
863 + " ! [rejected] private-branch -> private-branch (non-fast-forward)",
864 + failedPush,
865 + ],
866 + reason: "push_rejected_non_fast_forward" as const,
867 + detail: "Pull or rebase",
868 + },
869 + ])("names $label without quoting stderr", ({ stderr, reason, detail }) =>
870 + Effect.gen(function* () {
871 + const error = yield* failWith(stderr.join("\n"));
872 +
873 + assert.deepInclude(error, { reason });
874 + assert.include(error.detail, detail);
875 + for (const text of leakedText) assert.notInclude(error.message, text);
876 + }),
877 + );
878 +
879 + // A fetch into a diverged local branch prints the same rejected line, but
880 + // never "failed to push some refs".
881 + it.effect("leaves a rejected fetch unclassified", () =>
882 + Effect.gen(function* () {
883 + const error = yield* failWith(
884 + [`From ${remoteUrl}`, " ! [rejected] main -> side (non-fast-forward)"].join(
885 + "\n",
886 + ),
887 + );
888 +
889 + assert.equal(error.reason, undefined);
890 + assert.equal(error.detail, "Git command exited with a non-zero status.");
891 + }),
892 + );
893 +});
894 +
895 it.layer(layerTest)("GitVcsDriver core integration", (it) => {
896 describe("structured errors", () => {
897 it.effect("does not retain git arguments or stderr in command failures", () =>
@@ -1071,7 +1160,7 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
1160 }),
1161 );
1162
1074 - it.effect("does not read remote hook output as a git failure reason", () =>
1163 + it.effect("reads a hook-declined push from git's rejection line, not the hook's output", () =>
1164 Effect.gen(function* () {
1165 const parent = yield* makeTmpDir();
1166 const pathService = yield* Path.Path;
@@ -1100,7 +1189,7 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
1189 })
1190 .pipe(Effect.flip);
1191
1103 - assert.notProperty(error, "reason");
1192 + assert.deepInclude(error, { reason: "push_rejected_by_remote" });
1193 assert.notInclude(error.message, "(authentication_failed)");
1194 }),
1195 );
apps/server/src/vcs/GitVcsDriverCore.ts
+26 -2
@@ -456,8 +456,32 @@ const GIT_FAILURE_REASON_PATTERNS: ReadonlyArray<readonly [RegExp, GitCommandFai
456 /^fatal: (?:invalid reference: |not a valid object name|needed a single revision|bad revision |'.+' is not a commit and a branch '.+' cannot be created from it)/im,
457 "ref_not_found",
458 ],
459 + // `[remote rejected]` is only printed for a push. The remote's explanation
460 + // follows in parentheses; it is server text, so it is never quoted.
461 + [/^[ \t]*![ \t]+\[remote rejected\]/im, "push_rejected_by_remote"],
462 + // A fetch into a diverged local branch prints the same `[rejected]` line, but
463 + // only a push goes on to report "failed to push some refs".
464 + [
465 + /^[ \t]*![ \t]+\[rejected\][^\n]*\((?:non-fast-forward|fetch first)\)[\s\S]*^error: failed to push some refs/im,
466 + "push_rejected_non_fast_forward",
467 + ],
468 ];
469
470 +// Reasons the user can act on get a sentence in place of the generic detail.
471 +const GIT_FAILURE_REASON_DETAILS: Partial<Record<GitCommandFailureReason, string>> = {
472 + push_rejected_by_remote:
473 + "The remote rejected the push. Push this branch from a terminal to see the server's message.",
474 + push_rejected_non_fast_forward:
475 + "The remote has commits this branch doesn't have. Pull or rebase, then push again.",
476 +};
477 +
478 +function gitFailureDetail(reason: GitCommandFailureReason | null): string {
479 + return (
480 + (reason === null ? undefined : GIT_FAILURE_REASON_DETAILS[reason]) ??
481 + "Git command exited with a non-zero status."
482 + );
483 +}
484 +
485 // Existing non-commit objects share the missing-ref fatal diagnostic; Git
486 // distinguishes them with a separate error line.
487 const GIT_NOT_A_COMMIT_PATTERN = /^error: .+(?:, not a commit|expected commit type)/im;
@@ -1031,7 +1055,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1055 return yield* new GitCommandError({
1056 ...gitCommandContext(commandInput),
1057 ...(reason === null ? {} : { reason }),
1034 - detail: "Git command exited with a non-zero status.",
1058 + detail: gitFailureDetail(reason),
1059 exitCode,
1060 stdoutLength: stdout.text.length,
1061 stderrLength: stderr.text.length,
@@ -1123,7 +1147,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
1147 new GitCommandError({
1148 ...gitCommandContext({ operation, cwd, args }),
1149 ...(reason === null ? {} : { reason }),
1126 - detail: options.fallbackErrorDetail ?? "Git command exited with a non-zero status.",
1150 + detail: options.fallbackErrorDetail ?? gitFailureDetail(reason),
1151 ...(result.exitCode === null ? {} : { exitCode: result.exitCode }),
1152 stdoutLength: result.stdout.length,
1153 stderrLength: result.stderr.length,
packages/contracts/src/git.ts
+2
@@ -361,6 +361,8 @@ export const GitCommandFailureReason = Schema.Literals([
361 "host_key_unverified",
362 "not_a_repository",
363 "path_already_exists",
364 + "push_rejected_by_remote",
365 + "push_rejected_non_fast_forward",
366 "ref_not_found",
367 "remote_unreachable",
368 "tag_would_be_clobbered",