Skip to content

test(keybar): prove the shell took the bar's Enter by a command's output, not a prompt count - #2395

Merged
devswha merged 1 commit into
mainfrom
test/keybar-focus-enter-marker
Oct 29, 2026
Merged

devswha merged 1 commit into
mainfrom
test/keybar-focus-enter-marker

Conversation

@devswha

@devswha devswha commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Found by the flake-hunt lane: scripts/keybar-focus-regression.ts:72 (run by scripts/ui-contexts-regression.ts) timed out (waitForFunction: Timeout 10000ms exceeded) waiting for the shell to take the key bar's Enter. Over the 417 CI runs from 2026-10-28 03:26Z to 2026-10-29 18:22Z it passed only on its in-job second run 9 times and failed both runs once (latest 40864267912). In the failing log every key's input frame had already passed its check.

Cause (test flake)

The check counted the $ on screen before the key-bar taps and waited for the count to grow after Enter. The grid keeps no scrollback (scrollback: 0) and one shell serves the three contexts in turn, so a new prompt can push an old one off the top and leave the count flat.

Change

  • Marker, not count: before the taps, the check types a command without running it, printf 'KB_%s\n' <nonce>, waits for its echo, and after the bar's Enter waits for KB_<nonce>. The echo cannot hold the joined marker, so the marker drawn proves the shell ran the command.
  • A clean line: the typed command starts with C-g and C-u. Each context ends with an Escape tap to the same shell, and readline can still hold that Esc as a Meta prefix when the next context types, turning the command's first letter into M-p (a history search). C-g ends such a sequence (Esc C-g is abort), and C-u clears the line. The test shell is always bash --noprofile --norc in emacs mode (scripts/test-shell.ts).
  • Diagnostics: a timeout names the context and shows the screen's tail.

Proof

  • Fail-first, count flake: with the screen filled with prompts first (scratch), the old check failed 3/3 and the marker check passed 3/3.
  • Fail-first, pending Esc: with a lone Esc sent before the command (scratch), the version without C-g/C-u failed 2/2 and the fix passed 3/3.
  • Plain runs: bun run check run bun scripts/keybar-focus-regression.ts passed 5/5.
  • Local checks: bun run check fast ok.

Test-only.

Reviews

  • omo-native-code-reviewer:
    • Round 1: BLOCK on HIGH H1. The reviewer ran the script 13 times and saw 1 failure. It showed with python's pty and bash 5.3 that a lone Esc stays a Meta prefix, so the next command became a history search.
    • Fixed with C-g/C-u.
    • Round 2: APPROVE (CLEAR), with two LOWs.
      • The echo wait can match the nonce inside a search prompt. That is harmless, because the final marker wait decides the test.
      • The screen read in the error could hide the timeout if the page has closed.
  • Test-only, so no Codex review (notes/pr-policy.md).

…put, not a prompt count

The check counted the "$" on screen before the key-bar taps and waited for
more after Enter. The grid keeps no scrollback and one shell serves three
contexts, so a new prompt can push an old one off the top and leave the count
flat: the wait timed out (keybar-focus-regression.ts:72, flaky 9 times and
failed twice once in 417 CI runs). Type a command without running it that
prints a marker its echo does not hold, and wait for the marker after the
bar's Enter.

The command starts with C-g and C-u: each context ends with an Escape tap to
the same shell, and readline can still hold that Esc as a Meta prefix when
the next context types, turning the command's first letter into M-p (a
history search) so the Enter runs nothing. A timeout names the context and
shows the screen's tail.

Fail-first with the screen filled with prompts first (scratch): the old check
failed 3/3, the marker check passed 3/3. With a lone Esc left pending before
the command (scratch): without C-g/C-u it failed 2/2, with them it passed
3/3. Plain runs passed 5/5; bun run check fast ok.
@coderabbitai

coderabbitai Bot commented Oct 29, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 26 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 60808d7 and 48e1449.

Files selected for processing: 2
  • changelog.d/keybar-focus-enter-marker.md
  • scripts/keybar-focus-regression.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devswha

devswha commented Oct 29, 2026

Copy link
Copy Markdown
Owner Author

Merging 48e1449. Test-only (browser script): keybar-focus-regression proves the shell took the key bar's Enter by a typed command's unique output marker appearing, instead of counting prompts (with no scrollback a new prompt can push an old one off the screen), and clears readline first (C-g, C-u) so a leftover Escape cannot eat the command's first letter. Diff read by the merge pass; no CodeRabbit review needed.

@devswha
devswha merged commit 65573e0 into main Oct 29, 2026
18 of 20 checks passed
@devswha
devswha deleted the test/keybar-focus-enter-marker branch October 29, 2026 22:33
devswha added a commit that referenced this pull request Oct 29, 2026
…s instead of racing 2 s (#2402)

Found by the flake-hunt lane, with a Dori pin. The Pi listing tests
added by #2377 raced the two-second production deadline on busy runners:
- **`server/pi-session-metadata.test.ts`** "lists the newest 50 long
sessions within the deadline and reads zero bytes on repeat":
- #2391's Fast checks (run 40955829630): 6.6 s, "Pi sessions could not
be read right now".
  - #2397's Fast checks (run 40960224000): 8.96 s.
  - Both passed on rerun.
- **`server/api.contract.test.ts`** "lists a 202-session Pi store with
50 long transcripts through the real API without timing out": #2395's
Integration run (job 123744721790), a 503 for the same reason.

## Cause (test flake)

Both tests list about 200 MiB of Pi transcripts and check what is
listed:
- the newest 50 rows, with their titles and first prompts;
- zero bytes read on a repeat listing;
- chunk-sized reads, and an empty queue;
- a later rename (API test).

They did this under the listing's real deadline, `PI_READ_DEADLINE_MS`
(2 s of wall clock, queue time included). On a loaded runner, reading
200 MiB takes longer than that.

## Change

The deadline is injected rather than raced:

- **Reader:** `PiSessionReader` takes an optional `deadlineMs` beside
its existing `read` test seam and exposes it as `listingDeadlineMs`.
`piSessions` uses that for the listing's deadline. Unset, it is still
`PI_READ_DEADLINE_MS`.
- **Server:** `createServer` gets a test option, `piSessionDeadlineMs`,
passed to its reader. It is next to the other `*Ms` test options, such
as `attachHoldMs`.
- **The two tests:** each passes 120 s, past its own timeout. The unit
test's timeout is 30 s; the API case's goes from 20 s to 60 s. The "zero
bytes on repeat" and chunk assertions stay.
- **Docs and changelog:** `docs/development.md` and the changelog
fragment say this.

The shared two-second deadline is still covered, with a fake clock:
aggregate expiry, independent deadlines, queued expiry and FIFO
admission, in `pi-session-metadata.test.ts:484-505`, `:585` and `:627`.
Those tests also assert that the default is `PI_READ_DEADLINE_MS`. The
API's 503 shape is still checked by its own case.

## Proof

- **Fail-first (unit test):** with every 64 KiB read delayed 1 ms
(scratch), the old test failed 2/2 with the CI error ("could not be read
right now"), and the new one passed 3/3.
- **Wiring (API test):** with `piSessionDeadlineMs: 1` (scratch), the
API case fails with CI's 503, so the option reaches the listing.
- **Runs:** the API case passed 3/3 (`bun run check run bun test
./server/api.contract.test.ts -t lists.a.202-session`). The unit file
passed 5/5, then 39/39 again after the wording edits.
- **Local checks:** `bun run check fast` ok.

## Reviews

The PR changes product code (the reader and server test seams, with no
production behaviour change), so both reviewers ran.
- **omo-native-code-reviewer:** APPROVE (CLEAR) on both rounds. It
confirmed that no production caller sets the option:
`server/index.ts:738`, `server/remote-entry.ts:88`, the default reader,
and the QA script.
- LOWs fixed: the test name had claimed the shared-budget proof, and the
comment said "a bound no slow runner reaches". Both now describe what
the test checks.
- LOW, follow-up only: the neighbouring API case "streams ..." reads
about 17 MiB under the real 2 s deadline. That is about 0.7 s at CI's
worst rate, and it has never failed. If it ever does, it can pass the
same option.
- LOW, style: the docs paragraph's wording, and the fixture helper's
argument order.
- **Codex Sol 6.1 Fast xhigh:** APPROVE on both rounds.
- Round 1's LOW: the docs still said "under the ordinary deadline".
Fixed.
  - Round 2: no findings.
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