Skip to content

tooling: check the split runtime's rules on the concept modules - #2091

Merged
trueadm merged 3 commits into
nextfrom
refactor/runtime-split-check
Oct 15, 2026
Merged

trueadm merged 3 commits into
nextfrom
refactor/runtime-split-check

Conversation

@trueadm

@trueadm trueadm commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Once runtime.ts is split, the concept modules are the source of truth. On the split layout, node scripts/split-runtime.mjs check now checks the modules themselves. CI runs it through ci:workflow:test.
  • The map, split, order and --suggest are migration-only, and they refuse to run on the split layout.

Why

Changes

  • checkSplit() in scripts/split-runtime.mjs reads the facade and runtime/*.ts through benchmarks/lib/client-runtime.mjs, which now also reports each module's range and the chain its order links form. It enforces:
    • load: module-scope initializers read only their own module's bindings (the no-TDZ rule), plus the write and pure rules;
    • order: every order constraint, meaning a driver or an uninlined constant above the reads that fold or inline it, holds along that chain;
    • link: every module with code stays on the chain, so it keeps its export {} from order link.
  • Tests in scripts/split-runtime.test.mjs, which runs in ci:workflow:test:
    • the committed modules pass the check;
    • a fixture split fails it with a deliberately introduced cross-module initializer read, and again with a removed order link.
  • The root factories move from the map into the tool. The tool header, the map comment, the facade comment (regenerated from the map, so the split stays reproducible) and CONTRIBUTING.md now say the concept modules are what you edit, and drop the "re-run --suggest for new declarations" guidance.

Validation

  • node scripts/split-runtime.mjs check: 34 modules in the chain, 0 violations
  • pnpm ci:workflow:test: 434 tests, 0 failures
  • node --test benchmarks/lib/client-runtime.test.mjs
  • pnpm format:files:check on the changed files
  • The regenerated runtime.ts changes only its facade comment. No runtime code changes, so bytes and counters are unchanged.
  • perf-review: not applicable (tooling, plus a comment in runtime.ts)
  • concise-code: about 120 lines of tooling and tests. The check reuses the migration's analysis and rule functions, and the joined-runtime helper, rather than adding a second analyzer.

Risk / follow-ups

  • A runtime module that genuinely needs no runtime code at load (type-only) is exempt from the link rule. profile-probes is listed as off-chain in the tool.

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.


Note

Low Risk
Tooling and documentation only; runtime code is unchanged aside from facade comments, with new CI guardrails on module layout.

Overview
node scripts/split-runtime.mjs check now validates the post-split layout: it joins runtime.ts with runtime/*.ts (via extended joinClientRuntime metadata) and runs checkSplit() for load/write/pure rules, evaluation-order constraints along the order-link chain, and that every code module stays on that chain. Non-check commands are migration-only and error if the facade is already split.

ROOT_ENTRIES and an ORDER_BASELINE of legacy single-file order quirks live in the tool instead of the map; orderConstraints gains anyOrder for split-time checks. Docs and the runtime.ts facade comment now say concept modules are what you edit and CI enforces the check—no runtime behavior change beyond comments.

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

trueadm and others added 2 commits October 15, 2026 15:15
…nds migration-only

Once runtime.ts is split, the concept modules are the source of truth. On
that layout `split-runtime.mjs check` now reads the modules themselves and
enforces what matters going forward: module-scope initializers read only
their own module's bindings, every order constraint (a driver or uninlined
constant above the reads that fold or inline it) holds along the chain the
modules' order links form, and every module with code stays on that chain.
A test runs it on the committed modules in ci:workflow:test, and another
shows it failing on a cross-module initializer read and a removed link.

The map, `split`, `order` and `--suggest` are migration-only and refuse to
run on the split layout; the tool header, the map comment, the facade text
and CONTRIBUTING.md say so. The root factories move from the map into the
tool, and the joined runtime reports each module's range and the chain.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Generated, not edited: `node scripts/split-runtime.mjs split` on the
single-file runtime.ts of the split's parent with the updated map. Only the
facade comment changes: the concept modules are the source to edit, and
`check` enforces their rules.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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 15, 2026
@trueadm
trueadm marked this pull request as ready for review October 15, 2026 14:17

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Split order rule cannot fail
    • checkSplit now computes a sourceOrder mapping from the map's module order (original single-file layout) and passes it to orderConstraints, so the source-order filter uses the correct inter-module ordering instead of the chain evaluation order that hides inverted pairs.

Create PR

Or push these changes by commenting:

@cursor push b0d96c49b2
Preview (b0d96c49b2)
diff --git a/scripts/split-runtime.mjs b/scripts/split-runtime.mjs
--- a/scripts/split-runtime.mjs
+++ b/scripts/split-runtime.mjs
@@ -666,7 +666,7 @@
  * bundle with the read and never folds. `inline`: a primitive `const` above a
  * later read, unless Rolldown inlines it anywhere.
  */
-export function orderConstraints(model, map) {
+export function orderConstraints(model, map, { sourceOrder } = {}) {
 	const writers = writerIndex(model);
 	const reach = reachIndex(model);
 	// What every rendering bundle keeps: the intersection of what each root
@@ -684,7 +684,9 @@
 		for (const [name, r] of reader.refs) {
 			if (!r.read) continue;
 			const binding = model.unitByName.get(name);
-			if (binding.order > reader.order) continue;
+			const bPos = sourceOrder?.get(binding.id) ?? binding.order;
+			const rPos = sourceOrder?.get(reader.id) ?? reader.order;
+			if (bPos > rPos) continue;
 			if (isMutable(binding)) {
 				const kept = reach(reader);
 				const written = (writers.get(binding.id) ?? []).some(
@@ -813,6 +815,23 @@
 	const moduleOf = new Map(
 		model.units.map((u) => [u.id, moduleAt(model.sf.statements[u.statements[0]].getStart())]),
 	);
+	// The joined text orders modules by evaluation chain, but the source-order
+	// filter in orderConstraints must reflect the original single-file layout.
+	// Use the map's module order (which mirrors the unsplit source) when available;
+	// fall back to the joined text order when the map does not cover the modules.
+	let sourceOrder;
+	try {
+		const map = readMap();
+		const rank = new Map(map.modules.map((m, i) => [m.name, i]));
+		if (model.units.every((u) => rank.has(moduleOf.get(u.id)))) {
+			const stride = model.sf.statements.length;
+			sourceOrder = new Map(
+				model.units.map((u) => [u.id, rank.get(moduleOf.get(u.id)) * stride + u.order]),
+			);
+		}
+	} catch {
+		/* map unavailable; model order is the fallback */
+	}
 	const violations = moduleRules(model, moduleOf);
 	const position = new Map(chain.map((m, i) => [m, i]));
 	const offChain = new Set(OFF_CHAIN);
@@ -825,7 +844,7 @@
 			offChain.add(m);
 		}
 	}
-	for (const c of orderConstraints(model, { rootEntries })) {
+	for (const c of orderConstraints(model, { rootEntries }, { sourceOrder })) {
 		const [a, b] = [moduleOf.get(c.before.id), moduleOf.get(c.after.id)];
 		if (a === b || !position.has(a) || !position.has(b)) continue;
 		if (position.get(a) > position.get(b))

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit fdaf44b. Configure here.

Comment thread scripts/split-runtime.mjs Resolved
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

🟢 No byte growth, no added work, and no timing changes beyond ±3%.

Compares c4cbd556e, the merge commit's first parent (main has moved 1 commit(s) past the pull request's recorded base ee7d52073) with 128e066c5 on the same runner. Any increase in a js-framework work counter fails this check; byte changes are a report. 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.533 3.767 −1.6% −11.8% … +18.7% ⚪ within noise
octane-tsrx replace 7.558 7.875 −1.2% −4.6% … +3.0% ⚪ within noise
octane-tsrx add 2.775 2.883 −0.0% −5.7% … +2.0% ⚪ within noise
octane-tsrx update 0.083 0.089 +2.0% −1.6% … +3.5% ⚪ within noise
octane-tsrx select 0.007 0.007 +0.5% −3.9% … +7.7% ⚪ within noise
octane-tsrx swap 0.021 0.019 +1.4% −4.6% … +5.5% ⚪ within noise
octane-tsrx remove 0.020 0.018 ±0.0% −3.9% … +3.1% ⚪ within noise
octane-tsrx runlots 28.325 29.108 +1.4% −1.8% … +3.5% ⚪ within noise
octane-tsrx select_lots 0.007 0.007 +0.8% −1.9% … +2.2% ⚪ within noise
octane-tsrx clear 55.608 56.033 −1.5% −5.1% … +3.1% ⚪ within noise
octane-jsx run 6.783 7.083 −0.7% −10.0% … +15.0% ⚪ within noise
octane-jsx replace 11.742 10.817 −4.3% −10.6% … +5.7% ⚪ within noise
octane-jsx add 6.350 6.083 −3.6% −9.1% … +7.0% ⚪ within noise
octane-jsx update 0.313 0.297 +3.2% −4.3% … +9.2% ⚪ within noise
octane-jsx select 0.166 0.150 −2.4% −9.0% … +2.7% ⚪ within noise
octane-jsx swap 0.224 0.218 ±0.0% −2.7% … +8.1% ⚪ within noise
octane-jsx remove 0.226 0.214 −1.9% −13.0% … +2.7% ⚪ within noise
octane-jsx runlots 42.425 47.883 +6.6% −0.0% … +15.7% ⚪ within noise
octane-jsx select_lots 1.832 1.772 +0.2% −3.2% … +10.1% ⚪ within noise
octane-jsx clear 71.658 72.517 +3.2% −0.3% … +4.3% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

No changes across 93 measured values.

Public-import reachability bundles (bytes)

No changes across 123 measured values.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website 90e4ec8 Commit Preview URL

Branch Preview URL
Oct 15 2026, 02:55 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
octane-website-mcp 90e4ec8 Commit Preview URL

Branch Preview URL
Oct 15 2026, 02:55 PM

…ion order

checkSplit fed the joined modules to orderConstraints, which keeps only the
pairs whose binding already precedes its reader in the text, so a driver or
uninlined constant moved below its reader dropped out and was never
reported. The split check now collects every fold- or inline-dependent read,
wherever it sits, and compares the binding's and reader's evaluation order,
across modules and within one.

The 24 reads that already came before their binding in the single-file
runtime never folded and are listed in ORDER_BASELINE; an entry that comes
back into order is reported so the list only shrinks. The new test relocates
a driver below its folding reader and fails on the previous check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm merged commit d04cd86 into next Oct 15, 2026
34 of 53 checks passed
@trueadm
trueadm deleted the refactor/runtime-split-check branch October 15, 2026 15:04
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