fix(spring): a spring takes the same time on the clock at any frame rate (#945, #951) #976

Closed
kayg wants to merge 0 commits from flaky/spring-real-time into dev
Owner

Refs #945, #951 (WebKit toast specs). Found by the flaky lane (U4).

The bug. tick in packages/ui/src/primitives/spring/index.ts capped one frame at 1/20 s (Math.min(0.05, …)). Below 20 frames a second every spring-driven animation therefore ran in slow motion: a frame that took 1 s advanced it 50 ms, so about 20 times slower than the clock. On software WebKit under load (frames of 1 to 11 s) the toast stayed a small empty pill with its Undo inside for tens of seconds (screencast of a failing toast-bar.spec.ts:40 run: the pill still opening 11 s later). Real screens (frames under 50 ms) never reach the cap.

The fix. The cap is now 2 s, kept only as a guard for a gap of minutes (a background tab). Spring.step already integrates in fixed 1/240 s sub-steps, so a long frame is stable and lands at rest. Frames of 50 ms or less are unchanged by construction.

Tests (spring.test.ts, vitest, dev-01): three new tests drive run() with a stubbed requestAnimationFrame and clock. 1 s frames: 19 frames to settle before, 4 or fewer after. A 10 min gap: lands at rest in 1 to 2 frames. 60 fps: unchanged (the same 40 to 100 frames as before). Before: 6 passed, 2 failed. After: 8 passed.

What this does to the flake (honest numbers). WebKit, dev-02, the same two cargo build slots running alongside, --repeat-each=20 per width: the set (signout offline, toast-bar carries-on and wrap, swipe-rows Trash Restore, composer-tasks:51) on dev 789fdaa9: 2 genuine failures in 400, both toast-bar:40 (2 more were my own run's ENOENT, not counted). On this branch: 1 failure in 400, toast-bar:40 webkit-390, whose trace shows frames 11 s apart (host starved). toast-bar:40 alone, 50 per width: 1 failure in 100. That is an improvement, but one failure either way is not a statistically sound difference; the remaining failures look like whole-host starvation (one was "Tearing down context exceeded the test timeout" after the body finished).

Not done / for the reviewer. I did not run frame measurements on the Mac VM: at 20 frames a second or faster the maths is the same as before, but the brief's rule is that motion changes are measured there, so please decide whether that is needed. The prettier warning on index.ts is already on dev (the file was unformatted there); the test file is formatted.

🤖 Generated with Claude Code

Refs #945, #951 (WebKit toast specs). Found by the flaky lane (U4). **The bug.** `tick` in `packages/ui/src/primitives/spring/index.ts` capped one frame at 1/20 s (`Math.min(0.05, …)`). Below 20 frames a second every spring-driven animation therefore ran in slow motion: a frame that took 1 s advanced it 50 ms, so about 20 times slower than the clock. On software WebKit under load (frames of 1 to 11 s) the toast stayed a small empty pill with its Undo inside for tens of seconds (screencast of a failing `toast-bar.spec.ts:40` run: the pill still opening 11 s later). Real screens (frames under 50 ms) never reach the cap. **The fix.** The cap is now 2 s, kept only as a guard for a gap of minutes (a background tab). `Spring.step` already integrates in fixed 1/240 s sub-steps, so a long frame is stable and lands at rest. Frames of 50 ms or less are unchanged by construction. **Tests** (`spring.test.ts`, vitest, dev-01): three new tests drive `run()` with a stubbed `requestAnimationFrame` and clock. 1 s frames: 19 frames to settle before, 4 or fewer after. A 10 min gap: lands at rest in 1 to 2 frames. 60 fps: unchanged (the same 40 to 100 frames as before). Before: 6 passed, 2 failed. After: 8 passed. **What this does to the flake (honest numbers).** WebKit, dev-02, the same two `cargo build` slots running alongside, `--repeat-each=20` per width: the set (`signout` offline, `toast-bar` carries-on and wrap, `swipe-rows` Trash Restore, `composer-tasks:51`) on dev `789fdaa9`: 2 genuine failures in 400, both `toast-bar:40` (2 more were my own run's `ENOENT`, not counted). On this branch: 1 failure in 400, `toast-bar:40` webkit-390, whose trace shows frames 11 s apart (host starved). `toast-bar:40` alone, 50 per width: 1 failure in 100. That is an improvement, but one failure either way is not a statistically sound difference; the remaining failures look like whole-host starvation (one was "Tearing down context exceeded the test timeout" after the body finished). **Not done / for the reviewer.** I did not run frame measurements on the Mac VM: at 20 frames a second or faster the maths is the same as before, but the brief's rule is that motion changes are measured there, so please decide whether that is needed. The prettier warning on `index.ts` is already on dev (the file was unformatted there); the test file is formatted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Drives run() with 1 s frames and with a 10 min gap. Fails today: one frame advances a spring by at most 50 ms, so a second-long frame (software WebKit under load) slows every animation about 20 times.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
tick capped a frame at 1/20 s, so below 20 frames a second every animation ran in slow motion (a 1 s frame moved it 50 ms). On software WebKit under load that left the toast a half-open pill for 30 s with its Undo inside (#945, #951). The cap is now 2 s, only a guard for a gap of minutes; step already integrates in 1/240 s sub-steps, so a long frame is stable and lands at rest. Frames of 50 ms or less (every real screen) are unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
style: prettier on the new spring tests
Some checks failed
CI / server (pull_request) Has been cancelled
CI / rust (pull_request) Has been cancelled
CI / web (pull_request) Has been cancelled
Markdown extraction contract / markdown-native-contract (pull_request) Has been cancelled
Markdown extraction contract / markdown-editor-contract (pull_request) Has been cancelled
60e33b3450
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Author
Owner

#976 gates at 60e33b34: green except the Mac VM frames (pending: std VMs paused)

Contains dev 02cdf878.

gate result
lint / svelte-check / vitest web / ui primitives (incl. the spring test) / check-ui-primitives pass / 0 errors, 16 warnings (= dev) / 109 / 59 / clean
first-paint JS brotli (perf/web.sh --bundle-only --gate) 232.520 KB vs dev 232.617: −97 B; first CSS 17.952 = dev; gate rc 0
Chromium (dev-01) 1440+390: toast-bar, note-bars-motion, swipe-rows, pill-press, composer-open, select-rows 81 passed, 0 failed
WebKit (dev-02) same (run before the pause) 79 passed, 0 failed
Mac VM frames, toast morph, dev vs this head pending: std VMs paused. The job was queued behind other Mac jobs for ~2 h and is stopped (not started). First, flawed-metric run (3 × 12 morphs, ABAB, rAF deltas over 1.5 s after the delete; the toast did not appear in it, so that run is idle frames only): p50 17 ms on both, so nothing to compare yet. The corrected spec (rect of the toast capsule, spring settle time, frame deltas) is ready: ~/Developer/Worktrees/zz-toast-frames.spec.ts + macab.sh toast … origin/dev origin/flaky/spring-real-time 4.

Reasoning for why frames should be flat on the Mac: the cap only changes a frame gap above 50 ms (a late frame advances the spring by the whole gap instead of 1/20 s); at 60 Hz every gap is ≈17 ms, so the integration is identical. This is what the Mac run is for.

## #976 gates at `60e33b34`: green except the Mac VM frames (pending: std VMs paused) Contains dev `02cdf878`. | gate | result | |---|---| | lint / svelte-check / vitest web / **ui primitives (incl. the spring test)** / `check-ui-primitives` | pass / 0 errors, 16 warnings (= dev) / 109 / **59** / clean | | **first-paint JS brotli** (`perf/web.sh --bundle-only --gate`) | **232.520 KB vs dev 232.617: −97 B**; first CSS 17.952 = dev; gate rc 0 | | Chromium (dev-01) 1440+390: toast-bar, note-bars-motion, swipe-rows, pill-press, composer-open, select-rows | 81 passed, 0 failed | | WebKit (dev-02) same (run before the pause) | 79 passed, 0 failed | | Mac VM frames, toast morph, dev vs this head | **pending: std VMs paused.** The job was queued behind other Mac jobs for ~2 h and is stopped (not started). First, flawed-metric run (3 × 12 morphs, ABAB, rAF deltas over 1.5 s after the delete; the toast did not appear in it, so that run is idle frames only): p50 17 ms on both, so nothing to compare yet. The corrected spec (rect of the toast capsule, spring settle time, frame deltas) is ready: `~/Developer/Worktrees/zz-toast-frames.spec.ts` + `macab.sh toast … origin/dev origin/flaky/spring-real-time 4`. | Reasoning for why frames should be flat on the Mac: the cap only changes a frame gap above 50 ms (a late frame advances the spring by the whole gap instead of 1/20 s); at 60 Hz every gap is ≈17 ms, so the integration is identical. This is what the Mac run is for.
Author
Owner

#976 gates: GREEN at 60e33b34 (Mac VM toast frames flat vs dev)

Earlier gates (unchanged): first-paint JS 232.520 KB vs dev 232.617 (−97 B), spring unit tests 59 pass, Chromium 81 + WebKit 79 pass, check-ui-primitives clean.

Mac VM sanity (before the run): pill-press.spec.ts on Playwright WebKit at 1440 on the Mac VM: 2 passed, 4 skipped (the 390 and Linux-only cases), so the stack works on the internal-SSD VM.

Toast morph frames on the Mac VM (lume@calternal-macos-01-std, WebKit 1440, dev 7a9bd54e (A) vs this head (B), ABAB × 4 runs, each run 15 fresh notes after one warm-up note; per note: a 1.5 s idle baseline on the same page, then ⌘⇧K (delete the block) and 1.5 s of rAF deltas; the capsule's rect is watched for the spring's settle). Mac rules followed: memory checked before and after every run (free 1.8–2.3 GB plus 0.5–0.8 GB inactive, swap 0 MB throughout), one lock hold per run (released between runs, EXIT trap), idle baseline next to every animation run.

dev (A) #976 (B)
idle baseline: p50 / p95 / worst (ms) 17 / 22 / 44 17 / 22 / 71 (one frame, 1 of 4 runs)
morph: p50 / p95 (ms) 17 / 25.3 17 / 25.0
morph: frames > 24 ms per 1000 54.3 53.5
morph: frames ≥ 50 ms per 1000 6.7 (worst 68 ms) 6.7 (worst 73 ms)
spring settle (capsule stops moving), p50 / p95 over 60 morphs 73.5 / 93 ms 74.5 / 90 ms (Mann–Whitney z 0.03)
Undo button visible, p50 23 ms 23 ms

Flat on every row. The cap only changes a frame gap over 50 ms and the 60 Hz morph's frames are ~17 ms, as expected. (My probe also double-counts frames after the first recording of a page, the same way for both builds, so use the rates, not the counts.)

Separate finding, not from this PR: the morph itself has 50–68 ms frames on dev too (≈ 7 per 1000 frames, none in the idle baseline). Per the brief that is a must-fix for whoever owns the toast morph; this PR neither adds nor removes them.

## #976 gates: GREEN at `60e33b34` (Mac VM toast frames flat vs dev) Earlier gates (unchanged): first-paint JS 232.520 KB vs dev 232.617 (−97 B), spring unit tests 59 pass, Chromium 81 + WebKit 79 pass, check-ui-primitives clean. **Mac VM sanity (before the run):** `pill-press.spec.ts` on Playwright WebKit at 1440 on the Mac VM: 2 passed, 4 skipped (the 390 and Linux-only cases), so the stack works on the internal-SSD VM. **Toast morph frames on the Mac VM** (`lume@calternal-macos-01-std`, WebKit 1440, dev `7a9bd54e` (A) vs this head (B), ABAB × 4 runs, each run 15 fresh notes after one warm-up note; per note: a 1.5 s idle baseline on the same page, then `⌘⇧K` (delete the block) and 1.5 s of rAF deltas; the capsule's rect is watched for the spring's settle). Mac rules followed: memory checked before and after every run (free 1.8–2.3 GB plus 0.5–0.8 GB inactive, swap 0 MB throughout), one lock hold per run (released between runs, EXIT trap), idle baseline next to every animation run. | | dev (A) | #976 (B) | |---|---|---| | idle baseline: p50 / p95 / worst (ms) | 17 / 22 / 44 | 17 / 22 / 71 (one frame, 1 of 4 runs) | | morph: p50 / p95 (ms) | 17 / 25.3 | 17 / 25.0 | | morph: frames > 24 ms per 1000 | 54.3 | 53.5 | | morph: frames ≥ 50 ms per 1000 | 6.7 (worst 68 ms) | 6.7 (worst 73 ms) | | spring settle (capsule stops moving), p50 / p95 over 60 morphs | 73.5 / 93 ms | 74.5 / 90 ms (Mann–Whitney z 0.03) | | Undo button visible, p50 | 23 ms | 23 ms | Flat on every row. The cap only changes a frame gap over 50 ms and the 60 Hz morph's frames are ~17 ms, as expected. (My probe also double-counts frames after the first recording of a page, the same way for both builds, so use the rates, not the counts.) **Separate finding, not from this PR:** the morph itself has 50–68 ms frames on dev too (≈ 7 per 1000 frames, none in the idle baseline). Per the brief that is a must-fix for whoever owns the toast morph; this PR neither adds nor removes them.
Author
Owner

Merged into dev by the orchestrator (U1 GREEN).

Merged into dev by the orchestrator (U1 GREEN).
kayg closed this pull request 2026-11-06 08:09:54 +00:00
Some checks failed
CI / server (pull_request) Has been cancelled
CI / rust (pull_request) Has been cancelled
CI / web (pull_request) Has been cancelled
Markdown extraction contract / markdown-native-contract (pull_request) Has been cancelled
Markdown extraction contract / markdown-editor-contract (pull_request) Has been cancelled

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kayg/calternal!976
No description provided.