Skip to content

fix(responses): refuse oversized input and reframe routed compaction to SSE (#1128) - #1167

Closed
HoshimiRox1 wants to merge 2 commits into
lidge-jun:devfrom
HoshimiRox1:fix(codex)/responses-input-guard-compaction
Closed

fix(responses): refuse oversized input and reframe routed compaction to SSE (#1128)#1167
HoshimiRox1 wants to merge 2 commits into
lidge-jun:devfrom
HoshimiRox1:fix(codex)/responses-input-guard-compaction

Conversation

@HoshimiRox1

@HoshimiRox1 HoshimiRox1 commented Aug 7, 2026

Copy link
Copy Markdown

Summary

Two fixes on the Codex desktop context/compaction failure chain (reported upstream in #1128):

Verification

  • bun run typecheck — clean.
  • bun test tests/responses-input-guard.test.ts — 4 pass / 0 fail (guard above/below the window; compaction reframe with and without stream: true).
  • Live verification against a patched instance: a deepseek-v4-flash compaction turn now returns response.created -> output_item.done (compaction) -> response.completed -> [DONE] instead of bare JSON; an oversized input is rejected with 413 without reaching upstream.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed. (bug fix; no user-facing docs change — release note is maintainer-managed)
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults. (no credentials touched; rejection path only)

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • All CI tests are green on my local testing.

  • I pushed my PR to the latest dev commit.

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

A chained-turn replay can balloon a request far past the model's context window (observed: a 4x expansion pushed a ~400k-token conversation to 1.6M input tokens). The proxy forwarded it verbatim; processing it on Windows ballooned bun RSS and native-crashed the whole service (upstream Bun memory bug, lidge-jun#314), taking every active thread down until restart.

Reject the request with a clean 413 before any upstream I/O when the parsed input exceeds the model's configured modelContextWindows value. The client compacts well before the window, so the guard only fires on abnormal duplication.
The lidge-jun#875 transport policy forces a bounded JSON upstream for providers like deepseek (modelResponsesUpstreamStreaming: false), even when the client asked for SSE. The passthrough branch already reframes that JSON back to the canonical terminal SSE sequence, but routed-compaction turns skip the passthrough branch: they returned application/json, so Codex SSE parser hit EOF at the first byte and the remote compact task failed with "stream closed before response.completed", retrying 6x and leaving the thread unusable.

Mirror the passthrough reframe in both routed branches (runTurn and parseStream): when the client requested stream and the upstream policy forced JSON, emit response.created, one output_item.done per output item (including the synthetic compaction item), response.completed, then [DONE].
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: b7b4c56f-818a-46c2-a54b-61996c3ad713

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

⏳ DRAFT

  • review readiness checklist open (0/4 boxes ticked).

What to do

  • Tick all four boxes in the PR description once you're done (currently 0/4).

Review readiness checklist

  • ⬜ All CI tests are green on my local testing.
  • ⬜ I pushed my PR to the latest dev commit.
  • ⬜ I resolved all correct Codex and CodeRabbit findings.
  • ⬜ My PR is ready for review.

0/4 boxes ticked.

This PR stays in draft until every box above is ticked.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Aug 7, 2026
@HoshimiRox1

Copy link
Copy Markdown
Author

Closing for now — will re-open after reviewing the process. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant