Skip to content

fix: adopt parent CCR content store on anonymous fork adoption (#1340) - #1355

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

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

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes #1340

What

Fork/adoption (src/fork-adoption.ts) cloned blocks, blockContents and messageRefs from the parent but NOT the CCR content store (*.content-store.json companion envelope). A forked child of an armed parent therefore started with an EMPTY store while its history still carried [acp-stored #mNNNNN ...] placeholders and covered-ref spans — every acp_retrieve on an adopted ref missed, and with the pinned kernel\u2019s too-narrow placeholder guard (acp-kernel#432) the first post-fork fold stored placeholder text as "originals", converting honest misses into invisible fake hits.

How

  • New pure planForkStoreAdoption(store, reachableIds): ref-filters the parent\u2019s store to entries whose frozen rawId alias is in the reachable set, clones each entry independently (copy-on-fork; the parent envelope is never shared or mutated), trims byHash to exactly the referenced payloads; returns null when nothing survives so a CCR-less parent creates no artifact.
  • Reachable set = incoming request ids \u222a every id covered by an adopted block. Under the current adoptability gate the second term is implied by the first (a block is only adopted when ALL its covered ids are incoming); coverage follows the VIEW rather than the gate, so a future loosened gate cannot silently re-open the miss class (per review feedback from @BsoBird).
  • maybeAdoptForkBlocks adopts the result through the existing adoptContentStore (stats merge + contentStoreDirty flag \u2192 the fork persists its OWN companion via the existing dirty-gated persist path). Gated exactly like block adoption: enabled && >=1 adopted active block. Zero-block forks are fresh ref generations (kernel generation boundary) and correctly inherit nothing.

Acceptance criteria (#1340)

AC Result
Forked child resolves adopted refs via acp_retrieve — true original PASS — tests/fork-ccr-store-adoption.test.ts: retrieve hit asserted, injected text endsWith the true original; owner\u2019s folded-message scenario (arrival-stored msg inside an adopted block) covered
Child store contains no placeholder-shaped payloads PASS — inherits the parent\u2019s TRUE originals; residual poison only if the parent itself was poisoned (no worse than today); kernel-side hardening tracked at acp-kernel#432
Parent store untouched (append-only, first-write-wins) PASS — filter clones; test asserts parent envelope byte-identical post-adoption and not marked dirty
Child persists its own companion, survives restart PASS — dirty flag -> own .content-store.json; disk round-trip test (evicted parent loaded FROM DISK into the fork; child flush; cold-read of the child envelope yields the true original)
Fork of CCR-less parent unchanged (no empty artifacts) PASS — null-skip leaves no envelope materialized, no dirty flag, no file written

Behavior changes (flagged per repo policy)

  1. Forked children of CCR-armed parents now CREATE their own .content-store.json companion on disk (old: none existed for forks). Only when blocks were actually adopted; zero-block / disabled / CCR-less forks create nothing.
  2. Fork session stats now inherit storedBytes / storeBytesSaved from adopted entries (old: 0).
  3. New info log line: [fork-adoption] ... inherited N stored original(s) (~M chars) ... (bug(ccr): storeCoveredOriginals can persist placeholder text as an original #1340). The existing adoption log line is unchanged.
  4. acp_retrieve on adopted refs in fork children: old = always miss (or fake hit pre-kernel-fix) -> new = true hit. This is the fix itself.

Parent envelopes, non-fork sessions, and the zero-block fork path are behaviorally unchanged.

Coordination (release ordering)

  • This PR touches NO kernel pin — safe to land before or after acp-kernel#432. Landing it first already removes the fork-path trigger surface for the kernel bug (first-write-wins inheritance).
  • Kernel placeholder-guard fix: acp-kernel#432 (filed from this analysis).
  • Pin bump to the fixed kernel release: tracked at chore: pin-bump acp-kernel once the placeholder-as-original fix ships (acp-kernel#432) #1353 with the owner-mandated ordering constraint (must land together with or after this PR, never before).

Pre-flight (rebased onto current master d3c8af8)

  • npm run typecheck — clean
  • npm test — 2643 pass / 0 fail (includes 8 new tests)
  • npm run build — success, dist-import-annotations OK

Fork/adoption cloned blocks, blockContents and messageRefs from the parent
but not the CCR content store, so every acp_retrieve on an adopted ref in
the child missed (and pre-kernel-fix the first post-fork fold stored
placeholder text as originals — invisible fake hits).

planForkStoreAdoption ref-filters the parent's store to the ids the child's
view can cite (incoming request ∪ ids covered by adopted blocks — coverage
follows the view, not the adoptability gate), clones entries independently,
and trims byHash to referenced payloads; null when nothing survives so a
CCR-less parent creates no artifact. maybeAdoptForkBlocks adopts the result
via adoptContentStore (stats + dirty flag → own companion envelope).

Fixes #1340
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-25_fork-ccr-store-adoption (6326bf6)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-1355

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

Option B — Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

Duplicate of #1361 — closing.

Two parallel sessions independently implemented the same fix (#1340's Layer-1 fork-adoption gap vs #1341's identical OP): both adopt the parent CCR content-store entries into an anonymous fork at adoption time, both green on the full gate + CI. Keeping #1361, because its seed set (covered refs of adopted blocks ∪ refs cited by placeholder-shaped incoming messages) also covers the case where the placeholder message's own raw id differs from the stored original's raw id — exactly the failure mode where nothing else can restore the original. This PR's rawId-reachability filter structurally misses that case.

The one test unique to this PR ("adoption disabled leaves the fork without blocks or store") has been ported into #1361 as commit 3597eb35 (its "r50 folded into b3" scenario is already covered by #1361's covered-refs test). No work here is lost.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(ccr): storeCoveredOriginals can persist placeholder text as an original

1 participant