Skip to content

refactor(ccr): retrievals deliver in the tool result — kernel v2 lockstep (requires acp-kernel 0.0.99) - #1738

Merged
ranxianglei merged 2 commits into
masterfrom
2026-09-30_ccr-tool-result
Sep 30, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-09-30_ccr-tool-result

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

executeRetrieve now returns the retrieved original as the tool result itself and the #1343 queued-delivery channel for CCR is retired (kernel v2 retrieval contract, lockstep with the upcoming acp-kernel@0.0.99).

  • src/store.ts: executeRetrieve → applyRetrieve({store, ref, exportDir: retrievalExportDir()}), returns toolResultText directly; queueRetrieval deleted; retrieveDelivered counts at tool time. Originals ≥ 4000 tok export to stateDir()/retrieve/<ref>.txt with a pointer tool result (write failure degrades to a bounded head preview).
  • src/decompress-shared.ts: the feat: CCR v2 — covered-ref spans, range-level decompress, ID-returning search_context; CCR default-on (#1179) #1207 range-decompress rider rides as user, not system.
  • src/compress-settings.ts: spreads kernel DEFAULT_CCR_CONFIG first so new kernel ccr keys (retrieveInlineTokens) survive the deepEqual contract.
  • Carrier/ledger/drop-note machinery is kept for legacy pre-upgrade state and the range rider; tests seed that legacy state directly.

⚠️ CI is expected RED until acp-kernel 0.0.99 is on npm

package.json still pins acp-kernel: 0.0.98. This branch uses the v2 retrieval API (applyRetrieve input/output, RetrievalExport), so typecheck + tests fail against the registry 0.0.98. The kernel release lands first; a bump commit on this PR (0.0.98 → 0.0.99) then re-runs CI green. Do not merge before the bump.

Local validation: full suite 3295/3295 pass (17 live-e2e skips) against a locally built kernel with the v2 contract.

Test changes

… v2 lockstep)

executeRetrieve now calls kernel applyRetrieve({store, ref, exportDir})
and returns the result as the tool result directly — retrieval is a plain
tool call whose output carries the payload. The #1343 queued-delivery
lifecycle for CCR is retired: queueRetrieval deleted, delivery counts at
tool time, carrier/ledger/note machinery survives only for legacy state
and the #1207 range-decompress rider (which now rides as user).

Originals >= 4000 tok export to stateDir()/retrieve/<ref>.txt with a
pointer tool result; write failure degrades to a bounded head preview.
compress-settings spreads kernel DEFAULT_CCR_CONFIG first so new kernel
ccr keys (retrieveInlineTokens) survive the deepEqual contract.

Requires acp-kernel 0.0.99 (unreleased): package.json still pins 0.0.98
and CI is expected red until the kernel lands on npm — the bump commit +
re-run turns it green. Tests reworked to the atomic-delivery contract;
3295/3295 green against the local kernel overlay.
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-30_ccr-tool-result (930dd8c)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1706-pr.1738.90716ee

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

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

Review started

Picked up this PR. Initial state check:

  • acp-kernel on npm: latest is still 0.0.98 (npm view acp-kernel version). So per the issue body, CI stays red until the kernel release lands — the planned bump commit (0.0.98 → 0.0.99) goes on this branch once 0.0.99 is live. Watching for it.
  • Fetched 2026-09-30_ccr-tool-result (50d56bd): single commit on top of current master, 8 files (+170/−131): src/store.ts, src/decompress-shared.ts, src/compress-settings.ts, src/session.ts (doc-only), plus the four test files listed.

Now walking the code + tests + the CI failure mode. Full review conclusion follows in a second comment.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

Review complete — code is sound; gated on acp-kernel 0.0.99

What I verified

  • Fetched 2026-09-30_ccr-tool-result @ 50d56bd: single commit on top of current master (27c8774). Tight diff — 8 files (+170/−131), every line on-topic: src/store.ts, src/decompress-shared.ts, src/compress-settings.ts, src/session.ts (doc comment only), and the four listed test files. No lock-file churn, no unrelated edits (⑤ clean).
  • Reproduced the expected red locally (worktree at head, npm ci from registry): typecheck fails only in src/store.ts — all 9 errors are the v2 API surface (RetrievalExport, exportDir, toolResultText, export). Nothing else in the tree is out of shape against 0.0.98, so the red is 100% the pin with nothing hidden behind it.
  • Kernel side: acp-kernel#485 (security fixes incl. CCR retrieval delivery, 0.0.99) is OPEN, not published. npm latest is still 0.0.98 (no 0.0.99, no prerelease). The bump commit stays parked until that PR merges and CI publishes.

Direction (①) — correct layer. The #1343 channel delivered model-untrusted folded content as a host-synthesized system message on later requests — a trust-tier violation (the GHSA jc6g class). v2 delivers the original in the model's own tool-result slot, i.e. at the tier it came from. Root-cause fix at the contract (kernel), not a wire-side mask.

Regression walk (②) — existing behaviors touched, each judged:

  1. Tool-result content: ack receipt → framed original (acp-retrieved #ref, untrusted-data framing, full bytes inline; ≥ inline-threshold exports to <stateDir>/retrieve/<ref>.txt 0600 with a pointer result; write failure degrades to a bounded head preview instead of a dead path). Intended, disclosed. Wire-visible, both lanes — human-merge territory regardless.
  2. retrieveDelivered timing: counted at drain → counted at tool time. Intended, disclosed.
  3. bug(ccr): plugin-mode retrieve acknowledgement can outlive its volatile full-text delivery #1343 queue / drop / correction-note lifecycle: retired for CCR (an upstream 500 can no longer un-deliver or buffer a note); legacy ccr:true carriers left by pre-upgrade sessions still settle through the kept reconcile/commit/drop machinery, which is never re-created. Migration path preserved. Intended, disclosed.
  4. feat: CCR v2 — covered-ref spans, range-level decompress, ID-returning search_context; CCR default-on (#1179) #1207 range-decompress rider: role system → user. Intended, disclosed (restored conversation content is data, not operator speech).
  5. New bounded FS side effect: export dir under the shared XDG state dir, idempotent rewrites, 0600. Acceptable.
  6. compress-settings: kernel DEFAULT_CCR_CONFIG spread first so new kernel ccr keys carry through without a bili edit per key. Changes the deepEqual contract exactly as stated. Intended.

Code (③) — executeRetrieve flow is clean: miss path returns toolResultText (hallucinated-ref cost unchanged); hit path writes the export before counting delivered; the degradation path returns a bounded preview rather than handing the model a dead file pointer. writeRetrievalExport uses explicit mode: 0o600 (folded conversation content is not world-readable on multi-user hosts) and logs a warn on failure. Deleting queueRetrieval leaves no dangling callers (typecheck confirms).

Tests (④) — assertions have teeth: inline framed-original bytes, empty carrier queue, delivered-at-tool-time counters, no-note-on-failure atomicity across both the OpenAI and Anthropic plugin lanes, and the surviving legacy-lifecycle tests seed the old carrier shape directly (seedLegacyCarrier) so the kept machinery stays pinned. The #1457 rework correctly encodes "an upstream failure cannot un-deliver a tool result the model already received."

CI status — the latest runs are on the superseded sha 3df6a8b (the branch was force-pushed to 50d56bd afterwards) and all sit action_required; nothing has executed against the current tip yet. After the bump, expect the approval-gated runs to go green.

Verdict — code is sound and matches the issue description point-for-point. Remaining merge blockers, in order: (1) acp-kernel#485 merged + 0.0.99 published [human], (2) bump commit 0.0.98 → 0.0.99 on this branch [me — I'll add it the moment 0.0.99 is live on npm], (3) green CI on the bumped head, (4) human merge.

中文摘要:代码审查通过——v2 检索契约(原文直接作为工具结果交付、退役 #1343 队列投递通道)实现干净、diff 无杂质;本地复现确认当前 CI 红完全由 acp-kernel 钉在 0.0.98 所致、背后没有隐藏问题。等 acp-kernel#485 发布 0.0.99 后,我会立即在本分支补 0.0.98 → 0.0.99 bump 提交并让 CI 跑绿,之后即可合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

Follow-up — independent validation against the kernel PR build

While waiting for the official publish, I validated this branch against the pre-release build of acp-kernel#485 (it publishes an npm tag per push):

  • Installed acp-kernel@pr-485 → 0.0.98-pr.485.342 (built from kernel PR head 5591bfd) into a throwaway worktree at branch head 50d56bd (via --no-save; no repo files touched).
  • npm run typecheck — clean (all 9 v2-API errors against registry 0.0.98 are gone).
  • npm test — 3295 pass / 0 fail / 17 skip (the live-e2e skips), exactly matching your stated local numbers.

So the branch is confirmed correct against the v2 retrieval contract — not just per the local-build claim, but against the actual #485 artifact. Caveat: if acp-kernel#485 changes before merge, the bumped-head CI run is still the authoritative gate.

Status unchanged: 0.0.99 not yet on npm (kernel PR open, awaiting merge). Once it lands I'll add the 0.0.98 → 0.0.99 bump commit here and confirm green CI. Ping me here or on acp-kernel#485 if you want me to pick it up immediately.

中文摘要:已用 acp-kernel#485 的预发布构建(0.0.98-pr.485.342)独立验证本分支——typecheck 干净、测试 3295 全过,与作者本地数据一致;等 0.0.99 正式上 npm 后我立即补 bump 提交。

@ranxianglei
ranxianglei merged commit 32a0c16 into master Sep 30, 2026
13 checks passed
@ranxianglei
ranxianglei deleted the 2026-09-30_ccr-tool-result branch October 15, 2026 05:32
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.

1 participant