Skip to content

[PR] fix: isolate block summary/one CAS content parse in the unified storage reader (#7337) - #7338

Open
ranxianglei wants to merge 2 commits into
masterfrom
2026-11-20_block-cas-isolation
Open

ranxianglei wants to merge 2 commits into
masterfrom
2026-11-20_block-cas-isolation

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What & why

#7335 (PR #7336) isolated the message-content and block-payload parses in the unified storage reader, but the block summary/one CAS content (appendBlockContents, src/storage/ingest.ts) was left with a bare JSON.parse. A corrupt summary/one row — bad CAS bytes, or a missing CAS row leaving summary="" — threw out of the shared helper and aborted the whole cold load on BOTH the full-view and resident-field paths (the session fell back to the legacy file, or was discarded when none exists).

This closes the last gap in the poison-row isolation #7335 started.

How

Behavior change (flagged)

Dependency

This PR is based on and depends on PR #7336 (the #7335 fix that introduces skippedCorruptRows). It should merge after #7336. The diff against master currently includes #7336's changes because this branch is based on it; once #7336 merges I will rebase this branch on master so the diff shrinks to just this fix.

Tests

tests/storage-poison-row-isolation.test.ts — 3 new tests:

  • unit: corrupt summary/one rows are skipped and returned, not thrown (covers bad bytes, empty summary, and null one).
  • full-view: one corrupt summary CAS row degrades the view (messages + block metadata survive, the corrupt block's content is dropped).
  • resident-field: same via readResidentFieldsFor.

Verified the new tests FAIL on the pre-fix code (real regression tests). Targeted storage/persist suites + typecheck + build green locally; full suite on CI.

<-- ework-agent-pr -->

Fixes #7337

ranxianglei and others added 2 commits November 20, 2026 12:05
… in unified storage (#7335)

Field incident: 26 content rows of one pi session were poisoned by an
older dev build (CAS hash != stored bytes, JSON unparseable). The next
cold load threw out of LegacyViewBuilder, the legacy fallback found no
file, the state was discarded ('starting fresh') and a ~600K-token
context re-folded from scratch in 32 serial preflight summary rounds
(67-84s each) — a 12+ minute user-visible freeze.

Two structural gaps closed:
- writer (store.ts + mysql.ts putContent): caller-supplied digests are
  now verified against sha256(bytes) and a mismatch fails the save
  loudly instead of persisting a hash/bytes pair readers cannot use.
- reader (ingest.ts LegacyViewBuilder, shadow.ts): unparseable rows are
  skipped and recorded (skippedCorruptRows; tail rows counted into the
  existing tailGaps) and the load path logs which rows were dropped —
  the session loads degraded with all blocks/refs intact. The
  verify-sample verifier gets the same isolation (marks drift instead
  of failing every subsequent save).

Regression tests: tests/storage-poison-row-isolation.test.ts (poisoned
digest refused with full rollback; poisoned message row -> view loads
with tailGaps>=1 and all blocks; poisoned block payload -> view loads
with all messages).

Fixes #7335
… aborts the session load

#7335 isolated the message-content and block-payload parses in the unified
storage reader, but the block summary/one CAS content (appendBlockContents)
was left with a bare JSON.parse. A corrupt summary/one row — bad CAS bytes, or
a missing CAS row leaving summary="" — threw out of the shared helper and
aborted the whole cold load on BOTH the full-view and resident-field paths
(the session fell back to the legacy file, or was discarded when none exists).

appendBlockContents now skips an unparseable row and returns it; the full-view
path folds it into skippedCorruptRows (logged via warnCorruptSkips) and the
resident-field path logs it. The rest of the session loads degraded, with all
blocks/refs/messages intact — consistent with #7335's isolation.

Regression tests: tests/storage-poison-row-isolation.test.ts (unit: corrupt
summary/one rows skipped+returned; full-view: one corrupt summary CAS row
degrades the view; resident-field: same). Verified the new tests fail on the
pre-fix code.

Fixes #7337
@ranxianglei ranxianglei added bug Something isn't working p1 scope/storage labels Nov 20, 2026
@ranxianglei ranxianglei changed the title fix: isolate block summary/one CAS content parse in the unified storage reader (#7337) [PR] fix: isolate block summary/one CAS content parse in the unified storage reader (#7337) Nov 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-20_block-cas-isolation (146e5f7)

Latest build — install this exact version

npm install -g billion-context@0.0.11036-pr.7338.23240f8

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

Recent builds (commit → version)

commit version build
146e5f7 billion-context@0.0.11036-pr.7338.23240f8 build

Download artifact

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

(ai: vllm-qwen/qwen3.8-27b)

查重: 不重复。 本线程是 PR #7338 的镜像(带 ework-agent-pr 标记,工作已由 agent 完成),是 #7337 的唯一修复 PR,无并行 PR。依赖的 #7336 是 #7335 的独立修复 PR,不属重复项。

This is a [PR] thread — the work is done, so I verified the code, ran the targeted regression tests, and checked CI rather than redoing it.

What I verified

  • Code review (clean): appendBlockContents (src/storage/ingest.ts:619) now wraps the one/summary CAS JSON.parse in a try/catch, skips unparseable rows, and returns them — instead of throwing out of the shared helper. Both call sites handle the new return value: the full-view path (LegacyViewBuilder.addBlocks, src/storage/ingest.ts:727) folds skipped rows into skippedCorruptRows (logged via warnCorruptSkips), and the resident-field path (readResidentFieldsFor, src/storage/shadow.ts:764) logs them. No other callers exist, so no silent-skip. completeBlockContents (the other imported helper) does no JSON.parse, so it is not affected.
  • Real regression tests: ran tests/storage-poison-row-isolation.test.ts in a worktree. On the fixed code all 6 pass (3 pre-existing + 3 new). Reverting only src/storage to the pre-fix base makes the 3 new tests fail (they poison real CAS bytes in the DB, not mocks) — so they genuinely catch the bug.
  • Typecheck: clean (tsc --noEmit).

CI status (live): in progress — 11 checks pending (test shards ubuntu/windows × node 22/24, static-gates, mysql-contract), 0 failed so far. The full-suite verdict is CI's; my local run was targeted only (per local-testing discipline). I'll follow up when CI completes.

Dependency note: this branch is based on #7336 (still open), so its diff vs master currently includes #7336's changes. Per the PR description the author will rebase onto master once #7336 merges, shrinking the diff to just this fix. #7336 must merge first.

Labels: already applied (bug, p1, scope/storage) — correct for this diff.


结构化八问

  1. 是什么问题:统一存储读取器里 block 的 summary/one CAS 内容(appendBlockContents)还留着裸 JSON.parse;一行坏 summary/one(坏 CAS 字节或 CAS 行缺失致 summary="")会抛出并中止整个冷加载(会话回退 legacy 文件,无文件则被丢弃)。是 A single bad data row can blow up the entire session: storage writes don't verify content hashes, and a single row parse | 一条坏数据行可以炸掉整个会话:存储写入不校验内容哈希,加载时单行解析失败就丢弃全部状态 #7335 隔离毒行时漏掉的最后一处。
  2. 什么原因导致的:appendBlockContents 是 full-view 与 resident-field 两条读取路径共用的 helper,对每行裸 JSON.parse 且无 try/catch——单行损坏的异常直接穿透 helper 中止整个加载。
  3. 影响范围与严重程度:统一存储(BILI_STORAGE_UNIFIED)会话遇任一 block 的 summary/one CAS 行损坏时整个冷加载失败。p1——会话无法恢复/数据丢失类。
  4. 怎么修复的:appendBlockContents 改 try/catch 隔离——不可解析行跳过并返回(不再抛);full-view 路径并入 skippedCorruptRows(经 warnCorruptSkips 记 warn),resident-field 路径单独记日志;其余会话降级加载,所有 block/refs/messages 保留。与 A single bad data row can blow up the entire session: storage writes don't verify content hashes, and a single row parse | 一条坏数据行可以炸掉整个会话:存储写入不校验内容哈希,加载时单行解析失败就丢弃全部状态 #7335 一致。
  5. 是否有回归问题:审了 appendBlockContents 全部调用点(addBlocks、readResidentFieldsFor)均处理新返回值,无静默跳过;completeBlockContents 不做 JSON.parse 不受影响。行为变更(PR 已披露):旧=坏行中止整个会话加载;新=坏行跳过、会话降级加载(坏 block 内容丢弃、其余保留)+ warn 日志——有意且与 A single bad data row can blow up the entire session: storage writes don't verify content hashes, and a single row parse | 一条坏数据行可以炸掉整个会话:存储写入不校验内容哈希,加载时单行解析失败就丢弃全部状态 #7335 对齐,非回归。
  6. 是否破坏缓存:不涉及——存储读取容错,不触碰缓存/重试/增量游标/去重键。
  7. 是否改了设计方向:不涉及——沿用 A single bad data row can blow up the entire session: storage writes don't verify content hashes, and a single row parse | 一条坏数据行可以炸掉整个会话:存储写入不校验内容哈希,加载时单行解析失败就丢弃全部状态 #7335 既定毒行隔离机制(skippedCorruptRows + warnCorruptSkips),无架构转向。
  8. 是否引入了新的配置:不涉及——无新 env/config/默认值。

合并判定:代码干净、修复完整且最小、回归测试真实(pre-fix 失败 / fixed 通过)、typecheck 绿。待 CI 全量绿后可合(当前 CI 进行中、0 失败);前置条件为 #7336 先合、本 PR 随后 rebase 到 master 收敛 diff。

@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: vllm-qwen/qwen3.8-27b)

Superseded by PR #7336 — labelled, not closing (close is owner-only).

While this PR was in flight, PR #7336 landed a review follow-up (commit 34da63d) that independently found and fixed the same gap this PR targets — appendBlockContents's unisolated block summary/one CAS parse — and went further: it also isolates BatchedViewVerification.addBlocks (the verify-sample verifier's bare payload_json + summary/one CAS parse, which a corrupt block row would throw inside and fail every subsequent save).

So #7336's fix is a strict superset of this one (same appendBlockContents/addBlocks/readResidentFieldsFor coverage, plus the verify-sample verifier). The two PRs touch the same lines with slightly different designs (this one returns the skipped rows; #7336 passes a skipped? sink), so merging this on top of #7336 would conflict for no net gain.

Recommendation: close this as superseded and let #7336 carry the fix. Requesting owner action.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

Independently verified — the supersession is correct. I did not take the recommendation at face value; I examined #7336's actual code and confirmed the conflict.

What I checked

One nuance (test coverage only, not the fix): #7338 carries two tests #7336's branch does not — a direct unit test of appendBlockContents and a resident-field (readResidentFieldsFor) degradation test. The isolation logic itself is already in #7336, so this is coverage, not behavior. If you want #7336 to carry the full test value, I can port those two cases onto #7336's branch (the unit test needs adapting to #7336's sink-param signature; the resident-field test is behavior-based and ports as-is). Your call — no action needed otherwise.

I can't close #7338 (close is owner-only). The verification supports your recommendation: close this as superseded and let #7336 carry the fix.

CI (live): both still in progress, 0 failed so far — #7336: 12 pending; #7338: 11 pending. #7336's own commit reports storage-* family 326 pass / 0 fail.


结构化八问

  1. 是什么问题:[PR] fix: isolate block summary/one CAS content parse in the unified storage reader (#7337) #7338 修的 appendBlockContents 裸 JSON.parse 缺口,已被 [PR] fix: refuse unverifiable content digests and isolate unparseable rows in unified storage (#7335) #7336 的后续 commit(34da63ddfe8)覆盖——本 PR 属重复修复。
  2. 什么原因导致 supersede:[PR] fix: refuse unverifiable content digests and isolate unparseable rows in unified storage (#7335) #7336 在 review follow-up 里独立修了同一缺口,且额外修了 BatchedViewVerification.addBlocks(verify-sample 的裸 parse),是 [PR] fix: isolate block summary/one CAS content parse in the unified storage reader (#7337) #7338 的严格超集;两者改同一函数签名与调用点、设计不兼容。
  3. 影响范围与严重程度:不涉及 [PR] fix: isolate block summary/one CAS content parse in the unified storage reader (#7337) #7338 的行为——它不应被合并;修复由 [PR] fix: refuse unverifiable content digests and isolate unparseable rows in unified storage (#7335) #7336 承担。
  4. 怎么"处理"的:不修本 PR——独立核实(读 [PR] fix: refuse unverifiable content digests and isolate unparseable rows in unified storage (#7335) #7336 代码 + git merge-tree 确认三文件冲突)后确认 supersede 成立,建议关闭 [PR] fix: isolate block summary/one CAS content parse in the unified storage reader (#7337) #7338、让 [PR] fix: refuse unverifiable content digests and isolate unparseable rows in unified storage (#7335) #7336 带修复。
  5. 是否有回归问题:不涉及——[PR] fix: isolate block summary/one CAS content parse in the unified storage reader (#7337) #7338 不合并即无回归面;[PR] fix: refuse unverifiable content digests and isolate unparseable rows in unified storage (#7335) #7336 的修复已单独验证(storage 家族 326 pass / 0 fail)。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及——沿用 A single bad data row can blow up the entire session: storage writes don't verify content hashes, and a single row parse | 一条坏数据行可以炸掉整个会话:存储写入不校验内容哈希,加载时单行解析失败就丢弃全部状态 #7335 既定毒行隔离机制。
  8. 是否引入新配置:不涉及。

判定:supersede 成立,可关 #7338(关闭动作归 owner)。唯一可选增值:把 #7338 的两个测试补进 #7336 分支(需你点头)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

Status (re-verified live): nothing has changed since my last comment — the thread is waiting on your decision.

Where this stands (from my previous comment, unchanged):

Action needed from you: close #7338 as superseded (your call, owner-only). Optionally approve the 2-test port to #7336.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant