← Back to Pull requests

test_runner: do not crash on stdout that mimics a v8 frame #66273

Closed
unknown closed this pull request without merging on Oct 01, 2026 13:48 UTC
View on GitHub
unknown unknown commented on Sep 25, 2026 03:58 UTC
Author

Summary

node --test can crash the parent runner when a test writes bytes to stdout that look like a v8 report frame. A single console.log of the wrong bytes aborts the whole run with an internal error that does not point at any test:

Error: Unable to deserialize cloned data.
    at #processRawBuffer (node:internal/test_runner/runner:...)

Fixes: #66164

Root cause

The child test process multiplexes framed report messages and raw user stdout on one pipe. A frame starts with the two magic bytes FF 0F followed by a 4 byte size. #processRawBuffer scans for that magic, reads the size and hands the payload to the v8 deserializer. User output can contain those same bytes, so stray stdout with a plausible size reaches the deserializer, which throws. The call had no error handling, so the exception aborted the entire run. The earlier >>> 0 fix in #64706 hardened the size read only. This case has a valid looking size and fails one step later at the deserialize.

Fix

The reporter writes each frame as a v8 header, a 4 byte size, then a second v8 header, then the serialized value. So a real frame always repeats the FF 0F header at the start of its payload. #processRawBuffer now uses that structure instead of a blanket catch:

1. Validate before deserializing. A candidate is handed to the deserializer only when its payload is long enough and begins with the inner v8 header. Stray stdout that only mimics a frame fails this check and is emitted as stdout. A genuine frame with a valid inner header that still fails to deserialize is left to throw, so a real regression in the report protocol surfaces instead of being hidden.
2. Resync live. When the bytes only mimic a frame, one byte is emitted as stdout and the header search restarts right away, so a real frame that follows stray bytes is reported immediately instead of waiting for shutdown.
3. Single loop. #processRawBuffer is now one loop that inspects the head of the buffer on each pass and handles exactly one case: leading stdout, an incomplete frame, a frame that only mimics the header, or a real frame. This replaces the earlier nested loops and the mimicsFrame flag.

This turns a fatal crash into recoverable stdout, keeps any real frames that follow the stray bytes and surfaces genuine deserialize failures.

Tests

Added cases to test/parallel/test-runner-v8-deserializer.mjs:

  • stdout that mimics a frame with a plausible size becomes stdout and does not crash

  • that false frame followed by a real message: the parser resyncs live and reports the real event before drain()

  • a real message, then the false frame, then another real message: both real messages survive

  • several stray frames in a row are peeled off as stdout and a real message after them is still reported

  • the false frame split across two chunks still recovers as stdout

  • a frame whose payload is shorter than the inner header is treated as stdout

  • a genuinely corrupt frame with a valid inner header is left to throw instead of being hidden
  • Known limitation (possible follow-up, out of scope here)

    For stray bytes to be misread now they would have to reproduce the full frame shape, the outer header, a matching size, the inner header, then a valid serialized payload. This is pre-existing and extremely unlikely. Fully removing the ambiguity needs an escape mechanism or a separate channel for user stdout, which is a larger change. This PR removes the crash, which is the reported bug.

    Diff: 436 lines (+327 / -109) across 5 files Reviewer: MoLow Review duration: 9229m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.45) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 436 lines diff across 5 files
    0.45
    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.364
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #66273"
    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: 45.2% (MEDIUM) · Higher = larger blast radius
    45.2%
    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: 19.6% · Safe to merge
    19.6%
    Repository