Skip to content

Commit f140ec7

Browse files
t3dotggclaude
andcommitted
fix(server): Stop ends a Codex command after the thread was settled
Settling a Codex thread unsubscribes it, and Codex unloads it a minute later, killing its terminals. Stop then asked Codex to terminate the terminal, got "thread not found", and failed before the settle step, so the banner kept showing the command as running. Treat "thread not found" from terminate as already terminated, like an exited app-server. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 1302cca commit f140ec7

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3869,7 +3869,9 @@ describe("CodexAdapterV2 post-settle continuation", () => {
38693869
),
38703870
);
38713871

3872-
const backgroundStopCases = [true, false, "still_running"] as const;
3872+
// "thread_unloaded": the thread was settled, so T3 unsubscribed and Codex
3873+
// unloaded it (killing its terminals) before Stop arrived.
3874+
const backgroundStopCases = [true, false, "still_running", "thread_unloaded"] as const;
38733875
const makeBackgroundStopTranscript = (terminated: (typeof backgroundStopCases)[number]) => {
38743876
const stillRunning = terminated === "still_running";
38753877
return makeCodexReplayTranscript({
@@ -3888,9 +3890,15 @@ describe("CodexAdapterV2 post-settle continuation", () => {
38883890
{
38893891
type: "emit_inbound",
38903892
label: "terminate-background-command",
3891-
frame: { id: 4, result: { terminated: terminated === true } },
3893+
frame:
3894+
terminated === "thread_unloaded"
3895+
? {
3896+
id: 4,
3897+
error: { code: -32600, message: `thread not found: ${BG_NATIVE_THREAD}` },
3898+
}
3899+
: { id: 4, result: { terminated: terminated === true } },
38923900
},
3893-
...(terminated !== true
3901+
...(terminated === false || stillRunning
38943902
? [
38953903
{
38963904
type: "expect_outbound" as const,

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,6 +2053,13 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi
20532053
Effect.catchTags({
20542054
CodexAppServerProcessExitedError: () => Effect.succeed({ terminated: true }),
20552055
CodexAppServerInputStreamEndedError: () => Effect.succeed({ terminated: true }),
2056+
// The thread is unloaded, as Codex does a minute after a
2057+
// settle or archive unsubscribes it. Unloading kills the
2058+
// thread's terminals, so nothing is left to stop.
2059+
CodexAppServerRequestError: (error) =>
2060+
error.code === -32600 && error.errorMessage.startsWith("thread not found:")
2061+
? Effect.succeed({ terminated: true })
2062+
: Effect.fail(error),
20562063
}),
20572064
);
20582065
const result = yield* decodeCodexBackgroundTerminalTerminateResponse(response);

0 commit comments

Comments
 (0)