@devries-cameron20 / t3code Mirror · read-only / commits / cf3e714b0f
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 23, 19:15 UTC

fix(server): Stop ends a Codex command after its thread was settled (#15546)

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Theo Browne committed Oct 5, 2026 at 00:13 UTC cf3e714b0f58e29c8fa8660db50d2187e3263b65
2 files changed +18 -3
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
+11 -3
@@ -3917,7 +3917,9 @@ describe("CodexAdapterV2 post-settle continuation", () => {
3917 ),
3918 );
3919
3920 - const backgroundStopCases = [true, false, "still_running"] as const;
3920 + // "thread_unloaded": the thread was settled, so T3 unsubscribed and Codex
3921 + // unloaded it (killing its terminals) before Stop arrived.
3922 + const backgroundStopCases = [true, false, "still_running", "thread_unloaded"] as const;
3923 const makeBackgroundStopTranscript = (terminated: (typeof backgroundStopCases)[number]) => {
3924 const stillRunning = terminated === "still_running";
3925 return makeCodexReplayTranscript({
@@ -3936,9 +3938,15 @@ describe("CodexAdapterV2 post-settle continuation", () => {
3938 {
3939 type: "emit_inbound",
3940 label: "terminate-background-command",
3939 - frame: { id: 4, result: { terminated: terminated === true } },
3941 + frame:
3942 + terminated === "thread_unloaded"
3943 + ? {
3944 + id: 4,
3945 + error: { code: -32600, message: `thread not found: ${BG_NATIVE_THREAD}` },
3946 + }
3947 + : { id: 4, result: { terminated: terminated === true } },
3948 },
3941 - ...(terminated !== true
3949 + ...(terminated === false || stillRunning
3950 ? [
3951 {
3952 type: "expect_outbound" as const,
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+7
@@ -2054,6 +2054,13 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi
2054 Effect.catchTags({
2055 CodexAppServerProcessExitedError: () => Effect.succeed({ terminated: true }),
2056 CodexAppServerInputStreamEndedError: () => Effect.succeed({ terminated: true }),
2057 + // The thread is unloaded, as Codex does a minute after a
2058 + // settle or archive unsubscribes it. Unloading kills the
2059 + // thread's terminals, so nothing is left to stop.
2060 + CodexAppServerRequestError: (error) =>
2061 + error.code === -32600 && error.errorMessage.startsWith("thread not found:")
2062 + ? Effect.succeed({ terminated: true })
2063 + : Effect.fail(error),
2064 }),
2065 );
2066 const result = yield* decodeCodexBackgroundTerminalTerminateResponse(response);