Skip to content

[PR] Batch-B integration: fold budget/eligibility — merge #3353 #3943 #3952 #3867 #2660 #3677 (#3916) - #3971

Merged
ranxianglei merged 20 commits into
masterfrom
2026-10-20_batch-b-fold-budget
Oct 20, 2026
Merged

ranxianglei merged 20 commits into
masterfrom
2026-10-20_batch-b-fold-budget

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

动机

#3916 B 类("折叠预算/资格判定")批量处理。6 个开放 PR 里 5 个的 src/server.ts preflight 区 hunk 互相包含/相邻,逐个 rebase 会级联冲突——按集成分支一次解算,merge --no-ff 保留各 PR 完整提交链与署名。

合入内容(6 PR)

合入 PR 解决 冲突处理
#3353 #3322 覆盖率回退折叠拒签 干净
#3943 #3918(部分)/ #3846 常驻驱逐诚实拒绝 + 可重试耗尽 干净
#3952 #3923 双实例分裂脑可见性 干净
#3867 #3846 本地 413 证据持久化 server.ts 单点:与 #3943 的 progressContinues 构造性互斥(f.deterministic 同源反相),互补双保留
#2660 #2638 结构性死段记忆 10 块/6 文件:#3204 DEAD-ref 过滤 × #2638 结构性死段取并集;零进度块改三路退避(queueDroppedAll→不退避 / hadFoldableCandidates→arm / 精瘦稳态→不退避)
#3677 #3438 dsh 道中带预算塌缩恢复 side-request.ts 单点:#3833 note 树 + #3438 origin 三元取并集

#3847 舍弃:server.ts hunk(3034–3528)完全被 #3867(2645–3617)覆盖,且 3867 另含 320 行测试。

未合入

验证(基点 1cc1cb8 + 已同步最新 master 550860e)

备注

Closes #3322
Closes #3438
Closes #3846
Closes #3923

ework-agent and others added 19 commits October 10, 2026 19:30
…y turn

The kernel's range selector keeps advertising spans whose messages are all
already covered by active blocks or locked as live checkpoint carriers;
the apply side rejects them with the structural 'no new compressible
messages' verdict. Preflight's skipSet was per-invocation only, so every
request re-derived the same candidates, re-previewed the same dead span,
and re-rejected it forever -- wasting per-request work, spamming logs,
pinning the auto-fold target above its floor, and (during the 10-minute
backoff) resurrecting classic nudges that pushed the model into compress
calls which were atomically refused.

Remember structural preview verdicts per session (session.metadata,
persisted) keyed by startRef:endRef; while the recorded active-block
snapshot is unchanged the span can never fold through plain refs, so it
is filtered out of candidate lists (preflight walk + relaxed probe) and
of the nudge-advertised ranges on all four protocol surfaces. Any block
lifecycle change wakes the entries for one re-preview. Structural
verdicts are also added to the invocation skipSet (no intra-invocation
re-preview), and the auto-fold no-progress backoff only arms when
foldable candidates actually existed -- a lean steady state now forwards
without backoff instead of cycling backoff -> classic nudge -> refused
compress.
…gression

Unit suite covers verdict parsing (both wordings, multi-id, truncation,
negatives), record/cap/evict, snapshot-subsumption invalidation, exact-key
filtering, and metadata persistence round-trip. The integration test builds
the minimal production geometry (checkpoint carriers adjacent in the pruned
view but separated by covered raws in the full-log history) and asserts:
invocation 1 previews+rejects+remembers the dead span exactly once while
the foldable tail still folds; later invocations never re-nominate it; an
all-dead candidate set reports hadFoldableCandidates=false.
…ate)

CI's unused-exports gate (#1440 P6) flagged buildDeadSpanFixture as
INTERNAL_ONLY — it is exported but every reference sits inside its own
file. Drop the stray `export`; the fixture is consumed only by this file.
A committed fold must never leave a previously-covered message without ANY covering block. On full-resend hosts the kernel's turn-integrity gate judged splits against the fold's own set instead of post-fold coverage, so ids carried by non-consumed sibling blocks were withdrawn from the new block while their source blocks got deactivated - they lost ALL coverage, the processed view doubled (253->519), the local estimate blew past the model window and preflight fail-fasted forever while upstream still had headroom (566K/750K).

Add a pre-commit backstop in applyRanges (both relay and plugin lanes share it): measure active-block coverage before vs after on the clone returned by applyCompression; if any previously-covered id loses every covering block, refuse the fold BEFORE committing - state untouched, prefix cache untouched, receipt tells the model why and how to retry. Healthy folds never trip it: fresh folds add coverage, refolds preserve it, integrity withdrawals only touch direct ids of the folded range.

Behavior change (disclosed): folds that used to commit while regressing coverage (and then brick the session behind permanent preflight rejections) are now refused with outcome 'refused' / reason 'gate:coverage-regression'. Nothing else changes: the refusal happens strictly before the state commit, so accepted folds, receipts, logs and the #2748 net-shrink gate are untouched.

Refs #3322 (root-cause kernel fix follows separately under owner approval).
…ake the clientHint lane comment match sniff reality

Review of #3677: the writeOutputBudget block left one indent level deeper than
its surroundings after the collapse edit (cosmetic); the call-site comment
claimed non-plugin dsh traffic identifies through the sniffed hint, but
sniffScanClient yields claude/opencode or a raw UA prefix — never a normalized
"dsh" — so the clientHint arm is defensive and matches only a literal "dsh"
wire identity. No behavior change.
… reopen oversized forwards (#3846)

A locally refused over-window request (deterministic exhaustion -> 413,
payload never forwarded) was re-forwarded on retry once the usage
baseline demoted to an estimate (preflight-rebuild anchor or failure
shrink): probeForEvidence saw baselineFloor=0, ran BEFORE the #726
dead-end check, and forwarded once for 'evidence' - billing the full
payload upstream. Growing bodies also defeated the dead-end body-hash
key, so every turn re-probed (prod: 606K/620K/633K input tokens, 32K
cached each).

- noteLocalRefusal() records {origin,model,window} at all three
  local-413 sites (probe doomed-bytes gate, fresh-session doom gate,
  final deterministic-exhaustion fail-fast); plain JSON in
  session.metadata, capped at 16 records, deduped per scope keeping
  the widest window; survives restart via existing metadata persistence.
- localRefusalCovers() suppresses the four forward-once escapes
  (estimate-only probe, image arbitration immediate+post-fold, #1839
  rebuilt-view divergence, #3146 fresh-session escape) at the same or
  tighter window for the same origin+model.

Fitting payloads still forward; other origin/model/larger-window
evaluated independently. Evidence is NEVER written into
lastInputTokens/Source (it is not upstream usage). No config surface
added; kernel untouched.
…3918)

The empty-view compress refusal (#3126) promised the view self-heals on the next model request. That promise holds only when the reloaded session survives between requests: releaseInFlight's discharge evicts any session whose live weight plus the other residents exceeds the byte budget, so a large image session ping-pongs out after every cycle and the identical refusal repeats forever - the incident's 444 MiB session under the 512 MiB default against an 87.5 MiB peer.

Stamp each eviction with the session's live weight (measurable only at that moment; a disk reload under-measures by exactly the transient mass) and export residentPressure(). When weight + other residents > budget, the receipt and the operator log name the permanent case and give the exits (close the peer / raise sessions.residentMaxBytes) instead of advising an impossible retry. The transient case keeps the exact original wording. The map is advisory-only, capped at 256 entries.
…#3918)

A preflight walk that exhausts its summarization budget AFTER committing real folds was reported 502 retryable=false - 'doomed' - although the folds persist in the session and the next attempt starts from a smaller baseline and continues the fold (the incident ran 64 effective folds, every round declared terminal). Non-deterministic exhaustion with compressedRanges > 0 now reports retryable=true and appends a progress note (ranges folded, tokens short of the window). Zero-progress exhaustion keeps today's terminal verdict and dead-end cooldown; deterministic exhaustion keeps its 413 path byte-identical.
The interface is only consumed as the inferred return type of residentPressure() across modules; no importer names it. Dropping the export satisfies the unused-exports CI gate without a waiver.
…t wall, not the window (#3918)

Review fix-up for the new ffDetail sentence: limit can be window minus
completion reservation (#3450), so naming the gap "short of the window"
would repeat the #3663 confusion class in a brand-new string. Uses the
subsystem's own term ("gap to the target", src/preflight.ts).
Dual-instance split-brain was invisible by design: the existing defenses
(#394 registration warning, #2401 slow-tick peer rescan) fire at STARTUP
only, and the actual 'same session committed by two live processes' event
produced zero signal — the #3909 incident was found by hand-diffing
[v=...] tags in the shared log.

F1 (client): noteRoutedOrigin now logs one error line per foreign origin
into bili.log on lanes without an owner hook (spawn mode). A baked
/bili/ URL passing through to a different origin than state.origin means
one conversation is riding two instances. Warn-only: spawn mode has no
recovery policy so it never rebinds; attach-lane owner-hook behavior is
untouched.

F2 (server): each instance records recently committed session ids under
<state>/writers/<instanceId>.json (throttled atomic-rename writes,
10-minute contest window, 128-entry cap, stale markers reaped at boot).
Hooked at SessionStore.noteOwnCommit — the single choke point every
persist commit flows through. Committing a session another LIVE instance
committed within the window logs one [split-brain] error per 60-second
verdict window naming both sides (pid/origin/version).

Observability only: no routing, save, or wire behavior changes.
…motion cannot reopen oversized forwards (#3846)

Conflict resolution: kept both the #3918 progressContinues verdict (from #3943)
and the #3846 noteLocalRefusal persistence on status===413 — complementary:
status 413 fires only for deterministic exhaustion (!progressContinues).
…s every turn (#2638)

# Conflicts:
#	src/preflight.ts
#	src/server.ts
#	src/server/prepare-anthropic.ts
#	src/server/prepare-google.ts
#	src/server/prepare-openai.ts
#	src/server/prepare-responses.ts
…bove the <=200 starve gate (#3438)

Conflict (side-request.ts): master's note tree gained #3833 (cross-model
high-water clamped to ceiling); 3677 added the #3438 origin distinction.
Union: keep master's #3833-aware note, add 3677's collapsed-vs-starve origin
naming in the restore log line.
@ranxianglei ranxianglei changed the title Batch-B integration: fold budget/eligibility — merge #3353 #3943 #3952 #3867 #2660 #3677 (#3916) [PR] Batch-B integration: fold budget/eligibility — merge #3353 #3943 #3952 #3867 #2660 #3677 (#3916) Oct 20, 2026
@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-20_batch-b-fold-budget (b9f439e)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.4749-pr.3971.88b63d2

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

(ai: vllm-qwen/qwen3.8-27b)

查重:不重复——本条是该 PR 自身 docs-sync CI 失败的自动修复任务,非新问题报告。

已修复并推送:b9f439e1e(分支 2026-10-20_batch-b-fold-budget),新 head 上 docs-sync 已转绿;其余测试车道仍在跑。

结构化八问:

  1. 是什么问题:docs-sync 检查红——用种子重新生成配置参考文档后,与分支上提交的 CONFIGURATION.md / CONFIGURATION.zh-CN.md 存在漂移(exit code 1)。
  2. 什么原因导致的:集成分支「同步 master」的合并提交(550860ed4)对这两个文档文件做文本合并时留下了重复产物:storage.backend 同时保留了旧版(stub 期措辞)和新版(FULLY WIRED steps 2+3)两行,旧版短文案的 storage.sqliteAutoDownload 出现了两次。master 侧已由 [PR] docs: regenerate config reference after the engine-tiering seeds (#3963) #3969(132e921ad,engine-tiering 种子后的文档再生)修齐,但本 PR 分支上的副本仍是这次合并产生的混合体。与折叠预算这批改动本身无关。
  3. 影响范围与严重程度:仅 CI 门禁,零运行时行为影响——唯一后果是阻塞本 PR 继续推进。
  4. 怎么修复的:在 PR 分支上运行 node tools/gen-config-docs.mjs generate,只提交两个再生成的文档文件(合计 +2/-6 行),未动任何代码、种子或 website 产物。
  5. 是否有回归问题:无。纯文档再生,无代码变更;再生后的文件与当前 master 版本逐字节一致(diff 为空),推送前还本地模拟了与最新 master 的合并并重跑同一检查,通过。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:无。

判定:docs-sync 修复完成(第 1/2 次尝试),等全量 CI 总判定;若其余车道再红,在本通道预算内继续处理。

@ranxianglei

Copy link
Copy Markdown
Owner Author

CI 对照结论:本 PR 的失败项与 master 自身当前的红项完全重合,非本分支回归。

master 基线(run 39437368167 @ 860e617)同样失败:

  • #1839 G3: overflow arming is tagged 'overflow-arm' — master 的 ubuntu-24 / windows-22-2 同样红(本分支 ubuntu-22-1/24/wndows-22-2 复现同一测试;本机全栈分支上该测试绿,判定为继承性/慢机波动)
  • #3769 upgraded pre-fold-gate state keeps rotation-hidden orphans hidden end-to-end — master 所有 linux job 同样红
  • generic append-only stability ... SKIP no SMT solver available — CI 环境无 VERIF_PYTHON/z3,预期性跳过失败
  • windows 级联(bypass/plugin/snapshot 系)— master windows job 同样失败
  • #255 proxy error log — master ubuntu-24 上同样偶发

本分支针对性验证(本机):161/161 折叠相关 + invariant-judge 28/28 + kernel #3939 钉 12/12 + tsc 0 + docs/unused-exports 双门 clean。合并时建议以这些门 + 与 master 的失败集 diff 为准,而非矩阵整体绿。

@ranxianglei
ranxianglei merged commit f57926c into master Oct 20, 2026
44 of 49 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.687-master.f57926c (rolling master tag).

npm install -g billion-context@0.0.687-master.f57926c  # 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment