← Back to Pull requests

Gate guest entry during mutation application, not just in-flight calls #1

Closed
unknown closed this pull request without merging on Sep 01, 2026 03:45 UTC
View on GitHub
unknown unknown commented on Sep 01, 2026 02:25 UTC
Author

Fixes the second reentrancy window found in review (H1).

The queue added with the TodoMVC port (aee9b6d) serializes guest entries only while a handle-event call is in flight. But mutations are also applied inside the mutation stream's direct-read consume callback — synchronously inside the guest's write rendezvous, with a live guest turn on the stack. A scheduler-driven flush (timer / async re-render, no handle-event in flight) whose DOM application detaches a focused element fires focusout synchronously, and the delegated listener dispatched straight into the guest from inside the rendezvous:

  • traps on the pinned runtime ("cannot enter component instance … (reentrance forbidden)" — the reentrance bracket is turn-scoped, runtime/src/task/thread.ts / exec/boundary.ts:1376), and

  • violates embedder-api.md A21 outright: "Inside the callback, calls that can run guest code or operate this stream are forbidden (reentrancy)" — with the independent memory-safety reason that the DirectSource view aliases guest linear memory, which guest code could memory.grow/detach mid-decode.
  • (Post CM PR #705 the trap likely becomes an implicit deferral, but the A21 rule stays in force — this fix is portable across both.)

    Change

  • host/src/dispatch.ts (new): DispatchGate — pure, unit-testable serialization of guest entries across both forbidden windows (in-flight call, apply window). Queued dispatches capture payload/DomEvent at raise time and drain FIFO, one live entry at a time; the apply-window drain defers via queueMicrotask (an empty JS stack ⇒ the rendezvous turn has unwound ⇒ instance enterable). Idle dispatches stay synchronous so preventDefault keeps working in the native listener frame.

  • host/src/host.ts: consume brackets decoding with beginApply/endApply; dispatchEvent routes through the gate; comments updated for both triggers.

  • Folded in, same machinery: a synchronous throw from the export no longer wedges dispatch permanently (review M2), and dispose() drops queued entries instead of replaying them into the guest (the queued-replay part of review M1; the other teardown gaps are unchanged).
  • Gates

  • deno task check clean

  • deno test host/tests/ 43/43 (fullstack + counter round-trips included; 9 new dispatch_test.ts cases: FIFO replay, both-windows interleavings, sync-throw/rejection recovery, dispose, reentrant dispatch from a running call)

  • Rust untouched; cargo test green at base
  • Diff: 312 lines (+234 / -78) across 3 files Reviewer: lann Review duration: 80m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.40) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 312 lines diff across 3 files
    0.40
    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.344
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1"
    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: 40.3% (MEDIUM) · Higher = larger blast radius
    40.3%
    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: 17.4% · Safe to merge
    17.4%