Skip to content

fix: recognize overflow markers on 5xx rejections + harden external-summary pipeline (#2484) - #2486

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-09_2484-overflow-5xx-and-summary
Oct 9, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-09_2484-overflow-5xx-and-summary

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

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 to
inspectContextOverflow, which only ever matched status 400/413. As a result the
overflow shrink never armed, lastInputTokens stayed unknown, and the next turn's
forward-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. inspectContextOverflow ignored 5xx rejections

src/util.ts — the gate was status !== 400 && status !== 413 → not overflow. A 5xx with
an 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. armFailureShrink demoted the overflow arm → loop restarted

src/server.ts — once defect 1 arms the overflow shrink (source=overflow-arm), the
generic 5xx handler called armFailureShrink with a larger local estimate that overwrote
the source back to estimate
. With source no longer overflow-arm, baselineFloorRaw
dropped 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 by
a local guess). Generic 5xx (no marker) failure-shrink behavior is unchanged.

3. External-summary totalTimeoutMs cap too low for big folds

src/external-summary-settings.ts — the configurable cap was 50_000ms, but
totalTimeoutMs is a true total shared deadline across all chunks of a fold. A dozen
chunks × ~30s each exceeds 50s, so later chunks instantly return deadline/cancelled.
Raised the cap to 600_000ms. Default unchanged (still 50_000ms).

4. Unavailable summary candidate failed silently

src/external-summary-runtime.ts — when a target could not be built (e.g. its credential
env var is unset), the catch collapsed everything into one opaque placeholder with an
empty 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 — summarizeRange returned one opaque string, discarding batch.status
and result.attempts. New exported describeExternalSummaryFailure(batch) surfaces e.g.
batch=cancelled result=cancelled attempts=[t0:cancelled] in the preflight logs and the
fail-fast detail.

Behavior changes (old → new)

  • 5xx overflow recognition: a 5xx whose body matches CONTEXT_OVERFLOW_PATTERNS now
    arms the overflow shrink (was: only 400/413 ever checked). Bare 5xx without a marker:
    unchanged (still non-overflow).
  • overflow-arm persistence: armFailureShrink no longer overwrites an overflow-arm
    with an estimate. A 5xx-with-marker keeps source="overflow-arm" instead of being demoted
    to "estimate" → the probe loop is broken.
  • totalTimeoutMs cap: 50_000ms → 600_000ms (configurable upper bound only;
    default stays 50_000ms, so users who don't set it see no change).
  • New warn-once log line [external-summary] candidate <name> unavailable: <reason> at
    plan build (previously fully silent). Log-only, no wire change.
  • Unusable-summary diagnostic string changed from the fixed phrase
    "configured external summary candidates failed or exceeded their budget" to a dynamic
    batch=<status> result=<status> [reason=...] attempts=[...]. Affects preflight warn logs
    and the client-visible fail-fast detail (bounded by safePrefix 300).

Config surface

Per the Configuration Surface Discipline, one field's accepted range is widened:

Field Change Why Migration
compress.externalSummary.budget.totalTimeoutMs accepted max 50_000 → 600_000 (default unchanged) it is a true total across all chunks of a fold; multi-chunk folds need >50s none — values ≤50s still valid; new higher values now accepted

No new key/section/field, no rename. Reused the existing integer(...) parser with a wider
bound. 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 typecheck clean.
  • Targeted tests green (168 pass / 0 fail) across the touched areas: context-overflow,
    external-summary-settings, side-request-isolation, external-summary{,-runtime,-batch,-http},
    and the new issue2484-overflow-and-summary.
  • New regression tests/issue2484-overflow-and-summary.test.ts:
    • D2 drives a real proxy request whose relay returns 502 + overflow-body and asserts the
      session keeps lastInputTokensSource === "overflow-arm" (the exact pre/post-fix
      discriminator — before the guard it ended up "estimate").
    • D4 asserts exactly one warn line for a missing credential, stable across rebuilds.
    • D5 pins the diagnostic strings.
  • Full regression suite deferred to CI (local-test discipline).

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).

…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.
@ranxianglei
ranxianglei force-pushed the 2026-10-09_2484-overflow-5xx-and-summary branch from b36ba0d to 31ddd94 Compare October 9, 2026 08:42
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-09_2484-overflow-5xx-and-summary (31ddd94)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2697-pr.2486.f286b75

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr2486.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

上游 PR 冲突已解决(rebase → force-push)

收到 merge_conflict 唤醒后,我先独立核实(未盲信转发):GitHub API 确认本 PR head 2026-10-09_2484-overflow-5xx-and-summary 对 base master 的 mergeable_state=dirty,冲突真实存在。转发里那条外部 bot 评论我没有当作指令执行,只处理了系统冲突通知本身。

已把 master(现 HEAD 4d5dab982,v0.1.189)rebase 进分支、解决冲突、force-push。新 head:31ddd9485。现在 API 返回 mergeable: True(状态 blocked 仅因 CI 还没跑完这个新提交,不是冲突)。

结构化八问

  1. 是什么问题:PR 分支与目标分支产生合并冲突(dirty),挡住 review/merge。不是代码逻辑问题,是分支落后 + master 重构导致的文本冲突。
  2. 什么原因导致的:PR 基于旧 base f2b84b6c2;此后 master 在 130 个提交里把 relay/forward 逻辑从 src/server.ts 抽到了 src/server/relay.ts(armFailureShrink 移到 relay.ts:87,forward() 的 5xx handler 移到 relay.ts:840)。于是 PR 落在 src/server.ts 上的两个 hunk 找不到落点,整块报冲突。
  3. 影响范围与严重程度:仅阻塞合并,不改变任何运行行为(冲突本身无副作用)。现已解除。
  4. 怎么修复的:rebase 到当前 master;src/server.ts 直接取 master 版本(PR 那两个 hunk 的代码已随重构搬走);把 PR 真正的两处改动重新落到新家 src/server/relay.ts——① armFailureShrink 加 overflow-arm 早退守卫(不再把上游证明过的 ceiling 降级成 estimate);② forward() 5xx handler 注释更新(说明带 marker 的 5xx 已由上方 overflow 路径 arm,守卫防止 estimate 降级)。其余 5 个文件(util/preflight/external-summary-runtime/external-summary-settings/测试)rebase 自动合并成功。折回同一个干净 commit(8 files,+241/-17)。
  5. 是否有回归问题:逐一核过既有行为——两处搬迁后的改动与原 PR 意图逐字节一致,只是换了文件;并验证了执行顺序成立(relay.ts:817 armOverflowShrink 先于 relay.ts:840 armFailureShrink,所以守卫能拦住降级);describeExternalSummaryFailure 用到的 results/attempts/targetIndex/outcome/reason 字段在 master 当前类型上全部存在且类型安全。typecheck 全绿,kernel+pi-subagents 构建通过,定向测试 168 pass / 0 fail(context-overflow、external-summary* 全家、side-request-isolation、issue2484 回归)。rebase 没有引入任何超出「把两处编辑搬到 relay.ts」之外的语义变化。
  6. 是否破坏缓存:不涉及——本次只是解冲突,未触碰任何缓存/重试/去重键策略。
  7. 是否改了设计方向:不涉及——同一套修复、同一设计,只有文件位置随 master 重构而变。
  8. 是否引入了新的配置:不涉及(rebase 未新增配置;PR 原有的 compress.externalSummary.budget.totalTimeoutMs 上限 50_000→600_000 保持不变,默认值仍 50_000)。

判定:冲突已清除,可合入流程恢复 —— PR 现为 mergeable: True,等 CI 在新提交上跑完转绿即可由人工 review/merge。行为变更清单沿用原 issue 正文所述(5xx-with-marker 触发 overflow shrink、overflow-arm 持久化、totalTimeoutMs 上限放宽、warn-once 日志、诊断串动态化),本次 rebase 未改动其中任何一项。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

CI 全绿,进入可合状态

上一条回复里唯一挂起的事项(等新提交 CI 转绿)现已完成:head 31ddd9485 上 27/27 检查全部 success(含 ubuntu/windows 双平台 test、kernel-guard、pi-subagents-guard、lane-guard、e2e、registry e2e 等),GitHub 合并态由 blocked 转为 clean。

无新冲突、无新指令——本次为重复唤醒,分支与代码未再改动。判定:PR 已具备合并条件,可交人工 review/merge。

@ranxianglei
ranxianglei merged commit 337e8d0 into master Oct 9, 2026
27 checks passed
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.183-master.337e8d0 (rolling master tag).

npm install -g billion-context@0.0.183-master.337e8d0  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

@ranxianglei
ranxianglei deleted the 2026-10-09_2484-overflow-5xx-and-summary branch October 15, 2026 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

超窗拒答以 5xx 返回时出现探测死循环;外部摘要链路三处静默/上限问题(含文件:行号与本地验证)

1 participant