Repository navigation
[PR] feat(#2773): persist last-settled seam slot so the first post-restart request keeps body-stability attribution - #2790
ranxianglei wants to merge 2 commits into
Conversation
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.3073-pr.2790.ca32178This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2790.tgz
npm install -g packageInstall instructions are refreshed on each push. |
… request keeps body-stability attribution
…ata field The four render goldens pin digests of persisted state. This feature intentionally adds CacheLedger.seamSlot to session.metadata, so the metadata section digest moves. Per-wire diff is exactly two lines (stateDigest + sectionDigests.metadata); state/blockContents/stats sections and all wire-body shas are byte-identical. Determinism holds because src/storage/canonical.ts normalizes ms-epoch numbers to __TS__, pinning the slot's at field structurally.
94f17af to
ad02720
Compare
收到,这是我自己先前开的 PR(#2773 的修复)。按 [PR] 处理规范:拉分支核对代码 + 查 CI + 报结论,不重做。先说本轮唤醒直接面对的 CI 事件,再给八问。 CI 事件(已定位、已修复):首轮 CI 有 4 个 结构化八问:
行为变更披露(必须明示):① 首个 post-restart ledger 行: 判定:代码逻辑与 CI 修复均正确、已逐项核对;等最后 4 个单测 job 转绿即可由你合并(PR: https://github.com/ranxianglei/billion-context/pull/2790,分支现 tip |
✅ CI 全绿确认:分支 tip 结论不变:代码逻辑与 golden 修复均正确、已逐项核对,无回归。可以合并了(我不代合)——#2790 补充一句诚实标注:rebase + |
Closes #2773
What. The last-settled seam slot (the pairing source for
bs/bl/beon ledger lines) lives in a module-levelWeakMapand dies with the process: after a restart the first request of each session loses its #2131 body-stability attribution entirely. This persists the slot with the session and rehydrates it on load, per the fix direction proposed in the issue.How.
CacheLedger.seamSlot?— a capped-head projection{v:1, at, digest, msgs, str}of the last-settled slot, written at the point where the slot rolls intoseamLastSettledinsidesettleUsageReport.stris the head clipped atSEAM_BODY_CAP(≤512 KiB). The ≤8 MiBfullpayload is deliberately NOT persisted (per-turn state-file rewrite cost); when the pre-restart body exceeded the cap, classification degrades tobs:"unknown"rather than guessing (a capped head can produce a fake "append" if the tail diverged).rehydrateSeamSlot(session)(src/cache-ledger.ts) seeds the liveseamLastSettledWeakMap from the projection once per loaded Session object; called frompersist.buildSession, which is the single choke point for every disk-load path — boot/loadSync/web-detail, and both storage engines (the unified view also reconstructs viaviewToRecord → buildSession).SEAM_SLOT_RESTART_WINDOW_MS(30 min, hardcoded constant — precedent:WARM_HIT_PCT, learned-image-cost TTL) is refused at load. Rationale: crash/auto-update restarts take seconds–minutes (pairing still valid); beyond that the upstream cache is certainly cold and host-side volatile content may have drifted, so pairing would manufacture a false seam. On refusal the old behavior (fields absent) holds until the next settle overwrites the projection.be/bl/bsblock derivesprevBody = prevSlot.full ?? (str under cap ? str : null). Live-mode behavior is byte-identical to before (a live slot withfull:nullnecessarily had a capped str ⇒ same"unknown"outcome); the rehydrated case is the only new path. Boundary nuance: a body of exactlySEAM_BODY_CAPbytes degrades conservatively to"unknown"— it never misclassifies.Behavior change (old→new). First post-restart ledger line:
bdwas always present,be/bl/bsalways absent → now populated when a valid fresh (<30 min) projection exists. Additive forensics only — no wire or client-visible change. Detector scope intentionally unchanged:detectSeamstill early-returns forrs===1lines (separate mechanism per the issue text; left as an owner decision).#2690 (unified storage) status — updated post-rebase. #2690 merged to master while this PR was in flight (eacbb58). Re-evaluated against the merged code: the slot stays INLINE in
session.metadata. The ledger itself already lives there on every storage path (legacy JSON record and unified view→record), so a ≤512 KiB field rides the same record with zero extra I/O; the CAS store (src/storage) dedupes large block contents and is the wrong tool for a small structured field. Verified the unified load path goes throughbuildSession, so rehydration applies in shadow/full modes too. The four CI golden failures from the first push were exactly this interaction (see below) and are now fixed.Golden regeneration (required by tests/golden-storage-render.test.ts). The render goldens pin digests of persisted state; this feature intentionally adds
seamSlottosession.metadata, so the metadata section digest moves. Reviewed hunk-by-hunk: per wire file exactly two lines changed (stateDigest+sectionDigests.metadata); thestate/blockContents/statssections and all wire-body shas are byte-identical. Determinism holds becausesrc/storage/canonical.tsnormalizes ms-epoch numbers to__TS__, pinning the slot'satfield structurally (verified empirically: two consecutive regenerations are byte-identical). Regenerated vianode --import tsx scripts/update-storage-render-goldens.tsas its own labeled commit.No new dirty marks. The projection lives on the ledger object and rides the ledger's own debounced save — same bounded partial-loss window (crash within the 500 ms debounce interval) as any other ledger mutation; no extra save traffic.
Fork flow unaffected. Child sessions get fresh metadata plus the whitelist copy only (plugin.ts), so no cross-fork pairing is possible.
Tests. New
tests/issue2773-seam-slot-restart.test.ts(11 cases): projection shape at settle;be=1identical resend across restart;bs=mid(the edge case named in the issue — a genuine mid-history rewrite landing exactly on the first post-restart request, with exactbloffset),bs=head,bs=append; stale-slot refusal and the window boundary; capped-prev degradation to"unknown"(no fake append); malformed-projection rejection without crash; once-per-object; end-to-end through the real SessionStore (writeNow → loadSync → settle). Targeted blast radius green on the rebased head: 251 tests across the cache-ledger/seam set, persist set, and storage set (unified/engine-proofs/replicas/review-fixes/mode-label/corpus/pins + golden-storage-render) — 250 pass / 0 fail / 1 skip; typecheck clean; unused-export gate clean; build OK. Full regression deferred to CI per local-test discipline.Rebased onto master @ e7b94a2 (post #2690/#2772/#2788); no conflicts.