Skip to content

fix(proxy): trim Codex websocket full-replay continuations - #555

Closed
Komzpa wants to merge 11 commits into
Soju06:mainfrom
Komzpa:fix/websocket-codex-full-replay-trim
Closed

Komzpa wants to merge 11 commits into
Soju06:mainfrom
Komzpa:fix/websocket-codex-full-replay-trim

Conversation

@Komzpa

@Komzpa Komzpa commented May 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Validation

  • uv run ruff check app/modules/proxy/service.py app/core/clients/proxy_websocket.py tests/unit/test_proxy_utils.py tests/integration/test_proxy_websocket_responses.py tests/unit/test_proxy_websocket_client.py
  • uv run ty check app/modules/proxy/service.py app/core/clients/proxy_websocket.py tests/unit/test_proxy_utils.py tests/integration/test_proxy_websocket_responses.py tests/unit/test_proxy_websocket_client.py
  • uv run pytest tests/unit/test_proxy_utils.py tests/integration/test_proxy_websocket_responses.py tests/unit/test_proxy_websocket_client.py -q -k 'websocket or replay or trim or continuity or duplicate_tool_call'\n\nStack note: this PR is now the replay-core slice only. Merge fix(proxy): preserve websocket stream error statuses #585 and fix(proxy): suppress duplicate side-effect tool calls #586 after it for the pieces split out of the old oversized branch.

@Komzpa
Komzpa force-pushed the fix/websocket-codex-full-replay-trim branch from 78ab5eb to 87037a6 Compare May 6, 2026 12:13

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 78ab5eb280

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/modules/proxy/service.py Resolved
@Komzpa
Komzpa force-pushed the fix/websocket-codex-full-replay-trim branch 10 times, most recently from 90932ed to 52a9ccc Compare May 6, 2026 19:12
@Soju06

Soju06 commented May 9, 2026

Copy link
Copy Markdown
Owner

Heads up @Komzpa -- CI is red on 9434018:

FAILED tests/unit/test_proxy_utils.py::test_stream_responses_suppresses_duplicate_http_tool_call_bursts
  Left contains one more item:
  {'item': {'arguments': '{"session_id":1,"chars":"","yield_time_ms":1000}',
            'call_id': 'call_replayed',
            'name': 'write_stdin',
            'type': 'function_call'},
   'response_id': 'resp_tool_replayed',
   'type': 'response.output_item.done'}

Looks like the duplicate-burst guard is suppressing one more event than the test (or vice versa) expected -- probably an off-by-one or window-boundary case where a legitimate replayed-tool-call event under resp_tool_replayed is now folded into the dedupe instead of being passed through. This PR's body explicitly says replays under fresh/anonymous response ids should still be suppressed within the burst window, so the question is whether the test fixture is wrong (expected the new behavior to keep that item) or the implementation is wrong (suppressing too aggressively when the response_id changes).

Could you take another pass and either:

  • Update the test fixture if the new suppression boundary is the intended behavior (i.e. resp_tool_replayed is a duplicate burst and should be dropped), and add a sibling test case that asserts the same call text appearing later as a fresh model decision still gets through. The PR body promises this is the contract.
  • Or tighten the dedupe so it correctly distinguishes replay-burst from a re-issued tool call when the response_id changes inside the burst window.

Also kicking off @codex review on the current head so any other findings show up alongside.

PostgreSQL test failure is downstream of the same unit assertion -- once the unit test stabilizes that should clear too.

Will hold the merge until CI is green and a fresh review is in. The other PRs in your stack are landing as they get reviewed.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9434018c11

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/modules/proxy/service.py Resolved
@Soju06

Soju06 commented May 11, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f40c33b21e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/modules/proxy/service.py Resolved
@Soju06

Soju06 commented May 11, 2026

Copy link
Copy Markdown
Owner

Thanks @Komzpa -- the websocket replay-continuity work is the right shape and the test coverage looks careful. One more codex review pass on f40c33b surfaced two P2s in the new continuity / leading-context paths that I'd like to fold in before merging. The PR is mergeable as-is, but the continuity surface is sensitive enough that I want the guards explicit rather than relying on the broader fail-closed path.

P2 #1 -- anchor double-accept on ambiguous pre-response.created failure

app/modules/proxy/service.py:3020 injects previous_response_id so a fresh full-resend looks like a continuation. That is the right intent for the trim, but the direct websocket replay path (_pop_replayable_precreated_websocket_request_state + replay in proxy_responses_websocket) still forwards request_state.request_text verbatim on ambiguous pre-response.created failure. So in the failure window:

  • proxy sends anchored continuation A1 -> upstream may or may not have accepted it before the disconnect
  • proxy reconnects, the websocket replay path resends A1 verbatim (same anchored payload)
  • if upstream accepted both, continuity forks and model/tool work duplicates

The HTTP-bridge counterpart already guards this class: it only retries injected anchors by switching back to the stored unanchored full replay, and it fails closed for client-supplied or oversized anchors. The websocket injection path needs equivalent protection. Two options:

a. Reuse the same protection on websocket replay: when popping a replayable pre-created request, if the request was proxy-anchored, replay the stored fresh unanchored payload instead of the anchored request_text. Same shape as _pop_replayable_precreated_http_bridge_request_state already does.

b. Refuse to replay anchored requests on the WS path and surface stream_incomplete instead. This is what the PR body says is the intended behavior for client-supplied / oversized anchors, but it currently does not extend to proxy-injected anchors. Re-using the unanchored fresh resend (option a) is friendlier to the client.

P2 #2 -- preserve client-provided leading assistant items

app/modules/proxy/service.py:3175 drops every leading assistant / function_call / reasoning item whenever previous_response_id is set on the request. That is correct for proxy-injected continuations where we know the prefix is a stale replay, but Responses API clients can legitimately send leading assistant-role context as new input on the next turn (e.g. prefilled assistant scaffolding, partial tool plans, externally curated continuation context). Silent rewriting changes model behavior.

Suggested narrow:

  • only run the leading-item trim when the proxy itself injected the previous_response_id for this request (the proxy_injected_previous_response_id flag already exists on request_state)
  • for client-supplied previous_response_id, forward the leading context verbatim

Tests to add

  • WS replay double-accept guard: simulate a proxy-injected anchored request, force a pre-response.created disconnect, assert the replay uses the saved unanchored full resend rather than the anchored request_text.
  • Client-supplied previous_response_id with leading assistant input: assert the leading items are forwarded verbatim and not stripped.

Not blocking

The rest of the PR is solid -- the response-id-scoped tool-call dedupe, the serialization-time tool-call trim, the continuity-metadata wait/fail-closed, and the unanchored-only retry semantics all read cleanly. Just the two newly-introduced injection paths above need the same guards the HTTP bridge already has.

After you push, I'll re-run @codex review. Holding the merge until then.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f40c33b21e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/modules/proxy/service.py Resolved
@Komzpa
Komzpa requested a review from Soju06 as a code owner May 11, 2026 21:52
@Komzpa
Komzpa force-pushed the fix/websocket-codex-full-replay-trim branch 2 times, most recently from 18d1776 to d8b95d9 Compare May 11, 2026 23:32
@Komzpa
Komzpa force-pushed the fix/websocket-codex-full-replay-trim branch 12 times, most recently from d1eff49 to 80f1b4b Compare May 12, 2026 15:57
Komzpa added 11 commits May 13, 2026 13:38
(cherry picked from commit dc1bcb7ab5b7bbe686ce7df675e6cbd1eaffb70f)
(cherry picked from commit 5c74ede3189e002fa1acbb2567ec88d96bb11f8f)
(cherry picked from commit 5f323ef159d1a9e43d35bf98922a158d219a1baa)
(cherry picked from commit 994f2a0589f44bf0aa48ef50b689586e58bfeeb6)
(cherry picked from commit b7f7a64ce9abe121714cdc910827ceb44ccb174a)
(cherry picked from commit 858d0d76b975d31e88d1df05f87aaa60aa2dc1e9)
(cherry picked from commit 0dcd7c7fa97cd468c7f1f7b206597ebf2ba9f4b4)
(cherry picked from commit f9503feafb6125da5df46bd1382ed5a3700f5226)
(cherry picked from commit 99119a0948faa84b41d5694a2cc34cd09b16e059)
(cherry picked from commit ec174a1b82a6089d3677751ba8c9123f2e38eb47)
@Komzpa

Komzpa commented May 16, 2026

Copy link
Copy Markdown
Collaborator Author

Closing this draft because the replay/continuity work was split into reviewable replacement PRs: #650 for the continuity core, #651 for websocket previous-response trim handling, and #652 for HTTP bridge replay trimming. The active stack should track the split PRs.

@Komzpa Komzpa closed this May 16, 2026
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.

2 participants