Repository navigation
fix: preflight summary — name and recover thinking-budget exhaustion - #856
ranxianglei wants to merge 3 commits into
Conversation
…osis A thinking-on-by-default model spends its shared max_tokens budget on chain-of-thought before emitting any answer, so the preflight summary call returns HTTP 200 with finish_reason:"length", content:"" and a non-empty reasoning_content. diagnoseEmptySummary fell through to "the upstream returned a non-SSE body with no summary text", sending operators chasing gateways/MITM instead of the real cause (output-budget exhaustion). Add diagnoseReasoningExhaustion to detect this signature and emit an actionable message, and let diagnoseEmptySummary classify from the raw text when the caller does not supply the parsed json. Closes #853
…sts the summary output budget A thinking-on-by-default model spends its shared max_tokens budget on chain-of-thought before emitting any answer, so the preflight summary call returns HTTP 200 with finish_reason:"length" and content:"". Splitting the chunk smaller cannot recover these because the thinking overhead is per-call, so the existing smaller-chunk retry path keeps failing and preflight 502s. On that exact signature (finish_reason:length + empty content + non-empty reasoning_content) requestSummary now retries ONCE with a doubled max_tokens (8192 -> 16384) before giving up, bounded to exactly two upstream calls per range and logged as "budget-insufficient retry (#853)" for grep-ability. summaryPayload is parameterized to carry the raised cap. Refs #853
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-856Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr856.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 PR review complete — verified, one small defect fixed directly on the branch, one CI flake identified. Verified (pulled
Fixed directly (commit CI status: Two report-only findings (no action taken, your call):
Scope note confirmed: Responses-API bodies ( Once CI is green after the re-trigger, this is mergeable from my side — merging stays with you. 审查结论:PR 代码正确、diff 干净、回归测试到位;我已在分支上直接补修一个诊断误报( |
[bot] 🏷 CI update: all 7 checks now pass on head CI 更新:新 head e46552f 上全部 7 项检查通过(含此前偶发失败的 ubuntu-22 logger 测试,重跑即过),PR 已全绿可合并。 |
|
这个是最大值自己写小了又通过重试搞大,狗屁不通 |
…xianglei#853) The summary call's 8192 output cap starves reasoning-on-by-default models: reasoning_content spends the shared budget before any answer text (observed ~9.5k reasoning tokens on deepseek-flash, real ceiling 384k), guaranteeing content:"" + finish_reason:"length". - MAX_SUMMARY_OUTPUT_TOKENS 8192 -> 32768 (~3x headroom over observed) - clamp per model against known ceilings below the default, from a slim models.dev snapshot (npm run models-dev:snapshot; caps >= 32768 are omitted — they can never affect the clamp; max on cross-provider id collisions so a low claim cannot re-starve a model) - src/model-output-limits.ts: exact-id lookup with single namespace strip, same two-step resolution as the codex window lookup Supersedes ranxianglei#856 (hard-coded cap table, closed).
Fixes #853
Problem
For thinking-on-by-default models (
deepseek-flash/ DeepSeek-V4.1-Flash), the upstream writes chain-of-thought intoreasoning_contentwhilecontentis often"". Reasoning tokens share the summary request'smax_tokensbudget; once the budget is eaten by thinking, the call returns HTTP 200 withfinish_reason:"length",content:""and a non-emptyreasoning_content. bili judged "upstream returned no summary", discarded it, retried with smaller chunks (which cannot help — the thinking overhead is per-call), burned all 8 rounds and 502'd. Reported hit 4× in 2 days on 0.1.116.Two independent defects:
diagnoseEmptySummarymislabeled this as "the upstream returned a non-SSE body with no summary text" — sending operators chasing gateways/MITM instead of the real cause (output-budget exhaustion).max_tokens=8192cap regardless of chunk size.Changes
Commit 1 — accurate diagnosis. New
diagnoseReasoningExhaustion()detects the exhaustion signature (emptycontent+ non-emptyreasoning_content/finish_reason) and names the real cause: "the model spent its output budget on reasoning/thinking … this is a budget limit, not an upstream failure."diagnoseEmptySummary()now also classifies from the raw body when the parsed JSON isn't passed in.Commit 2 — bounded budget retry. On that exact signature (
finish_reason:"length"+ emptycontent+ non-emptyreasoning_content),requestSummary()now retries once with a doubledmax_tokens(8192 → 16384) before giving up — bounded to exactly two upstream calls per range, logged asbudget-insufficient retry (#853)for grep-ability.summaryPayload()is parameterized to carry the raised cap. Per the reporter's sign-off, single-call reasoning reaches ~9500 tokens (> 8192), so chunk-splitting provably cannot save these.Per the issue discussion we deliberately did not fall back to reading
reasoning_contentas the summary (it would inject CoT scratchpad into compressed blocks and degrade quality); the main loop already carries separate reasoning-truncation handling.Scope note
The retry predicate keys off the OpenAI/Anthropic
choices[]shape (the reported case). Responses-API bodies useoutput[]and are out of scope here — they'd need an analogous check if that protocol exhibits the same behavior.Verification
npm run typecheck— cleannpm test— 1652 tests, 1650 pass, 0 fail, 2 skipped (e2e-gated)tests/preflight-budget-retry.test.ts: retry-once-then-succeed (asserts the budget escalates 8192 → 16384 and the summary is applied) and stop-after-one-retry (asserts no unbounded loop when the raised budget still exhausts)tests/preflight-empty-summary.test.tsnpm run build— success; both log markers present indist/index.js