Repository navigation
fix(ccr): give plugin-mode retrieve delivery a lifecycle so acks cannot outlive lost text - #1367
Conversation
…t outlive lost text In plugin mode, acp_retrieve committed its success (ack text + retrieveHits) before the full text had any guaranteed delivery path: the ack rode the tool response immediately while the full text sat in the volatile in-memory session.pendingRetrievals queue, appended only to a LATER upstream request. A restart, an upstream failure after drain, a CCR disarm, or a long run of non-qualifying requests could each leave the ack on record while the text was silently lost or surfaced detached from context. Give queued retrievals a lifecycle (queued -> attached -> delivered | dropped): - executeRetrieve queues with a durable undelivered ledger in session.metadata (round-trips to disk; no on-disk schema change). - Plugin-lane prepares SNAPSHOT (not splice) the queue onto the outgoing body; forward() settles it at the final response: committed on 2xx, dropped-and- logged on network failure / non-2xx / transform failure. - Disarm terminates pending deliveries observably (no silent truncate, no stale flush on re-arm); reload reconciles acked-but-never-delivered refs; a TTL (BILI_CCR_RETRIEVAL_TTL_MS, default 10min) expires loudly. - Every loss logs refs+count+reason, bumps stats.retrieveDropped, and queues a corrective note flushed as an ephemeral trailing user message next round. - New additive counter stats.retrieveDelivered counts confirmed deliveries. retrieveHits semantics are unchanged. Range-restore riders (#1207) share the carrier but are ccr:false: removed at the delivery outcome but exempt from the CCR ledger/TTL/counters/note, so their original ride-along semantics are preserved. Proxy-mode drain is unchanged (atomic in-flow) -- four-wire happy path and pair integrity intact. Tests cover all four windows plus two-riders isolation and the proxy regression.
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-1367Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr1367.tgz
npm install -g packageInstall instructions are refreshed on each push. |
收到。这是 agent 已完成的 PR,我不重做——现在按 review 规范走:拉分支核对代码 → 回归审查(既有行为清点)→ 代码/测试有效性审查 → CI 状态确认,结论稍后贴在本线程。 |
… clears restored first) reconcileReloadedRetrievals gated on session.restored, but getSession() clears restored on the first request touch — BEFORE prepare runs the reconcile in that same request. The window-1 restart detection (#1343, the headline scenario of this PR) therefore never fired in production: acked-but-never-delivered ledger entries survived silently with no log, no counter, no corrective note. The unit test masked this by setting restored=true manually. Fix: persist's buildSession now arms ccrReconcilePending (in-memory one-shot); reconcile keys off it and consumes it. resetSessionCompression clears it alongside the ledger. W1/W1b updated to pin the production ordering (flag armed, restored already cleared).
…TORE line floor-9 polish item: the new delivery/drop counters were not surfaced anywhere user-visible. STORE line gains '· delivered N' / '· dropped N' segments when non-zero.
[bot] 🏷 PR #1367 review complete. Verdict: not yet mergeable — one blocker found & fixed on the branch; three contract gaps need your call. ① Direction (原 issue): sound. The lifecycle (queued→attached→delivered|dropped) fixes each window at its decision point rather than masking symptoms: snapshot-not-splice makes internal retries re-attach automatically, settlement is exactly-once per client request, every drop is observable (warn log + counter + corrective note). Root cause addressed, not papered over. ② Regression audit (existing behaviors touched):
③ Code review:
④ Tests: real teeth (counter values, ledger state, note text, pair-integrity regexes). The single gap was W1 masking the P1 ordering bug — now pinned. ⑤ Diff: clean — one original commit, 6 files, all in scope, no version bump, no lock churn. My three review-fix commits are clearly labeled above it. Evidence: CI fully green on original head Before merge: (1) your calls on P2/P3/P4 (accept-with-docs or fix); (2) rebase onto current master — the branch is 9 commits behind (incl. release v0.1.153); trial 中文摘要:审查了 CCR retrieve 投递生命周期 PR——发现并已在分支上直接修复核心缺陷「重启对账因 getSession 先行清除 restored 标志而永不触发」(改为一臂 ccrReconcilePending 一次性标志并更新测试钉住生产时序),补齐了 acp_status 展示与 TTL 环境变量文档;剩余三项(以 2xx 头而非流结束记 delivered、纠正注走 user 消息通道、proxy 模式在 drain 时即记 delivered)均偏离 floor-9 已批契约,需 owner 拍板接受留痕或修复;待拍板 + rebase 最新 master 后可合并。 |
[bot] 🏷 CI follow-up: all 11 checks green on new head Nothing else outstanding on my side — remaining pre-merge items are yours: (1) calls on P2/P3/P4 (accept-with-docs or fix), (2) rebase onto current master (9 commits behind; trial merge-tree is conflict-free) then re-run gates. Ping me with the calls and I'll handle the rebase / any fixes. 中文摘要:d8bb1654 的 CI 已全部通过(11/11),本地门禁同样全绿;待你对 P2/P3/P4 拍板并 rebase 最新 master 后即可合并。 |
|
Deep review: ✅ merge. Verified on the triple-stacked tree (#1367+#1361+#1360 — all pairwise and triple merges clean; typecheck + full suite 2659 tests / 0 fail on the stack). Design holds up. The lifecycle Points I probed specifically:
Non-blocking observations (no action needed):
Docs: |
[bot] 🏷 Thanks for the deep review and the triple-stack verification (#1367+#1361+#1360) — glad the lifecycle design held up under probing. On your two non-blocking observations: agreed on both. (1) Proxy-lane-only sessions keeping stale I've also addressed my own open item from the review thread: the PR body now carries a "Known bounded residuals (accepted at review)" section recording all five — plugin-lane 2xx-header settlement point, user-message note channel, proxy commit-at-drain, reconcile scope, and concurrent double-attach — so the merged PR is honest about what it does and doesn't close. No code changes involved. I can't merge PRs — system rules forbid it. Please merge yourself: #1367 (note 中文摘要:已按你的深度评审结论收尾——PR 描述补充了「已知有界残留」一节(五项残留全部留痕),无代码改动;合并操作按系统规则需你本人执行,合并前建议先 rebase 最新 master。 |
Summary
In plugin mode,
acp_retrievecommitted its success (ack text +retrieveHits) before the full text had any guaranteed delivery path: the ack rode the plugin tool response immediately while the full text sat in the volatile in-memorysession.pendingRetrievalsqueue, appended only to a later upstream request. A restart/eviction, an upstream failure after drain, a CCR disarm, or a long run of non-qualifying requests could each leave the ack on record while the text was silently lost — or surfaced detached from context turns later.This gives queued retrievals a delivery lifecycle so no ack can outlive a silently-lost text.
What changed
src/store.ts):queued → attached → delivered | dropped.executeRetrievenow queues with a durable undelivered ledger insession.metadata.ccrUndelivered(round-trips to disk; no on-disk schema change). New functions:queueRetrieval,snapshotPendingRetrievals,commitRetrievals,dropRetrievals,pruneExpiredRetrievals,reconcileReloadedRetrievals,flushRetrievalNotes.src/server.ts): prepares now SNAPSHOT (not splice) the queue onto the outgoing body (Prepared.attachedRetrievals);forward()settles it at the final response — committed on 2xx, dropped-and-logged on network failure / non-2xx / transform failure. Closes all four windows from the issue.stats.retrieveDropped, and queues a corrective note flushed as an ephemeral trailing user message next round. Disarm terminates pending deliveries observably (no silent truncate, no stale flush on re-arm — preserves feat: enable CCR (acp_retrieve) on host/plugin lanes (#1271) #1273). Reload reconciles acked-but-never-delivered refs. A TTL expires loudly.src/decompress-shared.ts) share the carrier but areccr:false— removed at the delivery outcome but exempt from the CCR ledger/TTL/counters/note, preserving their original ride-along semantics.drainPendingRetrievalsstays atomic in-flow (four-wire happy path + pair integrity intact); it now also commits delivery so proxy retrieves count inretrieveDelivered.src/session.ts,src/persist.ts): additivestats.retrieveDropped/stats.retrieveDelivered; restored on load.Behavior changes (old → new)
pendingRetrievalsretrieveHitscounted acked (incl. undelivered)retrieveHitsunchanged; newretrieveDeliveredcounts confirmed deliveries,retrieveDroppedcounts lossesBILI_CCR_RETRIEVAL_TTL_MS(default 600000 ms;0disables expiry)The agent-facing ack is unchanged (still synchronous, same text); only the bookkeeping around it becomes honest.
Known bounded residuals (accepted at review)
deliveredsettles at the upstream 2xx headers; a stream breaking mid-body after headers counts as delivered with no corrective note (rare; clean-finish settlement is a follow-up candidate).imageFullTrailingNote, Feature: image pre-compression for screenshot-heavy tool results (resize/quality routing) #1095), not a system-role ephemeral channel.ccrReconcilePendingis consumed by plugin-lane prepare only; a restarted session that stays on the proxy lane keeps its stale ledger rows in metadata until it next touches the plugin lane (model-invisible, bookkeeping only).Pre-flight
npm run typecheck— cleannpm test— 2628 pass, 0 fail, 10 skipped (new tests cover all four windows + two-riders isolation + proxy regression)npm run build— successCloses #1343