Repository navigation
fix: avoid one-token replies when context is exhausted - #161748
jacobtomlinson wants to merge 5 commits into
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: blocked before merge. Reviewed October 2, 2026, 3:13 AM ET / 07:13 UTC (Revision 5). ClawSweeper reviewWhat this changesThe OpenAI-compatible transport rejects automatically exhausted output budgets before provider requests while preserving deliberate short caps from runtime options and model parameters, with parameter and HTTP coverage. Merge readiness⛔ Blocked before merge - 3 items remain The prior configured-short-cap finding is resolved, and no remaining actionable code defect was found. The fix remains necessary, but its broader conservative-estimate refusal policy needs maintainer acceptance. Priority: P1 Review scores
Verification
How this fits togetherThe OpenAI-compatible transport converts conversation context and model settings into provider requests. Its output-budget decision determines whether a request reaches the provider or enters existing context-overflow recovery. flowchart TD
A[Conversation and tools] --> C[Request preparation]
B[Model settings and output cap] --> C
C --> D[Estimate remaining context]
D --> E{Exhausted automatic budget?}
E -->|Yes| F[Overflow recovery or visible error]
E -->|No or deliberate short cap| G[Provider request and reply]
Decision needed
Why: The control demonstrates a real compatibility tradeoff, and the prior recorded acceptance was limited to thinking-enabled stalls. Before merge
Agent review detailsSecurityNone. PR surfaceSource +19, Tests +97. Total +116 across 3 files. 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. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep overflow handling with the existing recovery owner; prefer preserving provider-controlled compatibility by default and making conservative refusal opt-in unless maintainers explicitly accept the broader default. Do we have a high-confidence way to reproduce the issue? Yes, source establishes the current-main path: a non-reasoning proxy model with a 1000-token context and a 3200-character system prompt receives a one-token cap. This review did not execute it; the linked reports and recorded Gateway observations supply runtime context. Is this the best way to solve the issue? Unclear pending policy acceptance. The revised provenance handling is a narrow repair, but conservative default refusal can reject provider-fitting requests; preserving compatibility with an opt-in strict policy is safer for upgrades. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9af47211ed1e. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Apply the existing useful-output floor to every context-driven clamp, including non-reasoning and thinking-off requests. Keep deliberately short caps when they fit and report exhausted room as context overflow. Builds on the investigations in #161748 and #158161. Refs #161254, #105729, #158159. Co-authored-by: Jacob Tomlinson <[email protected]> Co-authored-by: Alex Mittell <[email protected]>
…67878) Apply the existing useful-output floor to every context-driven clamp, including non-reasoning and thinking-off requests. Keep deliberately short caps when they fit and report exhausted room as context overflow. Builds on the investigations in openclaw#161748 and openclaw#158161. Refs openclaw#161254, openclaw#105729, openclaw#158159. Co-authored-by: Jacob Tomlinson <[email protected]> Co-authored-by: Alex Mittell <[email protected]>
Apply the existing useful-output floor to every context-driven clamp, including non-reasoning and thinking-off requests. Keep deliberately short caps when they fit and report exhausted room as context overflow. Builds on the investigations in #161748 and #158161. Refs #161254, #105729, #158159. Co-authored-by: Jacob Tomlinson <[email protected]> Co-authored-by: Alex Mittell <[email protected]> (cherry picked from commit e05ca71)
|
Thanks for this, and for the investigation behind it. The behavior this PR targets (oversized OpenAI-compatible requests returning one-token Closing this as superseded. If you see a one-token reply or a missing overflow error on a current build, please open an issue (or reopen this) with the request details and we'll take another look. |
Closes #161254
What Problem This Solves
Fixes one-token
lengthreplies when an OpenAI-compatible request grows beyond its configured context window.User Impact
When the estimated input exhausts an automatically chosen output budget, affected sessions enter context-overflow recovery and receive a visible error instead of treating a one-word partial completion as a normal reply. Deliberately requested short completions still reach the provider, including when the conservative estimate says the budget is exhausted.
Why This Change Was Made
The transport previously forced an automatically chosen remaining output budget to at least one token even when its input estimate exhausted the window. It now raises
context_length_exceededfor zero or negative remaining budget unless the caller explicitly requested fewer than 16 output tokens through runtime options or supported model parameters (maxTokens,max_completion_tokens, ormax_tokens). Such deliberate short requests retain the shipped one-token fallback. Positive 1–15-token budgets remain usable for non-reasoning and thinking-off requests, and the existing reasoning-enabled guard still rejects automatically clamped output below 16 tokens.Conservative-estimate tradeoff
A conservative estimate can reject an automatic request that a provider tokenizer would fit. The loopback control exercises that case: the synthetic provider accepts the same prompt when a one-token cap is explicit, while the automatic request enters context-overflow recovery before provider I/O. This PR chooses visible, recoverable overflow for automatically exhausted requests to avoid silently treating a truncated one-token answer as a complete turn. Explicit short caps remain provider-controlled. Maintainer review of this compatibility choice is requested before merge.
Evidence
node scripts/run-vitest.mjs packages/ai/src/transports/openai-completions-params.test.ts packages/ai/src/transports/openai-completions-stream.integration.test.ts --maxWorkers=1(4.64 seconds for one shard, 46 tests). The loopback HTTP control took 93 ms; it observes no provider request for an automatic exhausted budget and successful one-token replies for both runtime and configured caps.chat.send, returnedagent.wait.status=errorwith a visible “Context overflow: prompt too large for the model” recovery reply, and sent zero requests to the provider; no one-token request was emitted. The temporary proof harness was removed after the run. No live external provider was used.git diff --check, and focused tests passed.