Skip to content

Fix Codex command output loss and rename race - #1400

Merged
ymichael merged 2 commits into
mainfrom
bb/split-codex-runtime-correctness-fixes-into-pr-thr_zm5ci3rpua
Aug 12, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/split-codex-runtime-correctness-fixes-into-pr-thr_zm5ci3rpua

Conversation

@ymichael

@ymichael ymichael commented Aug 12, 2026 •

Copy link
Copy Markdown
Collaborator

Two Codex runtime reliability fixes, split out of #1385 so they can be reviewed on their own.

Bug 1: command output lost when Codex reorders events

Codex app-server normally reports a shell command as function_call → function_call_output (the full stdout) → item/completed. Sometimes the item/completed event arrives before the raw record carrying the output.

The adapter only repaired a completed item using output it had already captured. In the reordered case there was nothing captured yet, so it published the provider's truncated aggregatedOutput and the real output — which arrived a moment later — was dropped. Users saw a finished command with missing or partial output.

Fix: when a completed command item arrives while its shell call is still awaiting raw output, hold it instead of publishing it. Repair and emit it as soon as the raw record lands. If the raw record never arrives, flush the held item at turn completion, so output is at worst delayed rather than lost. Unparseable raw output clears the pending shell call so the completed item is released unchanged.

Bug 2: generated-title rename fails on a brand-new session

A new Codex rollout file can exist briefly before its first record is written. A generated-title rename landing in that window fails with rollout at <path> is empty, and the thread keeps its placeholder title even though the same call would succeed moments later.

Fix: retry only that exact transient error, and only for Codex, backing off 50 ms then 200 ms before a final attempt. Every other rename failure, and every other provider, still fails immediately.

The backoff is only ever paid when the rename has already failed — the happy path returns on the first attempt — and the full 250 ms only when it fails for good, where the alternative was failing instantly and leaving the thread on a placeholder title.

Protocol version

Bug 1 changes what the host daemon sends the server, so HOST_DAEMON_PROTOCOL_VERSION goes 109 → 110 with its contract test and comment updated. Older daemons can publish a truncated completed item, so enrolled machines must update.

Note for reviewers: #1408 bumped the constant to 109 and updated the assertion, but left the test name and comment describing 108. Rebasing onto it meant rewriting those exact lines, so this PR lands a correct 110 lineage and clears that stale wording as a side effect.

These are product reliability changes only — no database schema, migration, or Drizzle snapshot changes, and no other behavior from #1385.

Validation

  • turbo run typecheck --filter=@bb/agent-runtime --filter=@bb/host-daemon-contract — pass
  • turbo run typecheck --filter=@bb/host-daemon --filter=@bb/server (downstream protocol consumers) — pass
  • turbo run test --filter=@bb/host-daemon-contract — 49/49 pass
  • Rebased onto 3bd8e79a0 and fully re-validated
  • turbo run test --filter=@bb/agent-runtime — 921 pass, 0 failures
  • Prettier clean on all changed files

Three regression tests were each verified to fail against current main and pass with the fix:

  • adapter: repairs a completed item when the raw output arrives late
  • adapter: flushes the held item at turn end when raw output never arrives
  • runtime: retries the rename through one empty-rollout error and applies the title

A fourth test pins the exhaustion path: a rollout that stays empty makes exactly 3 attempts and then propagates the error, so the retry can neither loop nor swallow a genuine failure.

Previously-noted test failure is resolved upstream

Earlier revisions of this description flagged runtime.process-lifecycle.test.ts > bounds provider stderr while data arrives without a newline as failing locally on macOS. #1402 landed that fix on main (the fixture used process.exit(), which discards Node's async-buffered pipe output on macOS). After rebasing onto it, the full suite is green: 921/921 with zero failures.

AGENT GENERATED: by Claude Opus 5

@ymichael
ymichael force-pushed the bb/split-codex-runtime-correctness-fixes-into-pr-thr_zm5ci3rpua branch from 35f3092 to b258007 Compare August 12, 2026 21:36
ymichael and others added 2 commits August 12, 2026 15:18
Codex app-server can deliver a command's `item/completed` event before the
matching `rawResponseItem/completed` record that carries the full stdout. The
adapter repaired completed items only from output it had already captured, so
the reordered case published the provider's truncated `aggregatedOutput` and
the real output arrived too late to be used.

Hold a completed command item whose shell call is still awaiting its raw
output, repair it once the raw record lands, and emit it then. If the raw
record never arrives, flush the held item at turn completion so output is
delayed rather than lost. Unparseable raw output clears the pending shell call
so the completed item is released unchanged.

This changes what the host daemon sends the server, so it bumps
HOST_DAEMON_PROTOCOL_VERSION to 109.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A newly started Codex session can have its rollout file created before the
first record is written to it. A generated-title rename that lands in that
window fails with "rollout at <path> is empty", and the thread keeps its
placeholder title even though a retry moments later would succeed.

Retry only that exact transient error, and only for Codex, backing off 50ms
then 200ms before a final attempt. Every other rename failure, and every
other provider, still fails immediately. The backoff is only ever paid when
the rename has already failed, and the full 250ms only when it fails for
good.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@ymichael
ymichael force-pushed the bb/split-codex-runtime-correctness-fixes-into-pr-thr_zm5ci3rpua branch from b258007 to 6a0c042 Compare August 12, 2026 22:18
@ymichael
ymichael merged commit 8e7cc5d into main Aug 12, 2026
10 checks passed
@ymichael
ymichael deleted the bb/split-codex-runtime-correctness-fixes-into-pr-thr_zm5ci3rpua branch August 12, 2026 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant