Repository navigation
[PR] fix: interpret cache-diff byte offsets in original text coordinates - #6496
ranxianglei merged 16 commits into
Conversation
The suite baseline preload (preload-storage-baseline.mjs) pins BILI_STORAGE_UNIFIED="legacy" for the broad corpus. After ranxianglei#6480 flipped the storage default to pure-sqlite, the notice-registry suite's visibleNotices assertions expect the pure-sqlite default notice, which is gated on unifiedSelectionIsSqlite (unified "sqlite" or absent) — the preload's "legacy" made the notice silent, so the suite was born-red on master. Pin the selection explicitly (ranxianglei#4011 lesson: a test that depends on the production default passes locally but fails in CI).
…test The dsh plugin lane (ci-e2e-dsh.yml) runs node --import tsx --test WITHOUT the preload-storage-baseline.mjs preload, so BILI_STORAGE_UNIFIED is unset and the storage mode defaults to 'full'. Under the pure-sqlite default flip (5a80e2b, ranxianglei#6480), 'full' mode turns the JSON envelope writer OFF — so the .content-store.json sidecar is never written, and the test's readdirSync(namespace) hits ENOENT. Pin BILI_STORAGE_JSON_WRITER=on in the test so the content-store sidecar is written regardless of the storage mode. This keeps the corrupted-store detection path exercised in both full and legacy modes. Closes: dsh plugin lane red on master (run 43532980164, job 132255459726)
The pure-sqlite default flip (5a80e2b, ranxianglei#6480) turns the JSON envelope writer OFF, so the .json session file this lane asserts on is never written and 'proxy must persist the session' / 'no persisted session carried compressed blocks' fail after the 20s wait. Pin the writer ON in the spawned client's env (the bootstrapped proxy inherits it) so the envelope this test was written for is still produced. Closes: native opencode lane red on master (run 43547593803, job 132302438610)
Same pure-sqlite default flip (5a80e2b, ranxianglei#6480) as the opencode lane: the JSON envelope writer is OFF, so 'proxy must persist the session within 20000ms' fails — the on-disk .json session file is never written. Pin the writer ON in the spawned dsh client's env (the bootstrapped proxy inherits it). Closes: native dsh lane red on master (run 43547497015, job 132302138843)
…e2e lane Same pure-sqlite default flip (5a80e2b, ranxianglei#6480) as the opencode/dsh lanes: the JSON envelope writer is OFF, so 'session persisted' fails — the on-disk .json session file is never written. Pin the writer ON in the spawned pi client's env (the bootstrapped proxy inherits it). Closes: pi codex-responses WS lane red on master (run 43547626291, job 132302540960)
…lane 4th lane of the pure-sqlite default flip (5a80e2b, ranxianglei#6480) family: the JSON envelope writer is OFF, so 'proxy must persist the session' and 'at least one persisted session must carry compressed blocks' fail — the on-disk .json session file is never written. Pin the writer ON in the spawned pi client's env (the bootstrapped proxy inherits it). Closes: pi package-native lane red on ci-fixes (run 43558179054, job 132336647955)
Same pure-sqlite default flip (5a80e2b, ranxianglei#6480) family: the JSON writer is OFF, so the per-session CCR content-store sidecar (.content-store.json) that 'child persists its own companion and survives a proxy restart' asserts on is never written (0 !== 1). The earlier b1bc17b pin only covered tests/plugin-fork.test.ts, not this file. Pin the writer ON at module load (before any SessionStore is constructed). Closes: dsh plugin lane red on ci-fixes (run 43558179102, job 132336519539)
…lane Pure-sqlite default flip (5a80e2b, ranxianglei#6480) family: the JSON envelope writer is OFF, so 'proxy must persist the session' fails — the on-disk .json session file is never written. Pin the writer ON in the spawned opencode client's env (the bootstrapped proxy inherits it).
Pure-sqlite default flip (5a80e2b, ranxianglei#6480) family: the JSON envelope writer is OFF, so the on-disk .json session envelope this lane asserts on (exactly ONE persisted session under the raw key) is never written. Pin the writer ON in the spawned dsh client's env.
Pure-sqlite default flip (5a80e2b, ranxianglei#6480) family: the JSON envelope writer is OFF, so the on-disk .json session file this lane asserts on (state survival across the OLD→NEW update) is never written. Pin the writer ON in the spawned proxy's env (both update phases share envBase).
ranxianglei
left a comment
There was a problem hiding this comment.
(ai: vllm-qwen/qwen3.8-27b)
APPROVE — correct, minimal, well-tested root-cause fix.
Verified locally on the head (which is merged up to current master 1ff89e8785 + ci-fixes, so no stale-base concern):
- New Unicode suite: 8 tests fail on unchanged master, all 10 pass with the fix (teeth confirmed — I ran both).
- Existing cache-diff suite: all 19 pass (no regression).
tsc --noEmitclean.
The fix adds textOffsetAtByte to convert the UTF-8 byte offset to a UTF-16 text offset (anchoring at a code-point start when the differing byte lands inside a multibyte char), and uses it for the JSON-span comparisons in compareWires and the locateMessage/snippetAround evidence in classifyPair. Public byte offsets, prefix measurements, attribution, and the byte-based isMidInsertionAppend check stay in byte coordinates — exactly the scope #6495 asks for. This fixes the coordinate mismatch at the source, not a symptom.
The 10 BILI_STORAGE_JSON_WRITER / BILI_STORAGE_UNIFIED test pins are the sanctioned ci-fixes merge (inherited failures from the pure-sqlite default #6480, which is already in master with those lanes still unpinned) — not unrelated churn.
Note for the maintainer: the author requested the ci:full label for the full Windows/Node 24 matrix; the CORE matrix is green. Label application is your call.
审核八问
- 是什么问题:离线
bili acp-cache-diff诊断算出的是 UTF-8 字节偏移,却拿它去比 UTF-16 的 JSON span 索引、按字节下标切 JS 字符串;长 CJK/emoji 前缀会把「改写已有消息」误判成「正常尾部追加」,还丢消息索引、显示无关/空证据。 - 什么原因导致的:字节坐标与 UTF-16 代码单元坐标混用——
prefixCompare返回字节偏移,而elementSpans/snippetAround/locateMessage都在 UTF-16 字符串上按代码单元索引;多字节前缀下两者数值不等,比较/切片全部错位。 - 影响范围与严重程度:仅离线诊断的分类与证据展示,不涉及线上请求改写、缓存匹配或配置;触发条件 = 消息数组前存在长 CJK/emoji 前缀且发生改写。严重度:诊断准确性瑕疵(误分类 + 证据错位),不破坏可用性、不丢数据。
- 怎么修复的:新增
textOffsetAtByte把字节偏移换算成 UTF-16 文本偏移(落在多字节码点内部时回退到该码点首字节,避免把残缺前缀解码成替换符);compareWires三处 span 比较、classifyPair的locateMessage/snippetAround改用文本偏移;公开字节偏移、前缀度量、归因、isMidInsertionAppend字节检查保持字节坐标不变。 - 是否有回归问题:无。既有 19 条 cache-diff 测试全绿;改动只把「对 span/字符串的操作」从字节坐标切到文本坐标,字节坐标逻辑(前缀比较、归因、mid-insert 判定)一字未动。高危模式逐项过:无 fail-fast 变吞错、无阈值/时序/输出格式漂移(公开
byteOffset字段仍是字节值)。 - 是否破坏缓存:不涉及。纯离线诊断,不触碰缓存/重试/增量游标/去重键。
- 是否改了设计方向:不涉及。无架构/边界/数据流转向。
- 是否引入了新的配置:不涉及。无新 env/config/默认值。
判定:可合(APPROVE)。
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) Reviewed PR #6496 (fix: interpret cache-diff byte offsets in original text coordinates) end-to-end and APPROVED it — GitHub review id 5902772035, posted on the PR thread. What I verified (locally, on the head merged up to current master
Correctness: the fix adds Diff: core fix ( For the maintainer: the author requested the 审核八问
判定:可合(APPROVE)。 |
Resolve CI baseline conflicts using the current upstream test setup.
ranxianglei
left a comment
There was a problem hiding this comment.
(ai: vllm-qwen/qwen3.8-27b)
Re-review of the refreshed head 26723e1bce47cf318aa285ab043bcfc1da5abd91 — still APPROVE.
The head moved from 49b74242e to 26723e1bce purely via a master merge (commit 26723e1bce "Merge master into …"). I verified:
- The core fix (
src/acp-cache-diff.ts+tests/acp-cache-diff-unicode.test.ts) is byte-identical to the head I approved —git diff 49b74242ec 26723e1bce -- src/acp-cache-diff.ts tests/acp-cache-diff-unicode.test.tsis empty. - The PR is now up-to-date with master (0 commits behind;
origin/masteris an ancestor of the new head). - The master merge touches
src/storage/store.ts, test pins, and release files — none of which touch the core fix or its test. - Re-ran the targeted suites on the new head: 10/10 Unicode tests pass, 19/19 existing cache-diff tests pass,
tsc --noEmitclean.
The fix remains a correct, minimal, well-tested root-cause fix: textOffsetAtByte converts the UTF-8 byte offset to a UTF-16 text offset (anchoring at a code-point start when the differing byte is mid-codepoint) and is used only for the JSON-span comparisons in compareWires and the locateMessage/snippetAround evidence in classifyPair. Public byte offsets, prefix measurements, attribution, and the byte-based isMidInsertionAppend check stay in byte coordinates. No kernel/ changes, no behavior drift in the live path, no new config.
For the maintainer: the author's earlier request for the ci:full label (full Windows/Node 24 matrix) is still open; CORE is green. Label application is your call.
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) Re-review of the refreshed head The head moved from
The fix remains a correct, minimal, well-tested root-cause fix: For the maintainer: the author's earlier request for the 审核八问
判定:可合(APPROVE)。 |
|
Superseded by #6677 (merged as Landed into master via the real merge commit The fix for #6495 is now in master. Closing this PR as superseded — thanks for the careful, well-tested fix. |
Closes #6495
Problem
The offline cache-diff diagnostic computes the first differing UTF-8 byte correctly, but then uses that byte offset to compare JSON element spans and slice JavaScript strings, whose indices are UTF-16 code units. A long CJK or emoji prefix can therefore make a rewrite of an existing message look like a normal tail-field append. The diagnostic can also lose the message index or show an unrelated/empty evidence snippet, hiding the actual prompt-cache prefix break.
Changes
This changes offline diagnosis only; it does not rewrite requests, change cache matching, or add configuration.
Validation
On unchanged master 9674cfa, the new suite reports 8 failures and 2 passing controls. With the fix, all 29 tests across the new Unicode suite and the existing cache-diff suite pass, including the real loopback HTTP dump-name check.
Passed: npm run typecheck; npm run build; npm run check:unused-exports; npm run check:test-import-graph; git diff --check.
The zero-token Codex preflight finds the installed CLI and built distribution, but its local model endpoint is unreachable; the real-model case is skipped. No full real-model E2E or upstream CI pass is claimed.
Prior work and submission
Checked 61 author PRs, 162 fork heads, the complete acp-cache-diff history, and cache-diff/offset/Unicode PR and issue searches. Prior #2870 and #2341 concern the live cache-ledger module; they do not fix this offline byte-to-text coordinate mismatch.
Current master integration
Merged upstream master
fcc2e848486cc2152e36b6658c517fbfa51ec428into this branch without textual conflicts. The published merge commit is795c1b12449b3feaa7056b5e89eaf7062d932a35, with the original PR headb6c73fa3da5fc4e6e3b25688e9c6b1c7a164e3f3as its first parent and current master as its second parent.The cache-diff fix and its regression test file are byte-for-byte unchanged from the first parent; this update adds the current upstream history.
Fresh integration validation on Linux x64 / Node 24.22.1, after installing the locked dependencies:
npm run typecheck,npm run build,npm run check:unused-exports,npm run check:test-import-graphandgit diff --checkpass.cd679ce3c95c1d88548e0ac429b392b8b932ada6exactly matches the locally tested tree.The integration commit triggered hosted CI run 43377353291; its current result is available there. Complete hosted CI and real-model E2E are not claimed as passed by these local integration checks.
Review status
Linked to #6495 and ready for maintainer review. The latest integration validation includes upstream master
fcc2e848486cc2152e36b6658c517fbfa51ec428, as recorded above. Current hosted results are available in the Checks tab.Please apply the existing
ci:fulllabel to run the FULL matrix, including the required Windows / Node 24 checks. The default CORE matrix does not produce those checks.