Skip to content

fix(ai): harden Codex streaming transport - #1015

Closed
fettpl wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
fettpl:agent/941-codex-streaming-framing
Closed

fix(ai): harden Codex streaming transport#1015
fettpl wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
fettpl:agent/941-codex-streaming-framing

Conversation

@fettpl

@fettpl fettpl commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • decode Codex SSE streams line-by-line across LF, CRLF, mixed/CR framing, split line endings, split UTF-8, comments, multiline data, and terminal EOF events
  • reject pre-aborted WebSocket requests before construction, cache acquisition/reuse, send, or parse, and normalize cancellation through a shared AbortError path
  • clean listeners/sockets on connection failure, stream cancellation, cached-socket abort, fallback close/error, and every terminal settlement

Verification

  • focused issue regression: 15/15 passed
  • combined new and existing Codex stream suites: 32/32 passed
  • npm run check

Compatibility

  • no public API, model catalog, or daemon protocol change
  • cached sockets remain reusable after successful requests; active aborted sockets are evicted

Fixes #941

Note

Fix Codex SSE framing and WebSocket cancellation in streaming transport

  • Adds CodexSSEDecoder to handle mixed/split line endings (LF, CRLF, CR) and dispatch terminal SSE events without a trailing blank line, fixing dropped final events.
  • Hardens WebSocket lifecycle: pre-aborted requests, mid-setup aborts, and abort-during-streaming now all close sockets with a clear reason and propagate a consistent AbortError.
  • Centralizes abort detection with throwIfAborted, isAbortError, and createAbortError helpers; sleep now cleans up its abort listener to prevent leaks.
  • Adds Vitest tests covering SSE framing edge cases and WebSocket cancellation scenarios including cached socket eviction and SSE fallback.
  • Behavioral Change: aborted requests now set stopReason to 'aborted' with error message 'Request was aborted' instead of silently masking the abort.

Macroscope summarized 6eb7f43.

@fettpl
fettpl marked this pull request as ready for review August 8, 2026 17:54
@fettpl

fettpl commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@snimu This is ready for review. It hardens Codex SSE framing across split/mixed line endings and terminal EOF events, and makes WebSocket pre-abort, cache, send, fallback, and cleanup behavior deterministic.

Independent review is clean. All required CI checks pass at 6eb7f43b35866b5f455a817872b85b271efa8544.

@sethkarten

Copy link
Copy Markdown
Contributor

Thank you for the report and proposed work. This root cause is now covered by maintainer-owned stacked PR #1164, authored independently from upstream/main.

We did not inspect or reuse this PR's diff, branch, commits, implementation code, or tests; its public description/comments were used only as a bug report. To keep one review surface, this PR is superseded by #1164 and is being closed.

The complete review stack is #1158#1165. It is being left unmerged for human review after CI and review-bot findings are cleared.

@sethkarten sethkarten closed this Aug 10, 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.

Harden Codex streaming framing and pre-abort behavior

2 participants