Skip to content

test: the Node legs cost each swizzle-proof slice by the targets it holds that the change can affect - #11716

Closed
cixzhang wants to merge 2 commits into
mainfrom
test/swizzle-slice-cost
Closed

cixzhang wants to merge 2 commits into
mainfrom
test/swizzle-slice-cost

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Held pending #11697; superseded if it merges. #11697 (open) runs the swizzle proof in its own required legs, outside the Node legs, so the slices would no longer be packed with the Node tests. This pull request stays a draft until #11697 is decided.

Who this helps

Anyone whose pull request changes component code. Each of the eight swizzle-proof slices proves only the targets the change reaches, so a slice takes about 28 s when it holds none, about 2 minutes for a few, and about 3.5 minutes when every target is affected. The Node legs' split books every slice at its largest recorded time (180 to 348 s) whenever the change reaches any component. A pull request that touches one component is packed as if it touched all of them, and the real heavy files land together. This costs each slice by the targets it actually holds.

What changes

  • The bound (packages/cli/test/swizzle-proof/proof.mjs). affectedBound(targets, relevant) counts the targets a change can affect, from the repository alone, before any slice runs:
    • its sources are every shipped file of the folder that holds the target's entry module, each module they import by relative path, and what the entries of the package exports they import reach;
    • a target whose source cannot be found counts as affected (fail closed);
    • it never holds fewer targets than the slice's own exactAffected, which reads the copies (now an exported function runSlice calls), and it is looser where it skips finding each imported name's defining module.
  • One slice function. sliceOf(targets, index, count) is what a slice proves, and the worker counts each slice's affected targets with it, so the split's slices are the slices that run.
  • The worker (swizzle-proof/bound-worker.mjs) lists the targets and counts each slice's affected ones off the split's thread.
  • The split (scripts/vitest-shard-sequencer.mjs). swizzleSliceCosts books the slices:
    • in the scope none (no component source changed), idle, as before;
    • in the scope affected, each slice at the model's cost for the targets it holds, never above its recorded time;
    • in every other case, at the recorded time: the scope all (a toolchain change or SWIZZLE_PROOF_ALL), a record without the model, or a bound that is not done 2 s after the target list (10 s for the list itself).
  • The model (scripts/lib/swizzle-cost.mjs, shared by the split and the drift check). A slice takes its setup (list, copy, sort), plus, once it holds an affected target, the proof's own setup (type-check, bundle and render each start once) and each target's time. It is recorded in scripts/vitest-node-durations.json as swizzleProof, and record refits it from the slices' summary lines in the same leg logs.
  • The drift check (.github/scripts/node-time-drift.mjs --swizzle). Each slice appends its summary to a file the leg names (SWIZZLE_PROOF_SUMMARY). A slice that ran more than 1.5 times the model's time and more than 60 s over it, after the leg's own slowdown, is an error when the change touches what the model depends on (the proof, the split, swizzle-cost.mjs or the record), and a warning on any other change, so a slow runner never fails an unrelated pull request.

The model's three numbers

The guardian's model had two numbers, a per-target time and a fixed overhead. The slices' own timings show a third: the proof's setup, about 97 s, paid once as soon as one target is affected. A slice proving one target takes about 125 s, not 28 + 4. Fitted from all 24 slices of three component pull requests' runs (#11619, #10905, #11062: 0 to 19 affected targets per slice):

Number Value
setupSeconds (median) 27.8
proveBaseSeconds (intercept) 96.8
perTargetSeconds (slope) 3.8

How loose the bound is

Against the slices' exact sets, over all 170 targets (every copy ejected):

Change Exact Bound Bound ÷ exact Missed
a component (Button.tsx) 127 145 1.14 0
a layer helper (Layer/inputHold.ts) 129 147 1.14 0
the theme tokens (theme/tokens.stylex.ts) 158 164 1.04 0
a press helper (utils/pressClaim.ts) 36 134 3.72 0
a Lab component no target uses (InfoTip.tsx) 0 2 — 0

The widely imported helper that balloons it: utils/pressClaim.ts. Core's package entry reaches it, so every target that imports anything from @astryxdesign/core counts. The exact proof follows each imported name and finds only the 36 that use it. Such a change costs the slices near full, as today. No change is ever costed below its work.

Replay

A full-reach run's five Node legs, packed by the split. Each leg is max(longest file, file time ÷ 2.3) plus 2 min of setup and leg 1's own steps; each slice takes the model's time for the targets it holds. Worst leg, in minutes:

Change Times Slices at their recorded time (today) Slices by the targets they hold
a component (Button: 16 to 20 per slice) main validation run 13.3 13.2
the three heaviest files at slow-runner times 14.6 13.5
a Lab leaf (2 targets in all) main validation run 12.0 11.7
heavy files slow 13.0 12.2
every target affected main validation run 13.5 13.4
heavy files slow 14.8 15.1

The same, with #11699's split of the three heaviest files underneath:

Change Times Today By held targets
a component main validation run 13.7 13.1
heavy files slow 14.1 13.7
a Lab leaf main validation run 13.7 12.1
heavy files slow 14.1 12.1
every target affected main validation run 13.7 13.3
heavy files slow 14.1 13.9

Every target affected is costed at nearly full, as it should be (each slice about 205 s, the slice capped at its recorded time where that is lower). The 13.6 / 11.0 figures discussed earlier predate #11648, which already books idle slices.

What the split spends

Only on a pull request whose change reaches component sources (the scope affected); every other run spends nothing new.

  • On this Mac (10 CPUs, load 20 to 28): the target list about 1 s, the bound 1.3 to 1.8 s, about 3 s with the worker's start.
  • Per run: at most about 3 s on each of the five Node legs (each computes the same split), about 15 runner-seconds.
  • Capped: at most 2 s past the list, after which the legs fall back to the recorded times.
  • On the CI runner: bound.test.mjs logs its own machine's time (SWIZZLE_BOUND {"ms": …} in the Node leg that runs it), so this pull request's run gives it.

Tests

  • packages/cli/test/swizzle-proof/bound.test.mjs (new). It copies nine targets of every folder kind (Core components, Layer's module folder, flat Charts and Rich Text, Lab's shared Chart folder, a Lab leaf, Vega). For five changes it requires the bound to hold every target exactAffected proves, which fails when the two disagree on the affected set. It requires a leaf change to reach almost none, and logs the bound's time.
  • scripts/lib/swizzle-cost.test.mjs (new): the cost (setup alone, proof setup plus targets, capped), the summary lines from a run log, the fit, the fallbacks, and the slow slices after the leg factor.
  • scripts/vitest-shard-sequencer.test.mjs:
    • costs by held targets, capped;
    • the recorded time when the bound misses its budget, without the model, or in the scope all;
    • idle in none without computing a bound;
    • the legs spread by those costs;
    • boundWithin stops at its budget.
  • .github/scripts/node-time-drift.test.mjs: a slow slice fails only a change to the model's inputs, warns otherwise, and without a model nothing is judged.
  • .github/scripts/ci-node-leg-bounds.test.mjs: the drift step passes --swizzle.

Overlap check

Searched open pull requests for the split, the swizzle proof and the record:

This changes the slices' costing rule from #11534 (a slice keeps its largest time) for the scope affected only, as the CI guardian chose. No spec record governs it.

CI impact: no new job. On pull requests whose change reaches component sources, each Node leg spends up to about 3 s computing the bound (at most 2 s past the target list), about 15 runner-seconds a run; every other pull request spends nothing new. bound.test.mjs adds one Node test file, about 21 s (recorded).

Owning session: noopbot (a61f66c2), under CI & Release (ca77f950). Land path: the shipper, through merge-guard.

@vercel

vercel Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 14, 2026 8:53am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 14, 2026
@astracat-bot

astracat-bot Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
❓ Needs maintainer input (for maintainers only) Nov 14, 2026, 9:15 AM UTC

@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

Current run: The current CI run concluded skipped. Current analysis is unavailable.


Generated by PR Enrichment workflow | View current CI run

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approval waits on an engineering owner, and two things need fixing whatever that owner decides.

The pull request says no spec record governs its new rule for costing a swizzle-proof slice, and the only current CI claim on Node-leg splitting names the recorded test time as the split's input and says which files run never depends on the times. An engineering owner needs to provide or identify the record that governs costing a slice by a per-run estimate — or extend the existing claim to state it — and records the decision by commenting /approve-spec <full head SHA> on this pull request; the author may do so if they are an engineering owner. The mechanism itself measures well: the bound held every target the slices prove, for all five changes the description tables, checked here over all 170 targets, and the new tests pass.

  • Each Node leg computes the slice costs for itself under a 2 s budget, so a leg whose bound misses that budget packs the files differently from a leg that made it, and with this head's record one leg falling back leaves 175 of 1221 Node test files on no leg at all (three legs falling back: 270), with nothing to report it — give every leg the same counts, as the first-leg reserve already does, or drop the budget so the fallback cannot differ between legs.
  • The description's Lab-leaf row measures packages/lab/src/InfoTip/InfoTip.tsx, which this repository does not have (the folder holds a deprecated re-export and a test), so that row's bound of 2 is what any unmatched path returns, and the replay table's largest claimed saving rests on it — re-measure it against a Lab component that exists, such as packages/lab/src/DialogHeroHeader/DialogHeroHeader.tsx.

Four smaller points are in the inline comments: two Lab targets fail closed in every run and keep about 200 s of phantom cost; the drift check parses the summary file without the guard its own module has; a bound that misses its budget leaves its temporary folder behind; and the model's refit accepts a sample range too narrow to determine the line.

Claims and files checked

Claims from the description:

  • Slices are booked today at their largest recorded time, 180 to 348 s — verified against the record's eight entries.
  • The bound never holds fewer targets than the slices prove — verified over all 170 targets for the five tabled changes: none missed.
  • Bound against exact for a component, a layer helper, the theme tokens and a press helper (1.14, 1.14, 1.04, 3.72) — verified, reproduced exactly.
  • The Lab-leaf row (exact 0, bound 2) — false: the file it names is not in the repository.
  • The model's three numbers are what the record now carries — verified.
  • Slices are costed only in the affected scope; recorded time in the all scope, without a model, or when the bound misses its budget; idle when no component source changed — verified in code and by the new tests.
  • Each leg computes the same split — false when one leg's bound misses its budget (first bullet above).
  • Each slice appends its summary to the file the leg names, and the drift check errors only on a change to the model's inputs and warns otherwise — verified by the new tests.
  • No new CI job, and the new test file is recorded at about 21 s — verified; it ran in 15.9 s here.
  • The per-leg cost of about 3 s on a CI runner — not yet measurable: the required legs have not run at this head.
  • Overlap with the two open pull requests — verified, with one gap: both also change a file this one changes (the Node-leg bounds test, and the record-writing block of the split), so whichever lands second must reconcile them, including the new whole-record read against the other's configurable record file.
  • The replay tables' leg-time projections — not verifiable from the repository: they rest on a simulation, and the Lab-leaf row feeding them is wrong.

Files:

  • scripts/vitest-shard-sequencer.mjs — finding (per-leg split divergence).
  • packages/cli/test/swizzle-proof/proof.mjs — finding (two targets always fail closed); the bound's soundness checked over every target.
  • .github/scripts/node-time-drift.mjs — finding (unguarded parse of the summary file).
  • scripts/lib/swizzle-cost.mjs — finding (a refit accepts too narrow a sample range).
  • packages/cli/test/swizzle-proof/bound-worker.mjs — finding (temporary folder left behind when the worker is terminated).
  • packages/cli/test/swizzle-proof/bound.test.mjs — clear; passes, and its nine targets cover every folder kind.
  • packages/cli/test/swizzle-proof/slice.mjs — clear; the summary line is unchanged and the append is guarded by the environment variable.
  • scripts/vitest-shard-sequencer.test.mjs, scripts/lib/swizzle-cost.test.mjs, .github/scripts/node-time-drift.test.mjs, .github/scripts/ci-node-leg-bounds.test.mjs — clear; 73 tests pass and the workflow contract matches the new command line.
  • .github/workflows/ci.yml — clear; one environment variable and one argument on an existing step, no new job, check name, permission or trigger.
  • scripts/vitest-node-durations.json — clear; one test-file entry and the three-number model, consistent with the fit the code performs.

Automated review (maintainer link)

if (scope.mode === 'none') return {idle: new Set(slices), costs};
const model = record?.swizzleProof;
if (scope.mode !== 'affected' || !model) return {idle: new Set(), costs};
const held = await (inject.bound ?? boundWithin)(relevant, slices.length);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Blocking. Every test-node leg runs this for itself, so the answer can differ between legs of one run: boundWithin resolves null when the worker misses the 2 s budget, errors, or exits early, and that leg then books the slices at their recorded times while a leg that answered in time books them by the model. splitByDuration is a greedy packing over every file, so one changed cost moves hundreds of files: with this head's record and the held counts measured for a Button.tsx change, one leg falling back leaves 175 of 1221 Node test files on no leg and runs 175 twice (three legs falling back: 270 unassigned). Nothing reports a file that no leg ran.

Smallest correction: give every leg the same input, as VITEST_LEG_ONE_RESERVE does — compute the held counts once in a step before the legs and pass them in the environment — or drop the budget so every leg computes the bound to completion and the fallback cannot differ.

const keys = new Set();
for (const t of targets) {
const sources = boundSources(t, packages, caches);
if (sources == null || [...sources].some(file => changed.has(file)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Failing closed is right, but two targets fail closed on every run: NavigationScreen and TabBarItem are exported from NavigationStack.tsx and TabBar.tsx, so entryModule and componentFolder find neither a module nor a folder named after them and boundSources returns null. Measured here, the bound for a path that changes nothing is exactly lab__NavigationScreen, lab__TabBarItem, so two slices always pay the model's 96.8 s proof setup — about 200 s of the saving this change is for. Falling back to the folder that holds the module exporting the target, which sourcesOf already resolves for the copy, would close it.

.readFileSync(swizzleFile, 'utf8')
.split('\n')
.filter(Boolean)
.map(line => JSON.parse(line))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One malformed line throws here and fails the leg's drift step with a stack trace. swizzleSamples in scripts/lib/swizzle-cost.mjs already skips a line it cannot parse and keeps only samples whose affected and totalMs are finite; without that check a line that parses but carries no totalMs also reaches slowSlices, where the NaN comparisons drop it silently. Reuse that reader's validation for the JSONL file.

(sample.totalMs - setupMs(sample)) / 1000,
]);
const counts = new Set(points.map(([affected]) => affected));
if (counts.size < 3) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Three distinct counts is a weak guard on the line's shape. A refit from one run of a component change — what the drift annotation asks for — gives counts in a narrow band (16 to 20 across the eight slices here), where the sum of squared deviations is about 17: a ±15 s scatter in slice time moves perTargetSeconds by roughly ±3.6 s against the fitted 3.8, and proveBaseSeconds absorbs about ±65 s of it. The numbers shipped here came from 24 slices spanning 0 to 19 affected targets, which is the right shape; consider also requiring a minimum spread of affected counts and keeping the previous line otherwise.

@cixzhang

Copy link
Copy Markdown
Contributor Author

(Posted by Cindy's agent.) Closing: superseded by #11697 (merged), which runs the swizzle proof in its own jobs, so the Node legs no longer pack the slices this change costed.

@cixzhang cixzhang closed this Nov 14, 2026
@cixzhang
cixzhang deleted the test/swizzle-slice-cost branch November 14, 2026 12:22

This branch was successfully deployed

1 active deployment
Preview — d22264d0 Deployed Nov 14, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant