Repository navigation
fix(proxy): mask single previous response misses - #516
Conversation
9d9ebc2 to
1fe5fe6
Compare
14449fe to
f37065d
Compare
|
I validated this branch against a fresh local incident capture from Observed in
This branch matches the mitigation I would want for the continuity-loss class: mask Local validation on this PR branch:
Separate live smoke against the existing container, without deploying this PR: 60 small streamed |
54fe916 to
368e287
Compare
|
Cross-link note: #535 is a narrower overlapping PR for direct WebSocket This PR (#516) is the broader owned branch and should be treated as the canonical fix for our live incident class: HTTP bridge, direct WebSocket, compact/public masking, and the model-registry edge are all covered here. Live deployment note: the current local container image is |
|
Tested - resolves the To test locally: git clone https://github.com/Komzpa/codex-lb.git /tmp/codex-lb-pr516
git -C /tmp/codex-lb-pr516 checkout codex/mask-single-previous-response-miss
DOCKER_BUILDKIT=1 docker build -t codex-lb:pr516 /tmp/codex-lb-pr516Point compose.yaml at Works well. Would love to see this merged. |
5b85534 to
6854f57
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6854f57dc3
ℹ️ 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".
| if not ( | ||
| request_state.fresh_upstream_request_is_retry_safe and request_state.fresh_upstream_request_text | ||
| ): |
There was a problem hiding this comment.
Preserve direct WebSocket retries for safe full-resend misses
This new guard drops all previous_response_not_found retries unless fresh_upstream_request_is_retry_safe is true, but that flag is only set on the HTTP-bridge preparation path (not the direct WebSocket request path). As a result, direct WebSocket follow-ups that include a safe full-resend payload now fall through to a terminal stream_incomplete instead of reconnecting and replaying without previous_response_id, which regresses the recovery behavior this change intends to keep for full-resend requests.
Useful? React with 👍 / 👎.
|
Thanks @Komzpa -- the live-archive trace, fail-closed framing for short continuations, and the orthogonal model-registry / plan-filter hardening are all in good shape. Codex review came back with one P1 that needs a fix before merging. P1 -- direct WebSocket safe full-resend retries are now skippedThe new guard in # app/modules/proxy/service.py:6238
if retry_is_previous_response_not_found:
if not (
request_state.fresh_upstream_request_is_retry_safe
and request_state.fresh_upstream_request_text
):
# short continuation: anchor lost, no safe replay payload
retry_error_code = None
else:
# full-resend retry path
upstream_control.reconnect_requested = True
request_state.request_text = request_state.fresh_upstream_request_text
request_state.previous_response_id = None
...
This regresses one of the recovery cases this PR is trying to preserve, and contradicts the test name added in the same change ( Suggested fixPopulate the same retry-safety metadata on the direct WebSocket request path so the new guard treats full-resend variants identically across paths. Concretely:
If the direct WebSocket path also has cases that legitimately can't be classified as retry-safe at request-preparation time (because retry-safety depends on what upstream just sent), an alternative is to track retry-safety on the request state at receive time rather than relying on a flag set at request prep time -- but the simpler path is to propagate the existing flag. Notes on scope
Once the P1 fix lands I'll re-run |
|
To use Codex here, create an environment for this repo. |
|
I let a local mitigation soak for several days and wanted to share the result because it may be useful for this PR. Context: I initially staged PR #516 at the earlier head My local follow-up added a last-chance downstream WebSocket send / error-serializer sanitizer: if any outbound WebSocket payload still contains upstream After several days of normal use:
I have not yet validated the current PR head |
(cherry picked from commit 443feae6f9ea19c9b28c91eb95dd2268bd194b03)
(cherry picked from commit 6854f57dc32c37a9fd6b4f59a14ae0774e406fcc)
6854f57 to
a36b80e
Compare
Addresses codex-review P1 on the prior revision: a direct WebSocket turn whose semantic payload does not depend on the upstream anchor (no client-supplied `previous_response_id` and no proxy-injected anchor) was falling through to `stream_incomplete` after a `previous_response_not_found` error, instead of being transparently retried on a fresh upstream. The retry path in `_process_upstream_websocket_text` only attempts a reconnect-and-replay for a request flagged `fresh_upstream_request_is_retry_safe` with a populated `fresh_upstream_request_text`. The HTTP-bridge prep path already sets those flags; the direct WebSocket prep path (`_prepare_websocket_response_create_request`) did not, so every direct-WebSocket recovery short-circuited into the fail-closed branch -- including full-resend / fresh-turn variants that this PR explicitly wants to keep recovering. Mirror the classification in the direct WebSocket prep path: when a turn has no client-supplied `previous_response_id` and no proxy-injected anchor, populate both fields so the masking path treats both transport variants identically. Tests: - New integration test `test_v1_responses_websocket_marks_fresh_turn_as_retry_safe_at_prep_time` pins that connecting an upstream for a fresh-turn direct WebSocket request observes `fresh_upstream_request_is_retry_safe=True` and a populated `fresh_upstream_request_text` at prep time. - Updated `test_process_upstream_websocket_text_retries_precreated_previous_response_not_found` in `tests/unit/test_proxy_utils.py` to drive the retry path with the new retry-safety contract: `fresh_upstream_request_text` and `fresh_upstream_request_is_retry_safe=True` on the pending request state, and asserts the retry strips the stale `previous_response_id`, uses the fresh text, and consumes the retry-safety flag. - Full direct-WebSocket integration suite (38 tests) and proxy_utils / proxy_http_bridge / proxy_load_balancer_refresh unit suite (346 passing, 3 pre-existing skips) green.
|
Pushed What the fix doesThe retry path in Mirror the classification in the direct WebSocket prep path: when a turn has no client-supplied Why the classification is safeThe two conditions that gate the new flag —
Anything else (short continuation, anchored follow-up, proxy-injected anchor) leaves the flag at its default TestsNew integration ( Updated unit (
Verification on this headRe-triggering |
|
Codex Review: Didn't find any major issues. Breezy! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
Codex Review: Didn't find any major issues. Keep them coming! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
- E501: wrap long docstring referencing the inverse test name - F841: drop unused `downstream_text` assignment No behavior change.
|
Pushed
No behavior change; the test still passes locally ( CI is now rerunning against the new head. |
|
@all-contributors please add @Komzpa for code, test, doc |
|
@all-contributors please add @Komzpa for code, bug |
|
I've put up a pull request to add @Komzpa! 🎉 |
|
@all-contributors please add @mgwals for test, review |
|
@all-contributors please add @jumski for test |
|
@all-contributors please add @JeffKandt for test, review |
|
I've put up a pull request to add @mgwals! 🎉 |
|
I've put up a pull request to add @jumski! 🎉 |
|
I've put up a pull request to add @JeffKandt! 🎉 |
Release 1.18.0 — v1.17.0 → main, 27 PR. ## Pre-merge verification (release-gate e2e) - ✅ CI 18/18 (mergeStateStatus CLEAN) - ✅ baseline release-gate-smoke: 10/10 (`v1.models`, chat non-stream/stream/tool_call, responses non-stream/stream, unknown-msg-key drop, transient codes, dashboard 72-byte, alembic index) - ✅ per-PR e2e extra: 14/14 (#658 strict tool × chat valid/invalid/type-omitted + responses invalid, #650-652 trim replay markers, #516 prev-resp miss mask, #558 prolite plan, #600 token_expired, #635 device poll, #647 frontend 72B, #594 account selection, #640 alembic head, #653/#654 conv archive, #655/#656 weekly pace) - ✅ pytest 562 passed / 3 PG-only skip (unit + integration suite) - ✅ SDK e2e 20/20 (`tests/e2e/test_openai_sdk_compat.py` + `tests/e2e/test_v1_responses_openai_sdk.py`) - ✅ `scripts/verify_v1_responses_openai_sdk.py` 5/5 against live container with real account - ✅ ruff check + ruff format --check + uv run ty check — All clean - ✅ prod parity probe: #637 (unknown-key drop) + #658 (strict tool 400) both confirmed fixed vs prod 1.17.0 ## Behavior change to note in announcements - **#658**: `strict: true` function tool schemas missing `additionalProperties: false` (or other strict-mode requirements) now return a local **400 `invalid_function_parameters`** with `param=tools[N].function.parameters` (chat) / `tools[N].parameters` (responses). Pre-1.18.0 these were silently forwarded upstream; 1.18.0 enforces OpenAI's documented strict-mode contract locally before forwarding. OpenSpec changes shipped in this release (to be archived after tag publish): - deactivate-on-token-expired (#600) - drop-unknown-message-fields (#637) - mask-single-http-previous-response-miss (#516) - normalize-v1-responses-openai-sdk-stream (#639) - start-device-oauth-polling (#635) - support-prolite-plan-capacity (#558) - treat-upstream-overloaded-as-retryable (#601) - validate-password-length (#598) - validate-strict-function-tool-schema (#658)
Archive changes shipped in v1.18.0 and v1.18.1 per AGENTS.md "release 이후 archive" workflow. All 12 changes verified shipped in production at 10.0.0.113 (image 1.18.1, sha256:0431a474432d). 1.18.0 (9 changes): - deactivate-on-token-expired (#600) - drop-unknown-message-fields (#637) - mask-single-http-previous-response-miss (#516) - normalize-v1-responses-openai-sdk-stream (#639) - start-device-oauth-polling (#635) [delta header fixed: MODIFIED -> ADDED] - support-prolite-plan-capacity (#558) [delta header fixed: MODIFIED -> ADDED] - treat-upstream-overloaded-as-retryable (#601) - validate-password-length (#598) - validate-strict-function-tool-schema (#658) 1.18.1 (3 changes): - harden-long-codex-websocket-turns (#586) - suppress-duplicate-side-effect-tool-calls (#586) - hotfix-db-pool-pre-ping-and-firewall-cache-ttl (#679) Specs updated: 9 capabilities (admin-auth, api-firewall, chat-completions-compat, chat-completions-extensions, database-backends, frontend-architecture, responses-api-compat, usage-refresh-policy). openspec validate --specs: 19/19 passed. Co-authored-by: Hermes Agent <[email protected]>
* fix(proxy): mask single previous response misses (cherry picked from commit 443feae6f9ea19c9b28c91eb95dd2268bd194b03) * fix(proxy): fail closed for direct websocket anchor misses (cherry picked from commit 6854f57dc32c37a9fd6b4f59a14ae0774e406fcc) * fix(proxy): classify direct WebSocket fresh turns as retry-safe Addresses codex-review P1 on the prior revision: a direct WebSocket turn whose semantic payload does not depend on the upstream anchor (no client-supplied `previous_response_id` and no proxy-injected anchor) was falling through to `stream_incomplete` after a `previous_response_not_found` error, instead of being transparently retried on a fresh upstream. The retry path in `_process_upstream_websocket_text` only attempts a reconnect-and-replay for a request flagged `fresh_upstream_request_is_retry_safe` with a populated `fresh_upstream_request_text`. The HTTP-bridge prep path already sets those flags; the direct WebSocket prep path (`_prepare_websocket_response_create_request`) did not, so every direct-WebSocket recovery short-circuited into the fail-closed branch -- including full-resend / fresh-turn variants that this PR explicitly wants to keep recovering. Mirror the classification in the direct WebSocket prep path: when a turn has no client-supplied `previous_response_id` and no proxy-injected anchor, populate both fields so the masking path treats both transport variants identically. Tests: - New integration test `test_v1_responses_websocket_marks_fresh_turn_as_retry_safe_at_prep_time` pins that connecting an upstream for a fresh-turn direct WebSocket request observes `fresh_upstream_request_is_retry_safe=True` and a populated `fresh_upstream_request_text` at prep time. - Updated `test_process_upstream_websocket_text_retries_precreated_previous_response_not_found` in `tests/unit/test_proxy_utils.py` to drive the retry path with the new retry-safety contract: `fresh_upstream_request_text` and `fresh_upstream_request_is_retry_safe=True` on the pending request state, and asserts the retry strips the stale `previous_response_id`, uses the fresh text, and consumes the retry-safety flag. - Full direct-WebSocket integration suite (38 tests) and proxy_utils / proxy_http_bridge / proxy_load_balancer_refresh unit suite (346 passing, 3 pre-existing skips) green. * style(tests): fix ruff lint on direct WebSocket retry-safe test - E501: wrap long docstring referencing the inverse test name - F841: drop unused `downstream_text` assignment No behavior change. --------- Co-authored-by: Soju06 <[email protected]>
Release 1.18.0 — v1.17.0 → main, 27 PR. ## Pre-merge verification (release-gate e2e) - ✅ CI 18/18 (mergeStateStatus CLEAN) - ✅ baseline release-gate-smoke: 10/10 (`v1.models`, chat non-stream/stream/tool_call, responses non-stream/stream, unknown-msg-key drop, transient codes, dashboard 72-byte, alembic index) - ✅ per-PR e2e extra: 14/14 (Soju06#658 strict tool × chat valid/invalid/type-omitted + responses invalid, Soju06#650-652 trim replay markers, Soju06#516 prev-resp miss mask, Soju06#558 prolite plan, Soju06#600 token_expired, Soju06#635 device poll, Soju06#647 frontend 72B, Soju06#594 account selection, Soju06#640 alembic head, Soju06#653/Soju06#654 conv archive, Soju06#655/Soju06#656 weekly pace) - ✅ pytest 562 passed / 3 PG-only skip (unit + integration suite) - ✅ SDK e2e 20/20 (`tests/e2e/test_openai_sdk_compat.py` + `tests/e2e/test_v1_responses_openai_sdk.py`) - ✅ `scripts/verify_v1_responses_openai_sdk.py` 5/5 against live container with real account - ✅ ruff check + ruff format --check + uv run ty check — All clean - ✅ prod parity probe: Soju06#637 (unknown-key drop) + Soju06#658 (strict tool 400) both confirmed fixed vs prod 1.17.0 ## Behavior change to note in announcements - **Soju06#658**: `strict: true` function tool schemas missing `additionalProperties: false` (or other strict-mode requirements) now return a local **400 `invalid_function_parameters`** with `param=tools[N].function.parameters` (chat) / `tools[N].parameters` (responses). Pre-1.18.0 these were silently forwarded upstream; 1.18.0 enforces OpenAI's documented strict-mode contract locally before forwarding. OpenSpec changes shipped in this release (to be archived after tag publish): - deactivate-on-token-expired (Soju06#600) - drop-unknown-message-fields (Soju06#637) - mask-single-http-previous-response-miss (Soju06#516) - normalize-v1-responses-openai-sdk-stream (Soju06#639) - start-device-oauth-polling (Soju06#635) - support-prolite-plan-capacity (Soju06#558) - treat-upstream-overloaded-as-retryable (Soju06#601) - validate-password-length (Soju06#598) - validate-strict-function-tool-schema (Soju06#658)
…u06#682) Archive changes shipped in v1.18.0 and v1.18.1 per AGENTS.md "release 이후 archive" workflow. All 12 changes verified shipped in production at 10.0.0.113 (image 1.18.1, sha256:0431a474432d). 1.18.0 (9 changes): - deactivate-on-token-expired (Soju06#600) - drop-unknown-message-fields (Soju06#637) - mask-single-http-previous-response-miss (Soju06#516) - normalize-v1-responses-openai-sdk-stream (Soju06#639) - start-device-oauth-polling (Soju06#635) [delta header fixed: MODIFIED -> ADDED] - support-prolite-plan-capacity (Soju06#558) [delta header fixed: MODIFIED -> ADDED] - treat-upstream-overloaded-as-retryable (Soju06#601) - validate-password-length (Soju06#598) - validate-strict-function-tool-schema (Soju06#658) 1.18.1 (3 changes): - harden-long-codex-websocket-turns (Soju06#586) - suppress-duplicate-side-effect-tool-calls (Soju06#586) - hotfix-db-pool-pre-ping-and-firewall-cache-ttl (Soju06#679) Specs updated: 9 capabilities (admin-auth, api-firewall, chat-completions-compat, chat-completions-extensions, database-backends, frontend-architecture, responses-api-compat, usage-refresh-policy). openspec validate --specs: 19/19 passed. Co-authored-by: Hermes Agent <[email protected]>
Summary
previous_response_not_foundas an internal continuity-loss signal instead of leaking the raw upstream 400bridge_previous_response_not_foundmarker only for the single anonymous HTTP bridge caseprevious_response_idwhen upstream loses a just-completed anchor beforeresponse.createdprevious_response_not_foundintostream_incompleteinstead of replaying the same stale anchor and exposing the raw upstream 400no_plan_support_for_model503s after partial model-registry refreshes: account selection now only applies the plan filter when the registry has an authoritative entry for the requested model, and model refresh invalidates cached selection inputsprevious_response_not_foundpayload to retryablestream_incompleteso the missing response id cannot leak even if a lower recovery path misses itRoot Cause
The HTTP bridge only rewrote upstream
previous_response_not_foundwhen the upstream event had aresponse.idor there were other pending requests. A single pending follow-up with an anonymous upstream error could therefore propagate the raw invalid-request error to Codex clients.Live archive follow-up showed direct WebSocket Codex turns can receive
response.completedfor an anchor and then hitprevious_response_not_foundon the next turn seconds later on the same account/session. Full-resend turns can be recovered by reconnecting upstream and replaying the full payload withoutprevious_response_id; short continuation turns cannot, because the only semantic payload is the stale anchor, so they now fail closed as a sanitized continuity-loss signal.A DNS outage exposed a separate local-routing edge while the live container was running this PR stack: partial model registry data could make
responses/compactapply a plan filter for a model the registry did not actually know yet, producing local 503No accounts with a plan supporting model 'gpt-5.5'while adjacentresponsescalls on pro accounts were already succeeding.Fresh live incident check
Checked the live raw leak with
previous_response_id=resp_0bebc32c66e5a5990169f9d272ffbc8191801046ca030a311bfrom2026-05-05:2026-05-05 11:20:19 UTC: upstream createdresp_0beb...d272....2026-05-05 11:20:24 UTC: upstream returnedresponse.completedfor that response.2026-05-05 11:21:27 UTC: the same response stream recordedno close frame received or sent.2026-05-05 11:22:25 UTC: the next turn sentprevious_response_id=resp_0beb...d272...and got rawprevious_response_not_found/previous_response_id/400downstream.This was not a cross-account routing miss: the created/completed response, follow-up request, and raw error all used the same account family
c26b2ebf.... A new accountfe2708b6...appeared nearby in the archive, but for a different parallel request.So this PR's desired behavior is fail-closed masking: when upstream loses continuity even on the owner account, downstream gets
502 stream_incomplete, not rawprevious_response_not_foundor aresp_*id.Validation
.venv/bin/pytest -q tests/integration/test_proxy_websocket_responses.py(37 passed, 2 pre-existing aiosqlite thread warnings).venv/bin/pytest -q tests/integration/test_proxy_websocket_responses.py::test_v1_responses_websocket_masks_short_previous_response_not_found_without_retry tests/integration/test_proxy_websocket_responses.py::test_backend_responses_websocket_masks_short_previous_response_not_found_without_retry tests/integration/test_proxy_websocket_responses.py::test_backend_responses_websocket_masks_previous_response_not_found_when_message_omits_response_id tests/integration/test_proxy_websocket_responses.py::test_v1_responses_websocket_retries_full_resend_previous_response_miss_without_anchor(4 passed).venv/bin/pytest -q tests/unit/test_proxy_load_balancer_refresh.py tests/unit/test_graceful_degradation.py(42 passed, 3 skipped).venv/bin/ruff check app/modules/proxy/service.py tests/integration/test_proxy_websocket_responses.py.venv/bin/ruff check app/modules/proxy/load_balancer.py app/core/openai/model_refresh_scheduler.py tests/unit/test_proxy_load_balancer_refresh.py.venv/bin/ruff format --check app/modules/proxy/service.py tests/integration/test_proxy_websocket_responses.py.venv/bin/ruff format --check app/modules/proxy/load_balancer.py app/core/openai/model_refresh_scheduler.py tests/unit/test_proxy_load_balancer_refresh.pynpx --yes @fission-ai/openspec validate --specs(19 passed)git diff --check/home/kom/proj/codex-lb/.venv/bin/python -m pytest -q tests/unit/test_proxy_api_websocket_auth.py::test_public_previous_response_not_found_error_is_masked_to_stream_incomplete tests/unit/test_proxy_api_websocket_auth.py::test_public_previous_response_invalid_request_param_is_masked_to_stream_incomplete tests/integration/test_proxy_websocket_responses.py tests/integration/test_http_responses_bridge.py::test_v1_responses_http_bridge_rebinds_after_upstream_previous_response_not_found tests/integration/test_http_responses_bridge.py::test_v1_responses_http_bridge_masks_anonymous_previous_response_not_found_with_inflight_request(41 passed, rerun on2026-05-05)/home/kom/proj/codex-lb/.venv/bin/ruff check app/modules/proxy/service.py tests/unit/test_proxy_api_websocket_auth.py tests/integration/test_proxy_websocket_responses.py tests/integration/test_http_responses_bridge.py(rerun on2026-05-05)git diff --check(rerun on2026-05-05)GitHub CI for this PR head is green: 18/18 checks passed.
Notes
make -f src/Makefile precommitis not available in this repository; that Makefile belongs to the surrounding OpenClaw workspace..venv/bin/ty check app/modules/proxy/service.py tests/integration/test_proxy_websocket_responses.pystill reports the pre-existingservice.py:9018..9029diagnostics that are handled by neighboring PR fix(types): clear existing ty diagnostics #517.Related issues