← Back to Pull requests

Add Lock::with_handle_scope() and with_escapable_handle_scope() to Rust JSG #8725

Closed
unknown closed this pull request without merging on Nov 21, 2026 08:38 UTC
View on GitHub
unknown unknown commented on Nov 20, 2026 09:27 UTC
Author

Rust JSG has no way to open a nested v8::HandleScope: every handle a
Lock creates lives until the callback's scope closes, so a loop that
creates handles on every iteration, such as a benchmark calling a
function many times, grows the scope without bound. C++ opens a scope
per iteration for this, and uses js.withinHandleScope() with a
v8::EscapableHandleScope to build a value from many temporary handles
and keep only the result. This adds both to Rust JSG.

lock.with_handle_scope(|lock, _| ...) runs the closure in a new
HandleScope with a lock for that scope. Handles of the enclosing
scope stay usable inside, but none of the new scope's can escape the
closure; the compiler enforces both.

lock.with_escapable_handle_scope(|lock, scope| ...) opens a
v8::EscapableHandleScope, and scope.escape(local) moves one handle
into the enclosing scope. Unlike C++, which escapes the callback's
return value by type, escaping is an explicit call, so the handle can
come back in a jsg::Result or Option. escape() consumes scope,
since V8 only debug-checks a second escape and a release build would
overwrite the first handle.

A panic in either closure is resumed once the scope has closed, so it
never unwinds through C++. The jsg-test suite covers freeing handles,
escaping, nesting, pending exceptions and panics, and compile tests pin
the lifetime rules.

Diff: 172 lines (+129 / -43) across 2 files Reviewer: bartlomieju Review duration: 1390m
All Vouch review confidence checks passed
Residual risk 0.14 = Change Risk (0.35) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.35 · 172 lines diff across 2 files
0.35
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.308
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8725"
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: 35.3% (MEDIUM) · Higher = larger blast radius
35.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: 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: 13.9% · Safe to merge
13.9%