← Back to Pull requests

feat(runtime): give ArchiveRead search, line reads, and decoded paging #4380

Closed
unknown closed this pull request without merging on Sep 02, 2026 03:23 UTC
View on GitHub
unknown unknown commented on Aug 31, 2026 15:21 UTC
Author

What

Once a large tool result is archived, retrieving content from it was awkward (issue #4355, part of #4267):

  • no search-within-archive — you could only page blindly by character offset;

  • character-only reads — poor for line-oriented terminal output;

  • read sliced the JSON-escaped serialization — pages landed on escape bytes (\n, \") rather than decoded text;

  • inspect gave no preview or coordinate space for plain-text / object payloads (only keys for objects, valueType for scalars).
  • This extends ArchiveRead within the existing ≤TOOL_RESULT_ARCHIVE_MAX_RESPONSE_CHARS bounded-response invariant, so a read can never itself trigger another archive:

  • search operation — a literal, case-insensitive substring scan returning matched offset, line, and a bounded context snippet per hit; capped per page (TOOL_RESULT_ARCHIVE_MAX_SEARCH_MATCHES) with nextOffset/hasMore to resume.

  • line-based reads — unit: "line" pages whole lines by line offset/limit, trimmed by binary search to the response budget, with nextLineOffset. unit defaults to "char" so existing callers are unaffected.

  • decoded paging — string (terminal/text) payloads page the decoded string so offsets land on real characters; structured payloads still page their canonical JSON.

  • inspect positional index + preview — text payloads report totalChars/totalLines and a short preview; object/scalar payloads report totalChars and a preview (objects with an items[] manifest keep their existing shape).
  • Why it's safe

  • Search is literal, never a regex — no pathological backtracking, no ReDoS.

  • Every response path (search, line, char, inspect) is bounded to TOOL_RESULT_ARCHIVE_MAX_RESPONSE_CHARS — search stops adding matches, and line reads binary-search their line count, before the envelope overflows.

  • Scope is retrieval ergonomics only: the archive threshold behavior (active-tool-result-prune.ts) and the upstream Shell capture/preservation contract are deliberately untouched, per the audit.
  • Tests

    Six regression tests in tool-result-archive-resource.test.ts:

    1. inspect surfaces a positional index + preview for text payloads.
    2. read pages the decoded string, not the escaped JSON.
    3. read by line range returns whole lines and resumes with nextLineOffset.
    4. search locates a case-insensitive substring with offsets, line numbers, and snippets.
    5. search stays within the response budget and resumes (nextOffset) under a pathological dense-match input.
    6. search without a pattern fails closed.

    Causal proof (fail-without / pass-with): with the production dispatch temporarily reverted to the old char-only / serialized-JSON behavior, all six new tests fail (# fail 8, the extra two being the pre-existing inspect-manifest tests under the crude stub); with the change restored, the suite is green (# pass 11).

    Part of #4267. Closes #4355.

    Diff: 373 lines (+279 / -94) across 4 files Reviewer: liugddx Review duration: 2162m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 373 lines diff across 4 files
    0.43
    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%
    60%
    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.354
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #4380"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 42.8% (MEDIUM) · Higher = larger blast radius
    42.8%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 16.9% · Safe to merge
    16.9%
    Repository