… dropped; ui-contexts checks wait for the exact state (#4031)
## Why
`ui-contexts-regression` and `ui-contexts-layout-regression` were the
browser lane's least stable scripts over the last week of CI: 13
failures and 37 hidden second-run passes for the first, 2 and 12 for the
second, 5 of each on main. This finds the cause of each failure site
from the CI logs (the `browser-main` artifacts' `*.attempt-1.log`),
reproduces it in the CI runner image, and fixes the test races and the
one product bug at their cause. No sleep, timeout, retry or skip is
added.
What the product fix changes for a user, plainly: a key typed while a
pane taken back from another app's hold is drawing (after its attach
takes input, before its screen is drawn) now reaches the pane; on main
it was dropped silently. A key typed before the attach takes input,
including the one that takes the pane back, is still not delivered: it
is now refused with a notice instead of being dropped silently.
## Failure sites (7 days of CI)
| Site | Hits | Class | Cause | Fix |
|---|---|---|---|---|
| `newtab-typeahead-regression.ts:142-145` touch | 15 of 16 newtab hits
| (a) test race | When herdr answers before the first key, the
type-ahead field is gone; on a touch screen the new tab's terminal
deliberately takes no focus (no on-screen keyboard unasked), so every
key lands on `BODY` and is lost (`sent to it: ""`). | The case holds
herdr's answer until its keys are typed (`holdCreate`), as the other
held cases do; `touch-midway` stays the case of a tab that comes while
keys are typed. |
| `chat-size-regression.ts` `held` (old line 734) | 6 | (b) product bug
| After `attach_held`, `resume()` cleared the held state but left
xterm's `disableStdin` on until the new attach's first output was
parsed, so a key typed in that window was dropped by xterm before the
app saw it, without a word. | `resume()` reopens what the hold closed
(`src/lib/useTerminalMount.ts`). Until the taken-back pane's own screen
has been read for a masked prompt, a key goes as a password does:
**delivered** when typed after the new attach says `input-ready` (the
window the `held` check and CI's failure cover), **refused with a
notice** when typed before it, the key that takes the pane back included
(it might be a password, so it is never drafted). The `held` case types
with the page clock still paused, before the new attach's output can be
drawn: it fails on main every time. |
| `chat-size-regression.ts:1249` reclaim | 1 | (a) test race | A window
takes the pane back only once the server's `pane-geometry` has told it
another device took it; the test acted as soon as the shell reported the
new size. | Each size the pty takes is waited for in both windows
(`pane-geometry` frames) before either acts. |
| `mobile-tabs-regression.ts:334` | 6 | (a) test race | `.tab-strip`
also matches the phone's tab row in the header, so the wait after
resizing to a tablet returned before the new width was drawn. | Waits
for the row under the header (`.pane-slot .tab-strip`), as the file
already does above. |
| `terminal-copy-regression.ts:343` edge drag | 2 | (a) test race | A
press counts lines from herdr's own scroll position; the test read the
start line off a drawn screen that can still be one wheel step behind
herdr. CI's miss was exactly one wheel step (10 lines: ended at 259,
expected 229 + 42 - 2 = 269). Not reproduced locally (8 throttled runs
on main green); herdr's `pane.read` "visible" was checked to follow its
scroll position (S261 to S211 after a 50-line scroll). | Line numbers
are read once the drawn screen's top line is herdr's. |
| `secret-input-regression.ts:110` | 2 | (a) | Already fixed on main by
#3974. | - |
| `Timed out after 600s` | 7 jobs | (c) host | Self-hosted runners under
load: every check 2-5x its usual time, `ui-regression` timing out in the
same jobs (73341eb among them). | Not this PR's. |
| wake-lock:100, terminal-pinch:139, telemetry:118, hidden-mount | 1-3
each | not flaky | Failed twice on one PR branch each: that PR's own
breakage. | - |
## Not reproduced, not changed
Each got at least two honest attempts in the runner image; none failed,
so nothing was patched blind:
- `chat-size-regression.ts` `idle-secret` "the masked prompt is on the
watched screen" (3 hits, the newest today): 0 of 22 on main (10 alone,
12 in the whole lifecycle sequence under 2x CPU throttle, with screen
and frame diagnostics on failure).
- `usage-regression.ts:215/467` "the popover stays inside the phone's
screen" (3 hits): 0 of 8 under 2x throttle. The hypothesis that the
first roster closes a drawer opened before it was disproved (drawer
stayed open 5 of 5 with the roster held until it was open).
- `tab-menu-regression.ts:625` phone "Pane and tab…" sheet (1 hit): 0 of
8 under 2x throttle, 0 of 40 in a loop of the same steps.
- `newtab-typeahead-regression.ts:153` and `chat-size-regression.ts:62`
(1 hit each, 11-12/11-15).
## Follow-up (not this PR)
- Codex review, MEDIUM, not reproduced: after a pane let go of while its
view was not drawn (a hidden page), keys typed before the new attach
takes input are retained with the masked-prompt state of the last screen
seen, so a password typed at a prompt that appeared meanwhile could
reach a draft. That path exists on main for every pane let go of that
was never held. For a held pane this PR does not open it: keys typed as
a held pane is taken back count as a password until the new attach's
screen is read (raised by the omo review of 916689b and Codex's of
aa87bfc, answered in 745dac3).
- Codex re-review, MEDIUM, not reproduced: a held pane whose connection
drops while it is away comes back with stdin still closed
(`onDisconnect` clears the held state but not what the hold closed), so
its first keys are still dropped. Same on main; this PR reopens stdin
only on the resume of a pane still held.
- Both reviewers, MEDIUM, declined: on a touch screen, keys typed after
the new tab already exists (none typed ahead) are not caught: the app
does not focus a terminal unasked there, so they reach no field. That is
the touch focus policy (`takeKeyboard`), not the type-ahead contract,
which covers keys typed before the tab exists (`touch` now) and across
its arrival (`touch-midway`). Changing it would put the on-screen
keyboard up unasked; a product decision, not this PR's.
- omo review, LOW, declined: no browser step checks that an observer
stays read-only after a resume; `onData` refuses an observer's keys on
its own as well.
- Earlier review findings answered in later commits: the reopening is
limited to a pane that was held (a `terminal_unsupported` or ended pane
stays closed, 916689b); keys typed before the taken-back pane's own
current screen is read go as a password (sent once it takes input,
otherwise refused with a notice, never drafted), scoped to that pane and
not ended by a recovering attachment's replay (745dac3, cb6c734);
the `held` case asserts that its key went without a receipt, so it fails
if that rule goes (aa78006).
- Codex, MEDIUM, declined: a key sent under that password rule keeps no
unconfirmed copy, so it can be lost if the connection ends before the
bridge takes it. That is how every key typed at a masked prompt already
goes; on main these keys were dropped outright.
- Codex, LOW, declined: the `held` check does not record the input
frame's pane. That page shows the held pane only, so an input frame on
it is that pane's.
- Codex, MEDIUM, declined: the password rule ends at the first whole
frame of the taken-back pane's screen (`FrameGate`'s boundary), which a
synchronized-update marker split across chunks could fool. That boundary
is the product's existing proof for every masked-prompt read; the rule
ends exactly where that detection already trusts the screen.
- omo review of aa78006, LOW, follow-up: when a second client of the
bridge keeps a held attachment alive, the replay a returning tab gets
first is the screen from before the hold, and it ends the password rule;
on `attach-resumed` the keyboard then reopens with that screen's
masked-prompt state. Main has the same exposure on `attach-resumed`. A
fix would start the rule on `attach_held` too and end it only on a
screen of an attach that is not held.
- omo review of aa78006, LOW, follow-up: a program with focus
reporting on makes xterm send `ESC [ I` on the click that takes a held
pane back; refused as typed in the password window, it shows the "a
password is never held" notice although nothing was typed. `retainTyped`
could leave xterm's own replies silent before that notice.
- omo review of aa78006, LOW, declined: no check fails if the password
rule never ends. The `held` case stops at the window it covers; a later
key's receipt would need the new screen's parse awaited under the page
clock, more harness than the risk.
- Both reviews, MEDIUM/LOW, declined: while the rule holds, keys go as a
password does, so with no receipt and no unconfirmed copy: a connection
that ends before the bridge takes one loses it untold, as for any key
typed at a masked prompt. On main they were dropped untold every time.
- Merge pass, follow-up: a key sent after `input-ready` but before the
screen is drawn goes as a password, without a receipt, so it is lost
untold if the connection drops in that gap (in one narrow case main kept
such a key in a draft).
- Merge pass, follow-up: `syncedTop` in terminal-copy polls herdr with a
25 ms wait inside its 10 s bound.
- CodeRabbit (terminal-copy:316), follow-up: the drag's scroll writes go
one at a time and the last can still be queued after release, so
`syncedTop` can match an intermediate position. The exact wait is for
the page's in-flight scroll writes to reach zero (the script already
wraps `fetch`), not two equal reads.
## Validation
All browser runs are in the self-hosted CI runner image
(`herdr-ci-runner:local`, herdr 0.9.3, bun 1.4.2) on a heavy slot of two
cores (`~/.ovis-toolchain/heavy-run.sh`), each started only while
`/proc/pressure/cpu` avg60 was under 20, one at a time. "Throttled"
means Chromium's CPU slowed 2x through CDP
(`Emulation.setCPUThrottlingRate`), which reproduces CI's slow-runner
timing without loading the host.
**How large N is, and why it is per site.** CI's old rate on main for
these two scripts is about 10 first-attempt failures in 298 runs (3.4%).
Catching that rate whole-script at 95% confidence takes
ln(0.05)/ln(1-0.034) = 87 runs a side (about 9 hours of slot time each),
and an idle slot does not reproduce it (main whole-script: 4 of 4 green
before this work). So each site is proven where it can be made to fail,
with the N its own failure rate needs, and the whole scripts are run on
head as a check that nothing else broke.
| What | main (116252f) | head (aa78006) |
|---|---|---|
| `held` (product bug), the new check, `CHAT_SIZE_CASE=held` | 5/5 fail:
the wait for the typed `z` to go out times out (the CI symptom) | 5/5
pass |
| chat-size lifecycle under 2x throttle (CI's `held` symptom) | 4/12
fail (all the CI symptom: no `input` after `input-ready`, then the idle
release) | 8/8 pass; at 916689b 12/12. With p = 4/12, (2/3)^8 = 3.9%
and (2/3)^12 = 0.8% for an unfixed head to pass them all |
| newtab touch mechanism (keys typed after the new tab arrives on a
touch screen) | lost 5/5 (land on BODY) | the `touch` case now types
before herdr answers (holdCreate) |
| newtab-typeahead check, 2x throttle | 10/10 pass | 10/10 pass |
| mobile-tabs check, 2x throttle | 10/10 pass | 10/10 pass |
| terminal-copy check, 2x throttle | 8/8 pass | 10/10 pass |
| chat-size `reclaim` (`CHAT_SIZE_CASE=reclaim`) | - | 5/5 pass |
| both scripts whole, as CI's job runs them (`ci-browser-parallel`, 2
workers, `BROWSER_RETRY=0`) | 8/8 pass (an idle slot does not reach CI's
rate: no comparison, see N above) | 8/8 pass (303-381 s each) |
Not reproduced on main despite trying (see above): `idle-secret` 0/22,
usage popover 0/8, tab-menu 0/48, terminal-copy 0/8 (its fix rests on
CI's exact one-wheel-step miss).
Checks:
- `bun run check fast` once at aa78006, on the rented heavy server
(the default for heavy runs since today): workflow syntax, generated
types and themes, typecheck and build ok; unit tests failed only in the
three job-started hook tests of `scripts/self-hosted-runner.test.ts`
that fail on that server for a known test bug (its stderr is a socket
there), a file this PR does not touch. Every other unit file passed.
- `bun run typecheck` on this PC after each commit: ok.
- Not run: `bun run check full`, the integration suite, the other
browser scripts (only the two ui-contexts scripts and the five changed
checks were run).
- GitHub at aa78006: all 18 checks pass, including Fast checks (whose
unit tests include `scripts/self-hosted-runner.test.ts`) and Browser
regression (ui-regression), which runs both ui-contexts scripts.
Reviews before the handover, at aa78006: a fresh
omo-native-code-reviewer (claude-opus-5-5, high) CLEAR with four LOW,
and Codex (gpt-6.1-terra, xhigh, read-only) CLEAR; five rounds in all,
each round's findings fixed in the next commit or declined above with a
reason. `dori review #4031`: CLEAR at aa78006.
Summary
Test-only. In five browser scripts, a script started something without awaiting it, read a state before it was there, or let a diagnostic end the run:
scripts/newtab-typeahead-regression.ts:watch()installed the page's sent-frame counter with an un-awaitedpage.addInitScript(line 54) and its callers went on topage.goto. When the navigation won the race, the page had nowindow.sentByPage, so the wait "the page's frames for the new tab are all heard" comparedheard.count >= undefinedfor 15 s and timed out, though every key had arrived. Measured on main bcc55ef in the runner image pinned to 2 cores: 2 failures in 36 runs, both withsentByPageundefined. Nowwatch()is async and awaits the installation, and all three callers (typeAhead,composingAcrossHandOver,ownedPage) await it before theirgoto. If the counter is missing, the wait fails at once with<case>: the page has no frame counter (window.sentByPage is undefined): watch() must install it before the page loadsinstead of a 15 s comparison that can never be true.scripts/secret-input-regression.ts:accepted()read the fixture's file as soon as it existed.writeFileSynccreates or empties the file before it writes the count, so a read in between saw''(seen once:'' !== '17'at line 110). It now waits, bounded at 5 s, for the file to hold the expected count, and on timeout says what it last held. Forcing the race also showed a second site: the desktop "grid takes the typed secret" step polled for"13"while the file still held below-secret's"13"(same length), so it could pass on the old count, and the later control read (line 260) then landed in the new write's empty window. That step now clears the file first, as the other rounds do, and waits throughaccepted()with its own regression message.scripts/terminal-attach-regression.ts: same shape, avoid page.route(...)(inside a Promise executor) before the click that uploads. It is awaited now. It was not forced: losing that race would hang onawait reacheduntil the script timeout, and the call is ordered ahead of a multi-round-trip click, so it is fixed for its shape, not for a seen failure.scripts/omo-question-wheel-regression.ts: a diagnostic could end the runThe page's response log read every
POST /pane/scrollbody withvoid response.json().then(...)(line 94), and nothing caught a rejection. If the next fixture'spage.gotocame first, Chrome no longer had the body, and the rejection (json: Protocol error (Network.getResponseBody): No resource with given identifier found) ended the run after every check had passed. The CI supervisor measured this as 1 failure in 34 runs of main 1a16970. The threepage.waitForResponsepredicates (lines 153-155, 169-170, 207) read the body the same way. Forced, a predicate whose body is gone makes Playwright reject the whole wait with that protocol error; it does not keep waiting.The new
scripts/response-gone.tshas one helper,unlessGone(response, read). It skips only the errors that mean the browser no longer has the body:No resource with given identifier found(seen in a forced real case, below),No data found for resource with given identifier, andTarget page, context or browser has been closed(also seen, below). It logsresponse body gone: <method> <url> <error>and givesundefined. Every other error is rethrown, so a body that is not JSON still fails. In the wheel script:POSTwheel wait readsbody.scroll.offset_from_bottomstrictly, as main did, so an error's answer with noscrollfails the wait (TypeError). It only passes over a body that is gone.GET /pane/scroll?) keep?.scroll?., as main did, because a metrics read can answer{ scroll: null }. A comment there says so.(The first push of this PR caught every error and used
?.scroll?.on the POST wait, so a bad answer in the middle of the wheel sequence was skipped. The merge pass found it, and this push takes it back; see the forced cases.)scripts/terminal-attach-regression.tspick()andscripts/theme-first-paint-demo-regression.ts: the same kind of handlerpick()read each upload's answer (assert.equal(status, 200),await response.json()) in an asyncpage.on("response")handler that had no catch and was never removed. A wrong answer ended the run from the handler while the pick waited forever. Every earlier pick's listener also read later answers, up to the page's close. Now a wrong answer rejects the pick where it is awaited, and the listener leaves once every file is stored. Here a gone body is not skipped: within its pick the path is needed, so it fails the pick. The pick's promise is marked handled when it is made, so an early rejection is reported atawait responses.pathbefore it checks that nothing was typed. Forced: exit 1,the held upload is stored.allHeaders()andbody()with no catch, the same shape. A read that the page's close overtakes is now passed over throughunlessGone. The checks then report the missing boot response or CSP as they would on main (no boot script response,the page was served with null). Any other failure still ends the run. Not forced; run 5 times through CI's command (below).Can a wrong product answer now pass where it failed on main?
typeof sentByPage === "number"check only add a failure. The comparisontextOf(sent, second) === expected, "no key goes to the old tab" and "opens no other tab" are unchanged. Forced: an extra key typed after the command reaches the new tab, and the run fails withplus: every key reaches the new tab, in order('echo ahead-plus\rz'vs'echo ahead-plus\r').accepted()waits for the expected count, and a different count still fails when the 5 s bound ends. Forced: a fixture that takes one character more fails withMasked input never reached fixture: it took "16", not 15 characters. Clearing the file before the grid's typed secret removes a stale count of the same length that could have passed for it.scrollfail as on main.Every listener this PR removed or narrowed, and what it no longer reads
Each of these is answered by a forced run in the table below, not by reading the code.
pick()listener: removed once its files are stored. It no longer reads:POSTwheel wait: passes over a gone body only, and readsscrollstrictly.GETsize waits: pass over a gone body only. A metrics answer that is not JSON fails the wait. 67d1d11 had a hole here, closed at d73874e.Same shape elsewhere
The search for the same shape across
scripts/andsrc/(void page|context .addInitScript|route|exposeFunction|exposeBinding, and any of these calls not awaited or returned) found only the two fixed above (newtab-typeahead, terminal-attach).relay-shell-browser-qa.ts:1568returns theaddInitScriptpromise, and its callers await it. The CI supervisor's measurement found the question-wheel diagnostic. The merge pass found the two async response handlers (terminal-attachpick(), theme-first-paint), and both are fixed above. Per the merge pass's grep, the othervoid ….then(calls inscripts/have a rejection handler, or are page code over a promise that cannot reject.No fixed sleep was added. The existing 25 ms polls remain, inside bounded waits. No changelog fragment, because this is test-only.
Validation
Ran:
bun run check run -- bun <copy>in theherdr-ci-runner:localimage, pinned to one 2-core slot, with no network and no artificial load. Terminal-attach ran through a scratch runner (test herdr,createServeron port 0, its own workspace). Each cell says what happened: exit 1 after N s and the assertion or error that ended it; exit 0 when the script passed (in bold where it should have failed: the hole); or hangs: the run never ended by itself and was killed at the harness's limit (240 s, exit 124; main's first-pick case by hand after 349 s), which on CI would cost the job its whole timeout. No forced case hangs at this head: every cell in its column ended in 18 s or less, except theme-first-paint, which runs all 62 cases (about 72 s).undefinedtimes out,plus: the page's frames for the new tab are all heardplus: the page has no frame counter (window.sentByPage is undefined)…plus: every key reaches the new tab, in order'' !== '15''16' !== '15'Masked input never reached fixture: it took "16", not 15 characterserror: json: Protocol error (Network.getResponseBody): No resource with given identifier foundends the run200 "{not json"SyntaxError: waitForResponse: JSON Parse errorSyntaxError: waitForResponse: JSON Parse error500 {"error":…}(noscroll)TypeError … (await response.json()).scroll.offset_from_bottomTypeError … body.scroll.offset_from_bottom200 "{not json"SyntaxError: waitForResponse: JSON Parse error500 !== 200is reported as unhandled, then the pick waits forever; killed at the harness's hand stop after 349 s (does not pass)500 !== 200at the pick's await500 !== 200as unhandled, then the pick waits forever; killed at the harness's 240 s limit after 245 s (does not pass)500 !== 200at the pick's await500 !== 200twice, from leftover pick listenersthe held upload is storedboot response {…"status":500…}andboot request failed, thena frame showed another theme than the saved onethe page was served with null, thena frame showed another theme than the saved oneIn bold, where a version passed a fault or hung: 67d1d11's question-wheel holes (fixed at d73874e), d73874e's held upload (fixed at this head), and the picks that hang on main and 67d1d11 (fixed at d73874e, when a pick's wrong answer began to reject the pick).
timed out: plus: the page's frames for the new tab are all heardandsentByPage=undefined; the awaited 3 s install passes. A stand-alone harness (Bun.serve and the same Chromium) shows that awaitForResponsepredicate whose body is gone rejects the whole wait: main's shape givesREJECTED: waitForResponse: json: Protocol error (Network.getResponseBody): No resource with given identifier found, andbodyOfpasses over it and resolves on the next answer.BROWSER_SCRIPTS=scripts/ui-contexts-regression.ts BROWSER_WORKERS=2 BROWSER_RETRY=0 bun run check run -- bun scripts/ci-browser-parallel.ts. It ran 21 times (20 valid), each in the runner image pinned to one 2-core heavy slot with fouryeshogs on the slot's CPUs, as in the measurement. Runs 1-19 were on the first commit (its newtab and secret-input files are identical at this head); run 20 passed the script, butcheckvoided it because I edited the question-wheel file while it ran, so run 21 replaces it on this head.touchcase'sthe new tab ran the command typed ahead(sent to it: "", held for review: false). That case comes before its frame wait. Here the page sent the new tab nothing. This is the timeout test(newtab-typeahead): compare the page's frames once all are heard, and say why a run timed out #3691 already describes ("CI has seen this time out without saying why"). All three came within six minutes (11:06-11:11), while this PC's CPU pressure was at its limit, with four of these runs side by side. The other runs were one or four at a time at lower pressure, and all passed. This PR does not touch that step, and I found no way for awaiting the counter's installation to affect it. It is left to a separate look.scripts/ui-terminal-regression.ts(the part that runsterminal-attach-regression.ts), once with fouryeshogs: passed, includingPASS the input line's Attach button puts picked files' paths at the caret and sends nothing, and a stale pick or upload types nothing.scripts/omo-question-wheel-regression.tson this head: 5 runs, one at a time, no hogs. 5 of 5 passed, and no answer's body was gone.bun run check fast: passed on each of the four commits (workflow syntax, generated types/themes, typecheck, build, unit tests), the last time on this head.ui-terminal-regression.ts(terminal-attach, with the new held-upload check): 5 of 5 passed, each with the Attach button's PASS line.ui-contexts-regression.ts(newtab-typeahead and secret-input): 5 of 5 passed, each with both PASS lines.BROWSER_SCRIPTS=<script> BROWSER_WORKERS=2 BROWSER_RETRY=0 bun run check run -- bun scripts/ci-browser-parallel.ts) 5 times in a row, one container at a time. These runs were unloaded (noyeshogs), except the first four terminal-part runs, which were started before the CI supervisor asked for no load. The 20 loaded runs above stand as they were.scripts/omo-question-wheel-regression.ts: 5 of 5 passed.scripts/theme-first-paint-demo-regression.ts: 5 of 5 passed, noresponse body goneline.scripts/ui-terminal-regression.ts(terminal-attach): 5 of 5 passed, each with the Attach button's PASS line.scripts/ui-contexts-regression.ts(newtab-typeahead and secret-input): 5 of 5 passed, each with both PASS lines.Skipped:
bun run check full, and loaded runs for the follow-up (correctness, not load, was the question there), and the integration lane (no server, src or shared change); the Windows and macOS jobs (they run none of these scripts).