Repository navigation
Description
Summary
When Codex answers turn/start before emitting turn/started, the bridge fabricates a completed zero-work turn after 250 ms. If the real notification arrives later, BB records both turns and can tell a parent that its child completed with no output while the child is still working.
BB should correlate the accepted input with the real turn and emit exactly one lifecycle.
Versions and environment
- Reproduced on upstream
mainatec8f4ef04105c2cb5a59f7a9a9328bf2b16b39ce - Codex CLI
0.149.1 - Hermetic reproduction: Linux 6.8 x86_64, Node 24.19.0
- Also observed in production on a private bb deployment whose source matches upstream
31d66d9d45bc8ff1483d5e4c6401c434b610dc4bfor the files involved (details under Evidence)
Steps to reproduce
-
In
plugins/provider-codex/src/bridge/fake-codex-app-server.mjs, changeLATE_TURN_START_DELAY_MSfrom60to350. -
Run:
pnpm exec turbo run test --filter=bb-plugin-provider-codex -- --testNamePattern='lets a turn/started that lands after the turn/start response win the race'
-
Observe that the existing exactly-once assertion fails because the bridge emits two starts.
The same test passes with the fixture's 60 ms delay. The failure starts once the delayed notification crosses the bridge's 250 ms grace period.
Expected vs actual
Expected: one real turn/started and one real turn/completed
Actual: expected [ Array(2) ] to have a length of 1 but got 2
The first lifecycle is a synthetic zero-work completion. The second is Codex's real turn.
Evidence
- Reproduction base:
ec8f4ef04105c2cb5a59f7a9a9328bf2b16b39ce(upstreammain) - The timer and fabricated lifecycle:
bb/plugins/provider-codex/src/bridge/bridge.ts
Lines 1295 to 1326 in ec8f4ef
const ZERO_WORK_SETTLEMENT_GRACE_MS = 250; let syntheticZeroWorkTurnCounter = 0; function scheduleZeroWorkTurnSettlement(args: { clientRequestId: TurnStartParamsShape["clientRequestId"]; prepared: PreparedProviderCommandDispatch | null; session: CodexBridgeSession; }): void { const { clientRequestId, prepared, session } = args; if (prepared === null) { return; } const serial = session.serial; const timer = setTimeout(() => { const live = currentSession(session.bbThreadId, serial); if (!live || live.openCodexTurnIds.size > 0) { return; } if (!prepared.claim()) { return; } syntheticZeroWorkTurnCounter += 1; const providerTurnId = `zero-work-${syntheticZeroWorkTurnCounter}`; sendThreadDeltas(live, [ { kind: "turn.open", providerTurnId }, { kind: "input.accepted", clientRequestId, providerTurnId }, { kind: "turn.boundary", providerTurnId, status: "completed" }, ]); }, ZERO_WORK_SETTLEMENT_GRACE_MS); timer.unref?.(); } - The existing delayed-start fixture:
bb/plugins/provider-codex/src/bridge/fake-codex-app-server.mjs
Lines 60 to 68 in ec8f4ef
/** * A prompt answered BEFORE any turn notification, whose real turn then arrives * late. Codex normally emits `turn/started` ahead of its `turn/start` * response; this inverts that order so the bridge's zero-work settlement has * to lose the race to the real turn (fabricating a turn from a late signal is * the ACP bug 0c2f4cc9a). */ const LATE_TURN_START_PROMPT_TEXT = "/late-start"; const LATE_TURN_START_DELAY_MS = 60; - The exactly-once test:
bb/plugins/provider-codex/src/bridge/bridge.zero-work-turn.test.ts
Lines 161 to 191 in ec8f4ef
it("lets a turn/started that lands after the turn/start response win the race", async () => { const providerThreadId = await startSession(); harness.sendRequest(2, "turn/start", { threadId: THREAD_ID, providerThreadId, input: [{ type: "text", text: "/late-start", mentions: [] }], clientRequestId: "creq_atestart23", options: { ...sessionOptions }, }); await harness.waitForResponse(2); const events = await waitForEvents((all) => all.some((event) => event.type === "turn/completed"), ); await new Promise((resolve) => setTimeout(resolve, 500)); const settledEvents = threadEvents(); expect( settledEvents.filter((event) => event.type === "turn/started"), ).toHaveLength(1); expect( settledEvents.filter((event) => event.type === "turn/completed"), ).toHaveLength(1); expect( settledEvents.some((event) => event.type === "item/agentMessage/delta"), ).toBe(true); expect( settledEvents.filter((event) => event.type === "turn/input/accepted"), ).toHaveLength(1); expect(events.length).toBeGreaterThan(0); }, 30_000);
Production observation, from Codex child threads on a private bb deployment (source matching upstream 31d66d9d4 for these files; the affected thread ids live on that instance and are not resolvable here): the synthetic completion appeared 259 to 362 ms after thread identity, the real turn started 351 ms to 2.743 seconds later, and only the synthetic turn received the original clientRequestId, which rules out duplicate sends.
What you ruled out
- Not a duplicate user send: each affected child has one
client/turn/requested. - Not event replay: the synthetic and real lifecycles have distinct turn ids, and only the synthetic turn owns the request correlation.
- Not issue Codex thread shows
idle(no spinner) while actively running commands #1646: that report concerns work continuing after a genuine completed turn; this bug creates a separate synthetic completion before the genuine turn starts. - Not cross-provider behavior: the fixed 250 ms zero-work timer is in
provider-codex.
Suggested priority and effort
High impact, small-to-medium fix. A parent can start duplicate work in the same workspace based on the false completion, with no reliable user workaround.
AGENT GENERATED
Activity
SawyerHood commentedon Sep 9, 2026
Consolidating #2634 into this issue as the canonical tracker for the delayed Codex turn-start race.
Additional impact from #2634: a follow-up request can be accepted and completed in synthetic turn A, while its actual reasoning and tool calls appear in turn B without
turn/input/accepted. Consumers that bind tool effects to the accepted request must reject that work. The report describes recurrence on multiple fresh threads, after an ordinary first turn.The investigation on #2634 identifies the same 250 ms timer and points to this issue and PR #2639. Preserve the request-to-tool attribution case in validation: the real work must belong to the accepted request's turn, with no synthetic empty completion stealing the correlation.
This is consolidation of existing reports, not a new reproduction or a claim that the fix has shipped.
Correlate codex turn dispatches with the turn the turn/start response…
Correlate codex turn dispatches with the turn the turn/start response…
Reconcile daemon turns the server lost track of on explicit stop
Correlate codex turn dispatches with the turn the turn/start response…
Correlate codex turn dispatches with the turn the turn/start response…
Correlate codex turn dispatches with the turn the turn/start response…
Wait for a compaction's real turn instead of guessing with a timer
Correlate codex turn dispatches with the turn the turn/start response…
Wait for a compaction's real turn instead of guessing with a timer
Reconcile daemon turns the server lost track of on explicit stop
Correlate codex turn dispatches with the turn the turn/start response…
Wait for a compaction's real turn instead of guessing with a timer
Correlate Codex turn dispatches with the turn the turn/start response…