Skip to content

refactor(octane): move universal hook cells into the owner kernel - #1714

Merged
trueadm merged 1 commit into
mainfrom
refactor/owner-kernel-hooks
Oct 4, 2026
Merged

trueadm merged 1 commit into
mainfrom
refactor/owner-kernel-hooks

Conversation

@trueadm

@trueadm trueadm commented Oct 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This is Phase 2, slice 1 of #1055 (plan, §3.2 and §7; decision 3 in §10). It starts the host-neutral owner kernel. The universal core binds it today, and the dedicated Lynx runtime will bind the same hook cells later, so hook semantics have one source of truth instead of a second copy. The refactor is behavior-neutral.

What moves. packages/octane/src/owner-kernel/hooks.ts is new. It is stateless, imports nothing, and has no renderer or host dependency.

  • Types:
    • the cell shapes: StateHook, LinkedStateHook, ReducerHook, MemoHook, RefHook (shared by useRef and useLazyRef), IdHook, EffectEventCell, EffectEventHook, and EffectHook<Owner>;
    • the update-queue types: UniversalHookUpdateQueue<Batch> and AppliedUniversalHookUpdates<Batch>;
    • EffectPhase and UniversalTrackedThenable.
  • Pure helpers: depsEqual, isThenable, trackUniversalThenable, runEffectCreate, runEffectCleanup, and deactivateEffectEventCells. Each was copied from main verbatim.

How the core binds it. universal-core.ts imports the kernel and re-aliases its generic types under their existing names, such as type EffectHook = KernelEffectHook<UniversalOwnerRecord>. Every one of the existing call sites is unchanged. The core adds no export *, so no kernel name reaches octane/universal.

What stays in the core. It stays until a services interface exists in later slices:

  • anything that reads the current attempt, an owner record, or a scheduler: enqueueUniversalHookUpdate, applyUniversalHookUpdateQueue, collectEffectEventCells, and the owned effect runners;
  • module-level identity: PARKED_UNIVERSAL_LINKED_DRAFTS, EMPTY_UNIVERSAL_TRANSITION_BATCHES, and the slot stack;
  • the exported LinkedStatePrevious and LinkedStateOptions, because @octanejs/lynx imports them from the core.

The octane/internal/owner-kernel subpath waits for its first importer outside this package, so this PR publishes no new surface.

Prior art. The fork Huxpro/octane:new-lynx has a similar slice (universal-kernel.ts). It is out of date on main: its trackUniversalThenable would overwrite a foreign thenable status such as router-core's 'resolved', which universal-settled-wakeable.test.ts pins. That is why everything here was copied from main rather than from the fork.

Refs #1055

Tests

packages/octane/tests/universal-hook-dependencies.test.ts pins, through public universal hooks, what the moved helpers guarantee. No existing universal test covered these:

  • useMemo recomputes only on an Object.is change. NaN stays equal, +0 → −0 recomputes, a length change recomputes, and null deps recompute every render.
  • Layout and passive effects receive their dependency values as arguments. Compiler-hoisted, capture-free callbacks rely on this ABI.
  • Each effect cleanup runs exactly once for the create it belongs to, across a dependency change and unmount.

Each test was seen to fail against a deliberately broken kernel: === instead of Object.is, effects called without arguments, and a dropped cleanup.

Bundle evidence

node benchmarks/bench.mjs --ratios three-bundle-size lynx-bundle-size, base 77504c160c against this change, same machine:

bundle raw gzip brotli
Three octane-min ±0 +4 +125
Three octane-full ±0 −3 −162
Lynx background program +8 −2 +11
Lynx preview main ±0 ±0 ±0
  • Three: byte-identical in raw size, and all four Three ratio guards pass (octane-min gzip 1.032× ≤ 1.034).
  • Lynx background +8 raw: a token diff of the two background programs shows identical code. The moved helpers are emitted ahead of the core and take the short identifiers (k, O), which shifts a few later names to two characters.
  • Lynx main thread: unchanged; it does not import the universal core.
  • Exact backgroundRaw pin: ci(bench): reset the Lynx main-thread caps and background pin for #1700 #1710 re-pins it at 288,390. These +8 bytes need their own budget-only re-pin after both PRs land, and I'll open it.
  • DOM: the DOM runtime doesn't import this code, so DOM bundles are unaffected.

Validation

  • vitest run --project octane --project octane-prod packages/octane/tests/universal-hook-dependencies.test.ts: 6 passed.
  • pnpm typecheck:files on universal-core.ts, owner-kernel/hooks.ts, and the new test.
  • pnpm format:files:check on every changed file, and pnpm sync.
  • Bundle benchmarks as above.
  • The existing universal, Three, and Lynx suites were not run locally, under the local test-load rule. CI runs them, and they are the oracle for neutrality.
  • pnpm format:check, pnpm typecheck, and pnpm test were not run locally.

Risk / follow-ups

  • Risk: low. The change is types plus six pure functions copied verbatim. dist/ and dist/node each get their own copy of the module, which is safe because the module holds no state.
  • Next slices (plan §7): the owner abstraction, scheduling callbacks, transition batches, root services, claims, and transaction phases.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Low Risk
Behavior-neutral refactor: verbatim extraction of stateless types and pure functions with new tests; no auth, scheduling, or public API changes beyond internal module layout.

Overview
Starts the host-neutral owner kernel (#1055) by moving shared hook cell types, update-queue shapes, and six pure helpers (depsEqual, isThenable, trackUniversalThenable, effect create/cleanup, effect-event deactivation) into new packages/octane/src/owner-kernel/hooks.ts. universal-core.ts drops the inlined copies and binds the kernel via type aliases (e.g. EffectHook = KernelEffectHook<UniversalOwnerRecord>); scheduling, owner reads, and linked-state parking stay in the core unchanged.

Adds universal-hook-dependencies.test.ts to lock memo Object.is deps, effect callbacks receiving dep values as arguments, and one cleanup per create. Lynx bundle inventory attributes owner-kernel/ modules to universal-runtime like universal-core.

Reviewed by Cursor Bugbot for commit 4124ca0. Bugbot is set up for automated code reviews on this repo. Configure here.

Phase 2, slice 1 of #1055. The dedicated Lynx runtime will bind the same
hook cells as the universal core, so their shapes and pure helpers move
to packages/octane/src/owner-kernel/hooks.ts, the first module of the
host-neutral owner kernel:

- the state, linked-state, reducer, memo, ref, id, effect, and
  effect-event cell types;
- the update-queue types;
- depsEqual, isThenable, trackUniversalThenable, runEffectCreate,
  runEffectCleanup, and deactivateEffectEventCells.

The kernel is stateless and imports nothing. Owner- and batch-shaped
dependencies are type parameters, and universal-core re-aliases them
under their existing names, so every call site is unchanged.

Nothing that reads the current attempt, an owner record, or a scheduler
moves here; those slices need a services interface. LinkedStatePrevious
and LinkedStateOptions stay exported from the core, where Lynx imports
them. The octane/internal/owner-kernel subpath waits for its first
consumer outside this package.

universal-hook-dependencies.test.ts pins what the moved helpers
guarantee through public hooks: Object.is dependency equality, effects
receiving their dependency values as arguments (the hoisted-callback
ABI), and one cleanup per create. The Lynx inventory attributes the
kernel to the universal runtime.

Refs #1055

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm marked this pull request as ready for review October 4, 2026 15:54
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent refactor PR: internal restructuring, no behavior change labels Oct 4, 2026
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Benchmark report

🟢 No budget breaches, no added work, and no timing changes beyond ±3%.

Compares 7b15b4a70, the merge commit's first parent with 4cf6ec1ae on the same runner. A byte value over its committed budget or any increase in a js-framework work counter fails this check. Wall time is a report: base and head samples alternate in one browser, and an operation is called slower or faster only when the 95% confidence interval of its ratio excludes ±3%. Workflow run

js-framework: 1k/10k row operations

All 20 timed operations (20 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 3.133 3.125 +0.0% −4.6% … +6.1% ⚪ within noise
octane-tsrx replace 6.275 6.317 −0.0% −10.2% … +10.5% ⚪ within noise
octane-tsrx add 2.633 2.600 ±0.0% −3.6% … ±0.0% ⚪ within noise
octane-tsrx update 0.136 0.137 +0.5% −1.1% … +1.4% ⚪ within noise
octane-tsrx select 0.006 0.006 +0.0% −0.6% … +0.9% ⚪ within noise
octane-tsrx swap 0.038 0.038 ±0.0% −0.7% … +0.0% ⚪ within noise
octane-tsrx remove 0.020 0.019 −1.1% −1.9% … ±0.0% ⚪ within noise
octane-tsrx runlots 27.158 26.517 −4.4% −6.5% … −0.5% ⚪ within noise
octane-tsrx select_lots 0.006 0.006 ±0.0% −0.5% … +0.5% ⚪ within noise
octane-tsrx clear 47.417 49.850 +5.1% +2.8% … +6.1% ⚪ within noise
octane-jsx run 3.942 3.833 −1.1% −2.6% … +1.1% ⚪ within noise
octane-jsx replace 7.308 7.700 −1.9% −6.6% … +4.5% ⚪ within noise
octane-jsx add 3.475 3.408 −2.7% −2.9% … ±0.0% ⚪ within noise
octane-jsx update 0.264 0.266 ±0.0% −0.7% … +0.7% ⚪ within noise
octane-jsx select 0.143 0.137 −0.3% −0.5% … +0.5% ⚪ within noise
octane-jsx swap 0.238 0.242 +0.9% −0.3% … +1.7% ⚪ within noise
octane-jsx remove 0.190 0.182 −0.6% −2.5% … +0.3% ⚪ within noise
octane-jsx runlots 30.508 30.875 −1.4% −2.4% … +0.2% ⚪ within noise
octane-jsx select_lots 1.610 1.632 +0.6% −1.3% … +1.6% ⚪ within noise
octane-jsx clear 54.450 51.417 −4.9% −5.7% … −2.5% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

target metric base head Δ
octane-tsrx bindings_js_gzip 240,871 240,859 −12 (−0.0%) 🟢
octane-tsrx bindings_js_brotli 205,103 205,092 −11 (−0.0%) 🟢
octane-tsrx bindings_app_gzip 121,728 121,716 −12 (−0.0%) 🟢
octane-tsrx bindings_app_brotli 101,740 101,729 −11 (−0.0%) 🟢

50 other measured values are unchanged.

Public-import reachability bundles (bytes)

No changes across 105 measured values.

@trueadm
trueadm merged commit 66c3deb into main Oct 4, 2026
49 of 52 checks passed
@trueadm
trueadm deleted the refactor/owner-kernel-hooks branch October 4, 2026 16:15
trueadm added a commit that referenced this pull request Oct 4, 2026
#1714 moved the universal hook cells into the owner kernel, which adds
8 raw bytes to the background program. run.mjs pins that size exactly,
so the weekly lynx-bundle-size suite failed at 288,398 against the
288,390 that #1710 set. Budget value and comment only; the main-thread
caps are unchanged.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent refactor PR: internal restructuring, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant