← Back to Pull requests

Reject fetch() with the cause when the connection can't be made #8653

Closed
unknown closed this pull request without merging on Nov 21, 2026 04:53 UTC
View on GitHub
unknown unknown commented on Nov 19, 2026 06:47 UTC
Author

In workerd serve and local dev, fetch() to a host that doesn't resolve, or to a server whose certificate isn't trusted, rejects with an internal error that says nothing about what went wrong:

await fetch('https://does-not-exist.invalid/');
// Error: internal error; reference = u9huea2s0lhqrrns6d1g0cna

The outbound client, kj-hyper, turns the failed DNS lookup or TLS handshake into a FAILED kj exception with the I/O error as its description, which JavaScript only sees as an internal error. A refused connection is DISCONNECTED and already rejects with "Network connection lost.".

In this patch kj-hyper marks its failures with kj::Exception details instead of leaving fetch() to match their text:

  • A response head that doesn't parse gets an INVALID_RESPONSE_DETAIL_ID detail with the reason as its payload. fetch() reads the reason from it, so the message JavaScript sees doesn't change. kj's own HttpClient sets no detail, so fetch() still recognises its descriptions as before.

  • A connection that couldn't be made, when the cause is FAILED, fails with "Could not connect to the server: <cause>" and a CONNECT_FAILED_DETAIL_ID detail with the cause as its payload. DISCONNECTED and OVERLOADED connect failures keep their type and message.

  • fetch() turns that into "Network connection failed: <cause>", such as "Network connection failed: TLS handshake failed: invalid peer certificate: ...". Fetch treats this as a network error, so under fetch_invalid_response_type_error it rejects with a TypeError, like a response head that doesn't parse; without the flag it rejects with an Error. The flag has no enable date yet, and its documentation now covers this case too.
  • fetch-invalid-response-test checks a host that doesn't resolve and a TLS server with a self-signed certificate under both flags. The kj-hyper tests check both details, and that a refused connection stays DISCONNECTED without one.

    Fixes #8574

    Diff: 242 lines (+181 / -61) across 3 files Reviewer: littledivy Review duration: 2766m
    All Vouch review confidence checks passed
    Residual risk 0.15 = Change Risk (0.39) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 242 lines diff across 3 files
    0.39
    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.329
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #8653"
    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: 38.8% (MEDIUM) · Higher = larger blast radius
    38.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: 15.3% · Safe to merge
    15.3%