Repository navigation
fix: recognize overflow markers on 5xx rejections + harden external-summary pipeline (#2484) - #2486
Conversation
…ummary pipeline (#2484) A gateway that relays an upstream context-window rejection as HTTP 5xx (e.g. 502 {"message":"Your input exceeds the context window..."}) was invisible to inspectContextOverflow, which only ever matched 400/413. The overflow shrink never armed, lastInputTokens stayed unknown, and the next turn's forward-probe fired again -> a permanent probe loop for any session whose only over-window evidence arrives on a 5xx. Five defects in this failure domain, fixed together: (1) src/util.ts inspectContextOverflow: let 5xx reach the body-pattern check (the body remains the real gate); a bare 5xx without an overflow marker is still NOT an overflow. Refold path stays 400/413-only by design. (2) src/server.ts armFailureShrink: no longer demotes an existing 'overflow-arm' to 'estimate' (new early-return) - without it the 5xx overflow arm was immediately overwritten by the generic-failure estimate, restarting the loop. (3) src/external-summary-settings.ts parseBudget: raise the totalTimeoutMs configurable CAP from 50_000ms to 600_000ms so multi-chunk folds can set a total budget above the 50s shared deadline; DEFAULT unchanged (still 50_000). (4) src/external-summary-runtime.ts: a summary candidate that cannot be built (e.g. missing credential env var) previously failed silently into one opaque placeholder; now logs warn-once with the target name + a secret-free reason, and the placeholder error names the credential ref instead of throwing an empty Error(). (5) src/preflight.ts summarizeRange: the unusable-summary detail now carries the batch stop reason + per-attempt outcomes via a new exported describeExternalSummaryFailure helper. Tests: update tests/context-overflow.test.ts (5xx-with-marker IS overflow; bare 5xx is not) and tests/external-summary-settings.test.ts (widened cap boundary); add tests/issue2484-overflow-and-summary.test.ts (proxy regression for the overflow-arm guard, warn-once plan build, diagnostic strings). Behavior changes (see PR): 5xx-with-marker now arms the overflow shrink; totalTimeoutMs cap 50s->600s (default unchanged); new warn-once log line; unusable-summary diagnostic string now dynamic.
b36ba0d to
31ddd94
Compare
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2697-pr.2486.f286b75This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2486.tgz
npm install -g packageInstall instructions are refreshed on each push. |
上游 PR 冲突已解决(rebase → force-push)收到 merge_conflict 唤醒后,我先独立核实(未盲信转发):GitHub API 确认本 PR head 已把 结构化八问
判定:冲突已清除,可合入流程恢复 —— PR 现为 |
CI 全绿,进入可合状态上一条回复里唯一挂起的事项(等新提交 CI 转绿)现已完成:head 无新冲突、无新指令——本次为重复唤醒,分支与代码未再改动。判定:PR 已具备合并条件,可交人工 review/merge。 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.183-master.337e8d0 # this exact build
npm install -g billion-context@master # always the newest merged build
|
Closes #2484
What this fixes
A gateway that relays an upstream context-window rejection as HTTP 5xx
(e.g.
502 {"message":"Your input exceeds the context window..."}) was invisible toinspectContextOverflow, which only ever matched status400/413. As a result theoverflow shrink never armed,
lastInputTokensstayed unknown, and the next turn'sforward-probe (#2313) fired again — a permanent probe loop for any session whose only
over-window evidence arrives on a 5xx. This PR fixes that loop and hardens three adjacent
silent/limit problems in the external-summary pipeline.
Five defects, one failure domain (overflow-rejection handling + external-summary):
1.
inspectContextOverflowignored 5xx rejectionssrc/util.ts— the gate wasstatus !== 400 && status !== 413 → not overflow. A 5xx withan overflow-marker body was classified "not an overflow", so no shrink was armed. Now 5xx
reach the body-pattern check (the marker remains the real gate). A bare 5xx without an
overflow marker is still not an overflow. The refold path stays 400/413-only by design
(auto-refold-retry on a 5xx is riskier than folding on the next turn).
2.
armFailureShrinkdemoted the overflow arm → loop restartedsrc/server.ts— once defect 1 arms the overflow shrink (source=overflow-arm), thegeneric 5xx handler called
armFailureShrinkwith a larger local estimate that overwrotethe source back to
estimate. With source no longeroverflow-arm,baselineFloorRawdropped to 0 and the forward-probe re-fired every turn. New early-return: a local estimate
never demotes an existing
overflow-arm(an upstream-proven ceiling must not be replaced bya local guess). Generic 5xx (no marker) failure-shrink behavior is unchanged.
3. External-summary
totalTimeoutMscap too low for big foldssrc/external-summary-settings.ts— the configurable cap was50_000ms, buttotalTimeoutMsis a true total shared deadline across all chunks of a fold. A dozenchunks × ~30s each exceeds 50s, so later chunks instantly return
deadline/cancelled.Raised the cap to
600_000ms. Default unchanged (still50_000ms).4. Unavailable summary candidate failed silently
src/external-summary-runtime.ts— when a target could not be built (e.g. its credentialenv var is unset), the
catchcollapsed everything into one opaque placeholder with anempty error message. Now it logs warn-once with the target name + a secret-free reason,
and the placeholder error names the credential ref instead of throwing
new Error().5. Unusable-summary detail dropped batch/attempts
src/preflight.ts—summarizeRangereturned one opaque string, discardingbatch.statusand
result.attempts. New exporteddescribeExternalSummaryFailure(batch)surfaces e.g.batch=cancelled result=cancelled attempts=[t0:cancelled]in the preflight logs and thefail-fast detail.
Behavior changes (old → new)
CONTEXT_OVERFLOW_PATTERNSnowarms the overflow shrink (was: only 400/413 ever checked). Bare 5xx without a marker:
unchanged (still non-overflow).
armFailureShrinkno longer overwrites anoverflow-armwith an estimate. A 5xx-with-marker keeps
source="overflow-arm"instead of being demotedto
"estimate"→ the probe loop is broken.totalTimeoutMscap:50_000ms →600_000ms (configurable upper bound only;default stays
50_000ms, so users who don't set it see no change).[external-summary] candidate <name> unavailable: <reason>atplan build (previously fully silent). Log-only, no wire change.
"configured external summary candidates failed or exceeded their budget"to a dynamicbatch=<status> result=<status> [reason=...] attempts=[...]. Affects preflight warn logsand the client-visible fail-fast detail (bounded by
safePrefix300).Config surface
Per the Configuration Surface Discipline, one field's accepted range is widened:
compress.externalSummary.budget.totalTimeoutMs50_000→600_000(default unchanged)No new key/section/field, no rename. Reused the existing
integer(...)parser with a widerbound. Considered keeping 50s and adding a separate per-chunk knob instead — rejected because
the total is what the shared deadline enforces, and widening the existing bound is the minimal
change that expresses the user's actual need.
Verification
npm run typecheckclean.context-overflow,external-summary-settings,side-request-isolation,external-summary{,-runtime,-batch,-http},and the new
issue2484-overflow-and-summary.tests/issue2484-overflow-and-summary.test.ts:session keeps
lastInputTokensSource === "overflow-arm"(the exact pre/post-fixdiscriminator — before the guard it ended up
"estimate").Human review requested — defects 1 & 2 change wire/self-heal behavior (both compression
modes) and defect 3 widens the config surface; not auto-merge eligible (§7.4).