@devries-cameron20 / t3code-1 / commits / 0346d644a1
Fork 0

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

fix(server): every commit hook reports finishing with its real exit code (#22939)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>

MarcoDotIO committed Oct 31, 2026 at 04:41 UTC 0346d644a177b37856e987c35e25368cc8d53fac
2 files changed +60 -12
apps/server/src/vcs/GitVcsDriverCore.test.ts
+50
@@ -4851,6 +4851,56 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
4851 }),
4852 );
4853
4854 + const commitWithHooks = (hooks: Record<string, string>) =>
4855 + Effect.gen(function* () {
4856 + const cwd = yield* makeTmpDir();
4857 + yield* initRepoWithCommit(cwd);
4858 + const fs = yield* FileSystem.FileSystem;
4859 + const path = yield* Path.Path;
4860 + for (const [name, script] of Object.entries(hooks)) {
4861 + yield* writeTextFile(cwd, `.git/hooks/${name}`, `#!/bin/sh\n${script}\n`);
4862 + yield* fs.chmod(path.join(cwd, ".git/hooks", name), 0o755);
4863 + }
4864 + yield* writeTextFile(cwd, "a.txt", "a\n");
4865 + const events: string[] = [];
4866 + const result = yield* (yield* GitVcsDriver.GitVcsDriver)
4867 + .commit(cwd, "Add a", "", {
4868 + stage: { filePaths: ["a.txt"] },
4869 + progress: {
4870 + onHookStarted: (hookName) => Effect.sync(() => void events.push(`start ${hookName}`)),
4871 + onHookFinished: ({ hookName, exitCode }) =>
4872 + Effect.sync(() => void events.push(`finish ${hookName} ${exitCode}`)),
4873 + },
4874 + })
4875 + .pipe(Effect.result);
4876 + return { events, committed: Result.isSuccess(result) };
4877 + });
4878 +
4879 + it.effect("reports each commit hook finishing with its exit code", () =>
4880 + Effect.gen(function* () {
4881 + // The pre-commit hook runs git, whose own children reuse child_id 0 in the shared trace.
4882 + const { events, committed } = yield* commitWithHooks({
4883 + "pre-commit": "git -c alias.noop='!false' noop\nexit 0",
4884 + "commit-msg": "exit 0",
4885 + });
4886 + assert.isTrue(committed);
4887 + assert.deepEqual(events, [
4888 + "start pre-commit",
4889 + "finish pre-commit 0",
4890 + "start commit-msg",
4891 + "finish commit-msg 0",
4892 + ]);
4893 + }),
4894 + );
4895 +
4896 + it.effect("reports the exit code of a commit hook that rejects the commit", () =>
4897 + Effect.gen(function* () {
4898 + const { events, committed } = yield* commitWithHooks({ "commit-msg": "exit 3" });
4899 + assert.isFalse(committed);
4900 + assert.deepEqual(events, ["start commit-msg", "finish commit-msg 3"]);
4901 + }),
4902 + );
4903 +
4904 it.effect.each([false, true])(
4905 "preserves partial staging and split-index files (split: %s)",
4906 (split) =>
apps/server/src/vcs/GitVcsDriverCore.ts
+10 -12
@@ -648,10 +648,11 @@ const addCurrentSpanEvent =
648 }),
649 );
650
651 +// Nested Git processes share the trace file but reuse child IDs in their own sessions.
652 function trace2ChildKey(record: Record<string, unknown>): string | null {
653 const childId = record.child_id;
654 if (typeof childId === "number" || typeof childId === "string") {
654 - return String(childId);
655 + return typeof record.sid === "string" ? `${record.sid}\n${childId}` : String(childId);
656 }
657 const hookName = record.hook_name;
658 return typeof hookName === "string" && hookName.trim().length > 0 ? hookName.trim() : null;
@@ -702,10 +703,6 @@ const createTrace2Monitor = Effect.fnUntraced(function* (
703 return;
704 }
705
705 - if (traceRecord.success.child_class !== "hook") {
706 - return;
707 - }
708 -
706 const event = traceRecord.success.event;
707 const childKey = trace2ChildKey(traceRecord.success);
708 if (childKey === null) {
@@ -720,6 +717,9 @@ const createTrace2Monitor = Effect.fnUntraced(function* (
717 }
718
719 if (event === "child_start") {
720 + if (traceRecord.success.child_class !== "hook") {
721 + return;
722 + }
723 const now = yield* DateTime.now;
724 hookStartByChildKey.set(childKey, { hookName, startedAtMs: DateTime.toEpochMillis(now) });
725 yield* addCurrentSpanEvent("git.hook.started", {
@@ -731,22 +731,20 @@ const createTrace2Monitor = Effect.fnUntraced(function* (
731 return;
732 }
733
734 - if (event === "child_exit") {
734 + if (event === "child_exit" && started) {
735 hookStartByChildKey.delete(childKey);
736 - const code = traceRecord.success.exitCode;
736 + const code = traceRecord.success.code;
737 const exitCode = typeof code === "number" && Number.isInteger(code) ? code : null;
738 const now = yield* DateTime.now;
739 - const durationMs = started
740 - ? Math.max(0, DateTime.toEpochMillis(now) - started.startedAtMs)
741 - : null;
739 + const durationMs = Math.max(0, DateTime.toEpochMillis(now) - started.startedAtMs);
740 yield* addCurrentSpanEvent("git.hook.finished", {
743 - hookName: started?.hookName ?? hookName,
741 + hookName: started.hookName,
742 exitCode,
743 durationMs,
744 });
745 if (progress.onHookFinished) {
746 yield* progress.onHookFinished({
749 - hookName: started?.hookName ?? hookName,
747 + hookName: started.hookName,
748 exitCode,
749 durationMs,
750 });