Skip to content

Reject invalid output token budgets - #7379

Merged
diegosouzapw merged 5 commits into
cheaper-inference:release/v3.8.49from
JxnLexn:dev/context-overflow-output-budget
Jul 18, 2026
Merged

diegosouzapw merged 5 commits into
cheaper-inference:release/v3.8.49from
JxnLexn:dev/context-overflow-output-budget

Conversation

@JxnLexn

@JxnLexn JxnLexn commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Prevent requests from exceeding the target model’s context window by rejecting oversized prompts and capping or removing invalid output token limits before upstream dispatch.

Validation

  • npm run lint
  • npm run test:unit
  • npm run test:coverage
  • Coverage is still >= 60% for statements, lines, functions, and branches
  • SonarQube PR analysis is green or any remaining issues are explicitly documented below

Tests Added Or Updated

  • Added unit tests for output token budget enforcement.

Coverage Notes

  • Unit tests cover context overflow rejection, output budget capping, and removal of invalid numeric limits in open-sse/.

Reviewer Notes

  • The final target context check runs immediately before request translation and may adjust the shared request body for upstream dispatch.

@JxnLexn
JxnLexn requested a review from diegosouzapw as a code owner July 16, 2026 09:00

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a mechanism to enforce the target model's output token budget immediately before translation, capping or removing invalid or oversized output token fields (such as max_tokens and max_completion_tokens) to prevent upstream errors, and adds corresponding unit tests. The review feedback correctly identifies potential runtime TypeError crashes if the body parameter is null or undefined, suggesting defensive guards in both handleChatCore and enforceOutputTokenBudget.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread open-sse/handlers/chatCore.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3cfb300a3e

ℹ️ 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".

Comment thread open-sse/handlers/chatCore.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f5cf4cf3c7

ℹ️ 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".

Comment thread open-sse/handlers/chatCore.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b5bd75a101

ℹ️ 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".

Comment thread open-sse/handlers/chatCore.ts Resolved
@diegosouzapw

Copy link
Copy Markdown
Collaborator

Thanks for this — verified the whole chain locally: openai-to-claude.ts's adjustMaxTokens really does inject a 64000-token default when the client omits max_tokens, so the Claude-target default-budget check is solving a real gap, and the rejection message intentionally matches combo.ts::isContextOverflow400 so combo fallback still tries the next target instead of aborting the whole request — nice attention to detail. Ran the new output-token-budget.test.ts (6/6), the updated chatcore-sanitization.test.ts (21/21), eslint, and tsc -p tsconfig.typecheck-core.json — all clean. Error responses correctly go through createErrorResult/buildErrorBody. Only nit: no changelog.d/ fragment — I'll add one at merge time, no action needed from you. Merging as-is.

@diegosouzapw
diegosouzapw merged commit cb594ae into cheaper-inference:release/v3.8.49 Jul 18, 2026
15 checks passed
@diegosouzapw

Copy link
Copy Markdown
Collaborator

Thanks @JxnLexn! Merged into release/v3.8.49 after combined merge-train validation (static gates + tests + vitest green on the merged tree). Where quality gates flagged growth we decomposed/extracted inside your branch keeping you as author — including renumbering the reasoning-routing migration slot and the ProviderDetailPageClient rebaseline annotation.

diegosouzapw added a commit that referenced this pull request Jul 19, 2026
…ntext-window boundary

The 'disabled prompt compression leaves combo override requests unchanged'
integration test predates #7379 (enforceOutputTokenBudget): its 31.5k-token
body now trips the intentional pre-dispatch 400 context_length_exceeded
reject (test:integration only runs on the release-PR gate, so the red
accrued silently on the release branch). Resize the body into the
(70%-threshold, window) corridor — still proving disabled compression leaves
the request byte-identical — with a precondition locking the corridor, and
add chatcore-context-window-boundary.test.ts locking the reject path at the
integration layer (400 + context_length_exceeded + zero upstream fetches).
Red->green validated on the isolated file run.
HouMinXi pushed a commit to HouMinXi/OmniRoute that referenced this pull request Aug 2, 2026
* fix(context): reject invalid output token budgets

* fix(context): enforce output budgets across request formats

* fix(context): enforce default Claude output budgets

* fix(context): include Responses API input in token budget

* ci: rerun pull request checks
HouMinXi pushed a commit to HouMinXi/OmniRoute that referenced this pull request Aug 2, 2026
…inference#7379 context-window boundary

The 'disabled prompt compression leaves combo override requests unchanged'
integration test predates cheaper-inference#7379 (enforceOutputTokenBudget): its 31.5k-token
body now trips the intentional pre-dispatch 400 context_length_exceeded
reject (test:integration only runs on the release-PR gate, so the red
accrued silently on the release branch). Resize the body into the
(70%-threshold, window) corridor — still proving disabled compression leaves
the request byte-identical — with a precondition locking the corridor, and
add chatcore-context-window-boundary.test.ts locking the reject path at the
integration layer (400 + context_length_exceeded + zero upstream fetches).
Red->green validated on the isolated file run.
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
* fix(context): reject invalid output token budgets

* fix(context): enforce output budgets across request formats

* fix(context): enforce default Claude output budgets

* fix(context): include Responses API input in token budget

* ci: rerun pull request checks
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
…inference#7379 context-window boundary

The 'disabled prompt compression leaves combo override requests unchanged'
integration test predates cheaper-inference#7379 (enforceOutputTokenBudget): its 31.5k-token
body now trips the intentional pre-dispatch 400 context_length_exceeded
reject (test:integration only runs on the release-PR gate, so the red
accrued silently on the release branch). Resize the body into the
(70%-threshold, window) corridor — still proving disabled compression leaves
the request byte-identical — with a precondition locking the corridor, and
add chatcore-context-window-boundary.test.ts locking the reject path at the
integration layer (400 + context_length_exceeded + zero upstream fetches).
Red->green validated on the isolated file run.
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.

2 participants