Skip to content

[PR] fix(web): preserve frozen message whitespace on retrieval - #6718

Merged
ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-14_frozen-message-whitespace
Nov 14, 2026
Merged

ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-14_frozen-message-whitespace

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Closes #6717

Problem

When a message has left both the resident window and unified storage, the Web panel can recover it from a frozen block-content snapshot. That parser currently uses an empty accumulated string to detect the first body line and removes every trailing newline. Opening the original message therefore silently drops its leading and trailing blank lines, even though the frozen snapshot still contains them.

For example, a message whose exact text is \n\n first line is returned as first line; last line\n\n is returned as last line.

Change

Track whether a body line has been consumed separately from its contents. When another role header follows, remove only the one empty line contributed by the snapshot's two-newline separator. At the end of the snapshot, retain the entire body. Keep the existing first-marker eligibility separate from whitespace accumulation so ref anchoring continues to work around leading blank lines.

This changes only the read-only Web snapshot fallback. Snapshot serialization, retained originals, live/store lookup priority, byte caps, and the existing alignment/foreign-marker rejection checks remain intact. Plugin and proxy modes use the same diagnostic reader; neither request pipeline nor kernel source changes.

Verification

  • Added 18 round-trip cases through the real kernel collectBlockContent() serializer and public buildMessageContent() reader: leading/trailing blank lines, newline-only bodies, CRLF content, empty messages, and ordinary text, each at the first, middle, and last position. The old implementation fails 12 cases and passes six controls.
  • Added three marker cases preserving zero, one, or two leading blank lines while removing the recognized ref marker. All returned text and byte counts are checked, and the frozen snapshot remains unchanged.
  • 84/84 related tests pass across web-blocks-tree, web-storage-fallback, and web-sessions, including the existing shifted/foreign marker, partial snapshot, restamped-ref, lazy storage, and ordinary rendering controls.
  • Full npm run typecheck, npm run build, and git diff --check pass on current master 3858b6956abab52da781c2436c0245586ce18358 plus this change. Local targeted tests use the repository's preload chain and an isolated writable temporary directory.
  • Independent read-only review checked the producer's exact header/separator format and the parser's EOF, empty-body, and marker boundaries; no blocking finding remained.

Full-suite status comes from hosted CI on the pushed head.

History check

Reviewed the complete 111-entry Afloat16 changed-file/patch index and the relevant current-batch changes, plus focused all-state issue/PR searches. #6260 introduced this parser with the current whitespace loss; its actual patch was checked. #6593 changes the separate one-line preview allocator only. The open #6713 batch does not touch this source file. No previous matching whitespace-preserving snapshot read was found.

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

Review — PR #6718 fix(web): preserve frozen message whitespace on retrieval

Duplicate screening: no duplicate. Independent all-state search (frozen-snapshot whitespace / buildMessageContent / parseBlockContentMessages / leading-trailing blank lines) returns nothing; consistent with the PR's own history check (#6260 introduced this parser with the loss, no prior whitespace-preserving reader).

What I verified independently (not just the PR's claims):

  • Bug is real. Traced the old parseBlockContentMessages (src/web/sessions-data.ts:1655): it used cur.text === "" as the first-line marker (an empty first body line is conflated with "no body yet") and cur.text.replace(/\n+$/, "") (strips every trailing newline) — message body and the \n\n separator are treated as one. Reverting to the old parser and running the PR's new tests: 15 cases fail (12 round-trip + 3 marker), 6 controls pass — exactly the PR's stated numbers.
  • Fix is correct. Traced leading / trailing / blank-only / CRLF / empty / ordinary bodies at first, middle, and last position, plus marker-with-0/1/2-leading-blanks, through the real kernel collectBlockContent serializer and the public buildMessageContent reader — all byte-exact. Two subtle points are handled right: bodyLines (have I consumed any body line, for the join) is correctly separated from "text is empty" (ambiguous with leading blanks), and !hasText (no non-empty line yet) is the right marker gate so a marker after leading blanks still anchors — it is semantically equivalent to the old cur.text === "", so ref anchoring is unchanged.
  • No regression. The only behavior change is that the re-parsed text now keeps leading/trailing whitespace. Item splitting (header-driven) and ref alignment are untouched. Both consumers are covered: buildMessageContent (full text, the target) and buildSessionDetail (preview, which collapses whitespace so it's unaffected). The existing shifted / foreign-marker / partial / non-leaf rejection tests stay green. No kernel, config, wire, or persistence change.
  • Tests are real, not tautological. Round-trip through the actual kernel serializer + public reader (no mocks), asserting exact text and byte counts. They reproduce the bug (fail on old code) and pin the fix.
  • Local: typecheck clean, git diff --check clean, 98 targeted tests green (web-blocks-tree 52, web-storage-fallback + web-sessions 32, plus the 3 other sessions-data suites 14).

CI: still in progress on the pushed head (407deb5) — 5 gates green, 10 e2e lanes skipped, 15 test/build lanes still queued, no failures so far. The authoritative full-suite verdict is the remote CI test lanes on that head.

Auto-merge gate (§7.4): all 8 hold — single-module web-reader fix, reproducing regression test, green locally, no config/persistence/wire/kernel touch, pure fix:, clean 2-file diff, references #6717, no load-bearing infra. (The merge itself stays human-only.)


八问

  1. 是什么问题:Web 面板从冻结快照恢复单条消息时,会丢掉原文开头的空行和结尾的换行(快照里其实还在)。
  2. 什么原因导致的:parseBlockContentMessages 用 cur.text === "" 判断"首行"(空首行被误当成"还没有正文"),又用 replace(/\n+$/,"") 剥掉所有结尾换行——把消息正文和 \n\n 分隔符混为一谈。
  3. 影响范围与严重程度:只影响只读的 Web 单条消息视图,且仅在消息已离开驻留窗口、统一存储又无行、走快照兜底那条路径时;跨宿主车道。体验瑕疵级——完整块视图仍能看到原文,但单条点开会少空白字节。
  4. 怎么修复的:把"是否已消费过正文行"(bodyLines)和"是否出现过非空正文"(hasText)与正文内容分开跟踪;只在"后面还有 role 头"时剥掉分隔符贡献的那一个空行,EOF 处不剥;首标记资格判定改用 !hasText,与空白累积解耦。
  5. 是否有回归问题:无。消息切分(按 role 头)与 ref 对齐逻辑未动;!hasText 与旧 cur.text === "" 语义等价;两个消费方(全文/预览)都覆盖,预览折叠空白不受影响;shifted/foreign/partial/non-leaf 拒绝用例全绿。无 kernel/配置/协议/持久化变更。
  6. 是否破坏缓存:不涉及——纯只读 Web 诊断路径,不碰缓存/重试/增量游标/去重键。
  7. 是否改了设计方向:不涉及——快照序列化、保留原文、live/store 查找优先级、字节上限、对齐与外来标记拒绝检查全部原样。
  8. 是否引入了新的配置:不涉及。

判定:可合并(mergeable)。 修的是根因(解析器把正文与分隔符混淆),不是治标;测试是真回归测试(旧码 15 例红、新码全绿);diff 干净、无回归、无阻断项。等 CI 全绿后由 owner 合并即可。

@ranxianglei
ranxianglei merged commit 4792566 into ranxianglei:master Nov 14, 2026
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Frozen message retrieval drops original leading and trailing blank lines

2 participants