Repository navigation
fix(ai): clamp OpenAI Responses max_output_tokens to model capacity - #128282
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR caps OpenAI and Azure Responses output budgets at the selected model’s known capacity using the existing shared helper. Example: An agent requests 256 output tokens from a model with a declared capacity of 128.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it repairs a current Responses request bug, preserves the established unknown-capacity behavior, and has sufficient runtime evidence; no actionable patch defects remain. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherManaged transports and direct provider adapters combine caller output budgets with model metadata to construct requests sent to OpenAI or Azure Responses endpoints. flowchart TD
A[Caller output budget] --> C[Responses request owners]
B[Model catalog capacity] --> C
C --> D[Shared token clamp]
D --> E[Responses HTTP request]
E --> F[OpenAI or Azure endpoint]
Technical reviewBest possible solution: Land the shared-helper repair at both existing Responses request owners after the normal exact-head gates pass. Do we have a high-confidence way to reproduce the issue? Current-main source forwards 256 tokens for a model capped at 128, and the supplied CLI trace confirms the resulting rejection; this read-only review executed no target code. Is this the best way to solve the issue? Reusing the existing clamp at both request owners fixes the defect without caller workarounds while preserving unknown-capacity requests and managed fallback semantics. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 46053391a1ad. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +2, Tests +47. Total +49 across 3 files. Added test files: 1. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (10 earlier review cycles; latest 8 shown)
Reviewed October 13, 2026, 8:44 PM ET / October 14, 2026, 00:44 UTC (Revision 11). |
buildOpenAIResponsesParams published an authored request maxTokens unchanged even above the selected model's declared output capacity, while sibling Anthropic and OpenAI Completions transports clamp request-scoped caps (openclaw#127560). A valid agents.defaults.params.maxTokens or per-model/per-agent/run override could make strict endpoints reject every normal turn and compaction with a deterministic 400, and a global override could poison fallback candidates independently. Clamp at the canonical request boundary with the existing clampMaxTokensToModel helper, preserving current zero/undefined fallback semantics. The model catalog's maxTokens remains the capacity owner. Covers both OpenAI Responses and Azure Responses, which share this builder; Codex Responses continues stripping the field downstream. Closes openclaw#127560 AI-assisted (Claude); clamp regression tests fail pre-fix and pass post-fix.
1f2a167 to
938ed62
Compare
applyCommonResponsesParams floored authored maxTokens at 16 but never bounded it by the model catalog capacity, so default simple OpenAI and Azure Responses completions (reachable from plugin LLM completion without a managed transport requirement) could still send oversized max_output_tokens to strict endpoints. Clamp at the shared simple-path owner with the model cap as the authoritative upper bound while preserving the established 16-token minimum. Covers the ClawSweeper finding on openclaw#128282: managed and simple Responses routes now share the same capacity boundary.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed in f05fac4. Thanks @Parker-Fawcett! Verified with a built CLI: an over-limit maxTokens is now capped at the model's limit instead of failing the turn. |
…penclaw#128282) fix(openai): cap Responses max_output_tokens at the model's output limit The OpenAI Responses request builder forwarded a configured maxTokens even when it was above the selected model's output limit, so strict endpoints rejected otherwise valid turns with HTTP 400. The builder now caps the value at the model's maxTokens. In-range values are unchanged. Proof: built CLI against a recording Responses endpoint that rejects budgets above a 128-token model cap, with maxTokens configured to 256. On main the request sent 256 and failed with 400; with this change it sends 128 and completes. A 64-token control is unchanged, and a live openai/gpt-5.4-mini turn completes. Thanks @Parker-Fawcett. Co-authored-by: Ayaan Zaidi <[email protected]>
…128282) fix(openai): cap Responses max_output_tokens at the model's output limit The OpenAI Responses request builder forwarded a configured maxTokens even when it was above the selected model's output limit, so strict endpoints rejected otherwise valid turns with HTTP 400. The builder now caps the value at the model's maxTokens. In-range values are unchanged. Proof: built CLI against a recording Responses endpoint that rejects budgets above a 128-token model cap, with maxTokens configured to 256. On main the request sent 256 and failed with 400; with this change it sends 128 and completes. A 64-token control is unchanged, and a live openai/gpt-5.4-mini turn completes. Thanks @Parker-Fawcett. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit f05fac4)
Backport openclaw#128282 across both OpenAI Responses request owners. Co-authored-by: RomneyDa <[email protected]>
Closes #127560
What Problem This Solves
An explicitly configured output budget larger than the selected model's catalog capacity reaches strict Responses endpoints unchanged. They reject an otherwise valid agent turn with HTTP 400.
Why This Change Was Made
Both Responses request owners now reuse
clampMaxTokensToModelafter applying the existing 16-token minimum. This preserves explicit limits when custom-model capacity is unknown, fixes the previous simple-path NaN regression, and retains managed zero/undefined fallback behavior. No caller-side workaround or new configuration is introduced.Ported @Parker-Fawcett's contributor commits onto current request construction; thanks to the contributor and the reporter of #127560. Consolidated coverage around the two actual request owners instead of duplicating provider cases. No overlap with Pash/Sarah changes.
User Impact
Oversized budgets are capped at the model's declared output capacity. In-range budgets and unknown-capacity explicit budgets are unchanged. OpenAI and Azure Responses share these owners. Existing Codex unsupported-field stripping is unchanged.
Evidence
Built current main (
653003a010987ad75393bdd0ff067283f41a1be7) and candidate in a secretless Node 24 Docker container. Drove the shippedopenclaw --profile <isolated-profile> agent --local --agent main --message ... --thinking off --jsonentry point with anopenai-responsesprovider and an actual local HTTP recording endpoint. The endpoint rejects output budgets above the model's configured catalog capacity of 128 and otherwise returns a normal Responses SSE completion.Captured results:
Focused regression: pre-fix oversized case fails (
expected 256 to be 128); candidate's three selected suites pass (76 tests). Cases protect the upper cap, unchanged in-range budget, 16-token floor, unknown capacity, and managed zero/undefined fallback. Changed-file oxfmt and oxlint pass.Production +4/-2 (net +2: imports for the existing helper); tests +47/-0 against the merge base. No docs/configuration contract changes; changelog remains release-owned. Final revision only corrects the unknown-capacity test fixture typing; the six regression cases pass again and production/runtime proof inputs are unchanged.
Authenticated live gate on the same candidate:
openai/gpt-5.4-mini, requestedmax_output_tokens=128, CLI exit 0, final answerLIVE_OK. Credentials stayed in a temporary host-only 0600 file behind a request-forwarding proxy and were deleted afterward; none entered the container. The first proxy setup was blocked by the private-network guard; explicitly allowing this operator-controlled test endpoint fixed the setup, without product changes.Two-way door: a revert fully restores prior request shaping; no persisted-state or schema changes. Blast radius is output-budget shaping for OpenAI-compatible and Azure Responses requests.