Skip to content

Wait for hided to accept every click of a burst before typing into the last pane - #575

Merged
yansfil merged 1 commit into
mainfrom
fix/flaky-467
Oct 6, 2026
Merged

yansfil merged 1 commit into
mainfrom
fix/flaky-467

Conversation

@yansfil

@yansfil yansfil commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Refs #467

Summary

The test typed a marker right after a burst of 40 clicks and sometimes found it in the other pane's input.
Its barrier counted the clicks the page had sent, and treated any "Pane 1 focus confirmed" as the burst's end.
Under load hided still held a dozen of those focus messages, an earlier request's confirmation satisfied the check, and lagging snapshots then moved the browser's focus to the other pane before the keys arrived.
The test now counts every pane.focus.requested the page was sent against the focus changes it sent, waits until the page has applied every frame Playwright saw, and until the pane's terminal holds the keyboard.
The one test is split into three contracts on a shared startFocusStack helper: one held request, keys after a burst, an external focus.

Review

  • 판단해 주세요: The test name's contract (keys land on the last pane) is one a user expects without waiting, and this PR only makes the test wait for hided; the real gap is a snapshot older than the last click moving the browser's keyboard focus off the pane just clicked (PaneView.tsx effect, terminals.ts focusTerminal), a few hundred ms under load. It is not changed here; an issue draft is ready to file once you agree it is a product bug and not an accepted limit.
  • 조심해서 볼 파일: web/e2e/pane-focus-ordering.spec.ts - observeDiagnostics(...).added counts entries across a capped list that drops from its front.
  • 조심해서 볼 파일: web/e2e/test-size-baseline.json - the recorded entry goes away because the split test fits the budget.
  • Split cost: two more stack starts (about 15 s each) buy that the keys contract fails alone, and the external-focus assertion no longer rides on a 40-click burst.

Evidence

  • 확인한 것: A failing CI run (macOS, 4 attempts of this signature) read from its artifacts: the typed marker is in pane 2's input log, and hided accepted focus requests for 565 ms after the typing started.
  • 확인한 것: Local macOS under load (yes x4, load average above 60 from other work), old barrier: marker failed in 2 of 107 runs, and in 2 of 42 instrumented runs it returned with hided having accepted 24 and 36 of the 40 changes the page sent.
  • 확인한 것: New spec, same load: 47 of 47 runs of the single test, then 63 of 63 (21 runs of the three tests) before and 63 of 63 after the review fixes; web lint, size budget and typecheck pass.
  • 확인하지 못한 것: 0 failures in about 130 runs does not prove a 2% flake gone; the cause is shown by the 24 of 40 and 36 of 40 measurements, and main's next macOS runs are the real check.
  • 확인하지 못한 것: Linux and Windows were not repeated locally; one different signature (an external focus not followed) appeared once before the split and not in the 84 runs after.

…e last pane

The keys-after-a-burst test counted the clicks the page had sent, not the focus changes hided had accepted, so under load a confirmation of an earlier request in the burst satisfied its barrier while the rest were still queued: a lagging snapshot then moved the browser's focus to the other pane and the typed marker went there. The test now counts every pane.focus.requested diagnostic against the changes the page sent, waits for the page to have applied every frame Playwright saw and for the keyboard to be on the pane's terminal, and is split from the held-request and external-focus contracts it shared a stack with.
@yansfil
yansfil merged commit cf264b1 into main Oct 6, 2026
27 checks passed
@yansfil
yansfil deleted the fix/flaky-467 branch October 6, 2026 01:26
yansfil added a commit that referenced this pull request Oct 6, 2026
…hat click (#589)

Refs #585

## Summary

A snapshot that was already on its way when the operator's last click
was sent still names the pane clicked before, and the page moved DOM
focus to it, so keys typed right after landed in the wrong pane until
the snapshot that includes the click arrived.
The page now numbers each operator `focus_pane` it sends (a
per-page-load `client_id` and a `sequence`), the core records the last
number it applied per page in the snapshot's `focused.operator_focus`,
and a pane follows the snapshot's focused pane only once that number has
caught up with the last one sent.
After it has caught up, a snapshot naming another pane is a real move
(the core followed Herdr, or refused the click and kept its value) and
is followed as before.
There is no time window, and no input is dropped or delayed.

## Review

- **판단해 주세요**: A remote pane's focus (`remote_control`) is not numbered,
because the local core never applies it; a stale device session can
still pull focus there. Is that follow-up acceptable?
- **판단해 주세요**: For a moment after a click the header (`data-focused`)
can still follow the older snapshot while the keys stay on the clicked
pane; the header settles with the next snapshot.
- **조심해서 볼 파일**: `herdr-core/src/model.rs` and
`herdr-core/src/runtime/session.rs` - snapshot wire: new
`focused.operator_focus` list, skipped when empty, capped at 16 pages
with a logged eviction.
- **조심해서 볼 파일**: `herdr-core/src/runtime/events.rs` - the ack is
recorded for every operator focus before the core decides, so a refused
or redundant click still answers the page.
- **조심해서 볼 파일**: `web/src/ws.ts`, `web/src/PaneView.tsx` - the number
counts only once the frame has left the socket, and a new connection
awaits nothing.
- **비용 검토**: per click one small struct update in the core and one
`{client_id, sequence}` entry (about 60 bytes) in the next snapshot's
rest section.
- **비용 검토**: no new notification, subprocess, lock or timer; the page
adds one store write per click and one boolean selector per pane view.
The list is capped at 16 entries.

## Evidence

- **확인한 것**: `web/e2e/stale-snapshot-focus.spec.ts` holds the daemon's
frames at the WebSocket: with the last click sent and only an older
snapshot delivered the keys stay on the clicked pane, then the snapshot
that includes the click keeps them. With the gate removed it fails 3 of
3 at that assertion; with it, 6 of 6.
- **확인한 것**: A move Herdr makes with nothing pending still takes the
keys (second spec of the same file).
- **확인한 것**: `operator_focus.rs` (5 core tests) covers refused clicks,
newest number kept, restore origin and unnumbered events not recorded,
the cap and eviction, and the delta carrying the field;
`operatorFocus.test.ts` (4 tests) covers the store rule and a lost
socket. Core lib 1455 passed, web unit 1041 passed, clippy, fmt, eslint,
typecheck and the e2e size budget pass.
- **확인한 것**: `pane-focus-ordering` "rapid pane clicks" as it is on main
(without the wait for hided to accept every click from #575): 40 of 40
passed locally with 4 `yes` processes saturating the CPU.
- **확인한 것**: Click-to-snapshot latency (focus_pane sent until a snapshot
with its number arrives, macOS, 3 runs each). Idle one click: 19, 26, 22
ms. Idle 40 clicks queued back to back: p50 95-106 ms, p95 103-122 ms,
max 105-124 ms. Four `yes` processes: one click 12-19 ms; 40 clicks p50
99-167 ms, p95 106-264 ms, max 109-267 ms.
- **확인하지 못한 것**: Linux and Windows were not repeated locally; the new
specs run in CI.
- **확인하지 못한 것**: #575's barrier in `pane-focus-ordering.spec.ts` is left
alone; once this lands the test would pass without it, but removing the
wait is a separate change after main's runs confirm it.
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