Skip to content

feat(openai-chat): minMaxOutputTokens provider floor for guaranteed output budgets - #6696

Closed
ismell0992-afk wants to merge 9 commits into
lidge-jun:devfrom
ismell0992-afk:feat/min-max-output-tokens-floor
Closed

ismell0992-afk wants to merge 9 commits into
lidge-jun:devfrom
ismell0992-afk:feat/min-max-output-tokens-floor

Conversation

@ismell0992-afk

@ismell0992-afk ismell0992-afk commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add optional positive-integer minMaxOutputTokens for OpenAI Chat providers. Native Chat and translated Responses raise the effective caller/model/provider budget to the configured floor; larger budgets remain intact. With the option unset, existing fields and omissions remain unchanged. Native max_completion_tokens takes precedence over the legacy alias.
  • Admit spend against the final negotiated Chat budget, including Responses bridges, native combos and Copilot Auto. An unused prepaid seed whose estimate changes is retired through its existing owner and capacity is re-admitted before its permit is used. Each physical start captures its own estimate; started liabilities and proof ownership remain intact.
  • Preserve GLM checkpoint mitigation using the original declared cap before applying the floor. Add strict numeric configuration/editor validation, detached policy provenance, and provider/structure documentation. The contributor's original commit is preserved.

Verification

  • Final pushed/reviewed head: 249397048fbe87255715af90255bdb06d8bd017c; contained dev: 7af092ca4f78828238b425bf351d5989e237f89f; original contributor commit 95d9a3498fb7c5d3ad2a29071cec1c348dc31076 remains an ancestor.
  • bun test --isolate tests/responses/chat-output-floor-copilot-auto.test.ts tests/responses/chat-native-spend.test.ts tests/responses/chat-native-combo.test.ts tests/responses/responses-spend-anchor.test.ts tests/lib/execution-budget-permits.test.ts tests/lib/spend-seed-overflow.test.ts: 198 pass / 0 fail. The 12 Auto cases verify direct/combo streaming/buffered refusal with zero inference sends, unset-floor success, and sufficient-capacity reservations.
  • Final layout, layout-tooling, file-size and Lab guards: 53 pass / 0 fail. bun run typecheck, bun run structure:check, and bun run privacy:scan: exit 0.
  • Earlier focused verification for unchanged GLM/budget/policy source: 272 pass / 0 fail across seven files. The subsequent physical-start snapshot regression run passed 102 tests. Native wire-budget regression was red 25 pass / 28 fail, then green 53 pass / 0 fail; affected spend/policy cases were red 56 pass / 9 fail, then green 118 pass / 0 fail. These are historical scoped results, not a claim that every earlier suite ran at the final head.
  • bun run --cwd docs-site build: exit 0, 569 pages and 79,332 internal links; no dependency manifest or lockfile changes.
  • Fresh independent gpt-6.1-sol full-diff/security review PASS at the exact final head above, all 34 changed files reviewed, no concrete P0–P2 findings. Read-only probes covered re-admission, alias/proof ownership, stale refunds, delayed estimates, persistence recovery, numeric validation, editor redaction and immutability. Explicit maintainer security/merge disposition remains with the coordinator.
  • Full local/unfiltered changed-suite execution was impractical under concurrent worktree contention. The changed graph selected 1,782 files; the no-match selection probe executed zero cases and is not a correctness pass. Focused regressions and guards above provide local coverage. Full-suite, required hosted and cross-platform CI are deferred to the coordinator's final integration run.
  • Normal push to the contributor branch; no force push or rebase. PR remains draft. No merge or hosted workflow dispatch/approval/wait was performed.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Review readiness checklist

  • Required local validation passed; commands, results, and any full-suite exception are documented.
  • I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
  • I resolved all correct Codex and CodeRabbit findings.
  • My PR is ready for review.

…utput budgets

Add an optional minMaxOutputTokens floor on OcxProviderConfig: the effective
max_tokens sent upstream is max(declared, floor), where declared is the
caller's max_output_tokens, then modelMaxOutputTokens, then
defaultMaxOutputTokens. Motivating case is local/OpenAI-compatible servers
(llama.cpp, Ollama): a client sending a tiny budget would otherwise leave a
reasoning model zero tokens for content. Floor only; a larger declared value
always wins, and the floor is off when unset or <= 0.

- types/provider.ts: new optional field with doc comment
- model-rename-fields.ts: classified "none" (satisfies map is enforced)
- auth-cors.ts: field policy "editor", matching its budget siblings
- config-schema.ts: positiveIntegerConfigError parity with
  defaultMaxOutputTokens, so bad values are rejected at load
- summary-budget.ts: resolveMaxTokens applies the floor
- tests: unit + wire-level floor cases; config-schema accept/reject cases
- docs: providers reference row (English; translations follow)
@github-actions github-actions Bot added the intake: hygiene-blocked Deterministic PR hygiene checks failed label Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

⚠️ Deterministic hygiene checks failed.

  • unsponsored_surface — This changes an authentication, workflow, release-automation, or dependency surface. MAINTAINERS.md requires security review for these; ask a maintainer to apply maintainer-sponsored once they have reviewed it. Paths: src/server/auth-cors.ts.

@github-actions github-actions Bot added the enhancement New feature or request label Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

⏳ DRAFT

  • hygiene: unsponsored_surface.

What to do

  • Fix unsponsored_surface — This changes an authentication, workflow, release-automation, or dependency surface. MAINTAINERS.md requires security review for these; ask a maintainer to apply maintainer-sponsored once they have reviewed it. Paths: src/server/auth-cors.ts.
  • Tick all four boxes in the PR description once you're done (currently 0/4).

Review readiness checklist

  • ⬜ Required local validation passed; commands, results, and any full-suite exception are documented.
  • ⬜ I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
  • ⬜ I resolved all correct Codex and CodeRabbit findings.
  • ⬜ My PR is ready for review.

0/4 boxes ticked.

This pull request was already a draft. Its draft status will be preserved after every issue above is resolved.
@ismell0992-afk Tick the boxes once required local validation has passed with commands, results, and any full-suite exception documented, your branch is on the latest dev commit, and every correct Codex and CodeRabbit finding is resolved.

@github-actions
github-actions Bot marked this pull request as draft October 6, 2026 23:05
@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 38449fc4-19f1-4024-9988-99359f11be34











📥 Commits

Reviewing files that changed from the base of the PR and between 9099e4b and 511e0aa.












📒 Files selected for processing (10)
  • docs-site/src/content/docs/reference/configuration/providers.md
  • scripts/test-layout/layout.json
  • src/adapters/openai-chat/summary-budget.ts
  • src/config/schema/config-schema.ts
  • src/providers/model-rename-fields.ts
  • src/server/auth-cors.ts
  • src/types/provider.ts
  • tests/adapters/openai/openai-chat-min-max-output-tokens.test.ts
  • tests/fixtures/test-layout-expected.json
  • tests/server/config.test.ts











Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.













📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The change adds minMaxOutputTokens to provider configuration. OpenAI Chat uses it as a floor for the selected output-token budget. Configuration validation, editor handling, documentation, and tests are updated.

Changes

OpenAI Chat output-token floor

Layer / File(s) Summary
Provider setting and validation
src/types/provider.ts, src/config/schema/config-schema.ts, src/server/auth-cors.ts, src/providers/model-rename-fields.ts, docs-site/src/content/docs/reference/configuration/providers.md, tests/server/config.test.ts
Adds the optional minMaxOutputTokens provider setting, validates it as a positive integer, and classifies it for provider editor handling and model-field processing. The documentation describes how the setting affects the selected budget. Configuration tests cover valid and invalid values.
Budget resolution and tests
src/adapters/openai-chat/summary-budget.ts, tests/adapters/openai/openai-chat-min-max-output-tokens.test.ts, scripts/test-layout/layout.json, tests/fixtures/test-layout-expected.json
The resolver raises the selected output-token budget to the configured minimum when the minimum is positive. Tests cover declared, model-specific, default, and missing budgets, as well as disabled minimum values and the outgoing max_tokens field. Test-layout mappings include the new test.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

























































Merge Risk: ⚪ Minimal · up to 511e0

The OpenAI Chat token floor is ready to merge after normal checks.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 7 files. (3 skipped: 3 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely identifies the main change: adding a minMaxOutputTokens provider floor for the openai-chat adapter.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 7 files. (3 skipped: 3 unsupported.)


  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR











🧪 Generate unit tests (beta)
  • Create a new PR





















  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@ismell0992-afk

Copy link
Copy Markdown
Contributor Author

Self-review pass (senior-reviewer subagent) completed before marking ready. Outcome:

Applied: docs row now states explicitly that when nothing is declared, the floor itself is sent (8fbcb9cc2).

Considered, declined with reasoning: tightening the runtime floor guard from > 0 to a positive-safe-integer check. The adapter's existing trust boundary is the config schema (persisted config is validated; programmatic configs are trusted throughout) — defaultMaxOutputTokens and the caller's own max_output_tokens reach the wire with no runtime integer guard either (summary-budget.ts passes declared through as-is; the responses parser stores max_output_tokens unvalidated). Guarding only the new field would be internally inconsistent; guarding all of them is a larger behavioral change that doesn't belong in this PR. Malformed persisted values are already rejected at load by the added positiveIntegerConfigError parity.

Verification evidence (from the TDD run; reviewer was read-only so these are the executor's records): new test file fails 5/9 at the base commit (runtime red), 9/9 at head; bun run typecheck clean; tests/adapters/openai/ 612/612; tests/server/config.test.ts 199/199; layout guards 18/18; file-size ratchet 9/9.

Provider-management PATCH rejects patches naming only unrecognized fields,
so the field cannot be persisted through that path today; the guard belongs
in providerManagementConfigError regardless, so a future PATCH handler for
it cannot persist a value the schema load would reject and sink the whole
provider config to fallback. Also reconcile the type doc with the unset
behavior (the floor itself is sent when nothing is declared) and name the
openai-chat-only scope.

@Ingwannu Ingwannu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Scoped correctness review at 95d9a34; not a security sign-off or CI authorization. The configured floor is not enforced for native Chat ingress (inline P2). Please also document the owning configuration/Chat compatibility contract in structure/ when settling that scope. The independent auth-cors sponsorship/review gate remains outstanding; the checked self-review box does not satisfy it. No author-branch edits or live provider calls were made.

lidge-jun and others added 6 commits October 12, 2026 05:23
…kens-floor

# Conflicts:
#	scripts/test-layout/layout.json
#	tests/fixtures/test-layout-expected.json
Reuse Chat budget resolution for native streaming and buffered requests. Prefer max_completion_tokens and omit conflicting legacy caps when the floor is enabled; preserve unset behavior and caller state.

Co-authored-by: ismell0992-afk <[email protected]>
lidge-jun added a commit that referenced this pull request Oct 13, 2026
Some Azure Responses deployments reject Claude Code's tiny model-switch validation budget. Add opt-in provider setting minMaxOutputTokens for the azure / azure-openai adapter: explicit positive integer max_output_tokens below the floor are raised to it; unset providers, omitted or invalid budgets, and larger budgets are unchanged. Spend admission reserves the same effective cap at final route normalization and for each Combo target, and Combo restores the caller's ceiling for targets without a floor.

Based on #7012 by @tsruu. Supersedes #6696 by @ismell0992-afk.

Co-authored-by: tsruu <[email protected]>
Co-authored-by: ismell0992-afk <[email protected]>
@lidge-jun

Copy link
Copy Markdown
Owner

Thank you, @ismell0992-afk, and to everyone who iterated on this. The minMaxOutputTokens floor landed on dev through #7028 (squash d3d17d559a), which credits you with a Co-authored-by trailer.

#7012 and this PR solved the same problem with the same field, so we had to pick one design. #7028 takes the narrower one: opt-in, applied to the azure / azure-openai Responses adapter, raising only explicit positive caps and leaving an omitted budget omitted. This PR's Chat-side version also fills omitted budgets with the floor and reworks Chat spend re-admission across bridges, combos and Copilot Auto, which is a much larger change to the spend path than we wanted to take for this fix.

If you still need the floor on an openai-chat provider, a follow-up that reuses the same field with the explicit-caps-only semantics would be welcome. Closing this in favor of #7028. Thanks again!

@lidge-jun lidge-jun closed this Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request intake: hygiene-blocked Deterministic PR hygiene checks failed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants