Repository navigation
feat: bili acp-cache diff — prefix-diff attribution over ACP_DUMP_BODY dumps (#1266) - #1269
Conversation
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-1269Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr1269.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 PR #1269 reviewed — code verified against live master, all CI checks green. Per protocol I did not redo the work: fetched ① Direction (vs #1266): Right root-cause framing. #1249 showed that attributing cache-prefix instability required manual dump-diffing; this turns that procedure into one read-only command without touching the request path or the kernel. The two-tier comparison (byte-prefix first, then JSON message-array-aware) is the correct design — strict byte comparison would misread every healthy array append (the closing bracket shifts position) as a rewrite, which is exactly the false-positive class #1249 suffered from. The attribution ladder (incoming-append + outgoing-mid-drift = proxy; identical drift both sides = client; outgoing diverging earlier = both) matches the observed #1249 shapes, and correlating ② Regression inventory (existing behaviors on touched paths):
③ Code review: clean. Chunked 64KiB prefix comparison avoids double-buffering; the JSON-aware tier requires exact span-count equality before trusting element alignment (falls back to byte mode otherwise); usage alignment is timestamp-based with 2s slack; legacy-filename pairing is bounded to a 30s window. One theoretical weakness, acceptable for a diagnostic: ④ Test quality: real tests with teeth, not ceremony. The critical regression pin is present: "healthy message-array append is append(json-tail), not a rewrite (#1266)" — this fails precisely if the #1249 misread shape returns. Coverage spans all three categories, the attribution ladder (proxy/client branches), the miss-threshold boundary (missedPrefix 500 < 512 floor stays pure-append; 99000 → miss), legacy filenames, model-change notes, empty-dir error, ⑤ Diff cleanliness: every line serves the PR's purpose; no whitespace churn, no lockfile/generated noise. Single linear commit; GitHub reports mergeable=true (master moved +10 commits since the branch point, touching only different regions of the two CONFIG docs). F1 (minor, fixed in place): the comment at Verification: local typecheck ✅; Verdict: mergeable — ready for human merge whenever you are. 中文摘要:审查了 PR #1269(新增只读诊断命令 |
[bot] 🏷 Follow-up: CI on the updated head 中文摘要:新 commit |
|
Independent deep review complete — one real bug found and fixed (head Verified sound: two-tier compare (strict byte prefix / json-tail element stability — the array-append bracket-move problem is handled correctly), INCOMING↔REQ per-session pairing incl. legacy 30s adoption, attribution ladder (incoming append + outgoing drift → proxy; earlier incoming offset → client; passthrough-pair → client; both → both), prefix-stable-miss floors (512 abs ∧ 2% rel), worst-offender severity (earlier break ranks worse), JSON mode, session filter, and the INCOMING dump-site move in server.ts (trade-offs disclosed: pre-prepare rejections and bypass lanes lose INCOMING — they carry no attribution signal anyway). End-to-end smoke (synthetic dumps through the real CLI): proxy-rewrite shape → 🔴 Bug fixed — Gates: typecheck ✓ / 2469 tests 0 fail / build ✓. Existing prefix-stable-miss tests never caught this because they use a 6.5s request gap — the new test pins the 1.5s gap. |
[bot] 🏷 Independent verification of the Bug reproduction (independent of your analysis): traced the old condition Mutation check (done myself, not just taken on faith): reverted Fix review: direction is now correct — a sample can only attach to a request whose dump predates it (+50ms noise margin). The load-bearing invariant ("same-process clocks put the request dump before its own response's usage line") holds because Gates: local typecheck ✅; Verdict: fix verified end-to-end. PR is in final state ( 中文摘要:独立验证了 |
…Y dumps (#1266) New read-only diagnostic command 'bili acp-cache diff <dump-dir>': pairs adjacent same-session requests from ACP_DUMP_BODY dumps (INCOMING = client wire, REQ = proxy-rebuilt wire) and classifies each pair: - pure-append prefix stable, growth only at the tail (healthy) - mid-stream-rewrite first divergent byte inside the shared prefix; reports byte offset + first divergent message and attributes proxy vs client vs both by comparing where each side's wire first diverged (#1249 shape = incoming append + outgoing mid drift -> proxy) - prefix-stable-miss outgoing prefix append but provider usage shows the cached prefix collapsed (--log / bili.log correlation; upstream TTL/eviction, the unattributed bucket of acp-kernel#393) Comparison is two-tier: byte-prefix first, then JSON message-array-aware so a healthy array append (which moves the closing bracket) is not misread as a mid-stream rewrite. Output: per-pair lines + worst offenders; --json emits the machine-readable report. --log FILE / --no-log control usage-log correlation (default auto-discovers <dump-dir>/bili.log or defaultLogFile()). Prerequisite fix in the same issue scope: INCOMING dump filenames now carry the bound session id (<ts>-<sid>-INCOMING.txt; OUTGOING already had it) so concurrent sessions can be paired; the dump moves from the pre-prepare site to right after prepare, where the session is bound. Requests rejected before prepare no longer get an INCOMING dump (they never got a REQ dump either); legacy session-less INCOMING dumps still parse via timestamp proximity. Tests: synthetic dump pairs for all three shapes + legacy filenames + usage alignment + render modes (tests/acp-cache-diff.test.ts), parseArgs cases, and a full-proxy harness test pinning the new INCOMING filename. Behavior changes (disclosed): 1. INCOMING body-dump filename: <ts>-INCOMING.txt -> <ts>-<sid>-INCOMING.txt. Any external tooling keying on the old shape must adapt (none in-repo does; DUMP_FILE_RE regexes still match). 2. INCOMING dumps now written post-prepare instead of pre-prepare (content and masking unchanged); pre-prepare rejections (bypass/passthrough/unknown paths) no longer produce INCOMING dumps.
…mit REQ dumps under sid unknown (#1266)
…the predecessor's usage line The +2000ms window ran in the wrong direction: request B's dump could claim response A's usage line whenever B followed A by < 2s — exactly the compress-loop cadence this tool diagnoses. Request A then lost its usage data and prefix-stable-miss detection silently disabled. Same-process clocks put the dump before its own response's line; 50ms absorbs write-ordering noise only. Mutation-verified regression test (dense cadence, 1.5s gap).
51f0ee3 to
362cdd9
Compare
What
bili acp-cache diff <dump-dir>— read-only diagnostic that turns #1249's manual dump-diffing into one command (split out of #1254 suggestion ①).For each session in an
ACP_DUMP_BODYdump dir, it pairs adjacent requests (INCOMING = client raw wire; REQ = proxy-rebuilt wire) and classifies each pair:pure-appendmid-stream-rewriteproxy/client/both)prefix-stable-miss[acp-usage]lines from bili.logKey design points:
--log FILE,--no-log, or auto-discovery (<dump-dir>/bili.log, then the default log path). Samples align to requests by timestamp (≤2 s slack). Miss threshold:cached_B < input_A − max(512, 2%·input_A).--jsonfor machine-readable reports. Purely read-only — no request-path or kernel changes;ACP_DUMP_BODYstays a manual diagnostic switch.Prerequisite fix (in this issue's scope)
INCOMING dump filenames now carry the bound session id:
<ts>-INCOMING.txt→<ts>-<sid>-INCOMING.txt(OUTGOING already had it) — without it, concurrent sessions cannot be paired. The dump site moves from pre-prepare to just after prepare, where the session is bound; content/masking unchanged. Legacy session-less INCOMING dumps still parse via timestamp proximity (nearest OUT within 30 s).Behavior changes (disclosed)
<ts>-INCOMING.txt→<ts>-<sid>-INCOMING.txt. Why: multi-session pairing ([Enhancement]bili acp-cache diff <dump-dir>: prefix-diff attribution over ACP_DUMP_BODY dumps (from #1254 ①) #1266 req 1). No in-repo consumer breaks (allDUMP_FILE_REregexes still match).Pre-flight
npm run typecheck✅npm test: 2465/2470 pass. The 3 failures aretests/claude-native.test.tshook-e2e tests (ps-walk/spawn-based) that fail identically on clean master (verified by stash A/B) — sandbox environment issues, unrelated to this diff.npm run build✅tests/acp-cache-diff.test.ts(synthetic dump pairs for all three shapes, legacy filenames, usage alignment, render modes, plus a full-proxy harness test pinning the new INCOMING filename) + 2parseArgscases ✅ACP_DUMP_BODY=1(not set by e2e). Please run the CI manual-dispatch E2E before merging.Fixes #1266
中文摘要:新增只读诊断命令
bili acp-cache diff <dump-dir>,对 ACP_DUMP_BODY dump 做同会话相邻请求入站/出站前缀 diff,自动把缓存失效分类为 pure-append / mid-stream-rewrite(含代理 vs 客户端归因,#1249 形态可直接识别)/ prefix-stable-miss(对齐 bili.log 的 [acp-usage] 行,对应 acp-kernel#393 的 unattributed 桶),并顺带修复 INCOMING dump 文件名缺 session id 的前置问题;typecheck/build 通过、新增 18 个用例全绿,全量测试 3 个 claude-native 失败为沙箱环境问题(clean master 同样失败),完整 E2E 因本地上游服务临时不可用未跑通(clean master 一致),建议合并前跑一次 CI 手动 E2E。