Skip to content

fix(serving): a patch gets the keyboard when it opens - #1097

Merged
allisonmahmood merged 1 commit into
mainfrom
fix/frame-focus-1087
Oct 31, 2026
Merged

allisonmahmood merged 1 commit into
mainfrom
fix/frame-focus-1087

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

What changed

A patch's page didn't hear the keyboard when it opened. Focus stayed on Patchy's shell around the frame, so arrow keys, Space to scroll and any shortcut did nothing until the person clicked into the page. Now the shell gives the frame focus when it loads, unless Patchy's own UI, such as the starting cover, already holds it.

Closes #1087

Look at

  • packages/serving/src/broker.ts: the frame's load handler focuses the frame when document.activeElement is null or body. This covers every scripted frame. Since the tier fold, stored static pages are tier 1 too, so they also get the keyboard on load: Space and PageDown scroll them without a click. The broker is one-shot, so a second load of the same frame stops it before this line runs.
  • Tier 2's starting cover keeps its own handoff in stream-status.ts: clearStarting focuses the frame when the cover closes. This PR adds no second handoff; the new spec checks the two together.

test/browser-tier1/focus.spec.ts, red on main and green here:

main's broker
  ✘ a patch hears the keyboard once its frame loads
      Expected: "1"  Received: "0"
  ✓ shell UI that holds focus before the frame loads keeps it
  ✘ a tier 2 patch hears the keyboard on load and again once its starting cover clears
      Expected: "1"  Received: "0"

this branch
  ✓ a patch hears the keyboard once its frame loads (274ms)
  ✓ shell UI that holds focus before the frame loads keeps it (295ms)
  ✓ a tier 2 patch hears the keyboard on load and again once its starting cover clears (718ms)

The middle test passes on main because main never moves focus. With the guard removed, so the frame is always focused, it fails on the shell's button: Expected: focused, Received: inactive.

How it was verified

  • The spec above: on main, on this branch, and with the guard removed.
  • Done means, one test each: a tier 1 key press without a click; tier 2 on load, then again after its cover clears, with the cover holding focus in between; shell UI focused before the frame loads keeps focus. Before a frame loads, the only focusable shell UI today is the tier 2 cover, which is modal. So that test focuses a button placed in the shell's document instead.
  • pnpm verify: format, lint, typecheck, synth, postgres-concurrency, cli-smoke, install, tier2-smoke and the whole browser suite (77 specs) pass. test had 19 failures, none in serving:
    • The CLI stub-server cases record a stray GET /, a local port probe that doesn't happen on CI.
    • RequestEvents counted one route twice once. It passed five runs in a row after that.
    • LocalTaskProvider failed under load and passes on its own.
  • Not checked: Firefox and Safari, because the tier 1 suite runs Chromium only, and no one has pressed keys by hand in a real browser.

Release impact

Tick exactly one.

  • Breaking — requires action from anyone already running this

  • Not breaking — no action required. It changes only the shell's script: no contract, schema or configuration.

  • What does a revert leave behind? Nothing. Patches wait for a click again.

  • Does the release before it still work with that? Yes.

Built by Claude Opus 5.5 (claude-opus-5-5) in Claude Code, through T3 Code.

@github-actions github-actions Bot added area:server Touches the server area area:ci CI, shared testing infrastructure, development scripts and tooling size:s Under 100 changed lines labels Oct 30, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Sol review

No merge-blocking findings.

Standards: No UI consistency findings. The change preserves focused shell controls and the frame's existing accessible name and keyboard navigation. No method or YAGNI blockers: the guarded focus call is the smallest change described by the issue.

Spec: Matches #1087 and its scope within #1086. Focus moves only on the initial frame load when the shell has no focused control. The existing one-shot guard prevents another handoff on a second frame load; route changes do not use this path. Tier 2's starting cover retains its existing focus handoff in stream-status.ts.

Validation: All three tests in test/browser-tier1/focus.spec.ts passed in Chromium against the current broker. The tests send keys without clicking, delay frame loading while a shell button holds focus, and check keyboard delivery before and after the tier 2 cover. These assertions exercise the behavior that removing the focus call or its guard would break.

The call focuses the iframe rather than a text field; it adds no request to open a phone keyboard. Physical-phone behavior and screen-reader output were not tested.

Reviewed against origin/main, with one pass, no subagents, and no checkout changes.

@allisonmahmood
allisonmahmood force-pushed the fix/frame-focus-1087 branch 2 times, most recently from c5a0469 to 1b2ff25 Compare October 31, 2026 14:31
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Acceptance: PASS with notes

Checked 1b2ff2538583d03abc1e3c77ec6e23abee856577 (base 54438fa3303fe8867867f0a9b260536a033da0f6) on brightline, by Claude Opus 5.5 in Claude Code, through T3 Code. This re-checks the PR after its rebase onto main, which brought in Preact 11 (#975) and repo snapshots with patchy pull (#1003, #1004).

I brought up pnpm dev up brightline at the head and drove it with Playwright in Chromium and Firefox. I added three patches of my own with the environment's CLI. Two came from patchy init starters, which now bundle Preact 11.1.0, each with a window keydown counter:

  • key-counter-p11: tier 1.
  • key-counter-t2: tier 2.

The third, long-static, is a 400-paragraph page with no script. No check clicked into a frame before pressing a key. For before and after, I served the same instance's broker.js with the PR's one statement removed. That is main's broker.

Done means

  • Open a tier 1 patch and press a key without clicking, and the patch's own keydown sees it: passed. This held hosted and in patchy dev, in both browsers. On the Preact 11 tier 1 page, a key press gave keys=1, with the shell's activeElement on iframe#patch. With main's broker, keys=0 and focus stayed on body. patchy dev serves the same broker as the hosted shell, and its tier 1 page also gave keys=1.
  • The same holds for tier 2 once its starting cover clears: passed, hosted and in patchy dev, in both browsers. The tier 2 page hears a key on open (keys=1). With main's broker, keys=0. I held the runtime stream to raise the cover over a loaded frame. The cover took focus, Tab stayed on it, and a key pressed under it didn't count. Once the cover cleared, focus was back in the frame and keys=2.
  • Shell UI focused before the frame loads keeps focus: passed. On a real instance, the only shell UI that can hold focus before load is the tier 2 cover. I held both the stream and /~content/, so the cover was open and focused before the frame loaded. At load, focus stayed on the dialog and keys=0. After the cover cleared, focus moved to the frame and keys=1. The PR's spec covers a stand-in shell button.
  • A stored static page scrolls with Space and PageDown, no click: passed. long-static scrolled to scrollY 630, then 1260 in Chromium, and 682, then 1364 in Firefox. With main's broker it stayed at 0.
  • test/browser-tier1/focus.spec.ts at the head: 3 of 3 passed locally.
Driver output, Chromium (Firefox matches except the two lines in the first note)
PASS  tier 1 Preact 11 page hears a key on open, no click  keys=1 shell.activeElement=iframe#patch frame.hasFocus=true
PASS  new-version bar by keyboard: Tab out of the frame, Not now, focus back in the frame  bar shown, focus stayed=iframe#patch; Tab reached button[Reload], then button[Not now]; Enter hid the bar, focus=iframe#patch; key after: 4->5
PASS  folded chip by keyboard: Hide, then Reload, and the reloaded page hears a key  Tab reached button[Hide]; Enter folded it, focus=iframe#patch; Tab reached chip button[Reload]; Enter reloaded; focus=iframe#patch, keys=1
      main's broker: tier 1 Preact 11  keys=0 shell.activeElement=body
PASS  static page scrolls with PageDown then Space, no click  scrollY 630 then 1260, shell.activeElement=iframe#patch
      main's broker: static page  scrollY after PageDown=0, after Space=0
PASS  tier 2 page hears a key on open, no click  keys=1 shell.activeElement=iframe#patch
      main's broker: tier 2  keys=0 shell.activeElement=body
PASS  tier 2 starting cover over a loaded frame  at load focus=iframe#patch, keys=1; cover took focus=dialog[Starting your tools], Tab kept it=dialog[Starting your tools], key under cover counted=false; cleared, focus=iframe#patch, keys=2
PASS  tier 2 cover holds focus through the frame's load  before load focus=dialog[Starting your tools]; at load cover open=true, focus=dialog[Starting your tools], keys=0; cover cleared, focus=iframe#patch, keys=1
PASS  new-business opens with focus in its frame; first Tab stays in the patch  shell.activeElement=iframe#patch frame.hasFocus=true, first Tab -> button[Mine only]
PASS  kudos opens with focus in its frame; first Tab stays in the patch  shell.activeElement=iframe#patch frame.hasFocus=true, first Tab -> input
PASS  spend opens with focus in its frame; first Tab stays in the patch  shell.activeElement=iframe#patch frame.hasFocus=true, first Tab -> button[Export CSV]
PASS  patchy dev tier 1 hears a key on open, no click  keys=1 shell.activeElement=iframe#patch
PASS  patchy dev tier 2 hears a key on open, no click  keys=1 shell.activeElement=iframe#patch

focus.spec.ts at the head
  ✓ a patch hears the keyboard once its frame loads (269ms)
  ✓ shell UI that holds focus before the frame loads keeps it (189ms)
  ✓ a tier 2 patch hears the keyboard on load and again once its starting cover clears (363ms)

Risks beyond Done means

  • The shell's own controls by keyboard: passed in Chromium. With focus in the Preact 11 page, I published a new version. The bar appeared without taking focus. Tab left the frame and reached the bar's Reload, then Not now. Enter on Not now hid the bar and put focus back in the frame, and the next key counted. After another publish, Enter on Hide folded the bar into a chip. Enter on the chip's Reload reloaded the page, which opened with focus in its frame (keys=1). Firefox differs; see the first note.
  • The specs for the shell's other controls: passed locally at the head. starting, stream, downloads and single-file passed 38 of 38. They cover the cover's Tab trap and its Try again, the version bar, and download cards.
  • Real tier 2 tools: passed. New Business, Kudos and Spend open with focus in their frame. The first Tab lands on the patch's own first control, not the shell.

Golden journeys

  • Find and open a tool: passed. Every brightline patch opened with focus in its frame (frame.hasFocus=true).
  • Use a tier 2 tool: passed, keyboard only. Jordan reached a Lead card in 5 Tabs from a fresh open, with no click, and Enter opened it. Tab and Enter on Discovery moved the deal, and it moved on Allison's open board. Shift+Tab and Enter on Lead moved it back, which also showed on her board.
  • Sign in, Log a machine in, Share and unshare, Invite and join: not touched. They render no patch frame, and the diff changes only the frame's load handler.

Rollback answers: they match the diff. The PR changes the shell's broker.js, which is served under a digest-named URL, and adds one browser spec. A revert leaves no schema, rows or contract behind, and the release before simply doesn't move focus. No one-way label is needed. rollback-rehearsal passed on the head.

CI

  • The red postgres-concurrency on the head before the rebase (c5a0469) was not this change. The failing case was the hot-row test in packages/runtime/src/MutationTransaction.postgres.test.ts: 58 SERIALIZABLE mutations against real Postgres. It timed out at vitest's default 5,000 ms, and the 27 other cases passed.
  • Nothing in this PR is on that path. broker.ts is a browser script that the test setup only bundles, and packages/runtime doesn't import it. The same job passed on this head in 58 s, and main's last 30 CI runs are green. It reads as load. It isn't a filed flake yet, so open a flaky issue if it recurs.
  • On this head, every required check that has finished is green: browser, postgres-concurrency, rollback-rehearsal, tier2-smoke, test (24), lint, cli-smoke and clerk-live. Two required checks, test (22) and test (26), were still running when I posted. So were the optional install (linux), install (windows) and the Pidgeon live suite.

Not run

  • WebKit (Safari): Playwright's WebKit won't launch here because the host is missing system libraries. Chromium and Firefox ran.
  • Physical phones and screen readers: there is no device or assistive technology on this host.
  • Spend's refusal of self-approval: not re-run. The change doesn't reach handlers.

Notes

  • Firefox only, and the same on main: after Not now or Hide on the new-version bar, focus goes to the shell's body, not back to the frame. The next key reaches nothing until a click. Main's broker gives the same result in Firefox (after Enter focus=body; key 2->2), and Chromium returns focus to the frame with either broker. The cause is in stream-status.ts, which this PR doesn't touch. CI's browser suite runs Chromium only, so it can't catch this. It is worth a follow-up under sdk: hotkeys, so patches get shortcuts like G H and Mod+K #1086, because Firefox users would lose hotkeys after dismissing the bar.
  • The PR's evidence gaps on Firefox and on hands-on key presses are closed: every check above ran in Firefox and passed, apart from the pre-existing bar issue.

Keys go to the focused document, and the shell kept focus after a patch's
frame loaded, so nothing in the patch heard a key until a click. The frame's
load handler now focuses the frame unless the shell's own UI holds focus.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood merged commit 28273ac into main Oct 31, 2026
23 checks passed
@allisonmahmood
allisonmahmood deleted the fix/frame-focus-1087 branch October 31, 2026 22:50
allisonmahmood added a commit that referenced this pull request Oct 31, 2026
## What changed

This adds release 32's What's new entry, written from `58d94b3`. It
covers everything merged since release 31's `through` (`5888411`). It
also sets the `patchy` release to `0.32.0` in
`packages/patchy/package.json` and `CURRENT_RELEASE`.

| Change | PRs |
| --- | --- |
| Fixed: a patch has the keyboard as soon as it opens, so its shortcuts
work, and Space and Page Down scroll it, without a click first | #1097 |
| Improved: agents give a patch pages of its own, each view at its own
address under the patch, with back and forward working; repos pick it up
at their next refresh | #1095 |
| Fixed: a patch that hits Pidgeon's hold on a new message is told
nothing was sent and to reply in the conversation, not to wait and retry
| #1139 |
| Behind the scenes: refresh and `patchy dev` keep working when a repo
holds a skill the instance's release doesn't ship, so a rollback can't
break them | #1099 |

#1138 is a live test tier change with nothing that ships. #1140 is
release 31's own entry.

## Look at

- **The entry**, at the top of `releases` in
`packages/core/src/whatsNew.ts`.
- **Rollback safety, from the live commit `9e176cb` (release 31) to
`58d94b3`:** #1138, #1139, #1097, #1095 and #1099. None is labelled
`one-way`, and their Release impact answers agree:
  - #1097 changes only the shell's script.
  - #1095 changes only skill text.
- #1139 adds a `details.limit` value and a `details.message` on an
existing refusal.
- #1099 adds no skill, so a repo refreshed on this release holds only
skills release 31 also ships.
  - #1138 is tests only.
- **#1099 has to be live before #1092 (PR #1098, `patchy/hotkeys`)
ships.** That's why this release goes out alone. Once #1098 is live, a
rollback to release 32 or later keeps refresh and dev working for repos
that picked up the new `patchy-hotkeys` skill.

**Rollback line:** If this release misbehaves, roll back to `9e176cb`
(release 31).

## How it was verified

- **Tests.** `whatsNew.test.ts`, `schemas.test.ts` and
`WhatsNewPages.test.ts` pass (21 tests), and prettier passes on the
changed files.
- **The range.**
- #1097, #1095 and #1099 were each reviewed by GPT 6.1 Sol, with every
finding resolved. Each got a fresh acceptance PASS with notes after its
rebase onto Preact 11.
  - Each landed with all 12 required checks green on its final head.
  - #1138 and #1139 were merged from their own thread.
- **Deploy state.** The live commit, pinned from `/healthz/deep`, is
`9e176cb` (release 31). The Deploy run updated last succeeded, and none
is unfinished.

## Release impact

- [ ] **Breaking** — requires action from anyone already running this
- [x] **Not breaking** — no action required

Text and version numbers only. The `0.32.0` bump tells CLIs and patch
repos installed before this deploy to upgrade, as every release does.

- **What does a revert leave behind?** Nothing.
- **Does the release before it still work with that?** Yes.

Built by Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, through T3
Code.

Co-authored-by: Claude Opus 5.5 <[email protected]>
allisonmahmood added a commit that referenced this pull request Nov 4, 2026
## What changed

A patch is on screen and listening before its frame's load event, which
waits for the page's last subresource. The shell only gave the frame
focus in that load event, so a key pressed in between went to the shell
and the patch never saw it. Now the shell focuses the frame as it starts
loading the patch, so the first key pressed once the patch is listening
reaches it, with no click. Focus on the shell's own UI, such as the
starting cover, still stays where it is.

Closes #1171

## Look at

- `packages/serving/src/broker.ts`: one guarded `handOffKeys()` runs
just before `frame.src` is set, and again in the load listener. The
guard is unchanged from #1097: it moves focus only when
`document.activeElement` is `null` or `body`. The load call stays for
the case where focus falls back to the shell's body while the frame
loads.
- `test/browser-tier1/focus.spec.ts`, new case "a key pressed before the
frame's load event still reaches the patch". It opens the gap without
relying on timing. An init script stops the frame's load event from
reaching the shell's listeners, so the patch is up and listening and the
shell never runs its load handoff. A key pressed then must reach the
patch. Red on main, green here:

```
main's broker (Chromium)
  ✘ a key pressed before the frame's load event still reaches the patch
      Expected: "1"  Received: "0"

this branch (Chromium)
  ✓ a patch hears the keyboard once its frame loads (1.3s)
  ✓ a key pressed before the frame's load event still reaches the patch (1.2s)
  ✓ shell UI that holds focus before the frame loads keeps it (1.1s)
  ✓ a tier 2 patch hears the keyboard on load and again once its starting cover clears (2.1s)

this branch (Firefox, local config)
  ✓ a patch hears the keyboard once its frame loads (5.7s)
  ✓ a key pressed before the frame's load event still reaches the patch (2.3s)
  ✓ shell UI that holds focus before the frame loads keeps it (2.6s)
  ✓ a tier 2 patch hears the keyboard on load and again once its starting cover clears (3.2s)
```

Because the new case never lets the shell's load listener run, its pass
also shows that focus given to the frame before its document loads
survives the frame's navigation in both Chromium and Firefox.

## How it was verified

- Done means:
- A key pressed with the shell's body focused, once the patch is
listening, reaches the patch: the new case, in Chromium and Firefox.
- Shell controls and the starting cover keep focus: the two existing
cases still pass in both browsers. A stand-in shell button focused
before load keeps it. The tier 2 cover takes focus over a loaded frame
and hands it back when it clears.
  - A browser-tier case opens the gap on purpose: the new case.
- `pnpm check`, then one `pnpm verify` before CI took over as the judge:
format, lint, typecheck, synth, postgres-concurrency, cli-smoke,
install, tier2-smoke and the whole browser suite pass. `test` and `test
(bun)` failed outside serving: the CLI stub-server cases recorded a
stray `GET /`, the local port probe that doesn't happen on CI, which
also double-counts `GET /` in `RequestEvents`; the rest were 5 s
timeouts while other worktrees ran their suites on this machine.
- Not checked: WebKit (Safari), because Playwright's WebKit won't launch
on this host. Physical keyboards on phones and screen readers. CI's
browser suite runs Chromium only; Firefox ran from a local config.

## Release impact

Tick exactly one.

- [ ] **Breaking** — requires action from anyone already running this
- [x] **Not breaking** — no action required. It changes only the shell's
browser script, served under a digest-named URL: no contract, schema or
configuration.

- **What does a revert leave behind?** Nothing. A key pressed before the
frame's load event is lost again.
- **Does the release before it still work with that?** Yes.

Built by Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, through T3
Code.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling area:server Touches the server area size:s Under 100 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(serving): a patch gets the keyboard when it opens

1 participant