← Back to Pull requests

Handle lossy UTF-8 and multi-frame zstd safely in shared line readers #138

Closed
unknown closed this pull request without merging on Nov 25, 2026 01:32 UTC
View on GitHub
unknown unknown commented on Nov 23, 2026 04:44 UTC
Author

Split out from #130 as requested, covering only the shared reader changes in src/util.rs and their tests + CHANGELOG.md entry.

Changes

1. Lossy UTF-8 line decoding for under-cap plain files (session_lines_windowed):
- Uses the same byte-oriented read_until(b'\n') + String::from_utf8_lossy loop as for_each_line instead of truncating on the first bad byte (as on main) or failing the whole session on a torn mid-character final line.
- Real I/O errors continue to propagate.
- Added unit tests (including subsequent valid lines after invalid UTF-8) and a gptme integration regression test with a torn multibyte final JSONL line (tests/external_adapter_readers.rs).

2. Multi-frame .zstd/.zst reading without regressing single-frame Codex .zst:
- Existing .zst entry points (session_lines, session_lines_windowed, session_lines_keeping, for_each_line) keep single-frame decoding, preserving exact Codex compatibility when trailing bytes appear after frame 1 (tests/parse.rs).
- .zstd defaults to concatenated multi-frame decoding (ZstdFrames), and callers can opt .zst into multi-frame reading via util::session_lines_concat_zstd / util::for_each_line_concat_zstd.
- After at least one complete data frame, an incomplete trailing frame (truncated magic prefix, header, block, or checksum) is treated like a torn final JSONL line: complete newline-terminated records already decoded are kept and any partial unterminated line is discarded, while first-frame errors, non-EOF corruption, and genuine I/O errors still fail.

Validation


  • cargo fmt --check

  • cargo clippy --all-targets -- -D warnings

  • cargo test (370 passed, 0 failed)
  • Diff: 214 lines (+160 / -54) across 2 files Reviewer: youdie006 Review duration: 2687m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.37) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 214 lines diff across 2 files
    0.37
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.321
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #138"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 36.6% (MEDIUM) · Higher = larger blast radius
    36.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.8% · Safe to merge
    15.8%