Skip to content

fix(serving): a key pressed as a patch opens reaches the patch - #1183

Merged
allisonmahmood merged 1 commit into
mainfrom
fix/1171-focus-handoff-key
Nov 4, 2026
Merged

allisonmahmood merged 1 commit into
mainfrom
fix/1171-focus-handoff-key

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

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 fix(serving): a patch gets the keyboard when it opens #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

  • 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.

@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 Nov 1, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Review (GPT 6.1 Sol, xhigh) on 9504e7d: approve, no findings.

  • Both handoffs keep the body or null focus guard, so the shell's controls and starting cover keep focus.
  • Typing in a shell input, before the broker starts or while the frame loads, isn't interrupted.
  • All 4 focus tests pass in Chromium and Firefox. The base broker fails the deliberate-gap case, receiving 0 keys instead of 1.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Acceptance: PASS with notes

Checked 9504e7dd160730653827fcac3490a7ca2cf9c6bc (base 1f187a92b2c20da81e8a1d647ea28a60a075d6ef) on brightline, with main's broker measured on team, by Claude Opus 5.5 in Claude Code, through T3 Code.

Done means

  • With the shell's body focused, the first real key pressed once the patch is ready reaches it, with no click: passed. I published a tier 1 patch that records when it starts listening and every key it hears, then opened it in fresh windows and pressed a key about every millisecond from navigation on, without clicking. To hold the gap open without touching the shell, Playwright appended one image to the patch's content response that answers after 1.5 s, and loosened that response's CSP only enough to allow it. The patch is up, idle and listening while its frame's load event waits on the image:

    Broker Runs Runs where the shell got keys after the patch was listening First key the patch heard, after it started listening
    main 10 10 (23,070 keys in all) 1,480–1,491 ms, at the load handoff
    this head 10 0 20–41 ms

    Without the slow image, the natural gap here was 7–16 ms, and neither broker lost a key in 30 runs, which fits the issue's 1 in 60.

  • Focus on shell controls, or on the starting cover, stays where it is: passed. On the same environment at the head, a shell button focused while the frame waited on its load kept focus through the load, and the patch heard none of the keys pressed after. A button focused before the broker mounts kept focus through the mount and the load. New Business started in under 2 s here, so its starting cover never showed; focus went from the body to the frame at 74 ms. The spec's tier 2 case covers the cover taking focus and handing it back.

  • A browser-tier case opens the gap on purpose and shows the key arriving: passed. test/browser-tier1/focus.spec.ts passes 4 of 4 at the head in Chromium and in Firefox (from a local config). Over main's broker.ts, the new case fails and the other three pass:

    ✘ a key pressed before the frame's load event still reaches the patch
        Expected: "1"
        Received: "0"
    

Golden journeys

  • Find and open a tool (Jordan): passed. After Jordan set the onboarding guide's "Final step" aside with Later, Home listed New Business, Spend, Kudos and the Harbor & Pine kickoff. A search for "kudos" found Kudos, and it opened in its frame, with the shell's focus on the frame.
  • Use a tier 1 tool live (Jordan, Priya): passed. Jordan sent a kudos, and it appeared on Priya's open Kudos page 109 ms later, without a reload.
  • Use a tier 2 tool (Jordan, Allison): passed for the board. New Business opened with its 15 sample deals. Jordan moved "Saltwater Hotels, Loyalty app concept" from Lead to Discovery, and it moved on Allison's open board 80 ms later. Moving it back to Lead showed there too.

Rollback answers: they match the diff. Only the shell's browser script changes, served under a digest-named URL. Nothing is stored, and a revert only brings the lost key back. No one-way label is needed.

Not run

  • WebKit (Safari): Playwright's WebKit doesn't launch on this host, for missing system libraries. The PR didn't check it either. The load handoff is kept, so if WebKit dropped focus given before the frame's navigation, it should fall back to main's behaviour rather than something worse. That is read from the code, not observed.
  • Spend refusing self-approval: a server rule this change can't reach.
  • The starting cover in a live environment, for the reason above, and physical keyboards on phones and screen readers.

Notes

  • WebKit is the one engine still unverified for focus given before navigation. A Safari check on a Mac would close it.
  • CI is green on the head.

@allisonmahmood
allisonmahmood force-pushed the fix/1171-focus-handoff-key branch from 2b6e2c4 to fe096f5 Compare November 4, 2026 01:17
@allisonmahmood
allisonmahmood merged commit 832385f into main Nov 4, 2026
23 checks passed
@allisonmahmood
allisonmahmood deleted the fix/1171-focus-handoff-key branch November 4, 2026 01:29
allisonmahmood added a commit that referenced this pull request Nov 4, 2026
…ges publish (#1241)

## What changed

This adds release 36's What's new entry, written from `1acc968`. It
covers everything merged since release 35's `through` (`dd0e2ec`), and
sets the `patchy` release to `0.36.0` in `packages/patchy/package.json`
and `CURRENT_RELEASE`.

| Change | PRs |
| --- | --- |
| Improved: shortcuts work where you use them (keys for one part of a
patch, the closest wins, text boxes keep their typing keys) | #1231 |
| Improved: the shortcuts sheet shows what works where you are (Ctrl+/
and ⌘/ open it, its commands run, it opens from a patch's menu and in
view on a narrow screen, keeps the look, spells keys out away from a
Mac) | #1231, #1181, #1178, #1180, #1177 |
| Fixed: keys pressed while a patch opens reach it | #1183 |
| Fixed: pages styled with Tailwind 4 publish, and a look with the same
rule saves | #1191 |
| Fixed: an old copy of a patch no longer replaces newer work
(**Breaking** for such a copy: it needs `patchy pull` or one
`--allow-behind` publish) | #1179 |
| Improved: your agent can check a publish before sending it | #1188 |
| Improved: your agent hears what changed when it updates a patch |
#1186, #1185 |
| Fixed: your agent stops chasing false alarms (`pnpm install` exit
codes, `manifest.json` bytes, the description notice, a copied dev
record) | #1176, #1174, #1175 |
| Behind the scenes: fuller hotkeys instructions for agents; fewer
redraw costs for patches with many shortcuts | #1182, #1187 |

`patchChanges` has three sentences for the agent refreshing a patch
across this release:
- #1231's, from its PR: text fields keep their keys, `preventDefault()`,
and the sheet's Mod+/ and `.hotkey-row` buttons.
- The sheet's dialog renders in `document.body`, and element-only page
rules don't reach it (#1178, #1180). Its own row lists last (#1181). The
hotkey label helpers take only valid literals (#1177).
- Publish's `unknown_base_version` (#1179).

It also rewords release 33's "Press ? to see every shortcut a patch
has". That was true only for a patch that mounts the shortcuts sheet, so
it now says a patch *can* list its shortcuts.

The rest get no line:
- #1206, #1207, #1209 and #1220 are `pnpm dev eval` tooling.
- #1222 is release 35's own entry.

## Look at

- **The entry**, at the top of `releases` in
`packages/core/src/whatsNew.ts`, and release 33's reworded line.
- **Rollback safety, from the live commit `d28fdd0` (release 35) to
`1acc968`:**
- #1191 is labelled `one-way`. Its Release impact: a company look
published after this release with a nested `@supports` condition stays
stored after a revert. Release 35 refuses any bundle carrying it, so
repo publishes in that company would fail until an admin runs `patchy
look restore` to an earlier revision. Pages and Tailwind 4 repos already
published stay published.
- #1183 is the only change to what the server serves browsers: the
shell's script, under a digest-named URL. Its revert leaves nothing
behind.
- The hotkeys PRs change `patchy/hotkeys`, which patches bundle when
they are built. Published patches keep their copy.
- The CLI PRs change what a CLI writes and refuses. Release 35 reads
everything they leave behind: #1176's `allowBuilds` entry, #1174's
indented `manifest.json`, and the `version` recorded by an
`--allow-behind` publish.

**Rollback line:** If this release misbehaves, roll back to `d28fdd0`
(release 35). First check that no company's look has a nested
`@supports` condition, and `patchy look restore` an earlier revision
where one does (#1191).

## How it was verified

- **Tests.** `whatsNew.test.ts`, `WhatsNewPages.test.ts` and
`schemas.test.ts` pass (22 tests), and `bun fmt` passes on the changed
files.
- **Facts.** The sheet's new `document.body` home and its element-rule
reset were checked against `hotkeys.ts` and `hotkeySheet.ts` on main.
- **Deploy state.** I pinned the live commit from `/healthz/deep`:
`d28fdd0` (release 35). 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. Like every release, the `0.36.0` bump
tells CLIs and patch repos installed before this deploy to upgrade.

- **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]>
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.

A key pressed while the shell is handing focus to a patch can be lost

1 participant