Repository navigation
fix(transcripts): skip terminated torn prefixes instead of failing every read - #2301
Conversation
…ery read append_line's torn-tail fix-up terminates a crash-truncated tail with a newline, promoting the torn bytes into a complete line. The line still sniffs as its leading "type", so the layout indexes it — but it can never decode, and every layout-indexed read path hard-failed on it forever (session.get, session_search context, messageAround). vastsa#1636's fix only covers the invalid-UTF-8 variant, so a legal-UTF-8 torn prefix was the one case no reader tolerated. Decode failures that serde reports as EOF-category errors ("EOF while parsing ...", also surfaced inside the invalid-binary-storage reason for encoded lines) are now skipped with a warning in: - read_transcript_window_with_layout (message and compaction branches) - read_transcript_window (sequential path, binaryStorage variant) - find_message_position (reverse identity scan) - read_tool_call (identity and record decode) Corruption-blocking on the write path (binary_integrity verify) is unchanged: a truncated encoded line is indistinguishable from real corruption there, by design. Fixes vastsa#2298
There was a problem hiding this comment.
AIUO CodePilot · Preliminary review
Diff-only preliminary review of PR #2301 (host-core transcript torn-prefix skip). Change routes decode failures whose error text contains "EOF while parsing" into the existing skip-with-warning paths across indexed and sequential readers. No evidenced correctness defect found in the diff; matching is string-based on serde's error text and covered paths appear consistent with the stated scope. Tests/compile were not executed and repository state was not inspected, so formatting, compile errors, and behavior outside the diff remain unverified.
No evidenced findings in the supplied diff.
Head: fe68b42
Base: 7841a98
CI: pending; mergeable: true.
Validation: code/tests NOT EXECUTED. Diff-only preliminary analysis; not approval. Human review and repository gates remain required.
vastsa
left a comment
There was a problem hiding this comment.
Confirmed the torn-prefix failure from the production append/layout/read paths, and both new regression tests pass locally on a candidate integrated with main 30dd376. However, the new classifier introduces a corruption-handling regression: error.to_string().contains("EOF while parsing") also matches data/type errors containing that text as an offending value, not just EOF parse errors.
Independent executed reproduction: append a complete, newline-terminated message JSON whose binaryStorage is {"version":"EOF while parsing","data":[],"refs":[],"texts":[]}, refresh the layout, then call read_transcript_window_with_layout. Main correctly returns InvalidStorage (version must be u32); this candidate silently drops the row and returns success. A Rust regression asserting is_err passes on main and fails on this candidate. This violates the stated preservation of non-truncation corruption errors and can hide damaged user history. The same predicate also affects sequential reads.
Please preserve typed EOF classification at the JSON parse boundary, including the wrapped InvalidStorage case (e.g. retain a typed source/category rather than searching Display text), and use serde_json::Error::is_eof for direct serde errors. Keep complete malformed/structurally invalid encoded rows as hard errors regardless of their string values. Add this negative regression alongside the torn-prefix positive cases. No need to redesign the append/layout approach.
Validation: two new torn-prefix Rust tests PASS; independent corruption regression candidate FAIL / main PASS; diff check PASS. No full Host/Electron E2E or merge acceptance performed after finding this substantive blocker.
|
The plain-JSON variant is real and the skip fixes it. Before landing:
|
String-matching error.to_string() for "EOF while parsing" also matched corruption errors that merely contain that text as a value (e.g. a binaryStorage version field with that string), silently dropping rows that main reports as InvalidStorage. Keep typed EOF classification at the JSON parse boundary: - direct serde errors use serde_json::Error::is_eof() via downcast; - encoded lines keep the InvalidStorage category but wrap a serde EOF in a separately downcastable InvalidStorageEof (same Display, so writes keep blocking on it); - complete structurally-invalid encoded rows stay hard errors. Adds a negative regression for the maintainer's repro.
|
@koeria is attempting to deploy a commit to the vastsa's projects Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
AIUO CodePilot · Preliminary review
Diff-only preliminary review of PR #2301, which classifies serde EOF-category decode failures as torn prefixes and skips them in transcript read paths while keeping write-path mutation blocking. The typed-error approach avoids Display-string matching and includes regression tests. No concrete defect was evidenced on the added lines; verification is limited to the supplied patch text, with no build, test, or repository access.
No evidenced findings in the supplied diff.
Head: 4534e9f
Base: 7841a98
CI: pending; mergeable: true.
Validation: code/tests NOT EXECUTED. Diff-only preliminary analysis; not approval. Human review and repository gates remain required.
|
Follow-up on 4534e9f: the typed EOF classification fixes the Display-text false positive, and the new complete-encoded-row negative regression is present. I ran transcripts::tests:: on this head: 41 passed, including the torn-prefix and hard-error cases. The other 02:33 blocker remains. An independently executed production-module probe creates a terminated torn binaryStorage row, refreshes the layout, successfully reads the surviving message through read_transcript_window_with_layout, then attempts append_message: the append still returns an error. This follows directly from binary_integrity::verify rejecting InvalidStorageEof via is_error. Thus an apparently readable session still cannot persist a follow-up; the new test explicitly constructs the encoded fixture directly instead of proving append/restart recovery. Please either scope this PR to plain JSON and retain the existing fail-closed encoded read/write behavior, or implement a deliberate consistent encoded recovery policy with data-safety coverage. Add a restart/read/append regression for the chosen behavior. No need to redo the typed classifier. Not merging yet; no full Host/Electron E2E or integration acceptance claimed. The independent probe passed by asserting the remaining read-success/append-error mismatch; it is evidence of the blocker, not a successful recovery test. |
…rification binary_integrity::verify rejected every is_error from validate_line, including the typed InvalidStorageEof of a crash-truncated encoded row. Reads already skip such terminated torn prefixes, but the write path still refused the whole file, so a session could open after a crash yet never persist another message. Align verify with the read paths: skip InvalidStorageEof rows, keep every other InvalidStorage error a hard failure for mutations. Also add append/update regressions and split the corrupted-row fixture accordingly (the truncated JSON row is a torn prefix, not structural corruption). Fixes vastsa#2298
vastsa
left a comment
There was a problem hiding this comment.
已复核修订:类型化 EOF 判定保留完整 encoded 损坏为硬错误;写入 verifier 现在与读取一致,先前两个阻碍已解决。原始问题的独立生产模块复现及基线差异见此前 review。
本轮验证:以 main 22a55cf 集成的候选 transcript 92/92、locked Host build 均通过;独立真实 Host process 验证普通/encoded 截断的 stop → seed torn bytes → restart → append → restart → session.get 成功且原始截断字节保留;完整 encoded 损坏(含 EOF while parsing 字符串值)读取/追加均拒绝且文件字节不变。当前五项 Actions 通过,包括 Windows transcript cache 与 Electron E2E;Vercel preview 为团队授权限制。
等待 CI 期间 main 前进至 c39e301(会话协作功能,未改 transcript 代码)。已在独立工作树重新集成,最终候选树 e531687baf7a21f1f266e32765179697710ccd9c:重新运行92项 transcript、locked Host build 与上述三项真实进程验证全部通过。GitHub merge-ref 仍显示旧 base,最终以此最新 main 的本地可执行集成状态验收。
补充披露:本地全量 Host 为1306通过/1失败/1忽略;唯一 review_rpc_records_workspace_scratch_and_approved_external_write_edit 的 external/workspace 断言失败在未修改 main 22a55cf 独立工作树也同样复现,属于既有本地问题,非本 PR 回归。不声称本地全量通过,未调用付费模型/执行已安装客户端升级验收。
Summary
Fixes #2298.
append_line's torn-tail fix-up terminates a crash-truncated tail with a newline, promoting the torn bytes into a complete line. The line still sniffs as its leading"type"(the discriminator precedes the truncation point), so the layout indexes it as a message — but it can never decode, and every layout-indexed read path hard-failed on it forever:session.getbounded-window reads,session_searchcontext,messageAround,find_message_position's reverse scan,read_tool_call.with_layout_recoveryonly rebuilds onInvalidLayoutBoundary, so it never self-healed.#1636 (closed) only covers the invalid-UTF-8 variant; a legal-UTF-8 JSON prefix was the one case no reader tolerated.
Change
Decode failures that serde reports as EOF-category errors (
"EOF while parsing ...", which also surfaces verbatim inside theinvalid binary storagereason for encodedbinaryStoragelines) are now skipped with a warning, matching how the sequential path skips unparseable lines, in:read_transcript_window_with_layout— message and compaction branchesread_transcript_window— sequential path (fixes thebinaryStorage/InvalidStoragevariant, which previously hard-failed there too)find_message_position— reverse identity scanread_tool_call— identity and record decodeDeliberately unchanged:
binary_integrity::verifystill blocks mutations on anyInvalidStorageline. A truncated encoded line is indistinguishable from real corruption at the JSON level, and the write-path guard's contract (seemalformed_and_structurally_invalid_encoded_rows_block_mutations) is to block such files; this PR restores readability without weakening that.Tests
Two new regression tests (
terminated_torn_prefix_is_skipped_by_every_read_path,terminated_torn_encoded_prefix_is_skipped_too) drive a real torn tail throughappend_line's fix-up and assert all read paths return the surviving records instead of erroring.cargo test -p host-core: 1246 passed, 2 failed — the 2 failures (invalid_encoded_revision_blocks_stored_and_live_revision_appends,same_size_rewrite_restoring_mtime_cannot_reuse_a_verified_generation) fail identically on unmodifiedmain(pre-existing, unrelated).cargo fmtclean; clippy warnings present are all pre-existing (unrelated sites).