Skip to content

feat(plugin-utils): add openCompilerSession for per-app engine state - #965

Open
owjs3901 wants to merge 12 commits into
mainfrom
feat/compiler-sessions
Open

owjs3901 wants to merge 12 commits into
mainfrom
feat/compiler-sessions

Conversation

@owjs3901

@owjs3901 owjs3901 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Stacked PR: this branch was cut from feat/engine-session-bindings (#964), and #964 sits on feat/engine-sessions (#963). It must be merged after #963 → #964 are merged in that order; until then the diff also shows the earlier PRs' commits.

NXT-07 step 3: adds a session wrapper openCompilerSession(compiler) to plugin-utils.

  • Opens a new session on the shared compiler (WASM or native) and returns { id, compiler, close }.
  • compiler is a Proxy wrapping the original. Reading a function returns a wrapper that first calls selectSession(id) and then runs the original function.
    • Engine calls are synchronous and JS is single-threaded, so no other session's call can slip in between selecting the session and the call.
    • Each wrapper is created once per key and reused (a.getCss === a.getCss).
    • The real function is re-read at call time, so later function replacements, such as test spies, are picked up.
    • Non-function values pass through unchanged.
  • close() discards the session. Calls through the scoped compiler after that make the engine throw an engine session N does not exist error.
  • index.ts exports openCompilerSession and the CompilerSession type.
  • Step 4 (Next coordinator registry) uses this wrapper to give each app its own session.

Test plan

  • bun test packages/plugin-utils/src/__tests__/compiler-session.test.ts --coverage: 3 pass with the real WASM pkg, compiler-session.ts 100% coverage
    • The prefixes of two sessions do not mix, and interleaving calls gives the same results
    • Wrapper reuse and non-function pass-through
    • Calls after close fail
  • bunx tsc --noEmit (plugin-utils)
  • bunx prettier --single-quote --no-semi --check

스택 PR: 이 브랜치는 feat/engine-session-bindings (#964) 위에서 분기했고, #964는 feat/engine-sessions (#963) 위에 있습니다. #963 → #964 순서로 머지된 뒤에 머지해야 하며, 그 전까지 diff에는 앞선 PR의 커밋이 함께 보입니다.

요약

NXT-07 3단계: plugin-utils에 세션 래퍼 openCompilerSession(compiler)를 추가합니다.

  • 공유 compiler(WASM 또는 네이티브) 위에 세션을 하나 새로 열고 { id, compiler, close }를 돌려줍니다.
  • compiler는 원본을 감싼 Proxy입니다. 함수를 읽으면 selectSession(id)를 먼저 부른 뒤 원래 함수를 실행하는 wrapper를 돌려줍니다.
    • 엔진 호출은 동기이고 JS는 단일 스레드라서, 세션을 고르는 순간과 호출 사이에 다른 세션의 호출이 끼어들 수 없습니다.
    • wrapper는 키마다 한 번만 만들어 재사용합니다(a.getCss === a.getCss).
    • 실제 함수는 호출 시점에 다시 읽으므로, 테스트 spy처럼 나중에 함수를 바꿔도 그대로 반영됩니다.
    • 함수가 아닌 값은 그대로 통과합니다.
  • close()는 세션을 버립니다. 그 뒤에 scoped compiler로 호출하면 엔진이 engine session N does not exist 오류를 던집니다.
  • index.ts에서 openCompilerSession과 CompilerSession 타입을 export합니다.
  • 4단계(Next coordinator registry)에서 앱마다 세션을 하나씩 갖도록 하는 데 이 래퍼를 씁니다.

테스트 계획

  • bun test packages/plugin-utils/src/__tests__/compiler-session.test.ts --coverage: 실제 WASM pkg로 3개 통과, compiler-session.ts 100% 커버리지
    • 두 세션의 prefix가 서로 섞이지 않고 호출을 교차해도 결과가 같은지
    • wrapper 재사용과 non-function 통과
    • close 이후 호출이 실패하는지
  • bunx tsc --noEmit (plugin-utils)
  • bunx prettier --single-quote --no-semi --check

Refs #686

🤖 Generated with Claude Code

owjs3901 and others added 5 commits November 15, 2026 19:43
…bals

Two apps in one process shared the single process-wide engine state.
Gather the persistent state into values that can be exchanged with the
live globals:

- css::engine_state::CssState holds the prefix, debug flag, atom hoist
  threshold and plan, slot reservation, class map, file map, canonical
  map, file routes, custom shorthands, theme tokens and Tailwind
  definitions. css::test_state::TestStateGuard is now built on it.
- extractor::ExtractorCaches holds the vanilla-extract imported runs and
  stripped TypeScript of the calling thread.
- devup_ui_binding_core::session keeps session 0 live from the start and
  parks every other session's EngineState (CSS state + stylesheet).
  select_session swaps a parked state with the live globals,
  with_session runs a closure under the session lock and swaps back,
  also on unwind. Extractor caches are parked per thread and aligned on
  every switch, since they hold Rc values and session file numbers.
- PerSession<T> keys host values by the live session; the WASM and
  native module resolvers use it.

Existing call sites read the globals unchanged; until a host creates a
session the engine behaves as before.

Refs #686

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the engine session calls to the WASM and native engines:

- createSession() returns the id of a new session with a clean state
- selectSession(id) makes it live; every later call works on its state
- dropSession(id) drops it with its module resolver, returning whether
  it existed; dropping the live session makes session 0 live

The shared argument boundary checks the id as an unsigned 32-bit
integer before engine entry. The ABI grows from 29 to 32 names: the
WASM glue check, the native adapter and typings, the e2e ABI list, the
validation positions (47 in 20 functions, 283 invalid-input cases) and
a parity corpus scenario follow it.

Refs #686

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hape

Refs #686

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refs #686

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
openCompilerSession(compiler) creates an engine session on a shared
compiler and returns { id, compiler, close }. Every function read from
the scoped compiler selects the session before it runs; the calls are
synchronous and JavaScript is single-threaded, so no other session's
call can run between the selection and the call. close() drops the
session, after which calls through the scoped compiler throw.

Refs #686

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
bindings/devup-ui-binding/index.mjs 100.00% <100.00%> (ø)
bindings/devup-ui-binding/src/host.rs 100.00% <100.00%> (ø)
bindings/devup-ui-binding/src/lib.rs 100.00% <ø> (ø)
bindings/devup-ui-wasm/src/lib.rs 100.00% <100.00%> (ø)
bindings/devup-ui-wasm/src/reservation.rs 100.00% <100.00%> (ø)
bindings/devup-ui-wasm/src/state.rs 100.00% <100.00%> (ø)
bindings/devup-ui-wasm/src/state/tests.rs 100.00% <ø> (ø)
libs/binding/src/lib.rs 100.00% <100.00%> (ø)
libs/binding/src/session.rs 100.00% <100.00%> (ø)
libs/css/src/engine_state.rs 100.00% <100.00%> (ø)
... and 8 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

owjs3901 and others added 6 commits November 16, 2026 08:04
Keep main's check_resolved_path/resolved_module re-exports beside the
session re-exports in libs/binding. removeFile (#951) only touches the
file map, canonical map, class map and global sheet, which CssState and
EngineState already swap per session; a new session test pins that
forgetting a file in one session leaves another session's styles alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in main through #963, including removeFile (#951). The ABI now
holds 33 names: main's 30 plus createSession, selectSession and
dropSession. Updated script.js, the native typings and README, the
e2e ABI list and consumer, and compiler-types (32 without Output).

Validation covers 48 positions in 21 functions (288 cases), and the
summary reports 21 functions. The corpus keeps both new scenarios and
adds remove-file-stays-in-its-session, which checks that removeFile
only forgets the file in the live session (28 scenarios).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No conflicts. openCompilerSession wraps every compiler function in a
Proxy that selects the session first, so removeFile from main (#951)
runs on the scoped session like every other call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
extractor/lib.rs keeps both this branch's ExtractorCaches export and
main's vanilla_extract_theme_import_tests module. Main added no binding
exports since the last merge, so the counts stay: 33 ABI names, 21
validated functions with 48 positions and 288 cases, and 28 parity
scenarios. #967's serialization cache needs no session state: a session
switch swaps the sheet through a tracked mutable borrow, which forgets
the cached serializations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
extractor/lib.rs keeps both the ExtractorCaches export and main's
vanilla_extract_theme_import_tests module, as #963 and #964 resolved it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Takes #964's merge with main (33cf39c) into the stack. Its tree adds
nothing beyond the main merge before this one, so no file changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 added a commit that referenced this pull request Nov 17, 2026
Takes #965's merges with main and #964 into the stack. Its tree adds
nothing beyond the main merge before this one, so no file changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Picks up #990, which fixes main's hook-order and WASM ABI count tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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