Skip to content

test(harness): a page freeze, so a proof can act at an instant of the scene's own time - #9698

Merged
cixzhang merged 1 commit into
meta:mainfrom
vjeux:harness/page-freeze
Nov 3, 2026
Merged

cixzhang merged 1 commit into
meta:mainfrom
vjeux:harness/page-freeze

Conversation

@vjeux

@vjeux vjeux commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer impact

A proof that must act on a component mid-animation races the test process: on a loaded runner the motion has moved on, or ended, before the next command reaches the page. The proofs of Lab's TabBar, the drafts that follow, need to act at an instant of the scene's own time.

Intended invariant

No behavior change. A page that never calls installPageFreeze keeps its own clock and runs none of the freeze.

Change

The interaction harness gains a page freeze (src/freeze.ts) and a README section:

  • installPageFreeze, freezePage and thawPage stop and restart a scene in one page task. Its animations pause where they stand, timers and frame callbacks wait in the timer gate, and its clocks stand still. new Date() keeps the real clock.
  • freezePageOn(page, type) arms a freeze on the next pointer, touch, mouse, key, wheel or scroll event. The install adds one window capture listener per type before any page script runs, so the freeze lands before the page's own listeners.
  • freezePageWhen(page, predicate, arg) freezes on the first real frame the predicate holds. Its timeout runs on the real clock.
  • advanceFrozenPage(page, ms) moves the page's clock and every held animation on together.

At the thaw, every held animation resumes from where it stood on the timeline's own time, one the page dated while frozen included. Timeouts set before the freeze stop counting too, and come due on the page's clock after the thaw. Only the document timeline's animations are held: a scroll- or view-driven one follows its scroller. The timer gate gets freeze() and thaw() methods, which freezeTimers, thawTimers and the page freeze all call. It also carries the real clock: the harness's own waits time themselves on it, so they still sample, hold and time out on a frozen page. Its epoch stamps add back the frozen span in force when each time was taken. The span ends at the frame the held runs restart from, so they stay together. An interval skips its ticks while frozen. A CSS animation the page resumes while frozen is held where it stood, and a run it cancels while frozen stays cancelled.

Evidence

  • Failure before the change: each case Testing lists fails on the freeze as first drafted.
  • Success after the change: the harness's whole spec passes in Chromium (105, 1 skipped) and WebKit (93, 13 skipped).
  • Product/runtime behavior verified unchanged: harness only. No package imports it.

Scope

  • No intended public API, product behavior, visual direction, or policy change.
  • Product changes discovered during the work were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

Local gates at 0cadeb9, on main 7f1bace, node 24.22.1 from .nvmrc:

  1. The harness's own spec, whole file: Chromium 105 passed, 1 skipped; WebKit 93 passed, 13 skipped (Chromium-only evidence skips itself).
  2. Red-first, each on the freeze as first drafted: the armed-key case saw the page's own listener first (3/3); the thaw case read 87.6 ms where the run held at 100 (3/3); a freeze on a condition hung on a frozen page (2/2); a timeout came due 600 ms early on the page's clock (3/3); a scroll-driven animation made the freeze throw (3/3); on a frozen page sampleRects, armHold and blockMainThread never returned (2/2); a CSS animation resumed while frozen read 0 ms, not its 500 (3/3); a throwing condition left freezePageWhen pending (2/2); a transition reversed while frozen replayed its old run from the start over the reversal (3/3); after a thaw blockMainThread stamped its window 600 ms early (3/3); after a thaw waitForAnimation and sampleRects stamped about 500 ms early (3/3); a CSS run dated and then removed while frozen restarted at the thaw (5/5 in each engine); a run that finished before a freeze, read after the thaw, was dated about 600 ms late (3/3); ten freeze and thaw cycles put a run 66 to 95 ms ahead of the page's clock (3/3 in each engine). The new cases pass ×3 in both engines.
  3. Static: harness typecheck; strict ESLint, 0 problems; Prettier.

@vercel

vercel Bot commented Nov 3, 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 3, 2026 10:05am UTC

Request Review

@astracat-bot

astracat-bot Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 3, 2026, 10:12 AM UTC

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 0cadeb9

Storybook · Sandbox · built from this PR's head

Package size: no published package changed; no new dependencies.

Not run on this PR: add ci:run-visual, ci:run-a11y or ci:run-rtl to run them.


Generated by PR Enrichment workflow | View full report

@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.

Requesting changes: the page freeze solves a real race in mid-animation proofs, but three issues need fixing first.

  • On a page with a scroll- or view-timeline animation, freezePage throws and leaves the page half frozen, and installing the freeze already makes those timelines and then document.timeline.currentTime read NaN, because the currentTime patch on AnimationTimeline.prototype and the freeze loop assume millisecond numbers (freeze.ts:36-54, :163-167); limit both to document.timeline animations, as holdAnimations does.
  • Pending timers keep counting on the real clock through a freeze, so a 1000 ms end-of-animation timer started with a 1000 ms run fires with the run near 389 ms after a 600 ms freeze; re-time pending timeouts on the page clock, or document that timers stay on real time and drop "timers" from the header's "Stop a scene".
  • thawPage, the armed listener, freezePage and freezePageWhen copy the timer gate's release and frozen flag from thawTimers and freezeTimers (story.ts:212, :230-234), so give the gate freeze() and thaw() methods and call them from both sides.

A self-test with a view-timeline animation and one with a timer that spans a freeze would cover the first two. Separately, reverse() and replaying a finished run while frozen are not held yet; nothing in the repository does either today.

[Automated review]

if (own) Object.defineProperty(proto, name, Object.assign({}, own, make(own)));
};
define(Event.prototype, 'timeStamp', d => ({get() { return now(d.get.call(this)); }}));
const timelineProto = Object.getOwnPropertyDescriptor(AnimationTimeline.prototype, 'currentTime') ? AnimationTimeline.prototype : DocumentTimeline.prototype;

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.

This resolves to AnimationTimeline.prototype in Chromium, so the getter also serves ScrollTimeline and ViewTimeline. Their CSSUnitValue time becomes NaN and then sticks in the shared last, so document.timeline.currentTime reads NaN too. freeze() then throws on a scroll-driven run (line 167). Re-time only document.timeline, and skip animations on other timelines.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in e08149b. currentTime is now redefined on DocumentTimeline.prototype only, so scroll and view timelines keep their own getter. A new isTimed check limits holding, the startTime patch, play() and both freeze loops to the document timeline's animations. New self-test: a scroll-driven run follows its scroller while frozen, and the page's timeline keeps reading a number. It was red on the old code ("non-finite", 3/3).

Comment on lines +7 to +8
* `freezePageWhen` and `advanceFrozenPage`. Stop a scene (its animations,
* frames, timers and every time it reads), step it by its own clock, and

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.

Timers are not stopped. The gate starts each one with the real setTimeout and only queues its callback while frozen. After a thaw, a pending timer fires early on the page clock by the frozen span. Re-time pending timers on the page clock, or narrow this claim and the README.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in e08149b, by re-timing. With the page's clock stopped, the gate cancels the real timers of pending timeouts. advanceFrozenPage queues the ones the page's clock reaches, in due order. The thaw restarts the rest for what is left on the page's clock. New self-test: a 1 s timeout set beside a 3 s run comes due with the run 1 s in across a 600 ms freeze. It was 398 ms on the old code (3/3).

Comment on lines +368 to +371
gate.frozen = false;
while (gate.queue.length > 0) {
gate.queue.shift()?.run();
}

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.

This repeats the body of thawTimers (story.ts:230-234). Give the gate object a thaw() method, and a freeze() method for the three gate.frozen = true sites, and call them from both modules.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in e08149b. The gate now has freeze() and thaw() (plus catchUp() for an advance), and freezeTimers, thawTimers, freezePage, the armed listener, freezePageWhen and thawPage all call them. thaw() restarts the stopped timeouts in a finally, so a callback that throws doesn't leave the gate paused.

@vjeux
vjeux force-pushed the harness/page-freeze branch from 00c0e97 to e08149b Compare November 3, 2026 05:09
@vjeux

vjeux commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Round 1 is addressed in e08149b: the three points are fixed, each with a self-test that fails on the old code. Reversing or replaying a finished run while frozen is listed in the README as not held yet. The harness's whole spec passes in Chromium (96, 1 skipped) and WebKit (84, 13 skipped).

@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.

Requesting changes: the three earlier points are fixed, each with a self-test that passes, but one blocking issue remains.

  • On a frozen page the harness's own sampleRects, armHold and blockMainThread (and startBusyControl and waitForRest) never return, because they time themselves with performance.now() and the gate's frame, which the freeze stops (frames.ts:446, curves.ts:723, busy.ts:221); give the gate the freeze's frame and a real now, use them in every harness wait including freezePageWhen, and add a self-test that samples and arms a hold while frozen.

Smaller points, not blocking: watch rewinds a CSS animation the page resumes while frozen to its start (freeze.ts:128-131), a throwing predicate leaves freezePageWhen pending forever (freeze.ts:318), and intervals still drop their frozen ticks and keep the real clock while the header says a freeze stops timers.

[Automated review]

Comment on lines +149 to +152
// The real frames, for the harness's own waits while frozen.
frame: nativeFrame,
// The real clock, for the harness's own deadlines while frozen.
realNow: rawNow,

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.

Only freezePageWhen uses these. sampleRects, armHold, blockMainThread, startBusyControl and waitForRest still read performance.now() and the gate's frame, which is the wrapper at line 122, so on a frozen page they never return (sampleRects(box, 200) was still pending 3 s later; blockMainThread(page, 50) left the page unresponsive). Give the gate this frame and a real now, and use them in every harness wait.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a9b1284. The gate now carries the real clock (now: the freeze's realNow when it is installed). Every harness deadline reads it: sampleRects, armHold, waitForRest, startBusyControl and blockMainThread. blockMainThread's busy loop runs on the real clock when the page is frozen at the call. startBusyControl refuses a frozen page, since the freeze would hold its control. gate.frame stays as it was: the freeze's wrapper only maps the frame's time and never holds it, so the frames kept coming and only the clocks needed the change. New self-test: on a frozen page the harness samples, arms a hold and blocks the main thread. It timed out on the old code (2/2).

for (const animation of document.getAnimations()) {
if (isTimed(animation) && !state.held.has(animation) && playState.get.call(animation) === 'running') {
nativePause.call(animation);
currentTime.set.call(animation, 0);

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.

Not blocking: this rewinds every running animation not yet held, including one that existed before the freeze and that the page resumes by CSS (animation-play-state: running). A run paused at 516 ms read 0 ms here and replayed from 0 after the thaw. Hold an animation that existed at the freeze at its current time, or list the case under "Not held yet".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a9b1284. The freeze records each animation's time, and watch holds a run the page resumes at that time. Only a run new since the freeze is held at its start. New self-test: a CSS run paused 500 ms in and resumed by animation-play-state while frozen holds 500 ms and plays on from there. It read 0 on the old code (3/3).

// The real clock: the page's own stands still while it is frozen.
const deadline = freeze.realNow() + wait;
const tick = () => {
if (check(value)) {

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.

Not blocking: if check throws, the exception ends the frame loop and the promise never settles, so the proof waits for the test timeout. Catch the error and reject with it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a9b1284. A predicate that throws now rejects freezePageWhen with its error. New self-test; it hung on the old code (2/2).

@vjeux
vjeux force-pushed the harness/page-freeze branch from e08149b to a9b1284 Compare November 3, 2026 05:48
@vjeux

vjeux commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Round 2 is addressed in a9b1284. The harness's own waits now keep the real clock on a frozen page. The two smaller points are fixed, each with a self-test that fails on the old code, and the header and README say what a freeze does to intervals. The harness's whole spec passes in Chromium (99, 1 skipped) and WebKit (87, 13 skipped).

@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.

Requesting changes: the earlier points are fixed, each with a self-test, but two blocking issues remain.

  • A CSS transition the page reverses or retargets while frozen, or a CSS animation it removes, replays from its start after the thaw and overrides the page's new motion, because the thaw calls play() on a held run that went idle (freeze.ts:218-219); skip held runs that went idle, and add a self-test that reverses a transition while frozen.
  • After a thaw, blockMainThread stamps its window with the page clock, which trails real time by the frozen span, so busyWindowProof judges frames from before the block (600 ms early after a 600 ms freeze); read the real clock in both loops, as the other harness waits now do (busy.ts:238-256, :304-320).

Smaller points, not blocking: held CSS animations stop following animation-play-state after the thaw, and the wheel driver's delivery deadline (webInput.ts:461) still reads the page clock.

[Automated review]

Comment on lines +218 to +219
} else {
nativePlay.call(animation);

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.

A held run the page cancels by style while frozen (a CSS transition it reverses or retargets, a CSS animation it removes) reaches this branch with no current time, and play() restarts it from 0 above the page's new transition. A transition reversed at about 160 px read 33 px 100 ms after the thaw and 247 px at 630 ms, sliding the wrong way. Skip a run that went idle while held: } else if (playState.get.call(animation) !== 'idle') {.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 7f2b34f, as you suggested. The thaw replays a held run only when it isn't idle, so a transition the page reversed or retargeted, or an animation it removed, while frozen stays cancelled. New self-test: a transition reversed at about 160 px while frozen keeps heading back after the thaw. It slid the wrong way on the old code (3/3).

Comment on lines +243 to +246
const read =
freeze?.frozen === true
? () => freeze.realNow()
: () => performance.now();

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.

After a thaw the page is not frozen, so this reads the page clock, which trails real time by every frozen span. from and to below then miss the compositor frames busyWindowProof compares them with: 601 ms early after a 600 ms freeze. Read __harnessFreeze.realNow whenever it is installed, here and at line 309.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 7f2b34f. Both loops now read __harnessFreeze.realNow whenever the freeze is installed, and performance.now() only without it. On a page that installs the freeze but never freezes, the two clocks agree. New self-test: after a 600 ms freeze and thaw, the blocked window falls within 50 ms of the test's own clock. It was 600 ms early on the old code (3/3).

@vjeux
vjeux force-pushed the harness/page-freeze branch from a9b1284 to 7f2b34f Compare November 3, 2026 06:20
@vjeux

vjeux commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Round 3 is addressed in 7f2b34f. A run the page cancels while frozen stays cancelled at the thaw, and blockMainThread reads the real clock whenever the freeze is installed. Each has a self-test that fails on the old code. The wheel driver's deadline reads the real clock too. The README now lists, under "Not held yet", that a held CSS animation stops following animation-play-state. The harness's whole spec passes in Chromium (101, 1 skipped) and WebKit (89, 13 skipped).

@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.

Requesting changes: the round-3 points are fixed, each with a self-test, but two blocking issues remain.

  • After a thaw, waitForAnimation's interval and sampleRects' stamps trail the trace, screencast and blockMainThread stamps by the frozen span (about 605 ms after a 600 ms freeze), so a trace count or cast over that interval judges the wrong frames; map page times back to real time where the harness stamps epoch times (curves.ts:1326, :1356, frames.ts:454) and add a self-test like the blockMainThread one.
  • blockMainThread rebuilds the gate's real-clock choice from __harnessFreeze in both loops (busy.ts:239-243, :301-307) instead of reading the gate's now like the other harness waits, so read gate?.now in both and drop the two copies.

Smaller point, not blocking: a CSS animation the page dated and then removed while frozen replays after the thaw (freeze.ts:216-217); checking for idle before both fallbacks keeps it cancelled.

[Automated review]

},
thaw() {
if (state.frozenAt == null) return;
state.offset += rawNow() - state.frozenAt;

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.

From here on page times trail real time by the frozen span, but waitForAnimation (curves.ts:1326, :1356) and sampleRects (frames.ts:454) still turn them into epoch stamps with performance.timeOrigin + t. After a 600 ms freeze and thaw their stamps came about 605 ms early against the trace and screencast clocks, which stay real. Exposing the frozen span (for example __harnessFreeze.offset) and adding it at those three places keeps every harness epoch stamp on one clock.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 3a1faef, as you suggested. The freeze exposes the frozen span (offset). waitForAnimation adds it to the epoch it stamps intervals and finishes from, and sampleRects adds it to each sample's stamp. New self-test: after a 600 ms freeze and thaw, both stamp within 50 ms of the test's own clock. On the old code they were about 500 ms early (3/3).

Comment on lines +239 to +243
const freeze = (
window as unknown as {__harnessFreeze?: {realNow(): number}}
).__harnessFreeze;
const read =
freeze == null ? () => performance.now() : () => freeze.realNow();

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.

This rebuilds the gate's now (story.ts:169), and the during branch does it again at lines 301-307 with the gate's now already in scope as realNow (line 275). No freeze can start without the gate, so gate?.now ?? (() => performance.now()) serves both loops and keeps one real clock for every harness wait.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 3a1faef. Both loops now read the gate's now; the during loop reuses the realNow it already holds. The two copies are gone.

Comment on lines +216 to +217
} else if (deferred) {
startTime.set.call(animation, value + state.offset);

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.

Non-blocking: a run the page dated while frozen and then removed (a CSS animation whose name it cleared) reaches this branch with no current time and is restarted; 300 ms after the thaw it stood at about 88 px and running. The idle check below covers only the last fallback, so checking playState !== 'idle' before both keeps it cancelled.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 3a1faef. The thaw checks for an idle run first, before any way of resuming it. New self-test: a CSS animation started, dated and removed while frozen stays removed after the thaw. It restarted on the old code (5/5 in each engine).

@vjeux
vjeux force-pushed the harness/page-freeze branch from 7f2b34f to 3a1faef Compare November 3, 2026 08:04
@vjeux

vjeux commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Round 4 is addressed in 3a1faef. After a thaw, the harness's epoch stamps from page times add the frozen span back, so they share the trace's clock. blockMainThread reads the gate's real clock in both loops, and a run cancelled while frozen stays cancelled before every way of resuming it. Each change has a self-test that fails on the old code. The harness's whole spec passes in Chromium (103, 1 skipped) and WebKit (91, 13 skipped).

@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.

Requesting changes: the earlier points are fixed, each with a self-test, but two blocking issues remain.

  • After a thaw, waitForAnimation dates a run that finished before the freeze late by the whole frozen span (about 600 ms after a 600 ms freeze), because curves.ts:1302-1305 adds the offset at the read to the start and finish times the recorder stored under the earlier offset (curves.ts:126-133); keep each recorded time with the offset in force when it was recorded, and add a self-test for a run that ends before a freeze and is read after the thaw.
  • Each thaw puts the held runs up to a frame ahead of the page clock (11 to 13 ms per freeze and thaw, 79 to 114 ms after ten in Chromium), because thaw() restarts them from the timeline's last frame time (freeze.ts:220) but ends the frozen span at rawNow() (freeze.ts:199); ending the span at that same frame time keeps them together, and a self-test with several freeze and thaw cycles would hold it.

The rest checks out: the page-freeze cases pass three times over in Chromium, and the harness's whole spec passes there.

[Automated review]

Comment on lines +1302 to +1305
const epoch =
performance.timeOrigin +
((window as unknown as {__harnessFreeze?: {offset: number}})
.__harnessFreeze?.offset ?? 0);

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.

This adds the frozen span as it stands at the read, but the recorder stored finishStart, finishedAt (lines 126-133) and startedAt with the offset in force when they were recorded. After a 600 ms freeze, a 200 ms run that finished before it reads from about 600 ms late and finishedAt after the run was already over (3 of 3 in Chromium). Keep each recorded time with its own offset (or store it as epoch at record time) and add that here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 0cadeb9. The recorder now keeps real times: each page time gets the frozen span in force when it was recorded. waitForAnimation stamps those as they are and adds the current span only to live start times. New self-test: a run watched before it starts and finished before a 600 ms freeze, read after the thaw, is dated before the freeze began. On the old code it came about 600 ms late (3/3).

… scene's own time

A proof that must touch a component mid-animation, or sample an animation
from its start, races the test process: on a loaded runner the slide has
moved on, or ended, before the next command reaches the page. The page
freeze stops the scene instead. Every animation pauses where it stands,
and timers and frame callbacks wait in the timer gate. The page's clocks
stay at the freeze instant: performance.now(), Date.now(), event times,
frame times and the animation timeline (new Date() keeps the real clock).
Timeouts the page set before the freeze stop counting too, and come due on
the page's clock after the thaw. Only the document timeline's animations
are held: a scroll- or view-driven one follows its scroller. Input still
arrives. Thawed, the scene plays on from where it stood and the held
timers run in the order they came due.

- installPageFreeze (before the page loads, then installTimerGate),
  freezePage, thawPage.
- freezePageOn(page, type): the install adds one window capture listener for
  each pointer, touch, mouse, key, wheel and scroll event before any page
  script runs, and the call arms it, so the freeze lands in the input's own
  task, before any page listener for it.
- freezePageWhen(page, predicate, arg): freezes on the first real frame the
  predicate holds, and rejects after its timeout, which runs on the real
  clock.
- advanceFrozenPage(page, ms): the page's clock and every held animation
  move on together by ms; timers stay held.

The timer gate gets freeze() and thaw() methods, which freezeTimers,
thawTimers and the page freeze all call, and the real clock: the harness's
own waits (sampleRects, armHold, waitForRest, startBusyControl,
blockMainThread) time themselves on it, so they still run on a frozen
page. The freeze exposes the frozen span. The curve recorder keeps real
times, each page time with the span in force when it was recorded, and the
harness adds the current span only to live page times, so after a thaw its
epoch stamps share the trace's clock. An interval skips its ticks while
frozen. A CSS animation the page resumes while frozen is held where it
stood at the freeze, and a run the page cancels while frozen (a reversed
CSS transition) stays cancelled at the thaw.

At the thaw every held animation, one whose start the page wrote while
frozen included, resumes from the time it held on the timeline's own time,
so it is drawn where it stood in the thaw frame. The frozen span ends at
that same frame time, so the page's clock and its runs stay together
across freezes.

Self-tests in Chromium and WebKit: a frozen scene stands still and thaws
from where it stood; an armed freeze lands before the page's own listener
(against a control where that listener runs first and a late read finds
the run well along); an advance moves the clock and the held animation by
its step while timers stay held; a freeze on a condition stops on the
first frame it holds and times out otherwise, on a frozen page too; a
start the page dates while frozen resumes exactly where it held in the
thaw task; a timeout pending across a freeze comes due on the page's
clock; a scroll-driven animation follows its scroller while frozen; the
harness samples, arms a hold and blocks the main thread on a frozen page;
a CSS animation resumed while frozen holds its time; a condition that
throws rejects freezePageWhen; a CSS transition reversed while frozen
plays its reversal after the thaw; after a thaw blockMainThread,
waitForAnimation and sampleRects stamp on the real clock; a CSS animation
dated and then removed while frozen stays removed; a run that finished
before a freeze is dated where it ran when read after the thaw; the page's
clock and its runs stay together across ten freeze and thaw cycles; a page
without the freeze refuses one.

Opt-in: a page that never calls installPageFreeze keeps its own clock. It
lands ahead of its first user, TabBar's interaction proofs, so the Lab
batches change only Lab.
@vjeux
vjeux force-pushed the harness/page-freeze branch from 3a1faef to 0cadeb9 Compare November 3, 2026 09:54
@vjeux

vjeux commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Round 5 is addressed in 0cadeb9:

  • The curve recorder keeps real times, so a run that finished before a freeze is dated where it ran, even when read after the thaw.
  • The thaw ends the frozen span at the timeline's last frame time, the same instant the held runs restart from. The page's clock and its runs then stay together across freeze and thaw cycles. Ten cycles drifted 66–95 ms on the old code and stay under 5 ms now.
  • The README notes the one limit: a freeze in which no frame starts ends at the frame before it.
    The harness's whole spec passes in Chromium (105, 1 skipped) and WebKit (93, 13 skipped).

@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.

Approving from the automated review: both earlier timing issues are fixed, each with a new self-test.

  • A run that finished before a freeze is now dated where it ran after the thaw, and the page clock and its runs stay together across repeated freezes; the page-freeze cases pass three times over in Chromium, and the harness's whole spec passes there.
  • Non-blocking: the ActiveAnimation and waitForAnimation docs in curves.ts still call these stamps "page clock"; after a thaw they are on the trace's clock, while since stays on the page clock.

[Automated review]

@vjeux
vjeux marked this pull request as ready for review November 3, 2026 11:59
@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 3, 2026
@cixzhang
cixzhang marked this pull request as draft November 3, 2026 12:02
@cixzhang
cixzhang marked this pull request as ready for review November 3, 2026 12:02
@cixzhang
cixzhang merged commit 14550c0 into meta:main Nov 3, 2026
151 of 156 checks passed
@vjeux
vjeux deleted the harness/page-freeze branch November 3, 2026 12:28

This branch was successfully deployed

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

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) 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.

2 participants