Skip to content

fix(responses): refuse input beyond the advertised context window (#1128) - #1412

Draft
HoshimiRox1 wants to merge 1 commit into
lidge-jun:devfrom
HoshimiRox1:fix(codex)/responses-input-guard-compaction
Draft

fix(responses): refuse input beyond the advertised context window (#1128)#1412
HoshimiRox1 wants to merge 1 commit into
lidge-jun:devfrom
HoshimiRox1:fix(codex)/responses-input-guard-compaction

Conversation

@HoshimiRox1

Copy link
Copy Markdown

Summary

Supersedes #1167 after rebasing the contributor branch onto current dev; GitHub does not allow reopening a closed PR whose head history was rewritten.

  • Reject parsed /v1/responses text input when the shared model-aware token estimate exceeds the final routed model's advertised context window.
  • Run the guard after previous_response_id expansion and final route selection, but before authentication, adapter construction, or upstream I/O.
  • Contain abnormal replay expansion observed in production: a roughly 400k-token conversation became a 1.6M-token request, ballooned Bun RSS on Windows, and native-crashed the proxy. The guard returns a clean 413 without calling upstream.
  • This PR is intentionally limited to the independent input guard. The earlier DeepSeek compaction reframe was removed after upstream dev commit 0b8e608 restored live Responses streaming. Refs [Bug] DeepSeek V4 Flash remote auto-compaction needs v2.11+ reproduction #1128.

Verification

  • bun test tests/responses-input-guard.test.ts — 2 pass, 0 fail.
  • bun run typecheck — pass.
  • bun run privacy:scan — pass.
  • git diff --check — pass.
  • Full bun run test was attempted on Windows: unrelated codex-journal restoration tests remained red in isolation (8 failures), and the full run ended in a Bun 1.3.14 index-out-of-bounds crash after 816 seconds. The focused Responses tests and typecheck remain green, so this PR stays draft for CI confirmation.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed. No user-facing configuration or API contract changed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults. No credential or logging path changed.

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.
@coderabbitai

coderabbitai Bot commented Aug 10, 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: fa9f1df8-b055-46d8-b3d2-a5c5b443a7b7

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

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

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

Copy link
Copy Markdown
Contributor

⏳ DRAFT

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

What to do

  • Tick all four boxes in the PR description once you're done (currently 1/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.

1/4 boxes ticked.

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

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