From a6216cf3dc869c140ef92e09d5a929ff0247ea71 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 4 Aug 2026 16:20:30 +0200 Subject: [PATCH] fix(test): keep codex replay recovery off the repo checkout The codex resume test was the only replay scenario without a runtimePolicyOverride, so its checkpoint scope cwd fell back to process.cwd() and baseline capture ran real git over the entire checkout. Locally the capture short-circuits on checkpoint refs left behind by earlier runs; on a fresh CI checkout it is a cold multi-second capture that outlives the scenario wait budget, failing await_thread_idle while the run is still mid-checkpoint. Point the fixture's turn/start frames at the placeholder and checkpoint a throwaway git workspace like every other replay test. Scenario waits are also wall-clock-bounded now: the iteration budget counts event-loop turns, which burn at full speed while git/fixture IO is in flight, so exhaustion additionally requires a 60s real-time deadline to pass. Co-Authored-By: Claude Fable 5 --- ...estratorReplayRecovery.integration.test.ts | 18 ++++++-- .../testkit/OrchestratorScenario.ts | 45 ++++++++++++++----- .../codex_transcript.ndjson | 4 +- 3 files changed, 51 insertions(+), 16 deletions(-) diff --git a/apps/server/src/orchestration-v2/testkit/OrchestratorReplayRecovery.integration.test.ts b/apps/server/src/orchestration-v2/testkit/OrchestratorReplayRecovery.integration.test.ts index ad7cbc662f..f5c4feea07 100644 --- a/apps/server/src/orchestration-v2/testkit/OrchestratorReplayRecovery.integration.test.ts +++ b/apps/server/src/orchestration-v2/testkit/OrchestratorReplayRecovery.integration.test.ts @@ -40,7 +40,11 @@ import { projectionFor, } from "./fixtures/shared.ts"; import { runOrchestratorV2ProviderReplayScenario } from "./ProviderReplayHarness.ts"; -import { decodeProviderReplayNdjson } from "./ReplayTranscriptNdjson.ts"; +import { checkpointWorkspace } from "./ReplayFixtureWorkspace.ts"; +import { + decodeProviderReplayNdjson, + materializeReplayTranscriptWorkspace, +} from "./ReplayTranscriptNdjson.ts"; const FIRST_FINAL = "provider thread resume fixture first turn complete"; const SECOND_FINAL = "provider thread resume fixture second turn complete"; @@ -53,11 +57,11 @@ const readRawTranscript = Effect.fn("readRecoveryTranscript")(function* (file: U const text = yield* fs.readFileString(decodeURIComponent(file.pathname)); return yield* decodeProviderReplayNdjson(text); }); -const readCodexTranscript = Effect.fn("readCodexRecoveryTranscript")(function* () { +const readCodexTranscript = Effect.fn("readCodexRecoveryTranscript")(function* (workspace: string) { const transcript = yield* readRawTranscript( new URL("./fixtures/provider_thread_resume/codex_transcript.ndjson", import.meta.url), ); - return yield* decodeCodexTranscript(transcript); + return yield* decodeCodexTranscript(materializeReplayTranscriptWorkspace(transcript, workspace)); }); const readCursorTranscript = Effect.fn("readCursorRecoveryTranscript")(function* () { const transcript = yield* readRawTranscript( @@ -177,7 +181,11 @@ describe("orchestrator replay recovery", () => { () => Effect.scoped( Effect.gen(function* () { - const transcript = yield* readCodexTranscript(); + // Checkpoint against a throwaway git workspace: with no override the + // scope cwd falls back to process.cwd(), and a cold full-repo + // baseline capture on CI outlives the scenario wait budget. + const workspace = yield* checkpointWorkspace("provider_thread_resume"); + const transcript = yield* readCodexTranscript(workspace); const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; const tempDir = yield* Effect.acquireRelease( @@ -222,6 +230,7 @@ describe("orchestrator replay recovery", () => { commands: phase1Commands, steps: phase1Steps, projectionThreadIds: materialized.projectionThreadIds, + runtimePolicyOverride: { cwd: workspace }, }, harness, options, @@ -234,6 +243,7 @@ describe("orchestrator replay recovery", () => { commands: phase2Commands, steps: phase2Steps, projectionThreadIds: materialized.projectionThreadIds, + runtimePolicyOverride: { cwd: workspace }, }, harness, options, diff --git a/apps/server/src/orchestration-v2/testkit/OrchestratorScenario.ts b/apps/server/src/orchestration-v2/testkit/OrchestratorScenario.ts index 5c574d86da..f1d6334391 100644 --- a/apps/server/src/orchestration-v2/testkit/OrchestratorScenario.ts +++ b/apps/server/src/orchestration-v2/testkit/OrchestratorScenario.ts @@ -164,6 +164,14 @@ const hasActiveRun = (projection: OrchestrationV2ThreadProjection) => ); const SCENARIO_WAIT_ATTEMPTS = 10_000; +// Iterations count event-loop turns, not time: while async work (git +// subprocesses, fixture IO) is in flight the loop is idle and the counter +// burns at full speed on slow runners. A wait is exhausted only once BOTH +// the iteration budget and this wall-clock deadline are spent. +const SCENARIO_WAIT_DEADLINE_MS = 60_000; +const scenarioWaitDeadline = () => performance.now() + SCENARIO_WAIT_DEADLINE_MS; +const scenarioWaitExhausted = (attemptsRemaining: number, deadlineAt: number) => + attemptsRemaining <= 0 && performance.now() >= deadlineAt; const yieldToRuntime = Effect.yieldNow.pipe( Effect.andThen( @@ -231,6 +239,7 @@ export function runOrchestratorV2Scenario( const waitForPendingRuntimeRequest = ( threadId: ThreadId, attemptsRemaining = SCENARIO_WAIT_ATTEMPTS, + deadlineAt = scenarioWaitDeadline(), ): Effect.Effect< OrchestrationV2RuntimeRequest, OrchestratorV2Error | OrchestratorV2ScenarioStepError, @@ -242,7 +251,7 @@ export function runOrchestratorV2Scenario( if (request !== undefined) { return request; } - if (attemptsRemaining <= 0) { + if (scenarioWaitExhausted(attemptsRemaining, deadlineAt)) { const runState = projection.runs.map((run) => `${run.id}:${run.status}`).join(","); return yield* new OrchestratorV2ScenarioStepError({ scenario: scenario.name, @@ -250,19 +259,20 @@ export function runOrchestratorV2Scenario( }); } yield* yieldToRuntime; - return yield* waitForPendingRuntimeRequest(threadId, attemptsRemaining - 1); + return yield* waitForPendingRuntimeRequest(threadId, attemptsRemaining - 1, deadlineAt); }); const waitForThreadIdle = ( threadId: ThreadId, attemptsRemaining = SCENARIO_WAIT_ATTEMPTS, + deadlineAt = scenarioWaitDeadline(), ): Effect.Effect => Effect.gen(function* () { const projection = yield* orchestrator.getThreadProjection(threadId); if (!hasActiveRun(projection)) { return; } - if (attemptsRemaining <= 0) { + if (scenarioWaitExhausted(attemptsRemaining, deadlineAt)) { const activeRuns = projection.runs .filter((run) => ["preparing", "queued", "starting", "running", "waiting"].includes(run.status), @@ -279,13 +289,14 @@ export function runOrchestratorV2Scenario( }); } yield* yieldToRuntime; - return yield* waitForThreadIdle(threadId, attemptsRemaining - 1); + return yield* waitForThreadIdle(threadId, attemptsRemaining - 1, deadlineAt); }); const waitForRunSteerable = ( threadId: ThreadId, runId: OrchestrationV2Run["id"], attemptsRemaining = SCENARIO_WAIT_ATTEMPTS, + deadlineAt = scenarioWaitDeadline(), ): Effect.Effect => Effect.gen(function* () { const projection = yield* orchestrator.getThreadProjection(threadId); @@ -299,14 +310,14 @@ export function runOrchestratorV2Scenario( if (run?.status === "running" && providerTurn !== undefined) { return; } - if (attemptsRemaining <= 0) { + if (scenarioWaitExhausted(attemptsRemaining, deadlineAt)) { return yield* new OrchestratorV2ScenarioStepError({ scenario: scenario.name, step: `await_run_steerable:${runId}`, }); } yield* yieldToRuntime; - return yield* waitForRunSteerable(threadId, runId, attemptsRemaining - 1); + return yield* waitForRunSteerable(threadId, runId, attemptsRemaining - 1, deadlineAt); }); const waitForRunStatus = ( @@ -314,6 +325,7 @@ export function runOrchestratorV2Scenario( runId: OrchestrationV2Run["id"], status: OrchestrationV2Run["status"], attemptsRemaining = SCENARIO_WAIT_ATTEMPTS, + deadlineAt = scenarioWaitDeadline(), ): Effect.Effect => Effect.gen(function* () { const projection = yield* orchestrator.getThreadProjection(threadId); @@ -321,14 +333,20 @@ export function runOrchestratorV2Scenario( if (run?.status === status) { return; } - if (attemptsRemaining <= 0) { + if (scenarioWaitExhausted(attemptsRemaining, deadlineAt)) { return yield* new OrchestratorV2ScenarioStepError({ scenario: scenario.name, step: `await_run_status:${runId}:${status}:actual=${run?.status ?? "missing"}`, }); } yield* yieldToRuntime; - return yield* waitForRunStatus(threadId, runId, status, attemptsRemaining - 1); + return yield* waitForRunStatus( + threadId, + runId, + status, + attemptsRemaining - 1, + deadlineAt, + ); }); const waitForRunTurnItem = ( @@ -336,6 +354,7 @@ export function runOrchestratorV2Scenario( runId: OrchestrationV2Run["id"], itemType: OrchestrationV2TurnItem["type"], attemptsRemaining = SCENARIO_WAIT_ATTEMPTS, + deadlineAt = scenarioWaitDeadline(), ): Effect.Effect => Effect.gen(function* () { const projection = yield* orchestrator.getThreadProjection(threadId); @@ -345,14 +364,20 @@ export function runOrchestratorV2Scenario( if (hasTurnItem) { return; } - if (attemptsRemaining <= 0) { + if (scenarioWaitExhausted(attemptsRemaining, deadlineAt)) { return yield* new OrchestratorV2ScenarioStepError({ scenario: scenario.name, step: `await_run_turn_item:${runId}:${itemType}`, }); } yield* yieldToRuntime; - return yield* waitForRunTurnItem(threadId, runId, itemType, attemptsRemaining - 1); + return yield* waitForRunTurnItem( + threadId, + runId, + itemType, + attemptsRemaining - 1, + deadlineAt, + ); }); for (const step of scenarioSteps(scenario)) { diff --git a/apps/server/src/orchestration-v2/testkit/fixtures/provider_thread_resume/codex_transcript.ndjson b/apps/server/src/orchestration-v2/testkit/fixtures/provider_thread_resume/codex_transcript.ndjson index 81a3625140..dd86c03706 100644 --- a/apps/server/src/orchestration-v2/testkit/fixtures/provider_thread_resume/codex_transcript.ndjson +++ b/apps/server/src/orchestration-v2/testkit/fixtures/provider_thread_resume/codex_transcript.ndjson @@ -4,7 +4,7 @@ {"type":"expect_outbound","label":"initialized","frame":{"method":"initialized"}} {"type":"expect_outbound","label":"thread/start","frame":{"id":2,"method":"thread/start","params":{}}} {"type":"emit_inbound","label":"thread/start","frame":{"id":2,"result":{"thread":{"id":"019db117-b50d-7a01-a6b6-65e47d749c3e","forkedFromId":null,"preview":"","ephemeral":false,"modelProvider":"openai","createdAt":1776792614,"updatedAt":1776792614,"status":{"type":"idle"},"path":"/Users/julius/.codex/sessions/2026/04/21/rollout-2026-04-21T10-30-14-019db117-b50d-7a01-a6b6-65e47d749c3e.jsonl","cwd":"/Users/julius/.t3/worktrees/codething-mvp/t3code-c1e5e1d1","cliVersion":"0.120.0","source":"vscode","agentNickname":null,"agentRole":null,"gitInfo":null,"name":null,"turns":[]},"model":"gpt-5.3-codex","modelProvider":"openai","serviceTier":"fast","cwd":"/Users/julius/.t3/worktrees/codething-mvp/t3code-c1e5e1d1","approvalPolicy":"on-request","approvalsReviewer":"user","sandbox":{"type":"workspaceWrite","writableRoots":["/Users/julius/.codex/memories"],"readOnlyAccess":{"type":"fullAccess"},"networkAccess":false,"excludeTmpdirEnvVar":false,"excludeSlashTmp":false},"reasoningEffort":"xhigh"}}} -{"type":"expect_outbound","label":"turn/start","frame":{"id":3,"method":"turn/start","params":{"approvalPolicy":"never","cwd":null,"input":[{"text":"Respond with exactly: provider thread resume fixture first turn complete","type":"text"}],"model":"gpt-5.4","sandboxPolicy":{"type":"dangerFullAccess"},"threadId":"019db117-b50d-7a01-a6b6-65e47d749c3e","approvalsReviewer":"user"}}} +{"type":"expect_outbound","label":"turn/start","frame":{"id":3,"method":"turn/start","params":{"approvalPolicy":"never","cwd":"","input":[{"text":"Respond with exactly: provider thread resume fixture first turn complete","type":"text"}],"model":"gpt-5.4","sandboxPolicy":{"type":"dangerFullAccess"},"threadId":"019db117-b50d-7a01-a6b6-65e47d749c3e","approvalsReviewer":"user"}}} {"type":"emit_inbound","label":"thread/started","frame":{"method":"thread/started","params":{"thread":{"id":"019db117-b50d-7a01-a6b6-65e47d749c3e","forkedFromId":null,"preview":"","ephemeral":false,"modelProvider":"openai","createdAt":1776792614,"updatedAt":1776792614,"status":{"type":"idle"},"path":"/Users/julius/.codex/sessions/2026/04/21/rollout-2026-04-21T10-30-14-019db117-b50d-7a01-a6b6-65e47d749c3e.jsonl","cwd":"/Users/julius/.t3/worktrees/codething-mvp/t3code-c1e5e1d1","cliVersion":"0.120.0","source":"vscode","agentNickname":null,"agentRole":null,"gitInfo":null,"name":null,"turns":[]}}}} {"type":"emit_inbound","label":"deprecationNotice","frame":{"method":"deprecationNotice","params":{"summary":"`[features].collab` is deprecated. Use `[features].multi_agent` instead.","details":"Enable it with `--enable multi_agent` or `[features].multi_agent` in config.toml. See https://developers.openai.com/codex/config-basic#feature-flags for details."}}} {"type":"emit_inbound","label":"mcpServer/startupStatus/updated","frame":{"method":"mcpServer/startupStatus/updated","params":{"name":"uidotsh","status":"starting","error":null}}} @@ -42,7 +42,7 @@ {"type":"emit_inbound","label":"mcpServer/startupStatus/updated","frame":{"method":"mcpServer/startupStatus/updated","params":{"name":"codex_apps","status":"starting","error":null}}} {"type":"emit_inbound","label":"thread/status/changed","frame":{"method":"thread/status/changed","params":{"threadId":"019db117-b50d-7a01-a6b6-65e47d749c3e","status":{"type":"idle"}}}} {"type":"emit_inbound","label":"thread/resume","frame":{"id":2,"result":{"thread":{"id":"019db117-b50d-7a01-a6b6-65e47d749c3e","forkedFromId":null,"preview":"Respond with exactly: provider thread resume fixture first turn complete","ephemeral":false,"modelProvider":"openai","createdAt":1776792614,"updatedAt":1776792622,"status":{"type":"idle"},"path":"/Users/julius/.codex/sessions/2026/04/21/rollout-2026-04-21T10-30-14-019db117-b50d-7a01-a6b6-65e47d749c3e.jsonl","cwd":"/Users/julius/.t3/worktrees/codething-mvp/t3code-c1e5e1d1","cliVersion":"0.120.0","source":"vscode","agentNickname":null,"agentRole":null,"gitInfo":{"sha":"7eefb2eb1d98f6b814c9fd7f43652727059c3326","branch":"t3code/codex-turn-mapping","originUrl":"git@github.com:pingdotgg/t3code.git"},"name":null,"turns":[{"id":"019db117-b519-7fa3-85c8-7762b26478a7","items":[{"type":"userMessage","id":"item-1","content":[{"type":"text","text":"Respond with exactly: provider thread resume fixture first turn complete","text_elements":[]}]},{"type":"agentMessage","id":"item-2","text":"provider thread resume fixture first turn complete","phase":"final_answer","memoryCitation":null}],"status":"completed","error":null,"startedAt":1776792614,"completedAt":1776792622,"durationMs":8794}]},"model":"gpt-5.3-codex","modelProvider":"openai","serviceTier":"fast","cwd":"/Users/julius/.t3/worktrees/codething-mvp/t3code-c1e5e1d1","approvalPolicy":"on-request","approvalsReviewer":"user","sandbox":{"type":"workspaceWrite","writableRoots":["/Users/julius/.codex/memories"],"readOnlyAccess":{"type":"fullAccess"},"networkAccess":false,"excludeTmpdirEnvVar":false,"excludeSlashTmp":false},"reasoningEffort":"xhigh"}}} -{"type":"expect_outbound","label":"turn/start","frame":{"id":3,"method":"turn/start","params":{"approvalPolicy":"never","cwd":null,"input":[{"text":"Using the conversation history available in this resumed thread, first repeat the exact final answer you gave in the previous turn. Then on a new line write exactly: provider thread resume fixture second turn complete","type":"text"}],"model":"gpt-5.4","sandboxPolicy":{"type":"dangerFullAccess"},"threadId":"019db117-b50d-7a01-a6b6-65e47d749c3e","approvalsReviewer":"user"}}} +{"type":"expect_outbound","label":"turn/start","frame":{"id":3,"method":"turn/start","params":{"approvalPolicy":"never","cwd":"","input":[{"text":"Using the conversation history available in this resumed thread, first repeat the exact final answer you gave in the previous turn. Then on a new line write exactly: provider thread resume fixture second turn complete","type":"text"}],"model":"gpt-5.4","sandboxPolicy":{"type":"dangerFullAccess"},"threadId":"019db117-b50d-7a01-a6b6-65e47d749c3e","approvalsReviewer":"user"}}} {"type":"emit_inbound","label":"turn/start","frame":{"id":3,"result":{"turn":{"id":"019db117-d7ac-7462-90cf-8e244a290f78","items":[],"status":"inProgress","error":null,"startedAt":null,"completedAt":null,"durationMs":null}}}} {"type":"emit_inbound","label":"thread/status/changed","frame":{"method":"thread/status/changed","params":{"threadId":"019db117-b50d-7a01-a6b6-65e47d749c3e","status":{"type":"active","activeFlags":[]}}}} {"type":"emit_inbound","label":"turn/started","frame":{"method":"turn/started","params":{"threadId":"019db117-b50d-7a01-a6b6-65e47d749c3e","turn":{"id":"019db117-d7ac-7462-90cf-8e244a290f78","items":[],"status":"inProgress","error":null,"startedAt":1776792623,"completedAt":null,"durationMs":null}}}}