Skip to content

feat(napi): bind managed V8 work and reservations to instance lifetimes - #94

Closed
theduke wants to merge 1 commit into
split/napi-01-guest-isolationfrom
split/napi-02-managed-framework
Closed

theduke wants to merge 1 commit into
split/napi-01-guest-isolationfrom
split/napi-02-managed-framework

Conversation

@theduke

@theduke theduke commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

V8 background tasks used a process worker pool outside tenant scheduling. Resource reservations could be released while native work or store teardown still used the environment, and native bookkeeping could grow outside the aggregate memory budget.

Introduce lazy embedder-owned V8 lanes and a bounded queue, with host-controlled admission, accounting scopes, overload notification and stop/join hooks. Keep standalone execution supported. Preserve existing host imports when installing compatibility fallbacks, so an application-supplied WASIX/libuv helper is not overwritten. Serialize guest cancellation with permanent host stop and reject guest interrupt scheduling in managed execution. Shutdown wins activation races, active scopes remain valid until work leaves, and reservations stay owned through native teardown and store destruction.

Extend the shared budget to account native handle bookkeeping and host-owned resource categories. Keep guest heap bindings lazy for import-only modules, retain imported/shared memory ownership, preserve interruptible waits, and accept released EdgeJS's fixed runtime flags as inert defaults without letting a guest change process-wide V8 flags. Add native bounds and cleanup for module metadata, dynamic-import work, publication failure and teardown. Preserve the existing Node-API surface, including BigInt count-query, wrap/reference and external-buffer correctness fixes.

This is the provider framework layer. The following PR wires bounded guest snapshots, transient copies and queued-message ownership into those facilities. The lane lifecycle and its quota-retention rules stay together because splitting them would reintroduce already-fixed shutdown and release races.

Standalone metadata and its lockfile are kept compatible with current main, including the browser test dependencies. Wasmer dependency revisions are unchanged from current main.

Stack and provenance

#93 → #94 → #95 → #96 → #97 → #98 → #99 → #100 → #101

Part 2 of the audited split of #84, reconstructed on current main eac0a13fa65a4d6103864d875ed76ab7efb1816e. Review against split/napi-01-guest-isolation; predecessor branches are required. Original PR #84 remains unchanged. The stack preserves newer main host-JS behavior and deliberately excludes the unused frozen 0.0.1 ABI adapter.

Validation

v8_lazy_lane, context/unit tests for activation/stop/overload/admission/quiescence, and native BigInt/reference/context tests; compile with ./cargo-standalone.sh check --quiet --message-format=short --features cli.

Local standalone cargo check --quiet --message-format=short --features cli passed. All 22 ctx::tests passed on the independent framework snapshot, including imported-memory/start-section binding, host helper preservation, stop/admission and teardown cases. A few future message-accounting hooks are intentionally unused until the next layer; they produce warnings, not compilation failures. The wasm32+JS cargo check also passed. Further local tests were stopped at the user’s request. Final CI is still pending; keep draft.

Latest-main rebase

Rebased the dependency stack onto eac0a13fa65a4d6103864d875ed76ab7efb1816e after main merged PR #92. This preserves unsigned guest IDs, pointers and lengths, bounded result/argv writes, host-JS buffer failure cleanup and the high-pointer/high-ID regressions. Conflicts received independent native and host-JS source review. All historical local results above predate this rebase; no local tests or builds were run for it, as requested. Updated-head validation belongs to CI and may be pending. This PR keeps its prerequisite branch as its base to preserve the focused diff.

@theduke
theduke force-pushed the split/napi-02-managed-framework branch from 556b0be to b0861e1 Compare October 22, 2026 08:20
@theduke
theduke added this pull request to stack #102 October 22, 2026 08:24
@theduke
theduke marked this pull request as ready for review October 22, 2026 08:26
@theduke theduke closed this Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant