Skip to content

Commit db9cccf

Browse files
NathanFlurryclaude
andcommitted
chore: update progress for US-064
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent bb50c0f commit db9cccf

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

scripts/ralph/prd.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,8 +1352,8 @@
13521352
"Tests pass"
13531353
],
13541354
"priority": 69,
1355-
"passes": false,
1356-
"notes": "Spec: docs-internal/specs/v8-context-snapshot.md Phase 6."
1355+
"passes": true,
1356+
"notes": "Context::new on snapshot-restored isolate gives a clone of the default context with bridge IIFE state. replace_bridge_fns() overwrites 38 stub globals with real session-local functions. inject_snapshot_defaults uses READ_ONLY only (no DONT_DELETE) so inject_globals_from_payload can override per-session. Session thread skips bridge_code on snapshot path (from_snapshot flag). Tests: Part 18 (replace + dispatch), Part 19 (_processConfig override), Part 20 (multi-restore isolation)."
13571357
},
13581358
{
13591359
"id": "US-065",

scripts/ralph/progress.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ Started: Wed Mar 18 06:52:02 PM PDT 2026
5555
- `v8::ValueDeserializer::new(scope, Box::new(delegate), data)` + `read_header(context)` + `read_value(context)` for V8-native deserialization
5656
- Must `use v8::ValueSerializerHelper` and `use v8::ValueDeserializerHelper` to access methods on the serializer/deserializer structs
5757
- V8 serialization handles circular references, Date, Map, Set, RegExp natively — Error objects become plain objects (lose constructor name)
58+
- `Context::new()` on a snapshot-restored isolate clones the snapshot's default context with all state — use this instead of `get_current_context()` for fresh context per execution
59+
- Snapshot defaults: use `READ_ONLY` only (no `DONT_DELETE`) so `inject_globals_from_payload` can redefine per-session; `DONT_DELETE` makes non-configurable
5860
---
5961

6062
## 2026-03-18 - US-001
@@ -467,3 +469,26 @@ Started: Wed Mar 18 06:52:02 PM PDT 2026
467469
- Pre-existing SIGSEGV when running execution::tests AND snapshot::tests in the same process (V8 inter-test state issue) — run them separately: `cargo test execution::tests -- --test-threads=1` and `cargo test snapshot::tests -- --test-threads=1`
468470
- `inject_snapshot_defaults` uses inline JS evaluation to create config objects (avoids manual V8 object construction)
469471
---
472+
473+
## 2026-03-19 - US-064
474+
- Implemented context restore with bridge function replacement for V8 context snapshots
475+
- Added `replace_bridge_fns()` convenience wrapper in `bridge.rs` — calls `register_sync_bridge_fns` + `register_async_bridge_fns` in one call, returning both stores
476+
- Fixed `inject_snapshot_defaults()` in `snapshot.rs` — changed `_processConfig` and `_osConfig` from `READ_ONLY | DONT_DELETE` (non-configurable) to `READ_ONLY` only (configurable), so `inject_globals_from_payload` can redefine them per-session after restore
477+
- Modified session thread in `session.rs`:
478+
- Added `from_snapshot` flag tracking whether isolate was created from a snapshot
479+
- On snapshot path: `Context::new()` on snapshot-restored isolate gives a clone of the snapshot's default context (bridge IIFE already executed), bridge functions replaced via `replace_bridge_fns()`, globals injected, bridge_code skipped (pass empty string)
480+
- On fallback path: fresh context + full bridge code (existing behavior)
481+
- Unified bridge function registration: both paths use `replace_bridge_fns()` (works for both initial registration and stub replacement)
482+
- Added 3 new snapshot test parts:
483+
- Part 18: Full restore flow — create snapshot with IIFE, restore, replace bridge functions, verify IIFE state preserved + replaced functions work + getter facade resolves to replaced functions
484+
- Part 19: `_processConfig` override — verify configurable property can be overridden via `inject_globals_from_payload` after restore (cwd "/" → "/app", arch "x64" → "arm64")
485+
- Part 20: Multi-restore isolation — verify user state from one restore doesn't leak to another
486+
- Files changed: `crates/v8-runtime/src/bridge.rs`, `crates/v8-runtime/src/session.rs`, `crates/v8-runtime/src/snapshot.rs`
487+
- **Learnings for future iterations:**
488+
- `v8::Context::new(scope, Default::default())` on a snapshot-restored isolate gives a CLONE of the snapshot's default context — each call creates a fresh clone with the bridge IIFE state, no need for `get_current_context()`
489+
- `get_current_context()` requires a `ContextScope` (not available on plain `HandleScope<()>`) — use `Context::new()` instead
490+
- `define_own_property` with `READ_ONLY | DONT_DELETE` makes a property non-configurable — subsequent `define_own_property` calls fail silently. Use only `READ_ONLY` for snapshot defaults so they can be overridden
491+
- `Object.freeze()` on the value object does NOT make the global PROPERTY non-configurable — it only freezes the object's own properties
492+
- The `from_snapshot` flag is stable for the session lifetime — once set on isolate creation, all subsequent Executes on the same session use the same path
493+
- Pre-existing test failures: `__name` conflict in runtime-driver/node tests, Python tests (PythonRuntime not a constructor), project-matrix tests — all unrelated to this story
494+
---

0 commit comments

Comments
 (0)