Skip to content

Commit 83f34b6

Browse files
committed
test(server): assert automatic background cleanup after provider exit
1 parent 1094613 commit 83f34b6

4 files changed

Lines changed: 22 additions & 28 deletions

File tree

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

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4168,7 +4168,7 @@ describe("CodexAdapterV2 post-settle continuation", () => {
41684168
);
41694169
});
41704170

4171-
it.effect("Stop ends a background command no Codex process tracks any more", () =>
4171+
it.effect("settles a background command automatically after the Codex process exits", () =>
41724172
Effect.scoped(
41734173
Effect.gen(function* () {
41744174
const fs = yield* FileSystem.FileSystem;
@@ -4244,27 +4244,19 @@ describe("CodexAdapterV2 post-settle continuation", () => {
42444244
yield* worker.drain();
42454245
yield* Fiber.join(settled);
42464246
yield* worker.drain();
4247-
const before = yield* orchestrator.getThreadShell(threadId);
4248-
assert.deepEqual(
4249-
before?.pendingBackgroundTasks?.map((task) => task.kind),
4250-
["command"],
4251-
"the thread still shows the command the gone process never finished",
4252-
);
4253-
const run = (yield* orchestrator.getThreadProjection(threadId)).runs.at(-1)!;
4254-
yield* orchestrator.dispatch({
4255-
type: "run.interrupt",
4256-
commandId: CommandId.make("stop-background-untracked"),
4257-
threadId,
4258-
runId: run.id,
4259-
holdQueue: true,
4260-
});
4261-
yield* worker.drain();
42624247
const projection = yield* orchestrator.getThreadProjection(threadId);
42634248
assert.deepEqual(
42644249
projection.turnItems.flatMap((item) =>
42654250
item.type === "command_execution" ? [item.status] : [],
42664251
),
4267-
["interrupted"],
4252+
["failed"],
4253+
);
4254+
const command = projection.turnItems.find((item) => item.type === "command_execution");
4255+
assert.isDefined(command);
4256+
assert.isNotNull(command?.completedAt);
4257+
assert.notInclude(
4258+
projection.turnItems.map((item) => item.type),
4259+
"run_interrupt_request",
42684260
);
42694261
assert.equal(projection.runs.at(-1)?.status, "completed");
42704262
assert.deepEqual(

‎apps/server/src/orchestration-v2/testkit/fixtures/index.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,7 +1798,7 @@ export const ORCHESTRATOR_REPLAY_FIXTURES: ReadonlyArray<OrchestratorReplayFixtu
17981798
],
17991799
},
18001800
{
1801-
name: "stop_background_work_after_failed_turn",
1801+
name: "background_work_settles_after_failed_turn",
18021802
buildInput: stopBackgroundWorkAfterFailedTurnInput,
18031803
providers: [
18041804
{
@@ -1807,13 +1807,14 @@ export const ORCHESTRATOR_REPLAY_FIXTURES: ReadonlyArray<OrchestratorReplayFixtu
18071807
"./stop_background_work_after_failed_turn/registry_transcript.ndjson",
18081808
import.meta.url,
18091809
),
1810+
recordedScenario: "stop_background_work_after_failed_turn",
18101811
modelSelection: ACP_REGISTRY_MODEL_SELECTION,
18111812
assertOutput: assertStopBackgroundWorkAfterFailedTurnOutput,
18121813
},
18131814
],
18141815
},
18151816
{
1816-
name: "stop_background_work_after_release",
1817+
name: "background_work_stays_settled_after_release",
18171818
buildInput: stopBackgroundWorkAfterReleaseInput,
18181819
providers: [
18191820
{

‎apps/server/src/orchestration-v2/testkit/fixtures/stop_background_work_after_failed_turn/input.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export function stopBackgroundWorkAfterFailedTurnInput(): OrchestratorFixtureInp
77
return {
88
steps: [
99
{ type: "message", text: STOP_BACKGROUND_WORK_AFTER_FAILED_TURN_PROMPT },
10-
{ type: "stop_background_work", targetRunIndex: 1 },
10+
{ type: "capture_shell_snapshot", key: "after-exit" },
1111
],
1212
};
1313
}
@@ -17,7 +17,7 @@ export function stopBackgroundWorkAfterReleaseInput(): OrchestratorFixtureInput
1717
steps: [
1818
{ type: "message", text: STOP_BACKGROUND_WORK_AFTER_FAILED_TURN_PROMPT },
1919
{ type: "advance_clock", duration: "31 minutes" },
20-
{ type: "stop_background_work", targetRunIndex: 1 },
20+
{ type: "capture_shell_snapshot", key: "after-exit" },
2121
],
2222
};
2323
}

‎apps/server/src/orchestration-v2/testkit/fixtures/stop_background_work_after_failed_turn/output.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,22 @@ export function assertStopBackgroundWorkAfterFailedTurnOutput(
1919
assertSemanticProjectionIntegrity(projection);
2020
assertUserMessagesInclude(projection, [STOP_BACKGROUND_WORK_AFTER_FAILED_TURN_PROMPT]);
2121

22-
const before = result.capturedShellSnapshots
23-
.get("before-stop")
22+
const afterExit = result.capturedShellSnapshots
23+
.get("after-exit")
2424
?.threads.find((thread) => thread.id === projection.thread.id);
2525
assert.deepEqual(
26-
before?.pendingBackgroundTasks?.map((task) => task.kind),
27-
["command"],
28-
"the failed turn leaves its command on the Waiting strip",
26+
afterExit?.pendingBackgroundTasks,
27+
[],
28+
"provider exit settles the failed turn's background command",
2929
);
3030

3131
const command = projection.turnItems.find((item) => item.type === "command_execution");
32-
assert.equal(command?.status, "interrupted");
32+
assert.isDefined(command);
33+
assert.equal(command?.status, "failed");
3334
assert.isNotNull(command?.completedAt);
3435
const shell = result.shellSnapshot.threads.find((thread) => thread.id === projection.thread.id);
3536
assert.deepEqual(shell?.pendingBackgroundTasks ?? [], []);
36-
assert.include(
37+
assert.notInclude(
3738
projection.turnItems.map((item) => item.type),
3839
"run_interrupt_request",
3940
);

0 commit comments

Comments
 (0)