You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 1689be9
Browse filesBrowse the repository at this point in the historyBrowse files
Merge refactor-agent-realm-phase0 into refactor-agent-realm-phase1
Brings in #121, #122 and #107 through Phase 0.
Bridge: realm env states follow #107's rules. create_realm and get_realm
no longer hold g_mu across the provider call; AddRealmEnvState registers
the state in g_envs under the lock and adopts it on the agent's thread,
like NewAgentWithPrincipalEnv. Teardown marks the agent closing first,
then releases agent-wide resources through the principal env.
V8 contextify: GetModuleWrapState takes g_module_wrap_mu, next to Phase
1's agent-wide module lookups, which take it themselves. Promise hooks
for contextify contexts are collected under g_context_mu and applied
after releasing it, each with its realm env's hooks.
host-JS: buffer finalizer registration borrows the HostJsAgent behind
SharedAgent once, so its fields can be used together.
The design doc notes that realm env states belong to their agent's thread.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/realm-bound-env.md
+13-6Lines changed: 13 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -437,9 +437,10 @@ realm can still be reachable.
437
437
- **Guest value ids become agent-scoped**, so they stay valid across that
438
438
agent's realms.
439
439
- **`g_envs` validation** maps env → agent.
440
-
- **Lock scope (side benefit).** With an agent object it is natural to replace
441
-
the process-global `g_mu`, taken on every `unofficial_*` call, with a
442
-
per-agent lock.
440
+
- **Lock scope.** #107 already narrowed the process-global `g_mu`: it guards
441
+
only the env registry, teardown and interrupt bookkeeping, and the message
442
+
table. No call into the engine or guest holds it, except a terminate or
443
+
interrupt from another thread.
443
444
444
445
### Rust (`src/env.rs`, `src/guest/napi.rs`)
445
446
@@ -523,7 +524,8 @@ Every phase leaves the tests passing on V8, QuickJS and host-JS.
523
524
| Branch | Recommendation |
524
525
|---|---|
525
526
| `feat/contextify-enter-leave` | Superseded: "one realm per document or frame" becomes `create_realm` plus that env. Its commits are a list of the costs of a selectable context, which this design avoids: root vs selected context, the microtask queue split, finalizers and interrupts running in the wrong realm, the handle leak, and callback cost going from 5.9 to 11 ns. |
526
-
| `feat/concurrent-stores`, `perf/concurrent-envs` | Land first. "Ids never reused" and "scope id = env id" become "agent id = principal env id". Terminate and interrupt then target the agent. |
527
+
| `perf/concurrent-envs` | Landed as #107 and merged into this branch. Its teardown and interrupt state is per agent (§11). |
528
+
| `feat/concurrent-stores` | Land first. "Ids never reused" and "scope id = env id" become "agent id = principal env id". Terminate and interrupt then target the agent. |
527
529
| `fix/contextify-weak-records`, `fix/quickjs-contextify-collect` | Land first. Their lifetime model is the realm-env lifetime in §4.5. |
528
530
| `feat/trusted-script` | No conflict. Its hook is installed once per isolate, which is agent-level. |
529
531
@@ -603,7 +605,10 @@ is the QuickJS trampoline.
603
605
callback registry and bindings.
604
606
- **Scope frames remember the env that opened them.**
605
607
- **The value cap counts across the agent's envs.**
606
-
- **Unchanged:** `g_mu` and `g_envs`.
608
+
- **Threads and teardown (from #107):** `g_envs`, each thread's set of owned
609
+
envs and the `holders` count stay per env. The teardown state is per agent,
610
+
because releasing an env tears down its agent: `closing`, `stop_requested`,
611
+
`teardown_guest_calls` and pending interrupt requests.
607
612
608
613
### host-JS (`src/snapi_js.rs`)
609
614
@@ -702,7 +707,9 @@ The old context arguments still work: they resolve to the realm env.
702
707
703
708
**Bridge and Rust**
704
709
- **Bridge:** each realm env gets a `SnapiEnvState` on its agent. Realms made
705
-
by `make_context` are adopted the first time `get_realm` returns them.
710
+
by `make_context` are adopted the first time `get_realm` returns them. Like
711
+
the principal env, a realm env state belongs to the agent's thread and is
712
+
registered without holding `g_mu` across the provider call (#107).
706
713
- **Rust:** realm envs get guest ids with no owner scope, budget charge or
707
714
registry entry. Their ids stop resolving when their principal env is
0 commit comments