← Back to Pull requests

Fix JITted context tagging #8862

Merged
csjh merged 6 files (570 lines) on Nov 24, 2026 20:29 UTC
View on GitHub
csjh csjh commented on Nov 24, 2026 05:17 UTC
Author

Make promise context tagging work in JITted code.

Every promise now records the PromiseContextTag root, which is the hole outside any PromiseContextScope. Builtins copy and compare the tag inline and call the runtime only when the tags differ. Optimized code (Maglev and TurboFan) allocates promises inline while the PromiseHook protector holds, without tagging them, so setting the cross-context callback now invalidates the protector.

Patch changes:

  • Implement-Promise-Context-Tagging: the tag moves into a root, the default tag is the hole instead of Smi 0, tag checks happen inline in builtins, and a PromiseContextTagTest unittest is added.

  • Implement-cross-request-context-promise-resolve-handling: the root move now lives in the patch above, and the PromiseResolveContextCheck runtime call is replaced by the inline NeedsPromiseContextSwitch check.

  • Four other patches change only in their index lines.
  • This mirrors the same fix in internal V8 patches.

    🤖 Generated with Claude Code

    Diff: 570 lines (+259 / -311) across 6 files Reviewer: mar-cf Review duration: 911m
    All Vouch review confidence checks passed
    Residual risk 0.10 = Change Risk (0.48) × (1 − Review Confidence (0.79)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 570 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.67 · 1 substantive comment(s)
    0.67
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    79%
    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.380
    Real PR Conversation Timeline
    6 items
    clanky-the-clanker[bot] clanky-the-clanker[bot] commented on code on Nov 24, 2026 05:22 UTC
    Code Review
    patches/v8/2023-06-22-Implement-Promise-Context-Tagging.patch:1
    @@ -217,57 +224,56 @@ index f89b106d883569ad927d6864f1e63361a257907f..e6fa23f0640899a666776c925531bf63
      }
      
     diff --git a/src/execution/isolate-inl.h b/src/execution/isolate-inl.h
    -index de710c8fad334d5fc29ee0d4627b4eb370e58550..fb7d83dd6fcff7aa7aba2ba5ad533fa8b877e1e1 100644
    +index de710c8fad334d5fc29ee0d4627b4eb370e58550..38bbd3f3ea4031d7620541fed83c9bd05636a760 100644
     --- a/src/execution/isolate-inl.h
     +++ b/src/execution/isolate-inl.h
    -@@ -129,6 +129,25 @@ bool Isolate::is_javascript_execution_allowed() const {
    +@@ -129,6 +129,33 @@ bool Isolate::is_javascript_execution_allowed() const {
               javascript_execution_dump();
      }
      
    -+Tagged<Object> Isolate::promise_context_tag() { return promise_context_tag_; }
    ++Handle<Object> Isolate::promise_context_tag() {
    ++  return root_handle(RootIndex::kPromiseContextTag);
    ++}
     +
     +bool Isolate::has_promise_context_tag() {
    -+  return promise_context_tag_ != ReadOnlyRoots(this).the_hole_value();
    ++  return heap()->promise_context_tag() != ReadOnlyRoots(this).the_hole_value();
     +}
     +
     +void Isolate::clear_promise_context_tag() {
    -+  set_promise_context_tag(ReadOnlyRoots(this).the_hole_value());
    ++  heap()->set_promise_context_tag(ReadOnlyRoots(this).the_hole_value());
     +}
     +
    -+void Isolate::set_promise_context_tag(Tagged<Object> tag) {
    -+  promise_context_tag_ = tag;
    ++void Isolate::set_promise_context_tag(Handle<Object> tag) {
    ++  heap()->set_promise_context_tag(*tag);
     +}
     +
     +void Isolate::set_promise_cross_context_callback(
     +    PromiseCrossContextCallback callback) {
     +  promise_cross_context_callback_ = callback;
    ++  // Optimized code allocates promises inline as long as the PromiseHook
    ++  // protector holds, since inline allocation skips init hooks. It also leaves
    ++  // the promise untagged, so that its reactions would run in whichever context
    ++  // settles it. Context tagging is an init hook, so invalidate the protector
    ++  // to keep promise allocation in builtins and the runtime, which tag it.
    ++  if (callback != nullptr) UpdatePromiseHookProtector();

    <!-- durable-reviewer:finding -->
    ℹ️ INFO · Performance

    Setting the cross-context callback invalidates the PromiseHook protector, which turns off inline promise allocation (and other fast paths that depend on the protector) in Maglev and TurboFan for every Worker isolate.

    workerd installs this callback for every Worker isolate, so from here on optimized code never allocates promises inline. That is required for correctness, since inline-allocated promises would not be tagged. It is worth running a promise-heavy benchmark to measure the cost, and noting the trade-off so a later rebase does not drop this line as if it were a regression.

    clanky-the-clanker[bot] clanky-the-clanker[bot] commented on Nov 24, 2026 05:22 UTC
    Reviewer

    <!-- durable-reviewer:review run=347941be-6305-4b6e-9a6e-b90682063d41 -->

    Superseded by the review of d3533f2b.

    <details>
    <summary>This review, of <code>09ebc2d1</code></summary>

    💬 Approved with comments — No blocking or warning-level defects. There is one question about the new root's placement for debug builds and one informational note about the cost of invalidating the PromiseHook protector.

    Findings: 1 question · 1 info (1 is an inline comment on the diff)

    <sub>The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.</sub>

    ---

    📋 Code Quality: ❓ 1 question

    The patches are internally consistent. One question about how the new mutable root is set.

    Recommendation: 💬 Optional Nits

  • [QUESTION] Please confirm that the new PromiseContextTag root sits in a movable mutable root list, so Heap::set_promise_context_tag can be called after deserialization (on every PromiseContextScope entry) and can hold a young-generation object without tripping a debug-build DCHECK. (patches/v8/2023-06-22-Implement-Promise-Context-Tagging.patch:479)
  • <details>
    <summary>View full review</summary>

  • The index line chain across the six patches is consistent.

  • Moving the tag into PromiseInit, InnerNewJSPromise and Factory::NewJSPromiseWithoutHook covers the promise creation paths in the patch.

  • NeedsPromiseContextSwitch matches the runtime and JSPromise::Fulfill/Reject semantics.

  • One question: PromiseContextTag is a mutable root, and PromiseContextScope writes it on every scope entry after deserialization has finished. Please confirm it sits in a root list whose setter allows that, so debug builds do not hit a DCHECK.
  • </details>

    ---

    ⚡ Performance: 💬 1 info

    Invalidating the protector turns off inline promise allocation in optimized code for every isolate that sets the callback. The builtin changes are a net improvement.

    Recommendation: 💬 Optional Nits

  • [INFO] Setting the cross-context callback invalidates the PromiseHook protector, which turns off inline promise allocation (and other fast paths that depend on the protector) in Maglev and TurboFan for every Worker isolate. (patches/v8/2023-06-22-Implement-Promise-Context-Tagging.patch:258)
  • <details>
    <summary>View full review</summary>

  • Builtins now copy and compare the tag inline and call the runtime only when the tags differ. That removes the per-promise PromiseContextInit and PromiseResolveContextCheck runtime calls from the hot path.

  • The trade-off: set_promise_cross_context_callback invalidates the PromiseHook protector. workerd installs that callback in every Worker isolate, so Maglev and TurboFan never allocate promises inline there. This cost is required for correctness.
  • </details>

    ---

    <details>
    <summary>✅ All other checks passed</summary>

    🔒 Security: ✅ LGTM

    No security concerns in the reworked promise context tagging patches.

    ---

    📖 AGENTS.md: ✅ LGTM

    No AGENTS.md updates are needed.

    ---

    📝 Documentation: ✅ LGTM

    The patch commit message describes the new behaviour accurately.

    </details>

    ---
    <sub>Reviewed commit: 09ebc2d1</sub>

    </details>

    mar-cf mar-cf approved these changes on Nov 24, 2026 17:24 UTC
    Approved Reviewer

    Approved these changes.

    clanky-the-clanker[bot] clanky-the-clanker[bot] commented on Nov 24, 2026 17:31 UTC
    Reviewer

    <!-- durable-reviewer:review run=f49ed487-1eb4-4bb7-9ecf-78601ff2de7e -->

    💬 Approved with comments — No blocking or warning-level defects. There is one question about the new root's placement for debug builds and one informational note about the cost of invalidating the PromiseHook protector.

    Findings: 1 question · 1 info

    <sub>The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.</sub>

    ---

    📋 Code Quality: ❓ 1 question

    The patches are internally consistent. One question about how the new mutable root is set.

    Recommendation: 💬 Optional Nits

  • [QUESTION] Please confirm that the new PromiseContextTag root sits in a movable mutable root list, so Heap::set_promise_context_tag can be called after deserialization (on every PromiseContextScope entry) and can hold a young-generation object without tripping a debug-build DCHECK. (patches/v8/2023-06-22-Implement-Promise-Context-Tagging.patch:479)
  • <details>
    <summary>View full review</summary>

  • The index line chain across the six patches is consistent.

  • Moving the tag into PromiseInit, InnerNewJSPromise and Factory::NewJSPromiseWithoutHook covers the promise creation paths in the patch.

  • NeedsPromiseContextSwitch matches the runtime and JSPromise::Fulfill/Reject semantics.

  • One question: PromiseContextTag is a mutable root, and PromiseContextScope writes it on every scope entry after deserialization has finished. Please confirm it sits in a root list whose setter allows that, so debug builds do not hit a DCHECK.
  • </details>

    ---

    ⚡ Performance: 💬 1 info

    Invalidating the protector turns off inline promise allocation in optimized code for every isolate that sets the callback. The builtin changes are a net improvement.

    Recommendation: 💬 Optional Nits

  • [INFO] Setting the cross-context callback invalidates the PromiseHook protector, which turns off inline promise allocation (and other fast paths that depend on the protector) in Maglev and TurboFan for every Worker isolate. (patches/v8/2023-06-22-Implement-Promise-Context-Tagging.patch:258)
  • <details>
    <summary>View full review</summary>

  • Builtins now copy and compare the tag inline and call the runtime only when the tags differ. That removes the per-promise PromiseContextInit and PromiseResolveContextCheck runtime calls from the hot path.

  • The trade-off: set_promise_cross_context_callback invalidates the PromiseHook protector. workerd installs that callback in every Worker isolate, so Maglev and TurboFan never allocate promises inline there. This cost is required for correctness.
  • </details>

    ---

    <details>
    <summary>✅ All other checks passed</summary>

    🔒 Security: ✅ LGTM

    No security concerns in the reworked promise context tagging patches.

    ---

    📖 AGENTS.md: ✅ LGTM

    No AGENTS.md updates are needed.

    ---

    📝 Documentation: ✅ LGTM

    The patch commit message describes the new behaviour accurately.

    </details>

    ---
    <sub>Reviewed commit: d3533f2b — same changes as 09ebc2d1, so this is that commit's review (no new review was run; line numbers are as of 09ebc2d1)</sub>

    jasnell jasnell approved these changes on Nov 24, 2026 19:03 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    csjh csjh
    Labels
    risk: low confidence: 79.3% 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: 48.3% (MEDIUM) · Higher = larger blast radius
    48.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: 79.3% · Lower = rushed or shallow review
    79.3%
    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: 10.0% · Safe to merge
    10.0%