Skip to content

ci: the browser tier runs desktop Chromium, where a patch's frame has its own process - #1302

Merged
allisonmahmood merged 1 commit into
mainfrom
t3/fix-desktop-chromium-focus
Nov 12, 2026
Merged

allisonmahmood merged 1 commit into
mainfrom
t3/fix-desktop-chromium-focus

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

What changed

CI's browser tier ran Playwright's chrome-headless-shell, which keeps a patch's sandboxed frame in the shell's process. Desktop Chrome gives it its own process. That's how #1299 shipped: in desktop Chrome a patch didn't hear the keyboard until clicked, while CI was green. #1298 fixed #1299 on main.

This PR moves the tier 1 suite's chromium project to desktop Chromium, so a focus or keyboard bug that only Chrome shows fails CI. It no longer holds anything back: every test in the suite runs in desktop Chromium. #1407's firefox project still runs focus.spec.ts alone.

Closes #1299

Look at

playwright.tier1.config.ts. The chromium project sets channel: "chromium", the full build in new headless mode, and #1407's firefox project sits beside it unchanged. The headless-shell hold-out is gone. #1406 fixed the local-hotkeys test's accessibility helper, which couldn't read an out-of-process frame, and the test now passes in desktop Chromium. pnpm test:browser runs chromium, as on main, so package.json doesn't change.

What landed first. In desktop Chromium on CI, switcher.spec.ts failed often (#1402). #1412 fixed that on main, with one real desktop-Chrome focus race fixed in the shell's broker and switcher tests that acted too early. One of #1412's tests, the tab switch in switcher.spec.ts, skips in the headless shell, which keeps every tab focused. It starts running on CI with this PR.

The frame really is out of process. CDP's Target.getTargets lists it as its own iframe target in desktop Chromium, and not in the headless shell.

How it was verified

Hit every surface:

  • Dev loop docs: docs/DEVELOPMENT.md says the browser job runs desktop Chromium with focus.spec.ts also in Firefox, and that a script launching its own browser for a focus check passes the same channel. The CI job's and the Playwright action's comments say the same.
  • Doesn't apply: served pages, the wire contract, the CLI, vocabulary, migrations, company resources, reverse states and the repo layout.

Release impact

Tick exactly one.

  • Breaking — requires action from anyone already running this

  • Not breaking — no action required. Test and CI configuration and doc lines; nothing ships.

  • What does a revert leave behind? Nothing. CI goes back to the headless shell.

  • 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 area:docs Touches the docs area size:s Under 100 changed lines labels Nov 7, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Review (GPT 6.1 Sol, xhigh) at 5ead03e: nothing blocking.

  • Should-fix, fixed in a3c3626. A handoff queued by the window's focus event could run after pagehide closed the broker. focusPatch now checks closed.
  • Nit, dismissed: a tab-return test. Headless Chromium can't produce a real tab or window return; the reviewer's headless pages always reported focused and visible. A synthetic focus event would only test our own dispatch, not the browser. The listener is the same one the commit path exercises, and focus.spec.ts covers that in desktop Chromium.
  • Wording, fixed in the body. "Once the document has committed" was slightly stronger than the code. Focus moves one task after the commit, so a key in that brief gap is lost. The body now says so.

The reviewer also confirmed:

  • contentWindow.focus() grants the patch no user activation;
  • shell UI and modals keep focus;
  • CI runs 85 tests across the two Chromium projects;
  • the test step went from 4m34s to 6m36s.

#1301 no longer touches the projects line, so the only hand merge left is #1298's handOffKeys.

@allisonmahmood
allisonmahmood force-pushed the t3/fix-desktop-chromium-focus branch from a3c3626 to 1ade9bb Compare November 11, 2026 12:43
@allisonmahmood allisonmahmood changed the title fix(serving): a patch hears keys when it opens in desktop Chrome ci: the browser tier runs desktop Chromium, where a patch's frame has its own process Nov 11, 2026
@github-actions github-actions Bot removed the area:server Touches the server area label Nov 11, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Restacked onto main at 44acb65, the bottom of the chain main ← #1302 ← #1297 ← #1255 ← #1256 ← #1279 ← #1276 ← #1301. This one changed in substance, so its verdict doesn't carry over as is.

#1299 is already fixed on main. #1298 rewrote handOffKeys: the frame waits hidden (data-waiting) until its document's relay says hello, and only then takes focus. That's after the document commits in its own process, so no focus is dropped. On main, in desktop Chromium with the frame isolated (CDP lists it as its own iframe target), focus.spec.ts passes 4 of 4, and a real c with no click reaches the patch.

What I dropped: the broker.ts change. focusPatch() and the window focus listener have no case left on main:

  • The first key: nothing focuses the frame before its commit any more.
  • A tab return: in desktop Chromium, with focus emulation off, switching tabs and back gives focus straight back to the frame's document. The shell never gets a window focus event: frame hasFocus away false, back true; shell events ["blur active=IFRAME"].

I kept them through the hand merge first, then took them out once both probes showed nothing for them to do. To restore them, re-apply a3c3626's broker.ts hunks over the hello gating.

What it carries now: the CI move, unchanged from the reviewed version. That's the playwright.tier1.config.ts projects with #1306's hold-out, test:browser naming both projects, the action's comment, CI's step names and docs/DEVELOPMENT.md. It's one commit now, retitled ci: ….

Evidence:

Its own spec at its head (1ade9bb): focus.spec.ts passes 4 of 4 in desktop Chromium and 4 of 4 in the headless shell. At the top of the chain, pnpm verify passes, and its browser step ran 168 of 168 across both projects. This PR's CI is green.

@allisonmahmood
allisonmahmood force-pushed the t3/fix-desktop-chromium-focus branch from 1ade9bb to 7fd6e33 Compare November 11, 2026 14:13
allisonmahmood added a commit that referenced this pull request Nov 11, 2026
…h's sheet or the account menu (#1301)

## What changed

Speech input can type a letter that fires a patch's single-key shortcut.
#1224 lets each person turn those off. #1276 stores the choice and #1279
taught `patchy/hotkeys` to obey it, but nothing passed the choice to a
patch yet. Now Patchy's shell does:
- it names a viewer's patch frame with their setting;
- the shortcuts sheet's row opens Patchy's own dialog to change it;
- the account menu gets the same switch;
- a version built before the setting tells a viewer who turned shortcuts
off that its shortcuts still work.

This is the top of the stack `main ← #1297 ← #1255 ← #1256 ← #1279 ←
#1276 ← this`, and the six land together. #1302, CI's move to desktop
Chromium, waits on #1402 and lands later. It's restacked onto `main`
after the UI overhaul (#1332–#1354) and the switcher (#1298, #1304), and
ported to both. The restack comment says what changed beyond conflict
resolution.

Closes #1275
Closes #1224

## Look at

**1. The frame is named in the shell's static markup, not by a script
that creates it.** A parser-created iframe gets its `name` attribute
before its browsing context exists. So the server renders
`name="patchy:shortcuts=on|off"` on the existing static iframe, after
`main`'s `data-waiting`, and only for a company or local shell rendered
for its viewer (`shell.ts`, `Pages.ts`). A public shell is everyone's
document, a member's included since #1339, so it never carries one, and
`renderPatchWrapper` throws if asked to. Probed before choosing, in
Chromium and Firefox:

| Probe, a sandboxed frame whose `src` a deferred script sets | Chromium
| Firefox |
| --- | --- | --- |
| Static markup with `name`: first load, a reload after the value
changed, back after it changed | `off`, `on`, `on` | `off`, `on`, `on` |
| A `<template>` cloned by script, as the ticket's creator would | same
| same |

In desktop Chromium, where the frame runs in its own process, the patch
reads `window.name === "patchy:shortcuts=off"` on first load and after a
new version's Reload re-creates the frame. Static markup keeps three
things:
- **No inline script and no CSP change.** The shell still admits only
the switcher relay's hash.
- **Both mixed-release pairings work.** The markup is `main`'s plus one
attribute (and `data-shortcuts-note`), so an older broker mounts it
unchanged, and this broker mounts an older unnamed shell as before.
`render.test.ts` pins that the frame differs from the unnamed one only
by its name.
- **Every re-creation renders again.** A new-version reload is a fresh
server render.

**2. Patchy's dialog** (`packages/serving/src/shortcuts.ts`), from the
mock's direction C. A running patch's shell keeps its own pinned style
subset on `main` (`servedStyles`; the overhaul left patch shells alone).
So the dialog stays a `shell-scrim` over one `note-info` `note-float`,
with `glyph-sm`, the primary button and a quiet Cancel. The setting's On
or Off is a served `tag` after the question. The old `pill` isn't in
that subset, and `main`'s pin test would refuse it, so it's gone.

| | Desktop | Phone |
| --- | --- | --- |
| The sheet's row | ![The sheet with its Single-key shortcuts row
reading Off, and dashed
keycaps](https://github.com/user-attachments/assets/081d4f78-b123-40f3-a830-5ddcbd14fd2d)
| ![The sheet as a bottom sheet on a phone, its row reading
Off](https://github.com/user-attachments/assets/6b720ace-142a-4a84-a102-0deae6fd486e)
|
| Patchy's dialog | ![Patchy's dialog: Turn off single-key shortcuts in
every patch except public ones?, an ON tag, Turn off and
Cancel](https://github.com/user-attachments/assets/e90123d3-9e4f-47ec-babb-19534349f39a)
| ![The dialog centred on a
phone](https://github.com/user-attachments/assets/5e214a77-e990-4efe-a882-7f41efdd8cb9)
|
| A failed save | ![The dialog turned amber, saying Couldn't save.
Nothing changed., with Try
again](https://github.com/user-attachments/assets/ec24539c-2f35-4fd6-8a30-48d2f291b7c4)
| ![The failed save on a
phone](https://github.com/user-attachments/assets/d540007f-c910-4ac5-961b-b2b21c42181b)
|

The sheet is the SDK's, drawn in the patch's own frame by #1279, and
`main` hasn't touched it.

The copy and the failure pattern are as reviewed:
- The title says what the switch covers: "Turn off single-key shortcuts
in every patch except public ones?", or "Turn on …". The buttons are
**Turn off**, **Turn on** and **Cancel**.
- A refused save, a 200 without `{ value }` and an empty 200 all turn
the note `note-warn`, with the alert line "Couldn't save. Nothing
changed." and **Try again**.

The abuse rules, each a step of the browser spec:
- One dialog at a time.
- A question needs `navigator.userActivation.isActive` in the shell.
- However the dialog closes, it arms a flag: Turn off or Turn on,
Cancel, Escape, or the browser closing it, mid-save or not. The flag
holds new dialogs off until a 250 ms poll reads the old activation as
lapsed. So a request on the press that answered the last dialog gets the
value with no dialog, and only a fresh press opens another.
- Only an `isTrusted` click saves.
- Dismissing never waits. Cancel or Escape mid-save closes the dialog at
once and returns focus to the frame. The save keeps the one-dialog slot
until the route answers, and the operation then resolves with what the
route stored, or with the setting as it was if the save failed or timed
out after 35 s.
- While tier 2's tools are starting, a question gets the setting as it
is.
- **New with the switcher:** while Patchy's switcher is open, a question
also gets the setting as it is, as the starting cover waits for it. If
the switcher is open over the dialog when it closes, the dialog leaves
focus with the switcher, which hands it back.

**3. The account menu's switch**, a no-script form in `main`'s personal
menu: name, Your agents, the switch, Sign out. It posts the value it
switches to, with `return` set to the page. On the overhaul's component
set, the item is the switch: a `menu-item` with `role="switch"` and
`aria-checked`, the `keyboard` icon, and core's `switch` drawn at its
end in the item's state. Core's `fields` and `menus` chunks gained the
two selectors that draw it. The account menu is 248px wide, up from 220,
so the label stays on one line beside the switch.

| Before | Off | After the press: the receipt, and On |
| --- | --- | --- |
| ![The account menu with name, email, Your agents and Sign
out](https://github.com/user-attachments/assets/f1ba9ba2-2514-402a-a1bf-1f83643bbd7f)
| ![The account menu with the Single-key shortcuts switch
off](https://github.com/user-attachments/assets/171a45ef-a592-41a0-b810-09315d9013cb)
| ![The receipt Turned on single-key shortcuts, and the switch
on](https://github.com/user-attachments/assets/c4c0bfb2-71eb-4cfd-9661-dbf575eab48b)
|
| ![The phone menu
before](https://github.com/user-attachments/assets/e3c6daf1-7faf-4d7f-adc7-b80a9301fefc)
| ![The phone menu with the switch
off](https://github.com/user-attachments/assets/4c450fa9-8bea-4e0f-825c-66d74866f9ac)
| ![The phone menu after the press, the switch
on](https://github.com/user-attachments/assets/ea8ca452-812a-4804-9780-acc608bab291)
|

"Before" is this branch's page with the switch's form removed in the
browser, which is exactly `main`'s account menu. `ViewerApi.ts` reads
the form before the session, so a signed-out post that names `return`
goes back to that page, whose own door signs in there.

**4. D1's note.** The note shows to a viewer whose setting is Off, on a
version from 0.33.0 on that doesn't claim `shortcutSetting`, unless its
recorded imports leave out `patchy/hotkeys`.
- **Only a repo build claims `shortcutSetting: 1`**
(`MANIFEST_CAPABILITIES` in `@patchy/api`). A single HTML file may carry
an older SDK bundled inline, so it claims nothing.
- **Recorded imports refine D1's release rule.** A repo build without
`patchy/hotkeys` in `sdkImports` gets no note. A single file records no
imports, so the release rule decides: from 0.33.0 on, the note shows.
- The note reuses the new-version bar in the shared bottom stack: "This
patch's single-key shortcuts still work until it's updated." with a
quiet **Dismiss**, kept per patch in the shell's `localStorage`.

| Desktop | Phone |
| --- | --- |
| ![The note bar at the bottom over the 0.38 bundle: This patch's
single-key shortcuts still work until it's updated.
Dismiss](https://github.com/user-attachments/assets/456c09d9-7ca4-4d06-87d3-50df231178cb)
| ![The note as a bottom sheet on a
phone](https://github.com/user-attachments/assets/f312e473-d3c0-4e65-aa50-91a34fc7fca4)
|

**5. The flow**, desktop then phone. The sheet's row leads to Patchy's
dialog, Turn off brings the sheet back on its row reading Off, then the
account menu turns them back on.


https://github.com/user-attachments/assets/d604fe56-04cd-416c-83fa-42e4beebc2f0


https://github.com/user-attachments/assets/17f547e2-472b-4c2d-90ac-98884108c875

## How it was verified

- **Unit (vitest)**, with the rest of the stack's touched files: 35
files, 330 tests, plus core's style rules, gallery and served-style pin
(358 with `render.test.ts`):
- `render.test.ts`: the frame's name after `data-waiting` in static
markup, and that it is the only difference from an unnamed frame. A
public shell refuses a viewer's setting. `ignoresShortcutSetting`'s
cases.
- `html.test.ts`: the account menu's switch, its value, its `return`,
and escaping.
  - `ViewerApi.test.ts`: a signed-out form post goes back to its page.
- `devServer.test.ts`: each dev person's own setting, and the route,
which writes the file before it changes what shells read.
- `executeConfig.test.ts`: a repo build's manifest records
`shortcutSetting`.
- `served-styles.test.ts`: the served styles' digest moved on purpose,
for the one rule that keeps the dialog's tag whole.
- **The browser tier** (`test/browser-tier1/shortcut-setting.spec.ts`):
thirteen tests on published patches through the real shell and broker,
as reviewed. That includes the committed 0.38 bundle
(`hotkeys-0.38.html`), whose shortcuts still fire under this shell with
Off stored, with no row and with the note.

  | Engine | Result |
  | --- | --- |
| Desktop Chromium, `channel: "chromium"`, frame isolated, from a local
config | 13 passed |
  | Chromium headless shell, as CI runs it | 13 passed |

`hotkeys.spec.ts` and `focus.spec.ts` pass in both as well. Company
patches put the setting's row first in the sheet's Tab order. The
unnamed-frame test opens a public patch.
- **The whole tier 1 suite** at this stack's top (`06476fe`), as `pnpm
verify` runs it in CI's headless shell: 168 of 168. At the previous
push, with #1302's desktop project as well, it also passed 168 of 168.
- **The rollback rehearsal**, against the live release 41 (`7f93b91`):
`7f93b91 → 06476fe → 7f93b91 → 06476fe`, all four steps passed in 116 s.
It covers #1276's migration, and the live release serving a repo build
that this head's CLI wrote with `shortcutSetting`.
- `pnpm verify` at this head: format, lint, typecheck, synth,
postgres-concurrency, cli-smoke, install, tier2-smoke and browser pass.
`test` and `test (bun)` had 15 timeouts while the machine's load average
was near 30. All 11 files rerun alone pass (216 tests), as does Bun's
`PatchesApi` (63). The previous push's `pnpm verify` passed every step.
The served shell's page state is exempt from the page-markup rules in
`.oxlintrc.json`, and `shortcuts.ts` joins `stream-status.ts` and
`downloads.ts` there for the same reason.
- **Hit every surface.**
  - Wire contract: `docs/API.md` is regenerated and current.
- CLI: README, the `patchy-hotkeys` project skill and the capability
catalogue. No command, flag or exit code changed.
  - Dev loop: `docs/DEVELOPMENT.md` and the `patchy-dev-loop` skill.
- Vocabulary: the Companies and patchy glossaries, and
`docs/product.md`.
- Served pages: the `ui-consistency` spec names the menu's switch, the
dialog and note in the shell's exception, and `shortcuts.ts` in the lint
exemption.
  - Reverse states: the switch turns it back on from both places.
- Not applicable: migrations (#1276's), company resources and the repo
layout.
- **Not run on this head:** Firefox and WebKit. Firefox passed 12 of 13
before the port, the tier 2 test being Chromium-only. WebKit can't
launch here, and CI has no WebKit.

## Release impact

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

The release that carries this carries the whole stack. Nothing needs
action. A viewer's shortcuts stay on until they turn them off, and
patches published before it behave as they did until rebuilt.

Suggested `patchChanges` line for the release, beside #1279's:

> patchy/hotkeys: a viewer can now turn single-key shortcuts off. Then a
page-wide hotkey whose every step types a character, such as `A`, `G H`
or `?`, fires nothing, while chords, named keys and hotkeys `within` an
element still fire. Label those commands so the sheet keeps them as
buttons, and write a key that belongs to one part of the page `within`
it. `window.name` carries the setting and is Patchy's: don't set it.

Landing note: #1276's migration is `0038_single_key_shortcuts`, above
#1217's `0037_feedback`. If another migration lands first, it renumbers.

- **What does a revert leave behind?**
- `shortcutSetting: 1` in the manifests of repo builds published
meanwhile. The release before reads stored manifests without refusing
extra keys, and in the rehearsal it served a version that carried the
field.
  - People's stored settings, from #1276.
  - Dismissed-note keys in browsers' `localStorage`.
- A CLI of this release refuses to publish to an older instance before
sending anything, as any mismatched release does.
- **Does the release before it still work with that?** Yes. Its shell
names no frame, so every shortcut is on, the sheet hides its row, and no
note shows.

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
allisonmahmood force-pushed the t3/fix-desktop-chromium-focus branch from 7fd6e33 to a1762a9 Compare November 11, 2026 22:01
@github-actions github-actions Bot added size:m 100-500 changed lines and removed size:s Under 100 changed lines labels Nov 11, 2026
@allisonmahmood
allisonmahmood force-pushed the t3/fix-desktop-chromium-focus branch from a1762a9 to 93f459a Compare November 11, 2026 23:00
@allisonmahmood
allisonmahmood changed the base branch from main to fix/switcher-desktop-chromium November 11, 2026 23:00
@github-actions github-actions Bot removed the size:m 100-500 changed lines label Nov 11, 2026
@github-actions github-actions Bot added the size:s Under 100 changed lines label Nov 11, 2026
@allisonmahmood
allisonmahmood force-pushed the t3/fix-desktop-chromium-focus branch from 93f459a to d4113d1 Compare November 12, 2026 00:25
@allisonmahmood
allisonmahmood force-pushed the t3/fix-desktop-chromium-focus branch 4 times, most recently from 32d200d to e12a5fd Compare November 12, 2026 04:26
@allisonmahmood
allisonmahmood changed the base branch from fix/switcher-desktop-chromium to main November 12, 2026 17:10
allisonmahmood added a commit that referenced this pull request Nov 12, 2026
…s accessibility tree (#1406)

## What changed

The tier 1 browser test "local hotkeys: the narrowest place wins" failed
in desktop Chromium. Its `statuses()` helper looked for the patch's
frame in the page's frame tree, but desktop Chromium runs the sandboxed
patch frame in its own process, so that frame isn't in the page's tree
and the helper threw `TypeError: Cannot read properties of undefined
(reading 'frame')`. Main is green only because CI still runs
chrome-headless-shell, where the frame shares the page's process.

The helper now opens a CDP session on the patch frame itself
(`context.newCDPSession(frame)`). That works when the frame has its own
target, as in desktop Chromium. In the headless shell Playwright refuses
a separate session for an in-process frame, so the helper falls back to
the page's session as before. Either way it finds the `/~content/` frame
in that session's frame tree and reads that frame's accessibility tree
with `Accessibility.getFullAXTree`, so the assertions are unchanged.

Once this lands, #1302 can drop its `headlessShellOnly` hold-out and the
headless-shell project that runs it.

Closes #1306

## Look at

The one changed line in `test/browser-tier1/hotkeys.spec.ts`, inside
`statuses()`:

```ts
const session = await context.newCDPSession(frame).catch(() => context.newCDPSession(page));
```

To check that each browser takes the path I expected, I ran once with a
temporary log, since removed. Each of the three `statuses()` calls used
the frame's own session in desktop Chromium and the page's session in
the headless shell.

## How it was verified

For desktop Chromium I used a throwaway config outside the repo. It
imports `playwright.tier1.config.ts` and sets `channel: "chromium"` on
its project, and isn't committed. The headless shell runs through the
repo's config unchanged.

**Before, desktop Chromium: red**

```
✘ [chromium] › test/browser-tier1/hotkeys.spec.ts:1025:1 › local hotkeys: the narrowest place wins, ... › over a native modal dialog, the command's announcement is in the accessibility tree

  TypeError: Cannot read properties of undefined (reading 'frame')

    > 1061 |       frameId: content(frameTree)!.frame.id
  1 failed
```

**After, desktop Chromium: green**

```
✓ [chromium] › test/browser-tier1/hotkeys.spec.ts:1025:1 › local hotkeys: the narrowest place wins, fields keep their keys, handled keys stand down, and the sheet runs a dialog's commands (2.5s)
  1 passed (10.0s)
```

**After, headless shell (`playwright.tier1.config.ts`): green**

```
✓ [chromium] › test/browser-tier1/hotkeys.spec.ts:1025:1 › local hotkeys: the narrowest place wins, fields keep their keys, handled keys stand down, and the sheet runs a dialog's commands (2.6s)
  1 passed (8.5s)
```

`pnpm typecheck:tests`, `pnpm lint` and `bun fmt --check` pass. Locally
I ran only this test. CI's `browser` job runs the rest of the tier.

## Release impact

Tick exactly one.

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

Only a test helper changed, and no product code.

- **What does a revert leave behind?** Nothing. The helper goes back to
failing in desktop Chromium.
- **Does the release before it still work with that?** Yes. Nothing that
ships changed.

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 12, 2026
…the patch (#1407)

## What changed

In Firefox, pressing a button on Patchy's own shell controls with the
keyboard left focus on the shell's page, outside the patch. That covers
the new-version bar's Not now and Hide, a download card's Download, Not
now and Dismiss, the single-key shortcuts dialog's Cancel, and Dismiss
on the note an older version shows. The patch's keys and hotkeys then
went nowhere until the person clicked. Several of those controls could
also pull focus off another shell control the person was on. Now the
next key reaches the patch in Firefox, as it already did in Chromium,
and focus comes back only from the control itself or from nowhere. CI
runs the focus tests in Firefox too, so losing that fix can't pass on
Chromium alone.

Closes #1124

## Look at

**The cause is keyboard activation.** Firefox won't hand a frame focus
during the key event that pressed a button (Enter presses on keydown,
Space on keyup), so the shell's `frame.focus()` was dropped and focus
stayed on `body`. A mouse click already handed focus back. The
switcher's close works around the same Firefox behaviour in
`packages/core`, which this PR leaves alone. On main, where the next key
went:

| Control: button, how | Firefox | Firefox, Fission on | Desktop
Chromium | Headless shell |
| --- | --- | --- | --- | --- |
| Bar: Not now or Hide, clicked | patch | patch | patch | patch |
| Bar: Not now or Hide, Enter or Space | **body** | **body** | patch |
patch |
| Card: Download, Not now or Dismiss, clicked | patch | patch | patch |
patch |
| Card: Download, Not now or Dismiss, Enter or Space | **body** |
**body** | patch | patch |
| Dialog: Turn on or off, any way (it closes once the save answers) |
patch | patch | patch | patch |
| Dialog: Cancel clicked, or Escape, at rest or mid-save | patch | patch
| patch | patch |
| Dialog: Cancel, Enter or Space, at rest or mid-save | **body** |
**body** | patch | patch |
| Note: Dismiss, clicked | patch | patch | patch | patch |
| Note: Dismiss, Enter or Space | **body** | **body** | patch | patch |

With this PR, every cell is "patch". A click on the dialog's backdrop
doesn't close it; focus moves onto the dialog, and the next Escape hands
it back.

**The fix** is one helper, `handBackFocus` in
`packages/serving/src/hand-back-focus.ts`, which the bar
(`stream-status.ts`), the cards (`downloads.ts`), the dialog and the
note (`shortcuts.ts`) all call:

- Before a control is redrawn or removed, it notes whether focus is on
that control, or, for a press of the control's own button, nowhere (on
`body`, as after a click on a button that takes no focus).
- Afterwards it focuses the frame, then tries once more a task later if
focus is still on `body`. If the person moved focus somewhere in
between, it stays there.
- Before, the bar, the cards and the note called `frame.focus()`
unconditionally after a press. That could pull focus off another shell
control, such as another card.

The bar's passive redraws, such as a new version arriving, still hand
focus back only when it was on the bar. The dialog still leaves focus in
a switcher opened over it.

**The tests** are in `test/browser-tier1/focus.spec.ts`. They press
every button clicked, with Enter and with Space, then send one ArrowDown
that must reach the patch:

- the bar's Not now and Hide;
- a card's Download, Not now and Dismiss;
- the dialog's Turn on or off and Cancel, plus Escape, a backdrop click
then Escape, and Cancel (each way) or Escape mid-save;
- the note's Dismiss.

For the bar, the cards and the note, a last step checks that a press
that moves no focus leaves it on the shell control that has it. For the
dialog, it checks that a save answering under the switcher leaves focus
in the switcher. The dialog is modal, so the switcher is the only place
outside it that focus can be.

Red on main's `stream-status.ts`, `downloads.ts` and `shortcuts.ts`
(steps stop at the first failure):

```
✘ [firefox] › focus.spec.ts:145 › … new-version bar's Not now or Hide … › Not now, pressed with Enter   Expected: 3  Received: 2
✘ [firefox] › focus.spec.ts:182 › … a download card's Download, Not now or Dismiss … › Download, pressed with Enter   Expected: 2  Received: 1
✘ [firefox] › focus.spec.ts:229 › … the single-key shortcuts dialog closes … › Cancel, pressed with Enter   Expected: 1  Received: 0
✘ [firefox] › focus.spec.ts:341 › … Dismiss on an older version's note … › Dismiss, pressed with Enter   Expected: 1  Received: 0
✘ [firefox-fission]   the same four steps, the same counts
✘ [chromium-desktop]  bar, card and note › a press that moves no focus leaves it on the shell control that has it
    Error: expect(locator).toBeFocused() failed   Received: inactive
✓ [chromium-desktop]  dialog (Chromium never dropped its focus)
✘ [chromium]          bar, card and note, the same step
✓ [chromium]          dialog
14 failed, 2 passed
```

Green with this PR, the whole `focus.spec.ts` in all four setups:

```
✓ [firefox] › focus.spec.ts:229 › the next key reaches the patch after the single-key shortcuts dialog closes, by its buttons clicked or pressed, Escape or mid-save (3.7s)
✓ [firefox] › focus.spec.ts:341 › the next key reaches the patch after Dismiss on an older version's note, clicked or pressed (1.1s)
✓ [firefox-fission] › … both (3.6s, 1.2s)
✓ [chromium-desktop] › … both (3.0s, 1.1s)
✓ [chromium] › … both (2.5s, 789ms)
32 passed
```

**CI now guards the Firefox half.** Chromium hands focus back on the
first try, so before this, CI stayed green with the second try deleted.
Two guards now cover it:

- The tier 1 config has a `firefox` project that runs `focus.spec.ts`
alone, with `fission.webContentIsolationStrategy: 1`. The `browser` job
runs it after the Chromium suite (`pnpm test:browser:firefox`), and so
does `pnpm verify`.
- The bar's test makes the shell's first `frame.focus()` miss in any
browser. It checks that the second try hands focus back, and that focus
moved to another shell control between the two tries stays there. That
runs in the Chromium project too.

With the second try deleted from `hand-back-focus.ts`, both projects go
red:

```
✘ [chromium] › focus.spec.ts:172 › … new-version bar's Not now or Hide … › a first try that misses is made again once the press is over
    Error: expect(locator).toBeFocused() failed   Received: inactive
✘ [firefox]  › focus.spec.ts:172 › … new-version bar's Not now or Hide … › Not now, pressed with Enter
    Error: expect(locator).toBeFocused() failed   Received: inactive
```

With the second try made unconditional, ignoring where the person moved
focus:

```
✘ [chromium] › focus.spec.ts:172 › … › focus moved to another shell control between the two tries stays there
    Error: expect(locator).toBeFocused() failed   Received: inactive
```

Each next-key check now first waits for focus to be back on the frame.
Chromium runs input ahead of the second try's task, so an immediate key
could otherwise arrive first. On main or without the second try, focus
never comes back, so those checks still fail.

**The `browser` job's time** (this branch, the Chromium suite
unchanged):

| | `browser` job | Chromium suite | Firefox install | Firefox suite |
| --- | --- | --- | --- | --- |
| Before, at `6a44579` | 649 s | 620 s | none | none |
| After, at `f13a3fe` | 613 s | 542 s | 8 s | 26 s |

Firefox adds 34 s, its download included on this first run, which also
saved it to the cache. The Chromium suite's own time varies from run to
run, which is why the total fell.

## How it was verified

- `focus.spec.ts` passes in the tier 1 config's `chromium` and `firefox`
projects (16 tests). Through a throwaway config kept outside the repo,
it also passes in desktop Chromium (`channel: "chromium"`, where the
frame has its own process) and in Firefox with Playwright's default
isolation.
- The Firefox project takes 24 s locally with the browser installed. The
Playwright action takes a `browser` input. Chromium keeps its cache key
and path, so the other jobs' caches stay warm, and Firefox gets an entry
holding only `firefox-*`.
- `docs/DEVELOPMENT.md` says which spec runs in Firefox and why. It and
the README install Firefox beside Chromium, since `pnpm verify` now
needs it.
- #1302 edits the same config, action and docs. A trial merge of its
changes onto this branch merges the action, the workflow, `package.json`
and the docs cleanly. It conflicts only inside `projects: [...]` in
`playwright.tier1.config.ts`, where the fix is to keep its two Chromium
projects and add the `firefox` entry.
- `shortcut-setting.spec.ts` passes in all four setups, 54 passed and 2
skipped (the tier 2 case skips outside Chromium). Those tests pin the
dialog's abuse contract: one dialog at a time, and a fresh press after
any close.
- `downloads.spec.ts` and the bar's `stream.spec.ts` tests pass in
Chromium. `pnpm format:check`, `pnpm lint` and `pnpm typecheck` pass.
- The table comes from a probe that pressed every button every way in
all four setups, on main and with this PR. With the fix, all 128 cells
reach the patch.
- The `patchy-hotkeys` skill now names Hide beside Not now. Its line, "A
download card's buttons and the new-version bar's Not now and Hide hand
focus back themselves", reads true. Patch code has nothing to do about
the dialog, whose closing the page's sheet already follows.
- Not checked: headful Firefox and Safari on macOS, where a clicked
button takes no focus. The "from nowhere" rule is what keeps that case
handing focus back.

## Release impact

Tick exactly one.

- [ ] **Breaking** — requires action from anyone already running this
- [x] **Not breaking** — no action required. The shell's own script and
one project skill line change, with no API, schema or CLI change.

- **What does a revert leave behind?** Nothing. The shell script and the
skill are served with each release.
- **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 12, 2026
…patch (#1412)

## What changed

In desktop Chrome, where a patch's frame runs in its own process, the
keyboard could land on Patchy's shell instead of the patch just after
the patch opened. The patch showed a focused field, but typing went
nowhere, and ⌘⇧K could open the switcher while keys still went to the
patch. The shell now spots when its own page takes focus the person
didn't ask for, while it holds nothing of its own, and gives the keys
back to the frame. A press or selection on the shell's own content, such
as a download card, keeps its focus.

The other switcher failures in #1402 were tests acting before the
browser could keep up. They now wait for the real signal.

Closes #1402

## Look at

**The bug, in `packages/serving/src/broker.ts`.** A diagnostic run on
#1302's branch logged every trusted focus, blur, press and switcher
message in the shell and its frame. Of 405 switcher runs in desktop
Chromium on CI, the grabby case failed once:

```
+728 shell  message hello                    the broker focuses the frame
+728 shell  focus patch
+732 shell  focus patch, focus window        the browser focuses the shell's own page; activeElement is still the frame
+734 frame  focus window
+850 frame  mousedown field, focus field     the click reaches the field
+857 shell  keydown Control, Shift, K        the keys reach the shell, target the frame element
+868 shell  focus INPUT                      the menu opens; the frame is never told it lost focus
```

When a frame's new document commits while the shell's page holds focus,
Chromium gives the frame's process page focus without saying which frame
has it. Blink resets that process's focus to the main frame and reports
it back. If the broker's `frame.focus()` on `hello` reaches the browser
first, that stale report wins. The shell's page takes focus while the
frame is still its `activeElement`, and both sides then believe they're
in sync:

- `frame.focus()` does nothing, because the frame already is the focused
element.
- A click in the frame sends nothing, because the frame thinks it
already has focus.

Keys then go to the shell while the patch shows a caret. In the other
order they go to the frame while the shell thinks the menu has them,
which is where the flip case lost its Enter.

In that state the shell's window takes focus while the shell holds
nothing of its own. Its active element is still the frame, or the body
once the frame has had the keys back this way before: that move clears
the shell's focused element. The broker answers a task later with
`frame.contentWindow.focus()`, which moves focus into the frame for
real. A move to shell UI, such as the switcher or the starting cover,
has its own active element by then. A frame still waiting for its
relay's `hello` is left alone, as before.

It answers only focus the person didn't ask the shell for: the race, a
tab or window coming back, an alert or devtools closing. A press on the
shell's own content, such as dragging across a download card's file
name, brings the shell focus within that press's own task. So a
capturing `mousedown` on anything but the frame element marks that task,
and its focus stays. A press on the frame element is the misrouted one
meant for the frame. A window that comes back to text the person
selected in the shell keeps the keys too, as when they select a file's
name and switch tabs. Two conditions limit that:
- **The shell held the keys as its window last lost focus.** The shell
window's `blur` notes whether the frame was its active element, meaning
the keys went into the patch, by a click or the shell's own hand-off.
Once they have, a selection still showing in the shell holds nothing:
the fourth version missed that, and every fall after a click back into
the patch stayed on the shell. The race starts from the frame having the
keys, so it still repairs.
- **Only text the person can see and copy** (`getSelection().toString()`
isn't empty). A selection left in content since hidden, such as a
download card folded away under "1 more file", is still not collapsed
but copies nothing. Counting it, as the third version did, turned the
repair off for good.

A click on blank shell space then behaves as on `main`, with the keys
staying on the shell.

The new test is `keys that fall out of the frame onto the shell go back
to the frame, and ⌘⇧K ↵ still flips`. The frame's own `parent.focus()`
reproduces what the broker sees: keys on the shell's document while the
frame is still its active element. It doesn't reproduce the full
disagreement between processes, because `parent.focus()` blurs the frame
normally. So the test proves the keyboard comes back; the CI log above,
captured as it happened, is the evidence for the race itself. It falls
out twice, since the second time the shell's body is active: the first
version of this fix covered only the frame, and its test failed on
#1302's CI after an earlier repair had cleared the shell's focused
element.

Two more tests use a patch that offers four files, so the shell shows
three cards and folds the oldest away under "1 more file":
- `text selected in the shell's own content is what Copy copies, until
the keys go back to the patch` drags across a card's file name and
presses Copy. It then clicks back into the patch and makes the keys fall
twice; the patch must hear `x` each time.
- `across a tab and back, the shell keeps the keys for text it shows
selected, and only that` switches tabs for real, with focus emulation
off. Coming back to a visible selection, Copy still copies it. Coming
back to a selection in the folded card, the patch hears the next key.
The test selects that one by script, because folding the card over a
selection by hand leaves it there only some of the time. Playwright's
headless shell keeps every tab focused, so this test runs in desktop
Chromium only.

```
                                        copy, then back to the patch   across a tab
second fix, before the press guard      ✘ Copy reached the patch
third fix, any non-collapsed selection  ✘                              ✘ the hidden selection held the keys
fourth fix, any visible selection       ✘ the falls stayed on the shell ✓
now                                     ✓ 3 of 3, both builds           ✓ 3 of 3, desktop Chromium
```

The falling-out test:

```
before                       desktop Chromium   ✘ the frame never has focus again: Expected true, Received false
                             headless shell     ✘ the same
first fix, frame only        desktop Chromium   ✘ the second fall: the shell's body is active, never repaired
now                          desktop Chromium   ✓ 5 of 5
                             headless shell     ✓ 5 of 5
```

**Clicking a frame before it is drawn, in
`test/browser-tier1/drawn.ts`.** Desktop Chromium sends a press to the
frame's process by what the shell last drew. So a click as soon as the
frame shows in the DOM lands on the shell. A probe hides the frame with
`visibility` or `inert`, then clicks the moment it is back:

```
                   click at once         after two animation frames
desktop Chromium   5 of 500 on the shell 0 of 500
headless shell     0 of 60
```

A person can't click a frame before it is drawn. The switcher specs now
wait two animation frames before clicking into a frame they just showed.
With the broker fix, such a press no longer strands the keys on the
shell, but the field under it still never hears it.

**The notice case was a test race.** It recorded `/switcher.json` ahead
of the notice's own navigation request. A signed-out notice loads no
switcher, so that request came from the patch before it. That case, and
the public-patch case, now wait for the patch's own list request to land
before they watch.

That wait, `listedAfter`, counts only the destination page's own list.
An init script notes what the tab held as each page began, before any of
its own scripts run, and only a copy saved since counts. Reading the
tab's copy before going instead, as this PR first did, let an ask the
page before still had on its way satisfy the wait before the new page's
switcher had asked. Reproduced with the page before's request held past
that read and the destination's switcher script held 1.5 s:

```
copy read before going    ✘ the destination's /switcher.json was recorded
the page's own start      ✓ waits for that request, then records nothing
```

How #1402's five failures map:

| Case | Cause |
| --- | --- |
| grabby: the patch's `blur` never ran | the focus race |
| ⌘⇧K ↵ flips back: Enter went nowhere | the focus race, keys left in
the frame |
| notice: `/switcher.json` recorded | test race, the patch's own request
|
| public patch: `a` never typed | the focus race or an early click |
| relay at public scope: the shell claimed the chord | the focus race or
an early click |

## How it was verified

- **On CI's runners in desktop Chromium, at this head.** #1302, stacked
on this PR, ran its `browser` job twice in a row on one head, `e12a5fd`:
176 passed each time, none failed or skipped, so the tab test ran there.
- **This PR's own `browser` job, in the headless shell, failed once.**
The case was `hotkeys.spec.ts` "the sheet's row asks Patchy, waits past
the reply deadline…". Its stand-in shell loads no Patchy script, the
same case also failed on that machine with `main`'s broker, and no issue
tracks it yet. On its rerun: 175 passed, and the tab test skipped as
designed.
- **Earlier heads,** with #1302 stacked on this PR's earlier commits:
  - At the first head, five passes in a row.
- At the second, one `shell.spec.ts` failure, the known #1377 flake.
That test serves its own pages with no patch frame.
- Also at the second, one failure of this PR's own new test, the
twice-falling gap fixed above.
- At the third, three passes in a row. Its rule took Copy from shell
text, which Sol's review caught; the press guard fixes it.
- At the fourth, two passes in a row. Its selection guard also counted a
hidden selection, which Sol's review caught and the copyable-text check
fixes.
- At the fifth, two passes in a row, and one `test (bun)` failure in
`packages/execution/src/Fleet.test.ts`, a clock-step case that passed on
its rerun. Its selection guard held the keys after a click back into the
patch, which Sol's review caught and the `blur` note fixes.
- **Locally at this head:**
- Switcher, switcher-relay and focus specs, `--repeat-each=3`: desktop
Chromium 108 of 108; headless shell 105 passed, with the tab test's 3
skipped.
- The first desktop run of that set failed Test A once: its drag landed
before the shell had drawn the new cards, so the press reached the
patch. `openOffering` now waits for a drawn frame before any press on
them, as the other specs do before clicking into a frame they just
showed.
- One local run failed to start its test server because the port was in
use; its rerun passed.
- **Each test against older brokers, in desktop Chromium:**
  - At 246b760, the click-back test fails and the tab test passes.
  - At aa2fdeb, both fail, the tab test at its hidden selection.
- **Tier 1 suite locally, three heads back:** desktop Chromium 173
passed, with the hotkeys test #1302 holds out excluded; headless shell
174 passed.
- **Earlier locally:** `hotkeys.spec.ts` "the sheet's row asks Patchy…"
failed 9 of 10 in the headless shell with `main`'s broker. Its stand-in
shell loads no Patchy script, it passed in a later full run there, and
`main`'s CI passes it. It's flaky on that machine, unrelated to this PR.
- **`pnpm typecheck`, test typecheck and `pnpm lint` pass at this
head.** `pnpm check` at the first head: format, lint, typecheck and
synth passed. The offline tests' only failures were
`packages/sdk/src/install.test.ts`, where that machine's test
environment has no `npm` on PATH; this PR doesn't touch that package.
- **Not checked:** headed Chrome on a real display, and other browsers.
The tab test runs only in desktop Chromium; a window return from another
app is the same browser focus path but isn't run. Firefox doesn't blur
the shell's window when its frame takes focus, so the new listener
rarely fires there, and focusing an already-focused frame is harmless.

Hit every surface: only the shell's broker script changed, so served
pages; no HTML or CSS changed. The wire contract, CLI, dev loop,
vocabulary, migrations, company resources, reverse states and repo
layout don't apply.

## Release impact

Tick exactly one.

- [ ] **Breaking** — requires action from anyone already running this
- [x] **Not breaking** — no action required. One listener in the shell's
broker, and tests.

- **What does a revert leave behind?** Nothing. The shell goes back to
leaving those keys where Chrome put them.
- **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
allisonmahmood force-pushed the t3/fix-desktop-chromium-focus branch from e12a5fd to a92a7f1 Compare November 12, 2026 19:04
… its own process

Desktop Chromium runs a patch's sandboxed frame in its own process and
Playwright's default headless shell keeps it in the shell's, so focus and
keyboard checks could pass in CI and fail in Chrome (#1299, fixed on main by
the relay's hello handoff in #1298). The tier 1 suite's chromium project now
runs desktop Chromium in new headless mode, every test in it; the firefox
project still runs focus.spec.ts alone.

Closes #1299

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood force-pushed the t3/fix-desktop-chromium-focus branch from a92a7f1 to 6219540 Compare November 12, 2026 19:39
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Acceptance: PASS with notes

Checked 621954093193547076bca91153bf630e420876e4 (base 1f67b0dea97babc06d92980ad05a0ff9545b73bf, main) on the tier 1 suite's own throwaway instances, by Claude Opus 5.5 in Claude Code (through T3 Code). This replaces my verdict on d4113d1: since then the PR dropped the headless-shell hold-out (#1406 fixed that test) and rebased onto main.

git range-diff a92a7f1~1..a92a7f1 HEAD~1..HEAD prints 1: a92a7f18 = 1: 62195409, so the commit is unchanged since the builder's runs at a92a7f1. git diff a92a7f1 HEAD touches only #1413's files (scripts/dev/** and its hunks in docs/DEVELOPMENT.md).

Done means (#1299, the CI line; #1298 fixed the focus bug on main)

  • The suite runs desktop Chromium, and the patch's frame is out of process. Passed. I ran a throwaway wrapper config in the git-ignored .local/. It spreads this PR's playwright.tier1.config.ts with its projects untouched and adds one plain project for contrast. Its one probe opens a tier 1 patch, calls CDP Browser.getVersion and Target.getTargets, then presses a real c with no click. With DEBUG=pw:browser:
    $ DEBUG=pw:browser pnpm exec playwright test -c <wrapper> --project=chromium --project=contrast-headless-shell
    pw:browser <launching> …/chromium-1243/chrome-linux64/chrome --headless …
    pw:browser <launching> …/chromium_headless_shell-1243/chrome-headless-shell-linux64/chrome-headless-shell --headless …
    PROBE [chromium] channel="chromium" product=Chrome/153.0.8010.12
          targets=[browser_ui, browser_ui, page, iframe /~content/…] iframeTargets=1 realC-noClick=1:c
    PROBE [contrast-headless-shell] channel=null product=HeadlessChrome/153.0.8010.12
          targets=[page] iframeTargets=0 realC-noClick=1:c
      2 passed (7.0s)
    
  • Projects. Passed. Only chromium and firefox exist. firefox holds only focus.spec.ts, and nothing runs in the headless shell:
    $ pnpm exec playwright test -c playwright.tier1.config.ts --list
        180   [chromium]
          8   [firefox]      all 8 in focus.spec.ts
    Total: 188 tests in 27 files
    
    No spec, config or doc names headlessShellOnly or a chromium-headless-shell project. fix(serving): keys desktop Chrome leaves on the shell go back to the patch #1412's tab-switch test (switcher.spec.ts:396) skips unless project.use.channel === "chromium", so it now runs.
  • Locally, with the PR's scripts. Passed:
    $ pnpm test:browser test/browser-tier1/focus.spec.ts
    $ playwright test -c playwright.tier1.config.ts --project=chromium test/browser-tier1/focus.spec.ts
      8 passed (40.8s)
    $ PATCHY_TIER1_SKIP_BUILD=1 pnpm test:browser:firefox
    $ playwright test -c playwright.tier1.config.ts --project=firefox
      8 passed (19.3s)
    $ PATCHY_TIER1_SKIP_BUILD=1 pnpm test:browser test/browser-tier1/hotkeys.spec.ts -g "local hotkeys: the narrowest place wins" --repeat-each=3
      ✓ 1 [chromium] › hotkeys.spec.ts:1025:1 › local hotkeys: the narrowest place wins… (1.6s)
      ✓ 2 [chromium] › hotkeys.spec.ts:1025:1 › local hotkeys: the narrowest place wins… (1.6s)
      ✓ 3 [chromium] › hotkeys.spec.ts:1025:1 › local hotkeys: the narrowest place wins… (1.5s)
      3 passed (14.0s)
    
  • The npm scripts and docs match the config. Passed. test:browser is --project=chromium and test:browser:firefox is --project=firefox. docs/DEVELOPMENT.md says browser runs "tier 1 and 2 pages in desktop Chromium, and focus.spec.ts in Firefox", that focus.spec.ts alone runs in Firefox with pnpm test:browser:firefox, and that the suite uses channel: "chromium". All of that matches the config. scripts/verify.ts runs test:browser then test:browser:firefox, as the doc says. The action's new comment is accurate: the install line is still playwright install chromium without --only-shell, which puts both builds in Chromium's one cache entry.

CI

On the head (run), browser was still running when I posted. Install Chromium took 6s, a cache hit, and the desktop Chromium step started at 19:40:38Z and hadn't finished at 19:46Z. Its Firefox steps hadn't started. Every other check that had finished had passed. test (22), test (24) and test (26) were still pending. The commit and the suite match the builder's runs below: #1413 touches nothing the tier 1 suite loads, which imports only scripts/dev/src/postgres.ts from scripts/dev, and #1413 leaves that file alone.

The builder's two runs at a92a7f1, the same tree minus #1413 (run, attempts 1 and 2):

attempt 1  browser success  11m11s  desktop Chromium step 10m01s: Running 180 tests … 180 passed (10.0m)
                                     Install Firefox 8s; Firefox step 30s: Running 8 tests … 8 passed (29.0s)
attempt 2  browser success  12m48s  desktop Chromium step 11m37s: Running 180 tests … 180 passed (11.6m)
                                     Install Firefox 4s; Firefox step 34s: Running 8 tests … 8 passed (33.9s)
each: 180 ✓ [chromium], 8 ✓ [firefox], no ✘, none skipped, no [chromium-headless-shell] line;
      ✓ hotkeys.spec.ts:1025 "local hotkeys: the narrowest place wins…" and ✓ switcher.spec.ts:396 "across a tab and back…" in [chromium]

Golden journeys: none touched. The diff changes test config, CI step names, an action comment and doc lines. Nothing in it is served or shipped.

Rollback answers: they match the diff. git diff HEAD HEAD~1 --stat covers the same four files, and none of them is a migration, packages/api, apps/infra, package.json or the lockfile. A revert puts back { name: "chromium", use: { ...devices["Desktop Chrome"] } }, the same project as the probe's contrast project, which launched chrome-headless-shell. The action's cache key and install line don't change (only a comment does), so a revert leaves nothing in the cache to clean up. No one-way label is needed.

Not run

  • The full tier 1 suite locally. CI covers it, and this machine is shared.
  • Headed Chrome on a real display. New headless is the same build, and CDP shows the frame out of process.

Notes

  • The head's own browser job hadn't finished when I posted, so I can't cite its counts here. The CI evidence is the two green runs at a92a7f1, the same patch on the previous main. When the head's job finishes it should show Running 180 tests … 180 passed for [chromium] and Running 8 tests … 8 passed for [firefox]. If that job goes red from the change rather than a known flake, this verdict becomes a FAIL and the head needs a new run.

@allisonmahmood
allisonmahmood merged commit df0f62e into main Nov 12, 2026
26 checks passed
@allisonmahmood
allisonmahmood deleted the t3/fix-desktop-chromium-focus branch November 12, 2026 19:54
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Merged after its head's own browser job passed: 180 in desktop Chromium and 8 in Firefox, 13 minutes. That fills the gap the acceptance note left open.

allisonmahmood added a commit that referenced this pull request Nov 12, 2026
## What changed

A patch's page runs in a frame inside Patchy's page. A `<dialog>` opened
with `showModal()` makes only the patch's own page inert. So Tab past
the dialog's last control, or Shift+Tab before its first, moved focus
out of the frame onto Patchy's controls or the browser's, and Escape
could then stop closing the dialog.

Pages built with the SDK now keep Tab inside a **plain** modal dialog,
and leave every richer dialog's Tab to the browser, exactly as it moves
today. A small helper in `patchy` (`packages/patchy/src/modalTab.ts`)
handles a Tab that nothing on the page took, from the last stop of the
plain modal dialog focus is in. It focuses the dialog's first stop, and
the reverse for Shift+Tab. A plain dialog with no controls keeps focus.

`patchy/preact`, the generated client and `HotkeySheet` install it once
per document. Patchy injects nothing into served pages, so **published
patches keep the old behaviour until they're rebuilt and published again
on the release that ships this.**

Closes #1263

## Look at

**What "plain" means** (`isPlain`, an allowlist). Every element in the
dialog must be one of these:
- ordinary containers and text: `div`, `span`, `p`, headings, `label`,
`form`, an enabled `fieldset` and its `legend`, lists, sectioning
elements, table elements, inline text tags, `br`, `hr`, `img` without
`usemap`, and SVG that only draws (no `a`, `use`, `foreignObject` or
`tabindex`);
- controls Tab stops on once: `button`, `a`, `select` with options that
have no `tabindex`, `details` whose first child is its own `summary`,
checkbox and one-line text-like `input`s, and an element with `tabindex`
0 or -1.

It must also have none of these, anywhere in the dialog:
- a `popover` attribute, or an open popover anywhere in the page;
- a computed `display: contents`, a `reading-flow` other than `normal`,
or `interactivity: inert` that no `inert` attribute inside the dialog
explains (Chromium draws the attribute as `interactivity: inert` too,
and its subtree is never a stop);
- a shadow root or custom element;
- a dialog or descendant that scrolls;
- a positive `tabindex`;
- editable content, a textarea or a radio.

Anything else makes the dialog not plain, and then the helper does
nothing.

**Cost.** A Tab first checks, with a tree walker, that nothing after the
focused element (before it, for Shift+Tab) may take focus. Only at an
end does it walk the dialog and read computed styles, so a Tab between
stops costs no more than that check.

**How it decides, unchanged from the last round.**
- **The topmost modal** is the one focus is in.
- **It decides last.** A capture listener on `window` re-appends the
deciding listener to the end of `window`'s list, so it runs after every
listener already on the key's way, and a `preventDefault()` from them
wins.
- **When it wraps,** it calls `preventDefault()` and `focus()` during
the keydown. There are no timers, no `blur` handling and no retries, and
nothing is inserted into the author's dialog. Escape is the browser's.

**`HotkeySheet` keeps its own Tab handler,** as on main. Its dialog
scrolls once its card outgrows the viewport, which makes it not plain,
and its buttons are all it holds. So its own wrap stays sure, and the
sheet is never worse than main. The helper sees that handler's
`preventDefault()` and stays out, and the sheet still installs the
helper for the page's other dialogs.

**Sol's round 3.**

| Item | Now | Step |
| --- | --- | --- |
| 1. Popover | any `popover` attribute, or an open popover anywhere in
the page, isn't plain | from the control that opened a popover in the
dialog |
| 2. `display: contents`, and stops inside editable content | not plain
| before a shadow host laid out as display: contents; before an editable
region with a stop inside that shows |
| 3. A closed root on a standard element | **dismissed** (below) | |
| 4. `<area href>` | `img` with `usemap` isn't plain, and `map` and
`area` aren't on the list | before an image map's link |
| 5. A scrolling dialog | not plain | in a dialog that scrolls |
| 6. `reading-flow` | not plain | where reading-flow orders the dialog |
| 7. A canceller registered during capture | **dismissed** (below) | |

The two dismissals:
- **Item 3** can't be detected. A closed root on a standard element
exposes no `shadowRoot`, and it takes page code attaching one to a `div`
inside a modal. It's stated in the code.
- **Item 7** needs a page that registers a bubble listener on `window`
from a capture listener during the same key's dispatch. That's exotic.
There's no cheap exact fix: once the bubble at `window` has begun,
nothing added later in that dispatch can run after it. It's stated in
the code.

**Sol's round 4**, four tightenings inside the allowlist:

| Item | Now | Step |
| --- | --- | --- |
| 1. `<details>` without an authored `<summary>` | plain only when its
first child is its own `summary` | before a details element whose
summary the browser draws |
| 2. SVG `<a>` in `<defs>` drawn through `<use>` | SVG with `a`, `use`,
`foreignObject` or a `tabindex` isn't plain | after SVG that draws a
link through use |
| 3. CSS `interactivity: inert` | not plain, unless an `inert` attribute
explains it | where CSS makes the first control inert |
| 4. `<option tabindex="0">` | an option or optgroup with a `tabindex`
isn't plain | from a select whose option is given a tabindex |

Soft runs in `chromium` (desktop) and `firefox`:
- **Main:** all four new steps pass in Chromium.
- **9a9f2d8:** in Chromium, all four fail. In Firefox, items 1, 2 and 4
fail.
- **The Firefox exception:** Firefox has no `interactivity`, so there
the dialog is plain and wraps. Like reading-flow, the step checks for
support, and that branch fails on main in Firefox.
- **Two cases didn't reproduce at first,** so I rebuilt them to Sol's
setups. A `select multiple` showed its option, which the old end check
already saw, so the select case is a dropdown. In the earlier round, the
editable case needed the region itself to be no stop while a stop inside
it shows.

**Sol's round 5.**
- **The P2, an `inert` ancestor outside the modal:** a modal dialog
escapes its ancestors' inertness. Native Tab from A reaches B in
Chromium and Firefox, and both report `interactivity: auto` inside it.
The helper used `closest("[inert]")`, found no stops, and cancelled the
Tab. It now counts `inert` only from the dialog down to the element
(`isInertIn`), for stops and for the `interactivity` rule alike.
- **The new step,** "in a dialog inside an inert container, whose
inertness it escapes":
- **on main:** Tab from A reaches B in both browsers, and only the wrap
that follows fails, as in every wrap step;
  - **at 87129a3:** it fails at B in both;
  - **at head:** it passes, with the wrap.
- **The P3:** the skill now says CSS `interactivity: inert` outside an
`inert` subtree.

**Red and green.** Every assertion was made soft for a local run, with
base source restored by `git restore --source=<base> --
packages/patchy/src packages/sdk/src/generateClient.ts`. The runs were
in the headless shell, desktop Chromium (`channel: "chromium"`, now the
repo's `chromium` project after #1302) and Firefox.

| Step | Main | Previous head 90f4f7c | Head |
| --- | --- | --- | --- |
| both ways round its controls, past the ones Tab skips | ✘ | ✓ | ✓ |
| with rows added while it is open | ✘ | ✓ | ✓ |
| in a dialog opened over it, though that one comes first in the page |
✘ | ✓ | ✓ |
| on the dialog itself while it has no controls | ✘ | ✓ | ✓ |
| after a wrap, a click on Patchy's page keeps focus there | ✘ (at the
wrap) | ✓ | ✓ |
| onto a first field that takes a quarter of a second to focus | ✘ | ✓ |
✓ |
| from the dialog on top once the one below is written open | ✘ (at the
wrap) | ✓ | ✓ |
| the Preact page's Native `<dialog>` | ✘ | ✓ | ✓ |
| where a window listener the page added later takes Tab | ✓ | ✓ | ✓ |
| a control that takes Tab, a removed row, a date input, a closed shadow
root, a radio group, positive tabindex | ✓ | ✓ | ✓ |
| from the control that opened a popover in the dialog | ✓ | ✘ | ✓ |
| before a shadow host laid out as display: contents | ✓ | ✘ | ✓ |
| before an editable region with a stop inside that shows | ✓ | ✘ | ✓ |
| before an image map's link | ✓ | ✘ in both Chromiums | ✓ |
| in a dialog that scrolls | ✓ | ✘ in both Chromiums | ✓ |
| where reading-flow orders the dialog | ✓, ✘ in Firefox | ✘ in both
Chromiums | ✓ |

The native steps assert that nothing took the Tab, so the browser moves
focus as on main. Where the browser has no `reading-flow`, as in
Firefox, that dialog's order is the page's, so it is plain and wraps;
the step checks for that.

At head, 9a73b37:
- all of `focus.spec.ts` with `--repeat-each=3` in `chromium` and
`firefox`: 60 passed;
- `hotkeys.spec.ts` and `shortcut-setting.spec.ts`: 27 passed.

**Where it installs.**
- **`patchy/preact`:** the issue named `preact/runtime.ts`, but the
repo's lint forbids `../` imports from `packages/patchy/src/preact/`, so
the call sits in `src/preact.ts`, the `patchy/preact` entry. Pages may
import only SDK entry points, so every Preact page imports it to render.
- **The generated client:** it calls `keepTabInModals()` from
`patchy/client`. Pages reach `patchy/client` only through the generated
client.

## How it was verified

- **Browser, tier 1:**
- **`focus.spec.ts`:** the three-way comparison above, in the headless
shell, desktop Chromium and Firefox (CI's projects, with Fission on).
- **Hotkeys and the shortcut setting:** `hotkeys.spec.ts` and
`shortcut-setting.spec.ts` in the `chromium` project, now desktop
Chromium, 27 passed. That includes the sheet's own Tab round its
buttons.
- **Unit:** the `client.test.ts` case per tier checks that the generated
client's page bundle carries the helper. With `hotkeys`, `hotkeySheet`,
`hotkeyRules`, `devLifecycle` and `pageImports`, 75 passed.
- **Checks:** `pnpm format:check`, `pnpm lint`, `pnpm typecheck:tests`,
and the `patchy` typecheck and build.
- **Not run:**
  - `pnpm verify` in full, WebKit, and headful browsers.
- The SDK's `install.test.ts`, which fails on this machine because its
sandboxed `PATH` finds no npm. It doesn't touch this change.

**Hit every surface.** These applied:
- **The CLI:** `patchy/client` exports `keepTabInModals`, and the
generated client calls it. `packages/patchy/README.md` says Tab wraps in
plain dialogs and richer ones keep the browser's.
- **Project skills:** the `patchy-hotkeys` project skill, which is
release-bound and has no lock hash. Its Native `<dialog>` section says
what counts as plain in a sentence, including that an open popover
anywhere in the page turns wrapping off, and drops the rule #1256 added
that told agents to handle Tab themselves.

None of the others apply: no wire contract, dev loop, vocabulary,
migration or company resource change. Served pages are untouched, since
Patchy injects nothing. There are no reverse states and no layout
change.

**Release note.** The line for the next release's `patchChanges`:

> In pages on `patchy/preact` or the generated client, Tab now wraps
inside a plain modal `<dialog>` opened with `showModal()`: from its last
control to its first, and Shift+Tab from its first to its last; a plain
dialog with no controls keeps focus. A plain dialog holds only ordinary
containers and text with buttons, links, selects, checkboxes, summaries,
one-line inputs and elements with `tabindex="0"`. A richer dialog, such
as one with a textarea, radio, date input, frame, popover, custom
element, scrolling region or positive `tabindex`, keeps the browser's
own Tab, and so does every dialog while a popover is open anywhere in
the page. There, Tab can still leave for Patchy's page, where Escape
stops closing the dialog. A patch's own Tab wrapping for a plain dialog
can come out. Versions already published behave as before until they're
built and published again.

## Release impact

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

SDK page behaviour only, and only in patches rebuilt on this release.
Nothing changes on the server or in published versions.

- **What does a revert leave behind?** Patches built and published while
this was in place keep the helper in their bundles. Nothing else.
- **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 12, 2026
…ey shortcuts (#1421)

## What changed

This adds release 42's What's new entry, written from `1cd6d12`. It
covers everything merged since release 41's `through` (`a25a9c5`), and
sets the `patchy` release to `0.42.0` in `packages/patchy/package.json`
and `CURRENT_RELEASE`.

| Change | PRs |
| --- | --- |
| New: Tell Patchy what it's missing | #1217, #1218, #1219, #1227, #1228
|
| New: Turn off single-key shortcuts | #1276, #1279, #1301 |
| Fixed: Typing reaches the patch again | #1407, #1412 |
| Fixed: Dialogs in patches keep your place | #1420, #1255 |
| Behind the scenes: plainer facts for agents building patches | #1249,
#1256, #1297, #1418 |
| Behind the scenes: Patchy stores teams and audiences ahead of teams |
#1416 |
| Patch changes: Mod+/ and `client.close()` in patchy/hotkeys;
single-key shortcuts can be off; Tab wraps in plain modal dialogs |
#1279, #1301, #1420 |

#1376 is release 41's own entry. #1400, #1406, #1414, #1415, #1302,
#1413 and #1419 are test, CI and dev tooling and need no line.

The teams bridge (#1416) ships alone in this release so teams (#1417)
can follow in the next one with a release to roll back to that reads its
data closed.

## Look at

- **The entry**, at the top of `releases` in
`packages/core/src/whatsNew.ts`.
- **Rollback safety, from the live commit `7f93b91` (release 41) to this
PR's merge.** No PR in the range is labelled `one-way`, and every
Release impact answer says release 41 still works:
- **#1217** adds migration `0037_feedback`, a schema release 41 never
reads. **#1227** and **#1228** write into it.
- **#1276** adds migration `0038_single_key_shortcuts`, a column with a
default that release 41 never selects.
- **#1416** adds migrations `0039_company_teams` to
`0041_connection_audiences`, which hold tables that stay empty until
teams ship, and widens one scope check. Its CI rehearsal ran `7f93b91 →
head → 7f93b91 → head` on one set of data, and all four steps passed.
- **#1279**, **#1301**, **#1255** and **#1420** change the SDK and the
shell. Patches built on this release carry a `shortcutSetting` manifest
field that release 41 reads without refusing, and its shell names no
frame, so every shortcut stays on.
- **#1218** and **#1219** add CLI commands and an optional
`feedbackHint` in `--json` failures. A CLI from this release refuses to
publish to an older instance before sending anything, as any mismatched
release does.
  - Everything else is skill text, docs, tests and CI.

If this release misbehaves, roll back to `7f93b91` (release 41).

Written by Claude Opus 5.5 in Claude Code, through T3 Code.

🤖 Generated with [Claude Code](https://claude.com/claude-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:docs Touches the docs area size:s Under 100 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(serving): a patch doesn't hear keys until clicked in desktop Chrome

1 participant