@devries-cameron20 / t3code Mirror · read-only / commits / 023620d3a5
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 21, 09:45 UTC

fix(server): Codex health checks no longer kill ssh mid SSH-agent request (#37677)

Julius Marminge committed Nov 16, 2026 at 07:48 UTC 023620d3a51e815d49723d514ce7cae3a1a5a26f
1 file changed +40 -2
apps/server/src/provider/CodexProvider.ts
+40 -2
@@ -4,6 +4,7 @@ import * as DateTime from "effect/DateTime";
4 import * as Duration from "effect/Duration";
5 import * as Effect from "effect/Effect";
6 import * as Equal from "effect/Equal";
7 +import * as Exit from "effect/Exit";
8 import * as FileSystem from "effect/FileSystem";
9 import * as Layer from "effect/Layer";
10 import * as Option from "effect/Option";
@@ -676,9 +677,31 @@ export const withCodexAppServerClient = Effect.fn("withCodexAppServerClient")(fu
677 );
678 const initialize = yield* client.request("initialize", buildCodexInitializeParams());
679 yield* client.notify("initialized", undefined);
679 - return { client, initialize };
680 + return { client, initialize, pid: child.pid };
681 });
682
683 +// Codex runs git (ssh for ssh URLs) for plugin marketplaces at launch and exits without waiting
684 +// for it, so stopping a short probe mid-fetch strands ssh in an SSH-agent request.
685 +const CODEX_STARTUP_WORK_GRACE = Duration.minutes(1);
686 +
687 +const codexProcessGroupIsBusy = Effect.fn("codexProcessGroupIsBusy")(
688 + function* (pid: number) {
689 + const { stdout } = yield* spawnAndCollect(
690 + "pgrep",
691 + ChildProcess.make("pgrep", ["-g", `${pid}`]),
692 + );
693 + return stdout.split("\n").some((line) => line.trim() !== "" && Number(line) !== pid);
694 + },
695 + Effect.orElseSucceed(() => false),
696 +);
697 +
698 +const stopCodexAfterStartupWork = (pid: number, processScope: Scope.Closeable) =>
699 + codexProcessGroupIsBusy(pid).pipe(
700 + Effect.repeat({ schedule: Schedule.spaced("500 millis"), while: (busy) => busy }),
701 + Effect.timeoutOption(CODEX_STARTUP_WORK_GRACE),
702 + Effect.ensuring(Scope.close(processScope, Exit.void)),
703 + );
704 +
705 // Usage is an enrichment: a failure or a slow answer degrades to "no usage this
706 // probe" rather than costing the account and models.
707 const readCodexRateLimits = (
@@ -713,7 +736,22 @@ const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(fun
736 readonly skipNativeUsage?: boolean;
737 }) {
738 const spawnedAtMs = DateTime.toEpochMillis(yield* DateTime.now);
716 - const { client, initialize } = yield* withCodexAppServerClient(input);
739 + const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
740 + const processScope = yield* Scope.make();
741 + let pid: number | undefined;
742 + // Returning the snapshot must not wait for Codex's own startup work.
743 + yield* Effect.addFinalizer(() =>
744 + pid === undefined
745 + ? Scope.close(processScope, Exit.void)
746 + : stopCodexAfterStartupWork(pid, processScope).pipe(
747 + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
748 + Effect.forkDetach,
749 + Effect.asVoid,
750 + ),
751 + );
752 + const opened = yield* withCodexAppServerClient(input).pipe(Scope.provide(processScope));
753 + pid = opened.pid;
754 + const { client, initialize } = opened;
755
756 const versionMatch = initialize.userAgent.match(/\/([^\s]+)/);
757 const version = versionMatch ? versionMatch[1] : undefined;