Skip to content

fix(agent): pair the Codex WS delta boundary with a fresh response id (#194) - #213

Open
justrach wants to merge 1 commit into
mainfrom
fix/194-codex-ws-delta-boundary
Open

fix(agent): pair the Codex WS delta boundary with a fresh response id (#194)#213
justrach wants to merge 1 commit into
mainfrom
fix/194-codex-ws-delta-boundary

Conversation

@justrach

Copy link
Copy Markdown
Owner

Problem

stepResponses() advances the Codex WS delta boundary (codex_sent_upto) whenever a WS session is live, but only replaces codex_prev_id when the parsed response contains a new response.id. parseResponses() accepts output items without a terminal response id, so a response can lack one — leaving the old id paired with an advanced boundary.

buildBody() then sends previous_response_id: <old id> + messages[codex_sent_upto..], slicing off history the referenced response never held.

Fix

Move the id and the boundary in lockstep (agent_steps.zig):

  • New valid id → install it and advance codex_sent_upto together.
  • No usable id (or a failed dup) → reset both to null / 0 so the next request re-anchors with the full input (buildBody's prev_id == null path), instead of replaying a stale delta.

No WS teardown is needed — resetting the watermarks is enough; the next request sends the full input over the live session, exactly like the first request of any WS session.

Test

A unit test drives a codex-WS agent through stepResponses():

  • id-less responsecodex_prev_id is dropped and the boundary resets to 0 (full re-anchor).
  • id-bearing response → the id installs and the boundary advances in lockstep.

Leak-checked (testing allocator). zig build test green, zig fmt clean, and scripts/test-pty-codex-ws.py (WS-fail → SSE fallback, WS-off) still passes.

Closes #194

…#194)

stepResponses advanced codex_sent_upto (the delta boundary) whenever the WS was
live but only replaced codex_prev_id when the response carried a new response.id.
parseResponses accepts output items without a terminal id, so a response can lack
one — leaving the OLD id paired with an advanced boundary. buildBody then sends
previous_response_id + messages[codex_sent_upto..], slicing off history the
referenced response never held.

Move the two in lockstep: install the new id and advance the boundary together;
with no usable id (or a failed dup) reset both to null/0 so the next request
re-anchors with the full input (buildBody's prev_id==null path) instead of
replaying a stale delta against a response that never saw it.

Test: stepResponses drives a codex-WS agent with (a) an id-less response — asserts
prev_id is dropped and the boundary resets to 0 (full re-anchor); (b) an
id-bearing response — asserts the id installs and the boundary advances in
lockstep. Leak-checked.

Refs #194

Co-Authored-By: blackfloofie <265516171+blackfloofie@users.noreply.github.com>
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.

Codex WS can pair a stale response ID with an advanced delta boundary

1 participant