Repository navigation
[PR] fix: preflight one-shot gate must not block a replaced epoch's first fold (#7545) - #7558
Conversation
…fold (#7545) The merged one-shot gate (#7546) blocks preflight whenever the session has committed folds — but committed folds belong to the epoch that produced them. When the host wholesale-replaces the history under the same session id, fold-reconcile latches the epoch confirmation (#3641) and preflight itself suspends on the same latch (src/preflight.ts); the gate must suspend with it, or the new epoch's first over-window turn is forwarded unfolded (regression: the e2e in tests/issue6069-epoch-pause-over-window.test.ts, red on all 3 test shards of #7546 after merge). - gate (src/server.ts): skip the committed-fold block while epochConfirmPending(session) — the new epoch gets its own one-shot - re-arm (src/fold-reconcile.ts): an aborted attempt on the REPLACED epoch must not starve the new one — clear preflightRuns at the latch site (successful folds never set the latch, so the one-shot still holds within any single epoch) - test: case E in preflight-one-shot-gate (old epoch folds -> 3 replacement passes latch -> grown turn folds again -> next over-window turn blocked: the exception is scoped to the latch window)
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.11474-pr.7558.dd12eedThis exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr7558.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 Review of PR #7558 — follow-up to #7546, closes #7545 I independently reproduced the bug, reviewed the diff, and ran the targeted suites. Verdict: mergeable. Bug is real (reproduced on pre-fix). Checked out the PR's parent (9ad612e = #7546 merge) and ran Fix is correct and scoped. Two coordinated changes:
The exception is correctly scoped to the latch window: once the new fold commits and the latch clears on the first clean pass, the gate blocks again on the fresh committed count. Case E's final assertion pins this (the new epoch's one-shot is still ONE shot). No regression for non-replaced sessions. The change only alters behavior while the latch is pending (a confirmed wholesale replacement — 3 consecutive drift passes, no anchor match). Cases B/B2/C (managed session NOT replaced, aborted attempt) all pass unchanged. The #7545 livelock fix (abort → no retry; managed → no re-fold) is preserved. Verification (targeted, local):
Minor observations (non-blocking, pre-existing):
结构化八问(中文):
判定:可合。 单模块修复、回归测试复现原 bug 且现过、CI 全绿、不触碰 kernel/update/wire/config/持久化。建议 owner 合并。 |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.1281-master.73844f5 # this exact build
npm install -g billion-context@master # always the newest merged build
|
…ght epoch-exception fix The branch was cut from 9ad612e, before the ranxianglei#7558 fix (434bf68) landed on master. The e2e in tests/issue6069-epoch-pause-over-window.test.ts went red on all 3 test shards (windows 22/4, ubuntu 22/2, ubuntu 24/2) because the branch carried the ranxianglei#7546 one-shot gate without the ranxianglei#7558 epoch-exception fix. This merge brings in the fix; the contributor's commit is unchanged and the PR diff still shows only that commit.
…lict, round 7) Master moved 0b68ade -> 15f06c6 (kernel 0.0.205, +preflight emergency-digest default-off #7549, +preflight 413 passthrough #7548, +sessions reattach #7512, +opencode user-fork detection #5511, +acp-status uncompressed nudge-align #7536, +preflight gate epoch exception #7558, +413 egress fuse pins #7488, +Korean README #7551, +many host/test changes). Conflicts: 3 version-only files (kernel/package.json, kernel/package-lock.json, root package-lock.json). Resolved to kernel 0.0.206 (merged kernel = superset of master's 0.0.205 + PR #6720/#6762 changes; kernel/src changed vs master => must bump above master's 0.0.205). Auto-merged clean: kernel/src/compress.ts (PR markers 13x + master changes), src/stream.ts (PR markers 3x), src/server.ts, master's new test files, docs. Local verification: typecheck ✓, build ✓, kernel 1671 pass / 0 fail, host nudge/receipt 7 pass / 0 fail, kernel-guard ✓ (SRC_CHANGED=2 BUMPED=1 0.0.205->0.0.206), version-guard ✓ (root 0.1.216 untouched), lock-sync ✓.
The 3 red shards (ubuntu-22/1, ubuntu-24/1, windows-22/1) all fail the same inherited master-level test (e2e #6069, tests/issue6069-epoch-pause- over-window.test.ts:231) — the #7546 one-shot-gate regression of the #6069 contract. That fix landed on master via PR #7558 (73844f5). Re-merging master brings it in; no branch-side code change. Verified locally: #6069 suite 3/3 green, PR's own suites 27/27 green, typecheck clean.
Follow-up to #7546 (merged 2026-11-22, commit 9ad612e). Post-merge CI went red on all 3 test shards (ubuntu-24/1, ubuntu-22/1, windows-22/2) on the same test:
e2e #6069: history replaced under the same session id, then grown past the window: the turn is folded and forwarded(tests/issue6069-epoch-pause-over-window.test.ts:231, 'preflight summarized the new history' — expected true, actual false). Not one of the two declared pre-existing failures.Root cause
The one-shot gate blocks preflight whenever the session has committed folds (
compressionCount > 0) — but committed folds belong to the epoch that produced them. When the host wholesale-replaces the history under the same session id, fold-reconcile latches the epoch confirmation (#3641,foldEpochConfirmPending) and preflight itself suspends on that same latch (src/preflight.ts:1873: fits → verbatim pause, over-window → fold anyway). The gate did not read the latch, so the new epoch's first over-window turn was blocked on the REPLACED epoch's committed count and forwarded unfolded — the exact #6069 contract ("the paused preflight folds once the payload exceeds the window") regressed.Empirical trace (pre-merge baseline, instrumented): old 24-msg history folds (5 blocks) → unrelated 12-msg history resent 3× → old blocks deactivated, drift streak 3 → latch set → new history grows over-window → gate (merged code) blocks on
compressionCount>0→ no summary → assertion fails. With the fix: the gate sees the pending latch, the new epoch's one-shot fires, the fold commits, the in-request re-prepare reconcile clears the latch on the first clean pass, and the gate blocks again on the fresh committed count.Changes
epochConfirmPending(session)— the new epoch gets its own one-shot attempt. ThepreflightRuns(spent-attempt) branch is NOT epoch-exempted here; it is re-armed at the latch site instead, so an aborted attempt on the new epoch still kills its retry (livelock protection holds per-epoch).if (session.stats) delete session.stats.preflightRuns;— an aborted attempt on the REPLACED epoch must not starve the new one. Successful folds never set the latch, so the one-shot still holds within any single epoch. (Runtime guard: unit-test session fixtures omitstats.)Behavior change (disclosed)
Preflight one-shot gate: old (post-#7546) — a session with any committed fold is blocked from proxy-side preflight folding for the rest of its lifecycle, including after a wholesale history replacement under the same session id. new — while the #3641 epoch-confirm latch is pending (replacement confirmed, old substrate suspended), the committed-fold block is suspended and the new epoch gets its own single attempt; once the new fold commits and the latch clears on the first clean pass, the gate blocks again on the fresh committed count. The livelock fix for #7545 (abort → no retry; managed session → no re-fold) is unchanged for non-replaced sessions.
Verification (targeted, local)
preflight skips fully covered raw chunks…) fails identically on pristine master (pre-existing, declared in [PR] Add a one-time gate to preflight collapse-before-forwarding: only triggers on first use for new conversations / old sess | preflight 转发前折叠加一次性门槛:只对新对话/未用过 bili 的老会话首次触发,掐断死循环从机制上不可能 (#7545) #7546)Closes #7545