Skip to content

fix(responses): remap round-2 message lifecycle so codex stops dropping text deltas - #215

Merged
ranxianglei merged 1 commit into
masterfrom
2026-08-24_responses-round2-lifecycle
Aug 24, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-08-24_responses-round2-lifecycle

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Problem (issue #212)

After a compression, codex logs a flood of ERROR codex_core::util: OutputTextDelta without active item and the turn aborts.

Root cause

Codex uses the Responses API in wire (function-calling) mode. When the proxy executes a compress/acp_status tool it re-requests upstream (round 2+). In round ≥ 2 the responses adapter suppresses response.output_item.added / response.content_part.added for message items (firstRoundOnly: true) but still forwards raw response.output_text.delta events carrying the new upstream item_ids (core.ts forwards ev.raw unconditionally in wire mode). Codex never saw the output_item.added for those ids → every delta is dropped with the error above.

Introduced in v0.1.37 by 4deb563 (anthropic round-2 framing fix removed the round === 1 guard on raw forwarding; the anthropic adapter got matching lifecycle forwarding, the responses adapter did not). Affected: v0.1.37 – v0.1.47 (latest). v0.1.36 is fine.

Fix

Mirror the anthropic adapter's approach for round ≥ 2 in wire mode:

  • output_item.added (message) in round ≥ 2 is forwarded with a remapped proxy id and client-side output_index, and the full lifecycle (content_part.added, output_text.delta, output_text.done, content_part.done, output_item.done) is rewritten to the same id/index — real-time streaming preserved, SSE sequence coherent.
  • Round ≥ 2 deltas for items with no forwarded added no longer forward raw; they fall back to the synthesized emitText lifecycle (protocol-safe).
  • Round 1 and textProtocol paths unchanged.

Test

New regression test tests/responses-round2-lifecycle.test.ts (fails on master: orphan deltas: ["msg_2","msg_2"], passes with the fix): asserts every forwarded output_text.delta.item_id was introduced by a forwarded output_item.added, the round-2 item streams natively with remapped id, content order is preserved, and the item is closed with output_item.done.

Full suite: 532/532 pass, typecheck + build clean.

@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-08-24_responses-round2-lifecycle (55833a1)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-215

Each push to this PR publishes a new version under the pr-215 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr215.tgz
npm install -g package

This comment is automatically updated on each push.

@ranxianglei
ranxianglei merged commit 994190b into master Aug 24, 2026
6 checks passed
@ranxianglei ranxianglei mentioned this pull request Aug 24, 2026
@ranxianglei
ranxianglei deleted the 2026-08-24_responses-round2-lifecycle branch October 15, 2026 05:32
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