Repository navigation
fix #401: persist bounded folded-view snapshot instead of full raw history - #587
Merged
Merged
Conversation
…story The disk record now stores prune(lastMessages, state) truncated to the newest BILI_PERSIST_TAIL_TOKENS tokens (default 16384, 0=off) instead of the client's raw full history — the raw snapshot duplicated 63.2% of the 258MB sessions corpus (#401). - persist.ts: boundedFoldedSnapshot() + messagesFolded record flag - session.ts: Session.lastMessagesFolded (cleared on next live request — the client re-sends full raw history, restoring the invariant) - export.ts: restored snapshots render as-is (re-running prune on a truncated view would resurrect dropped summaries at index 0); --full recovers folded originals from blockContents - live in-memory sessions unaffected: export of a live session stays complete; memory footprint unchanged - tests/persist-tail.test.ts: 5 tests (fold, truncation, budget 0, restore roundtrip, live-flag reset)
Contributor
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-587Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr587.tgz
npm install -g packageThis comment is automatically updated on each push. |
3 tasks
Owner
Author
[bot] 🏷 Reviewing PR #587 now. Fetched head branch |
This was referenced Sep 6, 2026
Merged
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Replaces the persisted full raw conversation snapshot (
messages: session.lastMessages) with a bounded folded-view snapshot (#401).Root cause
buildRecordpersisted the client's raw full history every save. Corpus: 494 files / 258.3 MB, of which 63.2% was the messages field — nearly all of it duplicating content already durable elsewhere (block summaries instate, originals inblockContents).Fix
src/persist.ts—boundedFoldedSnapshot():prune(lastMessages, state)(the kernel rendererbili exportuses by default — summaries in place of folded ranges) truncated to the newestBILI_PERSIST_TAIL_TOKENStokens (default16384,0= disable message persistence entirely; whole-message boundary, ≥1 survivor). Record gains amessagesFoldedflag.src/session.ts—Session.lastMessagesFolded: true whilelastMessagesis a restored pre-folded snapshot;snapshotMessages()clears it on the next live request (the client re-sends full raw history, restoring the invariant automatically).src/export.ts— restored snapshots render as-is (re-runningprune()on a truncated view would resurrect dropped summaries at index 0 — anchors whose covered ids are absent insert at 0);--fullrecovers folded originals fromblockContents(same source the v2 fallback uses). Header sayspersisted folded snapshot.Semantics after this change
--fulloriginals from blockContents)Old files migrate organically: the next save of each session rewrites its record in the new shape.
Kernel invariant discovered while testing
prune()always keeps the first user message even when fully covered (conversation anchor) — covered by an explicit test assertion.Pre-flight
npm run typecheck✓npm test— 1085/1087 (2 known env fails in plugin-agent.test.ts, pre-existing baseline) ✓npm run build✓tests/persist-tail.test.ts5/5: fold-on-persist, budget truncation, budget-0 off, restore+export roundtrip (no summary duplication), live-request flag resetCloses #401