Skip to content

Keep the page map's target through a close that lands after its reopen - #227

Merged
max-sixty merged 2 commits into
mainfrom
fix/ci-33669852274
Sep 2, 2026
Merged

max-sixty merged 2 commits into
mainfrom
fix/ci-33669852274

Conversation

@leaf-agent

Copy link
Copy Markdown
Collaborator

Problem

The nightly leg of ci on main failed on test_spilled_reactions_keep_their_target_and_yield_to_the_map[click-390]: the press on a spilled reaction in the Page map sent nothing. It reproduces locally about half the time on that one parameter, and the cause is a real ordering defect in the runtime rather than the test reading early.

A <dialog> hides itself and restores focus synchronously but hands close to a task of its own. The test presses Esc off the overflow route and immediately reopens it from the same spill, so openSheet sets sheetFrom/sheetTarget and calls showModal() before the first close is delivered — and the close handler then cleared both on the opening that is standing now. With no sheetTarget, buttonContextContains stops reading the sheet as its target's own surface, so reactionContextContains is false, the mousedown of the next press reaches standDown, and the reaction is stood down mid-click. The press lands on a cluster that no longer exists and nothing is sent. Only the click parameter fails because standDown runs on mousedown; the keyboard route never generates one.

This is user-visible, not test-only: Esc out of the overflow map and back into it in one breath, then press a reaction, and it silently does nothing.

Solution

The close handler now reads whether the dialog is open again. A close overtaken by a reopen has nothing left to close, so it returns instead of clearing the return route and the target the later opening owns; the activation flag is consumed either way, since a skipped handler performs no focus return. That is the same level as the bug — the state belongs to one opening, and the handler is the one place that can tell whether it is still the current one.

The runtime's instructions gain the general rule beside the existing paragraph on <dialog> focusing steps, and the new test states the ordering the race reached by luck: close and reopen in one task, then hold until the late close has actually been delivered.

Testing

  • The new test_a_map_reopened_before_its_close_lands_still_presses_its_button fails deterministically without the runtime change and passes with it.
  • The originally failing test_spilled_reactions_keep_their_target_and_yield_to_the_map[click-390] went from ~7/15 to 15/15 green.
  • uv run pytest tests — 807 passed, 6 skipped.
  • uv run pytest tests/test_render_reactions.py tests/test_render_margin.py tests/test_render_pages.py tests/test_render_controls.py — 214 passed.
  • pre-commit run --all-files — all hooks pass.

Automated fix for failed run

A `<dialog>` hides and restores focus at once but hands `close` to a task of
its own. Escape off the overflow route and straight back onto the spill that
named it therefore reopens the sheet before the first close arrives, and that
handler then cleared `sheetFrom` and `sheetTarget` on the opening standing now.
With no target, `buttonContextContains` stops reading the sheet as its target's
own surface, so the mousedown of the next press inside it reaches `standDown`,
which stands the reaction down; the press lands on nothing and the reaction is
never sent.

The close handler now reads whether the dialog is open again and gives that
reopening its state back rather than taking it, consuming the activation flag
either way. Add a test that states the ordering the race reached by luck --
close and reopen in one task, then hold until the late close has been delivered
-- and a paragraph in the runtime's instructions for the general rule.

Tests: the new case fails without the fix and passes with it; the failing
`test_spilled_reactions_keep_their_target_and_yield_to_the_map[click-390]` went
from ~50% to 15/15 green. `uv run pytest tests` (807 passed), plus
`test_render_reactions.py`, `test_render_margin.py`, `test_render_pages.py`, and
`test_render_controls.py` (214 passed). `pre-commit run --all-files`.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The runtime change reads right: close is the only handler that owns the sheet's per-opening state, and sheet.open is the one fact that tells it whether the opening it was queued for is still standing. I checked the sibling case — the preview popover's toggle handler clears previewEntry/previewButton on the same shape, and closePreview(false) immediately followed by openThreads in render() is a real same-task close-then-reopen — but the popover toggle task tracker coalesces the pair into one newState: "open" event, so that handler's existing guard already covers it. Nothing else in the runtime opens a <dialog>.

One note on the new test's wait, inline.

Comment thread tests/test_render_reactions.py Resolved
`page.evaluate` takes no timeout in any binding, so awaiting the `close`
listener's next call inside it was a wait nothing bounds: a close that never
arrived would have spent the worker's whole step rather than failing this test
under its own name. Record the delivery as a synchronous flag on the page and
poll it with `wait_for_function`, whose driver-side deadline names the test.
@max-sixty
max-sixty merged commit 4d130e3 into main Sep 2, 2026
6 checks passed
@max-sixty
max-sixty deleted the fix/ci-33669852274 branch September 2, 2026 22:32
max-sixty pushed a commit that referenced this pull request Sep 2, 2026
## Problem

The nightly `ci` failures in #226 are the suite losing a send, not the
page swallowing a press. On
`test_a_comment_hidden_by_narrowing_is_revealed_in_the_open_panel` the
page does everything right: the `Enter` posts the comment, the server
appends it, the answer settles the draft and the composer closes. What
never happens is Playwright seeing that POST — neither the route the
test installed a keystroke earlier nor `page.on("request")` reports it —
so `Traffic.sends` stays at nought and the wait times out on counters
that were never going to move.

Chromium arms request interception the first time a page is routed at
all, and Playwright's acknowledgement of `page.route` outruns that
arming. A request issued in the milliseconds after the call goes
straight to the server. It is the escape `held_events` was already
written around, and `tests/CLAUDE.md` already names it — the guidance
was to route from navigation onward, which twenty-nine live
`page.route("**/api/event", …)` sites do not.

## Solution

`open_page` arms each page it makes on a pattern nothing ever asks for,
beside the `Traffic` watcher and before the first navigation. Nothing is
intercepted by it and no request's behavior changes; a route a test
registers later only adds a pattern to a list the browser is already
consulting. `tests/CLAUDE.md` states the invariant beside the rule it
completes.

## Testing

Reproduced first, at ~1 run in 12, by running the named case under eight
CPU burners on this four-core runner. Instrumenting `placeFab`,
`showFab`, `settleAcceptedDrafts` and `postEvent` in a failing run gave
the mechanism above; the issue's own diagnosis (the placement gate
withdrawing the bar) is ruled out — `placeFab` never returned false, and
the bar was still being placed while the withdrawal came from
`settleAcceptedDrafts` closing a composer whose draft the server had
genuinely accepted.

| arm | route registered | loaded runs | failures |
| --- | --- | --- | --- |
| A | a keystroke before the press (today) | 80 | 4 |
| B | before the panel opens | 40 | 0 |
| C | late, but interception pre-armed (this fix) | 40 | 0 |

`test_a_comment_hidden_by_narrowing_is_revealed_in_the_open_panel` then
ran 40 more times under the same load with no failure.
`tests/test_render_drafts.py` is 61 passed; the everyday suite is 807
passed, 6 skipped. The change costs nothing measurable — that file runs
43.8s without it and 44.7s with it.

<details><summary>The other failure in #226 is a different defect, fixed
in #227</summary>


`test_render_reactions.py::test_spilled_reactions_keep_their_target_and_yield_to_the_map[click-390]`
failed with the same counters on the next nightly run, but it installs
no route at all, so interception cannot be its cause. #227 traces that
one to a `<dialog>` `close` landing after its own reopen and clearing
the new opening's target. The two failures share a shape and nothing
else.

</details>

---
Fixes the drafts half of #226; #227 has the reactions half.

Co-authored-by: leaf-agent <[email protected]>
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.

2 participants