Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3869,7 +3869,9 @@ describe("CodexAdapterV2 post-settle continuation", () => {
),
);

const backgroundStopCases = [true, false, "still_running"] as const;
// "thread_unloaded": the thread was settled, so T3 unsubscribed and Codex
// unloaded it (killing its terminals) before Stop arrived.
const backgroundStopCases = [true, false, "still_running", "thread_unloaded"] as const;
const makeBackgroundStopTranscript = (terminated: (typeof backgroundStopCases)[number]) => {
const stillRunning = terminated === "still_running";
return makeCodexReplayTranscript({
Expand All @@ -3888,9 +3890,15 @@ describe("CodexAdapterV2 post-settle continuation", () => {
{
type: "emit_inbound",
label: "terminate-background-command",
frame: { id: 4, result: { terminated: terminated === true } },
frame:
terminated === "thread_unloaded"
? {
id: 4,
error: { code: -32600, message: `thread not found: ${BG_NATIVE_THREAD}` },
}
: { id: 4, result: { terminated: terminated === true } },
},
...(terminated !== true
...(terminated === false || stillRunning
? [
{
type: "expect_outbound" as const,
Expand Down
7 changes: 7 additions & 0 deletions apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2053,6 +2053,13 @@ export function makeCodexAdapterV2(adapterOptions: CodexAdapterV2Options): Provi
Effect.catchTags({
CodexAppServerProcessExitedError: () => Effect.succeed({ terminated: true }),
CodexAppServerInputStreamEndedError: () => Effect.succeed({ terminated: true }),
// The thread is unloaded, as Codex does a minute after a
// settle or archive unsubscribes it. Unloading kills the
// thread's terminals, so nothing is left to stop.
CodexAppServerRequestError: (error) =>
error.code === -32600 && error.errorMessage.startsWith("thread not found:")
? Effect.succeed({ terminated: true })
: Effect.fail(error),
}),
);
const result = yield* decodeCodexBackgroundTerminalTerminateResponse(response);
Expand Down
Loading