Skip to content

studiobench: bound the scroll gesture at both ends, at the extent's own allowance - #9610

Merged
danielhanchen merged 8 commits into
mainfrom
p130-scroll-bounds
Aug 25, 2026
Merged

danielhanchen merged 8 commits into
mainfrom
p130-scroll-bounds

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Two findings on scroll_travelled, both accepted during the review of #9439 and left open
there. They are the same mistake in opposite directions: one quantity judged against a
tolerance meant for a different quantity, and one judged against no upper bound at all.

The extent was allowed 10 percent and then 2

scroll_extent grants the extent EXTENT_TOLERANCE, 10 percent, because a windowed list
computes its total height from estimated row heights and corrects them as real rows are
measured; it says so in its own comment. scroll_travelled then compared the SAME physical
quantity through _same_number, which routes through the 2 percent EXACT_TOLERANCE. An
arm inside the declared allowance was reported behaviourally BROKEN on scroll_after.

A false red is not free here. A broken behavioural invariant removes the cell from
readings_by_arm, takes its healthy partner with it through the arm intersection, and
since unmeasured_planned_cells learned to consult these gates it can VOID the plan.

It is worse than the report said, and this is the part worth spelling out because it reads
as a subtle one. bottom is scrollHeight - clientHeight and _drift is PROPORTIONAL, so
subtracting a shared viewport height AMPLIFIES the drift by H / (H - C). On the 10,000 px
extent and 800 px viewport measured here that is 1.087. The effective allowance was
therefore TIGHTER than the 2 percent it appeared to be, and the two checks printed two
different percentages for one scrollbar.

So the fix is not a wider tolerance on the same number. The extent is reconstructed from
viewport_client_height, which the census has carried beside the scroll height all along,
and then the allowance means exactly what EXTENT_TOLERANCE says. clientHeight is the
viewport's own height and does not change while the viewport scrolls, so reading it from
the census and bottom from the gesture is not mixing two instants of a moving quantity.
Falls back to comparing bottom when either arm's census lacks the field, and the detail
names which of the two it compared so the tighter effective allowance is never silent.

_same_number is deliberately NOT widened. Its other keys are selected_chars,
visible_chars and clipboard_chars, none of which is an extent, and all of which are
correctly strict at 2 percent.

The gesture had no ceiling

The predicate was fraction >= 0.9 and nothing above it, so an arm whose viewport moved
TWICE as far as the gesture asked passed exactly as 1.0 did and the pair returned MATCH.
travelled is a sum of |scrollTop_after - target_before|, so every pixel above
commanded is the viewport being moved by something other than the gesture, which is the
anchor instability this action exists to detect, in the other direction.

The ceiling is DERIVED, which is what was missing when this was deferred: a bound above
needs a number, and a number picked to look symmetric with 0.9 either leaves the hole open
or starts failing correct arms.

Overshoot has one legitimate source, a windowed list correcting estimated row heights, and
a correction moves the offset by the error in the estimate. The total of those errors is
the error in the arm's extent, and this file already declares how far the extent may be
wrong. So the gesture may travel further than it commanded by at most EXTENT_TOLERANCE of
the arm's OWN scrollable extent, both terms read off the row rather than assumed: 920 px of
a 9,200 px extent against a 5,880 px gesture, a ceiling of 1.156. No second constant, and
it scales with the rung instead of being another 100K-era figure of the kind this suite
keeps finding. A row carrying no extent gets the lower bound alone and says so in its
detail, because a ceiling of zero would fail every correct arm and a ceiling of infinity is
what is being fixed.

Tests

scroll_travelled had no direct test at all before this. Seven, in
analysis/selftest/test_studiobench_scroll_bounds.py -- a new file beside the code rather
than more of the ui-parity command's own suite -- including both controls, because widening
one bound and adding another is exactly where a check quietly stops checking:

  • an extent that is a FRACTION of the real one is still BROKEN, which is the failure
    EXTENT_TOLERANCE was chosen against: a virtualizer that drops rows instead of sizing
    spacers has a scrollbar that lies
  • a gesture snapped back to the bottom is still BROKEN, which is the failure the lower
    bound was written for
  • an ordinary estimate correction at 1.1 passes the derived ceiling

Mutation: restore _same_number on bottom and three fail, including one asserting the
two checks now print the same percentage for one scrollbar; drop the upper bound and the
overshoot test fails with assert 'match' == 'broken'.

pytest tests/studio/studiobench -q: 1306 passed, up from 1298. ruff clean.

Follow-up to #9439, where both were accepted as correct and deliberately not fixed.

…wn allowance

Two findings on `scroll_travelled`, both accepted during the review of #9439 and left open
there. They are the same mistake in opposite directions: one quantity judged against a
tolerance meant for a different quantity, and one judged against no upper bound at all.

## The extent was allowed 10 percent and then 2

`scroll_extent` grants the extent `EXTENT_TOLERANCE`, 10 percent, because a windowed list
computes its total height from estimated row heights and corrects them as real rows are
measured; it says so in its own comment. `scroll_travelled` then compared the SAME physical
quantity through `_same_number`, which routes through the 2 percent `EXACT_TOLERANCE`. An
arm inside the declared allowance was reported behaviourally BROKEN on `scroll_after`.

A false red is not free here. A broken behavioural invariant removes the cell from
`readings_by_arm`, takes its healthy partner with it through the arm intersection, and
since `unmeasured_planned_cells` learned to consult these gates it can VOID the plan.

It is worse than the report said, and this is the part worth spelling out because it reads
as a subtle one. `bottom` is `scrollHeight - clientHeight` and `_drift` is PROPORTIONAL, so
subtracting a shared viewport height AMPLIFIES the drift by `H / (H - C)`. On the 10,000 px
extent and 800 px viewport measured here that is 1.087. The effective allowance was
therefore TIGHTER than the 2 percent it appeared to be, and the two checks printed two
different percentages for one scrollbar.

So the fix is not a wider tolerance on the same number. The extent is reconstructed from
`viewport_client_height`, which the census has carried beside the scroll height all along,
and then the allowance means exactly what `EXTENT_TOLERANCE` says. `clientHeight` is the
viewport's own height and does not change while the viewport scrolls, so reading it from
the census and `bottom` from the gesture is not mixing two instants of a moving quantity.
Falls back to comparing `bottom` when either arm's census lacks the field, and the detail
names which of the two it compared so the tighter effective allowance is never silent.

`_same_number` is deliberately NOT widened. Its other keys are `selected_chars`,
`visible_chars` and `clipboard_chars`, none of which is an extent, and all of which are
correctly strict at 2 percent.

## The gesture had no ceiling

The predicate was `fraction >= 0.9` and nothing above it, so an arm whose viewport moved
TWICE as far as the gesture asked passed exactly as 1.0 did and the pair returned MATCH.
`travelled` is a sum of `|scrollTop_after - target_before|`, so every pixel above
`commanded` is the viewport being moved by something other than the gesture, which is the
anchor instability this action exists to detect, in the other direction.

The ceiling is DERIVED, which is what was missing when this was deferred: a bound above
needs a number, and a number picked to look symmetric with 0.9 either leaves the hole open
or starts failing correct arms.

Overshoot has one legitimate source, a windowed list correcting estimated row heights, and
a correction moves the offset by the error in the estimate. The total of those errors is
the error in the arm's extent, and this file already declares how far the extent may be
wrong. So the gesture may travel further than it commanded by at most `EXTENT_TOLERANCE` of
the arm's OWN scrollable extent, both terms read off the row rather than assumed: 920 px of
a 9,200 px extent against a 5,880 px gesture, a ceiling of 1.156. No second constant, and
it scales with the rung instead of being another 100K-era figure of the kind this suite
keeps finding. A row carrying no extent gets the lower bound alone and says so in its
detail, because a ceiling of zero would fail every correct arm and a ceiling of infinity is
what is being fixed.

## Tests

`scroll_travelled` had no direct test at all before this. Seven, in
`analysis/selftest/test_studiobench_scroll_bounds.py` -- a new file beside the code rather
than more of the ui-parity command's own suite -- including both controls, because widening
one bound and adding another is exactly where a check quietly stops checking:

- an extent that is a FRACTION of the real one is still BROKEN, which is the failure
  `EXTENT_TOLERANCE` was chosen against: a virtualizer that drops rows instead of sizing
  spacers has a scrollbar that lies
- a gesture snapped back to the bottom is still BROKEN, which is the failure the lower
  bound was written for
- an ordinary estimate correction at 1.1 passes the derived ceiling

Mutation: restore `_same_number` on `bottom` and three fail, including one asserting the
two checks now print the same percentage for one scrollbar; drop the upper bound and the
overshoot test fails with `assert 'match' == 'broken'`.

`pytest tests/studio/studiobench -q`: 1306 passed, up from 1298. `ruff` clean.

Follow-up to #9439, where both were accepted as correct and deliberately not fixed.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f71fe7a46c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +452 to +454
b_ext, b_full = _extent_of(base_row)
t_ext, t_full = _extent_of(treat_row)
drift = _drift(b_ext, t_ext)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Fall back both arms when either client height is missing

When only one arm lacks census.viewport_client_height—for example, after a census failure or when comparing payloads with different field availability—these independent calls return a reconstructed scrollHeight for one arm and a raw bottom for the other. Identical viewports with bottom=1200 and clientHeight=800 are therefore compared as 2000 versus 1200 and reported BROKEN, despite the documented fallback and the scroll_extent check agreeing. Decide whether both client heights are available before reconstructing; otherwise compare both raw bottoms.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct, and your example reproduces exactly. Two arms at bottom=1200 over a client height of 800, one census missing the field, scored bottom (no client height on both arms) 2000.0 vs 1200.0 (40.0% drift, 10% allowed) and BROKEN, with a detail line describing a pair it was not comparing.

Fixed in 2178177. _comparable_extents makes the decision once for the pair: both arms are reconstructed or neither is, and the fallback compares the raw bottoms at the same allowance. The same case now reads 1200.0 vs 1200.0 (0.0% drift) and MATCH.

test_one_arm_missing_its_client_height_does_not_compare_an_extent_with_a_bottom fails on the previous head.

Comment on lines +420 to +423
if isinstance(commanded, (int, float)) and commanded > 0 and isinstance(
bottom, (int, float)
):
ceiling = (commanded + EXTENT_TOLERANCE * abs(bottom)) / commanded

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Derive the overshoot allowance from the full extent

For a non-negligible viewport, this applies EXTENT_TOLERANCE to bottom = scrollHeight - clientHeight, although the tolerance is defined and enforced against the full scrollHeight. This recreates the tighter allowance the preceding reconstruction is intended to eliminate: with a 10,000 px base extent, an 800 px viewport, and a treatment estimate of 9,050 px, a legitimate 950 px correction is within the 10% extent tolerance, but this ceiling permits only 825 px and marks the gesture BROKEN. Use the reconstructed full extent, or the permissible inter-arm extent delta, when deriving the ceiling.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct. This is the same mistake the check below it was written to fix, left in the ceiling: bottom is scrollHeight - clientHeight, so EXTENT_TOLERANCE taken on it grants 920 px of a 10,000 px extent behind an 800 px viewport where the tolerance says 1,000.

Reproduced before fixing: a 941 px correction, 9.4% of the extent, printed allowed 0.9 to 1.156: 10% of the arm's own 9200 px extent and came out BROKEN. It now reads allowed 0.9 to 1.170: 10% of the arm's own 10000.0 px extent and MATCH.

Fixed in 2178177 by deriving the ceiling from _extent_of(row), which already falls back to bottom when the census carries no client height, so the no-extent degradation is unchanged.

One existing assertion moved with it: test_an_ordinary_estimate_correction_still_passes_the_ceiling pinned the literal 1.156 and now pins 1.170. That is the number the fix deliberately changes, not a loosened expectation, and test_the_ceiling_grants_the_tolerance_against_the_extent_not_against_bottom pins both edges (1.160 inside, 1.171 outside) so the ceiling is still a bound. Both fail on the previous head.

Comment on lines +455 to +456
reconstructed = b_full and t_full
what = "scroll extent" if reconstructed else "bottom (no client height on both arms)"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep differing viewport heights in the comparison

When both arms publish client heights but those heights differ, reconstructing bottom + clientHeight on each side erases the difference in their actual scrollable ranges. For example, arms with the same 10,000 px scrollHeight but client heights of 800 and 2,000 have bottoms of 9,200 and 8,000; this code reports zero drift and MATCH even though the gesture has 1,200 fewer pixels available in one arm. Only treat the client height as a shared offset after verifying that the heights agree, or retain a separate check of the bottoms/client heights.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct, and your numbers are the ones it reproduces on. Same 10,000 px scrollHeight, client heights 800 and 2,000, bottoms 9,200 and 8,000: the pair scored scroll extent 10000.0 vs 10000.0 (0.0% drift) and MATCH over 1,200 px less room for the gesture on one arm.

Fixed in the same _comparable_extents in 2178177: the client height is treated as a shared offset only once it is shown to be shared. When the heights disagree the raw bottoms are compared at the same allowance, which gives bottom (client heights differ: 800.0 vs 2000.0) 9200.0 vs 8000.0 (13.0% drift, 10% allowed) and BROKEN. scroll_extent keeps comparing the scroll heights and still reads True there, so the two checks now answer two different questions instead of one twice.

test_client_heights_that_disagree_are_not_treated_as_a_shared_offset fails on the previous head, and test_client_heights_that_agree_are_still_treated_as_a_shared_offset is the control that keeps the ordinary case on the reconstruction path.

Comment on lines +433 to +434
else:
ok = 0.9 <= fraction <= ceiling

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Mark overshooting actions failed at collection time

This upper bound exists only in the behavioural parity analyzer, while _scroll in scene/actions.py still sets expect_ok from the lower bound alone (travelled >= 0.9 * commanded). Consequently, an overshooting action can be BROKEN here but retain expect_ok=True; scoring/from_payload.py::_action_measure then accepts its gesture_ms as the scroll_settle_ms performance reading, and report/payload.py does not exclude the cell. Since the new predicate defines such movement as something other than the commanded gesture, apply the same ceiling when constructing the action result so invalid timings cannot enter experiment results, including runs scored structurally rather than behaviorally.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The observation is accurate and I am not disputing it: _scroll sets expect_ok = commanded > 0 and travelled >= 0.9 * commanded, and _action_measure admits gesture_ms whenever expect_ok is not False. Not taking the change, though, for three reasons.

Layering. scene/ imports from runtime/ and scene/ only, never from analysis/ (0 such imports today), and EXTENT_TOLERANCE is defined in exactly one place, analysis/behaviour.py. Putting the ceiling in the collector means either inverting that direction or copying the constant, and a copied predicate drifting from its original is the failure this suite has already been bitten by.

Reach. expect_ok = False is not just a dropped timing. It puts the cell under EXCLUDED CELLS in report/payload.py, it is what --assert-liveness singles out, and in the parity layer a one-arm assertion failure fails the whole run. A new collection-time failure mode with that reach is a larger change than the invariant under review, and this file's own note records what a false red there costs.

Evidence. The ceiling was added against a hypothetical: an arm moving twice as far as commanded scoring the same as 1.0. No payload in hand trips it. Deciding at collection time, on one arm, with no second arm to compare against, is where a wrong ceiling is most expensive and least observable.

The shape is caught where it is a finding: scroll_travelled reds the pair, and after 2178177 the allowance is the extent's own, so the ceiling is no longer tighter than it says. If a real payload turns up with an overshoot whose gesture_ms was scored, the refusal belongs in scoring/from_payload.py, which reads the payload and is already the layer that decides a timing must not be quoted.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 21781779e8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

and commanded > 0
and isinstance(extent, (int, float))
):
ceiling = (commanded + EXTENT_TOLERANCE * abs(extent)) / commanded

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Size the ceiling from the paired reference extent

When the treatment underestimates the base extent while remaining within EXTENT_TOLERANCE, this uses the already-underestimated treatment extent as the allowance denominator and therefore rejects corrections that the extent check explicitly permits. For example, extents of 10,000 and 9,050 pass scroll_extent at 9.5% drift, but a 950 px estimate correction fails because this ceiling grants only 905 px. Fresh evidence in this revision is that _extent_of now reconstructs the treatment's 9,050 px full extent, yet the ceiling still uses that arm-local value rather than the paired 10,000 px reference used by _drift; derive the allowance from the paired reference/larger extent so the two checks enforce the same tolerance.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct, and reproduced with your numbers before fixing it. Fixed in 89dae8a.

The root of it is that the two checks read one tolerance off two different denominators. _drift divides by the LARGER of the two extents, so scroll_extent grants 10% of 10,000; the ceiling divided by the arm's own, so it granted 10% of 9,050. On that pair the harness said both of these at once:

scroll_extent            ok=True   viewport scrollHeight 10000 vs 9050 (9.5% drift, 10% allowed)
scroll_travelled:treatment ok=False  travelled 1.1616 of what it commanded, allowed 0.9 to 1.154

The 950 px correction that closes that very gap was BROKEN against an allowance derived from the underestimate itself. The arm that most needs the allowance is exactly the arm whose own extent is the worse yardstick for it, so the ceiling is now taken on the pair's reference extent and the printed detail says so.

Two things pinned so this stays a bound rather than just a bigger number. Past the reference allowance it is still reported. And an arm carrying no extent still gets no ceiling instead of borrowing its partner's, since newly bounding an arm that has always been unbounded above is the one direction that could invent a red rather than retire one.

danielhanchen and others added 4 commits August 24, 2026 09:52
The overshoot ceiling and scroll_extent read one tolerance off two different
denominators, and disagreed inside it. _drift divides by the LARGER of the two
extents; the ceiling divided by the arm's own. So extents of 10,000 and 9,050
pass scroll_extent at 9.5% drift, while the 950 px estimate correction that
closes that very gap came out BROKEN against a ceiling granting 10% of 9,050:
1.162 travelled against 1.154 allowed.

The arm that most needs the allowance is exactly the arm whose own extent is
the worse yardstick for it. An estimate correction is the arm closing the gap
to the real extent, so the gap is what bounds it, and the pair's reference
extent is the honest basis.

A false red is not free here: it removes the cell from readings_by_arm, takes
its healthy partner with it through the arm intersection, and
unmeasured_planned_cells can then VOID the plan.

This only ever loosens, since max is never below the arm's own extent. An arm
carrying no extent still gets no ceiling rather than borrowing its partner's,
because newly bounding an arm that has always been unbounded above is the one
direction that could invent a red rather than retire one. Both are pinned:
past the reference allowance it is still reported, and the no-extent arm still
prints NO CEILING.
@danielhanchen
danielhanchen merged commit 68a40ef into main Aug 25, 2026
32 of 34 checks passed
@danielhanchen
danielhanchen deleted the p130-scroll-bounds branch August 25, 2026 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant