Repository navigation
Handle downstream client disconnects consistently for all SSE writes #18
Description
Outcome
Centralize every downstream SSE write in the Python Gateway so a client close is classified once, unwinds upstream work, and completes the request as HTTP 499 without being mistaken for an upstream transport or protocol failure.
Design and scope
- Route all SSE header, event, keepalive, terminal, error, converted-protocol, and transparent relay writes in
src-python/codex_proxy.pythrough one downstream-write seam. - The seam must handle
BrokenPipeError,ConnectionResetError, and other downstreamOSErrorvalues consistently, record a sanitized downstream-close disposition, and prevent duplicate terminals or retries after exposure. - When the downstream closes, promptly close/cancel the associated upstream response/reader and let the handler unwind. Preserve normal stream bytes and ordering.
- Final request accounting is exactly one
request_completewith status 499 for a downstream close. Do not relabel it as an upstream error and do not synthesize a protocol terminal to the closed client. - Preserve transparent route identity and existing successful Responses and Chat behavior.
Deterministic acceptance
- Every production SSE write path uses the central seam; no direct streaming
wfile.writepath bypasses it. - Tests inject downstream close before first output, mid-event, during keepalive, during converted Responses/Chat output, and after upstream terminal.
- Tests prove upstream close/cancel, no further write, no fallback/retry, exactly one sanitized completion, and 499 classification.
- Targeted tests cover
tests/test_routing.py,tests/test_proxy_event_logging.py,tests/test_chat_completions_gateway.py, andtests/test_proxy_shutdown.py.
Final-SHA real-client gate
After the E2E foundation issue, every final candidate SHA must build Debug and pass all twelve cases in VM snapshot codexhub-real-client-e2e-v1:
- Desktop and CLI:
gpt-5.6-lunaandvolc/glm-5.2. - OpenCode, ZCode, Pi, and OMP: the candidate-managed Luna selector and exact
codexhub-volc/glm-5.2. - Each case uses a disposable sentinel file, a real read-only tool call, and a streamed short sentinel; it proves canonical model, expected terminal, exactly one
request_complete=200, and no duplicate, fallback, or unclassified reconnect. - Desktop and ZCode are structured human GUI cases. Login, credentials, and GUI are fail-closed; never use host shared sessions or fabricate evidence.
- Only one retry is allowed for a pre-output provider-capacity 429/503. A new SHA invalidates all evidence.
Issue-specific real-client cases additionally require Desktop/Luna Stop and OMP/Volc Ctrl+C. Both must classify the downstream close as 499, cancel upstream work, emit one completion, and leave no orphaned reader/process.
Verification and integration
python -m pytest -q tests/test_routing.py tests/test_proxy_event_logging.py tests/test_chat_completions_gateway.py tests/test_proxy_shutdown.py
python -m pytest -q
git diff --check
python scripts/report_quality_gates.pyThe quality-gate command is report-only. The final SHA also requires Debug build, GitHub Actions, a strict heavy Reviewer, and the human VM gate above. Squash to dev only; never merge to main.
Hotset
src-python/codex_proxy.pytests/test_routing.pytests/test_proxy_event_logging.pytests/test_chat_completions_gateway.pytests/test_proxy_shutdown.py
Activity
NOirBRight commentedon Jul 9, 2026
Agent Brief
Category: bug
Summary: Classify downstream client disconnects separately from upstream stream failures.
Current behavior:
System.Collections.Hashtable.Current
Desired behavior:
System.Collections.Hashtable.Desired
Key interfaces:
Acceptance criteria:
Out of scope:
NOirBRight commentedon Jul 20, 2026
1 remaining item
NOirBRight commentedon Jul 25, 2026
Phase 0 decomposition note: this parent outcome is intentionally
orch:blockedwhile bounded implementation slices #221 → #222 → #223 land. After #223 satisfies the parent contract, the Coordinator will close #18 rather than dispatching the obsolete all-at-once contract.NOirBRight commentedon Jul 25, 2026
Parent work completed by Issue #223 / PR #231 and merged into
devatf00373f7cf28ab5288691b1aebfc696ec187e9c9. Exact candidate CI was 7/7 successful and the commit-bound review passed with no findings.