Skip to content

fix #401: persist bounded folded-view snapshot instead of full raw history - #587

Merged
ranxianglei merged 1 commit into
masterfrom
2026-09-06_persist-bounded-folded-snapshot
Sep 6, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-09-06_persist-bounded-folded-snapshot

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

Replaces the persisted full raw conversation snapshot (messages: session.lastMessages) with a bounded folded-view snapshot (#401).

Root cause

buildRecord persisted 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 in state, originals in blockContents).

Fix

  • src/persist.ts — boundedFoldedSnapshot(): prune(lastMessages, state) (the kernel renderer bili export uses by default — summaries in place of folded ranges) truncated to the newest BILI_PERSIST_TAIL_TOKENS tokens (default 16384, 0 = disable message persistence entirely; whole-message boundary, ≥1 survivor). Record gains a messagesFolded flag.
  • src/session.ts — Session.lastMessagesFolded: true while lastMessages is 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-running prune() on a truncated view would resurrect dropped summaries at index 0 — anchors whose covered ids are absent insert at 0); --full recovers folded originals from blockContents (same source the v2 fallback uses). Header says persisted folded snapshot.

Semantics after this change

before after
live session export complete complete (unchanged) — in-memory full snapshot, refreshed every request
restored session export complete folded view + newest ~16k tokens (+ --full originals from blockContents)
disk raw full history × every session folded view + bounded tail
memory unchanged unchanged

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 ✓
  • new tests/persist-tail.test.ts 5/5: fold-on-persist, budget truncation, budget-0 off, restore+export roundtrip (no summary duplication), live-request flag reset

Closes #401

…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)
@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-06_persist-bounded-folded-snapshot (3d69851)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-587

Each push to this PR publishes a new version under the pr-587 npm tag.

Option B — Download artifact

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

This comment is automatically updated on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 ework agent · qwen3.8-27b

[bot] 🏷 Reviewing PR #587 now. Fetched head branch 2026-09-06_persist-bounded-folded-snapshot (top commit 3d69851, 7 files / +305). Note: the branch is stacked on 8 commits from other open PRs (#552 compat-roles, #387/#389 acp-status, #337 soft-zone, ...) that are not in master yet — I'll verify the #401 fix itself independently of that stack (cherry-pick onto clean master + full pre-flight), then report findings.

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

Labels

None yet

Projects

None yet

1 participant