Skip to content

Fix the intermittent task editor scroll check - #793

Open
melonpuff wants to merge 2 commits into
sysprog21:mainfrom
melonpuff:fix-task-scroll-wait
Open

melonpuff wants to merge 2 commits into
sysprog21:mainfrom
melonpuff:fix-task-scroll-wait

Conversation

@melonpuff

@melonpuff melonpuff commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem and behavior

The task editor scroll check failed in CI with [900, 2276, 2276] because its wait could be met before the layers followed the scroll it waits for. page.fill leaves the caret at the end of the 120 lines, so the textarea scrolls to 2276 and the layers follow it there on the next frame, through the scroll listener and the paint in web/editor-view.js. When that frame lands between the fill and scrollTop = 900, the layers already sit at 2276, scrollTop > 0 holds at once, and the assertion reads them before the scroll event for 900 arrives. Locally the frame usually lands after the assignment, which is why the test passed here and only sometimes failed on a loaded runner.

The product side is not at fault: in a listener registered after the editor's own, both layers equalled the textarea on every scroll event (8 of 8), so they move before the page paints. The defect is the wait, and nothing stopped the next wait of that shape from landing, since scripts/check-test-timing.mjs only knew deadlines and fixed sleeps.

Approach

The test now waits for the layers to follow the fill before it scrolls, so every run starts from the state CI failed in, and then waits until both layers reach 900. The first wait is also a check: removing the paint-time syncScroll() leaves the layers at 0 after the fill, which the old test let pass on two runs out of three.

scripts/check-test-timing.mjs gains a third rule: a wait right after an assignment is refused when the condition it polls compares the property just set with anything but === or == (>, <, >=, <=, !=, !==, with the property on either side), or with either of those two against another literal than the one set (=== 1 or == 1 after = 900, signed numbers included), and the message names the property and asks for the value set. An === beside the bound does not exempt it: code.scrollTop === 900 && layer.scrollTop > 0 holds as soon as the textarea is set, while the layer still sits where it was.

The rule reads the same blanked code as the other two and only the argument the wait polls: the first, or the second for reaches(page, predicate). It ties a wait to an assignment only when the assignment runs before it: in the statement right before it, whether or not the wait's result is kept (const reachable = await reaches(...)), at the wait's own level or in a callback of a call that statement awaits, and on the same page as far as the names tell, the page being the receiver of the .evaluate that runs the assignment, inside Promise.all or t.test too. A step between the two, a function stored for later, a wait on another page or an assignment in another test is left alone. A deliberate bound, such as a counter reset below its threshold, carries timing-ok:.

The reach is kept short on purpose: over tests/browser, upstream main and every open pull request that touches it, the rule flags only the wait replaced here. What it does not see is stated in the file's header: a property read into a local before the comparison, a property on the right behind brackets two deep, a value set or compared that is not written out as a number, true, false or null, an assignment in a call that is not awaited where it is written (such as a bare page.evaluate(...) without await), a wait kept with var, a destructuring or a plain reassignment, or wrapped in another call, and a wait that does not directly follow the assignment.

Validation

  • Old wait with the fill wait added, node --test --test-name-pattern='paints syntax colours and line numbers' tests/browser/task-workspace.test.js: failed 5 of 5, actual: [ 900, 2276, 2276 ]. New wait: passed 10 of 10, about 1.4 s each.
  • Mutants in web/editor-view.js, each reverted after: without the scroll listener the test fails after the 30 s wait with [ 900, 2276, 2276 ]; without the paint-time syncScroll() it fails with the layers at [ 0, 0 ] after the fill.
  • node scripts/check-test-timing.mjs with both commits applied: no findings in tests/browser. Run on the test as it was before the fix, it flags the wait Task editor scroll-sync test fails intermittently in CI #654 is about: task-workspace.test.js:596: wait bounds .scrollTop, which the test just set; wait for the value set.
  • The rule over tests/browser of upstream main (f728575, and 498d1c0 after it moved on) and of each of the 15 open pull requests that touch it, at the heads fetched for this review: each reports only task-workspace.test.js:596, the line this change fixes, and Synchronize browser test request assertions #789, the one that also edits that file, merges with this branch without conflict.
  • python3 tests/test_check_test_timing.py: 39 tests OK, 22 of them for this rule. Each condition of the rule fails a test when broken: the tie to the next statement, the deduplication, the polled argument and the commas inside it, the awaited call and the stored function, the brackets around the assignment and nested call arguments on both sides, the page on each side and the .evaluate that names it, the reversed and bracketed operands, the literal comparison with its sign and the expressions it leaves alone, and === or == counted as a bound. Two mutants survive: reading the brackets around the assignment outermost first is equivalent, since no statement nests one .evaluate in another; letting any text stand before the wait's await differs only for a wait wrapped in another call, such as assert.ok(await reaches(...)), which the header names as a limit rather than a test pinning it. Removing <= from the operators fails nothing, since < still matches <= 1. ruff check scripts tests .claude/skills is clean with 0.15.2, the version CI pins.
  • The fixtures from the review threads behave as asked: the comparison in until's message, the deferred resetScroll, and the wait on secondPage, directly or after Promise.all, pass; === 1 and == 1 after = 900, === 0 after = -1, const reachable = await reaches(page, () => layer.scrollTop > 0), 0 < document.querySelector(selectorFor("layer")).scrollTop, 2000 > (await top()).scrollTop and an awaited page.locator(sel("#code")).evaluate(...) are refused.
  • ./scripts/test.sh browser on macOS, at an earlier head with the same browser test: 3653 tests, 3651 pass, 1 skipped (no ffmpeg), 1 fail, lobby.test.js "the picker keeps the page's classic scrollbar", which asserts a classic scrollbar that macOS overlay scrollbars never give; this branch does not touch that test or web/.
  • ./scripts/test.sh portable at this head on this macOS machine fails three gates, the same three that fail on the base commit and none in a file this branch touches:
    • git-hooks (10 of 488 checks): commentflow, shfmt and timeout are not installed here.
    • interactive-review-hook-tests: the test expects a /var/... path where macOS resolves /private/var/....
    • run-budget-tests: the sampler records no resident memory for the process tree on macOS.
  • task-authoring-tests, a wall-clock check of the rubik starter, passed in this run; under the lane's parallel load it has missed its margin on earlier heads of this branch, and neither the test nor the code it times is touched here.
  • Not run locally: the Rust lane (no Rust change) and Linux Chromium. At the previous head (514d9c8) every CI gate passed, the three browser shards on Linux included.

Close #654

cubic-dev-ai[bot]

This comment was marked as resolved.

jserv

This comment was marked as resolved.

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

Checked out 3a81851 on macOS 26.2 arm64 with Node v26.10.0, Python 3.9.6 and Playwright Chromium:

  • python3 tests/test_check_test_timing.py: 24 tests OK
  • node --test --test-name-pattern="paints syntax colours and line numbers" tests/browser/task-workspace.test.js: 1 pass, 0 fail (1140 ms)
  • node scripts/check-test-timing.mjs: no findings, exit 0

The test fix works for me. The two inline comments are about the new rule: forms of the same bound that it does not see, and a message that does not name the property.

Comment thread scripts/check-test-timing.mjs Resolved
Comment thread scripts/check-test-timing.mjs Resolved
jserv

This comment was marked as outdated.

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

Reviewed 3a81851 against #654. On WSL with Node 22.22.1, Python 3.14.4, and Playwright 1.65.0:

  • python3 tests/test_check_test_timing.py — 24 passed.
  • CI=1 node --test --test-name-pattern="paints syntax colours and line numbers" tests/browser/task-workspace.test.js — 1 passed, 0 skipped.
  • node scripts/check-test-timing.mjs — exit 0 on the repository's browser suite.
  • node scripts/check-test-timing.mjs ../pr793-timing-fixtures — exit 1. The separate-tests fixture produced one false positive, and the duplicate-diagnostic fixture printed the same diagnostic twice.

Comment thread scripts/check-test-timing.mjs Resolved
Comment thread scripts/check-test-timing.mjs Resolved

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

Reviewed 3a81851c on Windows with Node v24.22.1 and Python 3.14.7. The timing checker’s Python suite passed all 24 tests. I also ran node scripts/check-test-timing.mjs <fixture-dir> on the small fixtures described in the inline comments.

Comment thread scripts/check-test-timing.mjs Resolved
Comment thread tests/test_check_test_timing.py Resolved
The scroll check in the task editor test set the textarea to 900 and
then waited until the highlight layer's scrollTop passed 0. The fill
before it leaves the caret at the end of 120 lines, so the textarea
has already scrolled to the bottom, and when a frame lands between the
fill and the assignment the layers have followed it there. The wait
then holds at once and the assertion reads [900, 2276, 2276], as it
did in CI. Whether that frame lands depends on how busy the runner is,
which is why the failure was intermittent. Waiting for the layers to
follow the fill first makes every run take that path, and with the
old wait it then fails every run; waiting for both layers to reach
900 passes on every run. The check that the layers follow the fill
also catches a paint that forgets to resync them, which the old test
let through on two runs out of three.

Change-Id: I1d5cb112fa597fa816bd4150685279488a4556c6
@melonpuff
melonpuff force-pushed the fix-task-scroll-wait branch from 3a81851 to b91cf43 Compare November 21, 2026 18:09
jserv

This comment was marked as resolved.

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

Reviewed b91cf43 on Windows with Node.js v22.17.0 and Python 3.13.5.

All 32 tests in python tests/test_check_test_timing.py passed. Running node scripts/check-test-timing.mjs produced no diagnostics (exit 0).

I left two inline comments with additional fixtures and reproduction results.

Comment thread scripts/check-test-timing.mjs Resolved
Comment thread scripts/check-test-timing.mjs Resolved

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

Reviewed b91cf43 on Windows 10 (WSL, Ubuntu 26.04.1 LTS, x86_64) with Node.js v26.13.1 and Python 3.14.4.

Verified results:

  • python3 tests/test_check_test_timing.py: all 32 tests passed.
  • node scripts/check-test-timing.mjs: exit 0 on the existing browser test directory.
  • Additional fixtures reproduced one false negative and two false positives in the new bound-wait rule.

I left three inline comments below. One is related to an issue raised by another reviewer but covers a different edge case.

Comment thread scripts/check-test-timing.mjs Resolved
Comment thread scripts/check-test-timing.mjs Resolved
Comment thread scripts/check-test-timing.mjs Resolved
@melonpuff
melonpuff force-pushed the fix-task-scroll-wait branch from b91cf43 to 5cd2ef5 Compare November 22, 2026 18:30
cubic-dev-ai[bot]

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

@melonpuff
melonpuff force-pushed the fix-task-scroll-wait branch from 5cd2ef5 to 3fdd9fb Compare November 23, 2026 06:02
jserv

This comment was marked as resolved.

@melonpuff
melonpuff force-pushed the fix-task-scroll-wait branch from 3fdd9fb to 514d9c8 Compare November 23, 2026 07:28
jserv

This comment was marked as resolved.

The previous commit fixed a test that set a textarea's scrollTop to 900
and then waited for a layer's scrollTop to pass 0: a layer that had
followed an earlier scroll met that bound before it followed this one,
so the wait returned at once on one runner and held on another, and
nothing stopped the next wait of that shape from landing. The gate now
refuses a wait that bounds, with >, <, != or their kin and the property
on either side, a property the statement right before it set, and asks
for the value set; === and == are the exact comparisons. An exact
comparison beside the bound does not exempt it, since
`code.scrollTop === 900 && layer.scrollTop > 0` holds as soon as the
textarea is set, and neither does `=== 1` or `== 1` after `= 900`, which
the stale value can meet just the same; where both values are written
out as literals, signed numbers included, the two are compared. Only the
argument the wait polls is read, and only an assignment that runs before
the wait is tied to it: in the statement right before it, its result
kept or not, at its level or in a callback of a call that statement
awaits, and on the same page as far as the names tell, the page being
the receiver of the .evaluate that runs the assignment, inside
Promise.all or t.test too. So a function stored for later, a step
between the two, a wait on another page or an assertion after the wait
is left alone; that short reach keeps the rule to the wait replaced here
over tests/browser and the open pull requests. It leaves a property read
into a local first, brackets two deep and a value that is not a literal
as limits the header states. A reset the bound cannot meet is deliberate
and carries timing-ok:.

Close sysprog21#654

Change-Id: Ifa16fe0c70ab66bccf01e6ab1adfb8bedb58be05
@melonpuff
melonpuff force-pushed the fix-task-scroll-wait branch from 514d9c8 to 4370221 Compare November 23, 2026 15:17
@github-actions github-actions Bot added the ready for maintainer review The pull request ready for maintainer review. label Nov 23, 2026
// kept with `var`, a destructuring, a plain reassignment or inside another
// call, none of which the tests write.
const tied =
/^[^;]*;[\s)}\];,]*(?:(?:const|let)\s+[\w$]+\s*=\s*)?(?:await\s+)?(?:[\w$]+\s*\.\s*)*$/;

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.

An assignment in a block-bodied callback that is passed an argument is never tied to the wait after it: [^;]*; stops at the first ; inside the callback, and the , 900) after its } is not among what may follow. So await page.locator("#code").evaluate((node, top) => { node.scrollTop = top; }, 900); followed by await page.waitForFunction(() => layer.scrollTop > 0); exits 0 (as does the same with node.scrollTop = 900; }, undefined)), while the expression form (node, top) => (node.scrollTop = top), 900 is refused, and the browser tests already pass arguments to evaluate this way (tests/browser/test-results-filter.test.js, tests/browser/candidate-cases.test.js). Let the arguments after the callback stand between the two as well, for instance by testing what follows the outermost bracket setOn finds rather than what follows the first ;, with an assertRejected case for the block form.

@github-actions github-actions Bot removed the ready for maintainer review The pull request ready for maintainer review. label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Task editor scroll-sync test fails intermittently in CI

7 participants