Repository navigation
fix: close the four retrieval-delivery loss windows (#1343) - #1350
ranxianglei wants to merge 3 commits into
Conversation
The retrieve ack promises the full text rides the next request, but delivery rode volatile state with four loss windows: - W1 restart: the queue was never persisted (persist.ts reset it to []); now it rides the session file (buildRecord/buildSession), bounded by the in-memory cap. - W2 post-drain forward failure: drainPendingRetrievals spliced the queue destructively before the upstream send, so a network failure or 5xx silently ate the promised text. drain now hands back a requeue ticket (session.lastRetrievalDrain, transient); forward's network-fail catch and the >=500 branch requeue the tracked batch onto the queue for the next successful forward. A fresh drain invalidates the ticket, so a delivered batch can never be resurrected by a later request's error. - W3 disarm: storeEffectiveCcr cleared the queue silently; now logs the dropped count before clearing (ack'd, never delivered). - W4 unbounded float: a lane that never drains (non-CCR wire, client stops re-requesting) accumulated full-text injections forever; the queue is capped at 4, oldest dropped with a log line. Fixes #1343
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-1350Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr1350.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 Reviewing PR #1350 (fixes #1343) now. Plan: (1) direction gate — check the implementation against the contract approved in #1343 floor 9 (delivered-at-completion, retry semantics, restore path, uniform coverage at all drain sites); (2) regression inventory on |
The W1 record line read session.pendingRetrievals.length unconditionally, throwing TypeError on any Session object lacking the field (hand-built test fixtures across ~20 suites; typecheck covers src/ only). Defensive read at the serialization boundary; behavior unchanged for well-formed sessions.
[bot] 🏷 Review of #1350 (fixes #1343) — reviewed against current master (d3c8af8), full local verification run, duplicate screening done. Verdict: mergeable pending two owner rulings below. One blocking defect found and already fixed on the branch (commit ① Direction gate (original issue)#1343 is real and correctly layered: the ack promises "full text rides the next request" while delivery rode volatile ② Regression audit (existing behaviors touched)
③ Code findingsA. [BLOCKING — FIXED in B. [OWNER RULING NEEDED] Terminal 4xx after drain = silent loss. Requeue covers network-throw + C. [OWNER RULING NEEDED] Floor-9 point 3 (corrective notes) absent. W3/W4 losses are logged but the model is never told "your retrieve was not delivered — re-issue", so "correctable" in criterion 1 currently means "recoverable from the store if the model remembers to look". The floor-9 contract said corrective notes ride the system-role ephemeral channel. My recommendation: defer to a follow-up issue — the core no-silent-loss property holds, the note is model-honesty polish, and this PR is already tight. Your call: defer (+issue) or implement here. D. Floor-9 point 4 partially met. Stream-lane inline atomicity ( E. Nits (non-blocking). ① Requeue ④ Test qualityThe 5 new tests have teeth: order preservation + no-duplicate-on-second-failure, delivered-never-resurrected guard, cap with oldest-dropped, and a real disk round-trip ( ⑤ Diff cleanlinessClean: 5 files, every line on-purpose, no lockfile/version churn, linear history. Duplicate screening: searched open+closed PRs/issues — this is the only work touching #1343 (#1345 and #1357 are distinct root causes). No parallel effort. Bottom line: core delivery-safety verified end-to-end (local A/B + full suite + e2e green on 中文摘要:修复了 CCR retrieve 承诺文本的四个丢失窗口(队列随会话文件持久化、转发失败重排队、disarm 显式告警、队列上限 4);本轮 review 直接在分支上修掉了 |
A lane switch left the in-flight drain ticket armed: an already-delivered batch could be resurrected by an unrelated later forward failure once the lane re-armed (the exact stale-trailing-full-text case the disarm branch guards against). Clear lastRetrievalDrain on disarm; regression test proves red-on-parent.
|
[bot] 🏷 关闭为已取代(superseded)— 已对 master c030b56 逐窗核验。 #1343 的四个丢失窗口全部由 #1367(merge
测试:#1367 内 设计差异留档:master 选择 TTL 限界寿命而非硬大小上限——队列规模由 TTL 窗口内的 retrieve 活跃度界定而非常数;如日后想要硬上限是独立小改动,不属于本 PR。 Superseded by: #1367(merge 2a0eff7;reload-reconcile 旗标修复 6d7c9c3)。审计记录见 #1417。 |
Fixes #1343
What & why
The retrieve ack (
retrieveToolName(ref)tool result) promises "the full text rides the next request" — but delivery rode volatile state with four loss windows where the ack was sent, the hit counted, and the text never arrived:persist.ts—pendingRetrievalsnever persisted (buildSessionreset[])drainPendingRetrievalsspliced destructively inprepare*, then the upstream send could fail (network throw / 5xx)storeEffectiveCcr— lane switches to a non-CCR wire →pendingRetrievals.length = 0silentlyFix
buildRecordwritespendingRetrievals(only when non-empty; old files stay byte-compatible),buildSessionrestores it with a shape filter. Bounded by the in-memory cap, so the file bloat is bounded too.drainPendingRetrievalsnow also clears a transient requeue ticket (session.lastRetrievalDrain, never persisted); the twoprepare*drain sites calltrackRetrievalDrainafter appending the batch to the outgoing list;forward()'s network-failure catch and the>= 500branch callrequeueRetrievalsOnFailure→ batch goes back to the front of the queue, rides the next successful forward. Any new drain invalidates the ticket — a delivered batch can never be resurrected by a later request's error. Retries withinforward(role-rewrite ladder, [bug] 假完成:模型把工具调用写成文字(无 tool_use 块)→ 轮次提前终止,agent 显示正常完成(#361 根因 follow-up) #371 backstop) re-send the same body, so they don't interact with the ticket.[ccr] lane disarmed with N undelivered retrieval injection(s) (ack'd, never delivered) — dropping queue (#1343).RETRIEVAL_QUEUE_MAX = 4; overflow drops the oldest with a log line (honest loss, same shape as disarm).The stream-lane drains (non-stream tool rewrite,
stream.ts) deliver inline in the tool result — ack + full text return atomically to the client, no failure window, no ticket needed (a fresh drain there still invalidates any stale ticket).Tests
tests/ccr-retrieval-delivery.test.ts(new, 5):writeNow→loadSyncdisk round-trip restores the queue; empty queue writesundefined(byte-compatible files).Existing
store/ccr-plugin/ccr-v2suites: 31/31 unaffected. Typecheck 0. Red-on-master: the new file fails to import the new API (1 fail) — behavior covered by the fix diffs above.