Skip to content

fix: fork adoption carries the parent's CCR content-store entries (#1341) - #1349

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-09-25_fork-store-adoption
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-09-25_fork-store-adoption

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes #1341

What & why

applyForkAdoption (src/fork-adoption.ts) seeded blocks + blockContents + messageRefs + tokenSnapshot — but not the CCR content store. The forked session ended up half-adopted: decompress worked (cached views were cloned), covered-ref spans displayed correctly (v2 covered-ref surfacing), yet every acp_retrieve(mNNNNN) on an adopted ref missed — breaking the implicit v2 promise that surfaced covered refs are retrievable.

(The store is a separate per-session companion envelope, *.content-store.json, lazily loaded — adoption simply never touched it.)

Fix

In applyForkAdoption: load the parent's store (contentStoreOf), and for every ref in the plan copy its entry + content blob into the child's store:

  • copy-on-fork — parent deep-cloned per entry, never mutated (same contract as blocks/views);
  • first write wins in the child (append-only store contract — refs never rewritten);
  • entries whose content blob is missing from the parent's byHash (corrupt envelope) are skipped, not copied as broken hits;
  • stats.storedBytes follows contentStoreStats; contentStoreDirty set only when entries actually moved (no-growth forks write nothing).

No kernel change needed — the kernel store is pure data; this was purely the host adoption scope.

Complements #1340 (kernel, PR ranxianglei/acp-kernel#433): without both, the first fold after a fork stored placeholder bytes as originals (fake hits); with #1340 alone the refs would still miss (no entries); with this PR the real parent entries are present and retrievable.

Tests

tests/fork-adoption-content-store.test.ts (new, 3):

  1. adoption carries entries + content blobs copy-identically, marks the envelope dirty, parent untouched;
  2. corrupt-envelope entry (byRef present, byHash blob gone) is skipped — misses beat broken hits;
  3. parent without a store → no dirty flag, no write.

Red on master (1 fail), green with fix. Existing tests/fork-adoption.test.ts e2e (2) unaffected.

)

applyForkAdoption seeded blocks + blockContents + messageRefs + token-
Snapshot but not the content store — the forked session showed covered-ref
spans (decompress/search worked off cloned views) while every
acp_retrieve(adopted ref) missed: a half-adopted state that breaks v2's
'these refs are retrievable' promise.

Adopt the parent's store entries for the plan's refs, copy-on-fork:
- first write wins in the child (append-only store contract);
- entries whose content blob is missing from the parent (corrupt
  envelope) are skipped — honest beats broken hits;
- storedBytes follows contentStoreStats, contentStoreDirty set only when
  entries actually moved.

Fixes #1341
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-25_fork-store-adoption (9c1cd5f)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-1349

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

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1349.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

[bot] 🏷 Review of PR #1349 — verdict: superseded by #1361; closing this one. #1361 is ready for human merge.

What I verified (pulled both heads onto current master d3c8af84, ran the full local gates + checked CI):

#1349 (9c1cd5f) #1361 (ca97d99)
CI 10/10 green 10/10 green
typecheck / build ✅ / ✅ ✅ / ✅
full suite 2649 tests, 0 fail 2651 tests, 0 fail
fork tests 5/5 (3 new + 2 existing e2e) 7/7 (5 new + 2 existing e2e)

Findings on #1349 itself:

  1. The mechanism is sound where it goes: copy-on-fork deep clone, first-write-wins in the child, corrupt-envelope entries (byRef present, byHash blob gone) skipped rather than copied as broken hits, and no-growth forks set no dirty flag / write nothing (checked against the saveContentStore dirty gate in src/persist.ts). The 3 new tests have real teeth (copy-identity, parent immutability, skip-corrupt, no-store-noop).
  2. But it seeds only part (a) — the refs covered by adopted blocks (plan.refs, built solely from adopted blocks' effectiveMessageIds). The acceptance criteria pinned in bug(ccr): fork adoption carries covered refs without adopting their content-store entries #1341 (floors 5/7) require the explicit UNION with part (b): refs cited by placeholder-shaped live incoming messages. Such a message's bytes differ from the original, so its raw id maps to no parent ref — under fix: fork adoption carries the parent's CCR content-store entries (#1341) #1349 alone, acp_retrieve on exactly those refs still misses, i.e. the reported bug class survives for that scenario.
  3. Regression audit of the touched path: adoption bail paths, block seeding, and the existing log line are unchanged; the new code is strictly additive after applyForkAdoption. No wire/message-shape change, no config-schema or persistence-format change, acp-kernel pin untouched (0.0.93), no version/lockfile churn. Diff clean (2 files, both on-topic).

Duplicate situation (why I'm closing): two open PRs for one issue (#1341) trips the one-issue-one-PR loop guard, and these are the same root cause with overlapping code regions — merging both would conflict. #1361 implements exactly the agreed union seed (covered ∪ cited), adds restart-survival and parent-append-only tests, and strictly subsumes #1349's coverage. The one edge where #1349 differs — skipping payload-less entries outright instead of copying them — has no user-visible difference: kernel retrieveByRef (acp-kernel 0.0.93) returns an honest not-found whenever the blob is missing from byHash, so a copied but payload-less entry degrades to the same miss, never a broken hit.

Actions:

中文摘要:#1349 机制正确但只种了「被采纳块覆盖的 ref」(part a),漏掉 #1341 定下的另一半(incoming 占位符消息引用的 ref),与后开的 #1361(完整并集、测试更全、代码区间包含前者)构成同一根因的重复 PR——已按重复规则关闭 #1349,#1361 本地+CI 全绿、回归审查无漂移,可交人工合并。

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(ccr): fork adoption carries covered refs without adopting their content-store entries

1 participant