Skip to content

fix(serving): in Firefox, Patchy's shell controls hand focus back to the patch - #1407

Merged
allisonmahmood merged 1 commit into
mainfrom
t3/37255863
Nov 12, 2026
Merged

allisonmahmood merged 1 commit into
mainfrom
t3/37255863

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Nov 11, 2026 •

Copy link
Copy Markdown
Owner

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.
  • ci: the browser tier runs desktop Chromium, where a patch's frame has its own process #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

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

@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:m 100-500 changed lines labels Nov 11, 2026
@allisonmahmood allisonmahmood changed the title fix(serving): in Firefox, dismissing the new-version bar hands focus back to the patch fix(serving): in Firefox, the new-version bar and download cards hand focus back to the patch Nov 11, 2026
@allisonmahmood allisonmahmood changed the title fix(serving): in Firefox, the new-version bar and download cards hand focus back to the patch fix(serving): in Firefox, Patchy's shell controls hand focus back to the patch Nov 11, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Review (GPT 6.1 Sol), two rounds.

Round 1, at 6a44579: nothing blocking.

  • Should-fix, fixed in f13a3fe: nothing on CI guarded the Firefox retry. A firefox project now runs focus.spec.ts in CI's browser job, with Fission on. It adds 34 s, measured on CI.
  • Nit, fixed in f13a3fe: nothing tested a deliberate focus move between the two tries. A forced-miss hook now covers it.

Round 2, at f13a3fe: nothing blocking.

  • The guard works: with the retry removed, both projects fail.
  • The hook is sound: it models a dropped focus call and stays within its test page.
  • CI is set up right: Chromium's cache key and path are unchanged, and Firefox has a separate entry. Firefox launched without --with-deps and reused Chromium's build. Firefox ran exactly its eight tests.
  • One nit, dismissed: the new "focus is back on #patch" wait inherits the config's 15 s timeout, so it wouldn't catch a slow recovery.
    • Why dismissed: the wait is there to order the test after the retry's timer task. The retry is a single zero-delay timer, so the only thing that can stretch it is machine load. A tight bound would add exactly that kind of flake on a loaded runner, without guarding any path the code has.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Acceptance: PASS with notes

Checked f13a3fe (base b9dc456) on the tier 1 browser harness's throwaway instances, by Claude Opus 5.5 in Claude Code, through T3 Code. This replaces the verdict at 6a44579, which checked the product fix. packages/serving is unchanged since then, so this run checks what f13a3fe adds: the Firefox project and its CI step, the forced-miss steps, and the wait for focus before each next key.

$ git diff 6a44579 f13a3fe --stat
 .github/actions/playwright/action.yml | 39 +++++++++++++++++------
 .github/workflows/ci.yml              |  9 ++++++
 README.md                             |  2 +-
 docs/DEVELOPMENT.md                   |  8 ++++-
 package.json                          |  1 +
 playwright.tier1.config.ts            | 15 ++++++++-
 scripts/verify.ts                     |  2 +-
 test/browser-tier1/focus.spec.ts      | 59 ++++++++++++++++++++++++++++++-----
 8 files changed, 113 insertions(+), 22 deletions(-)

Done means

  • In Firefox, after Not now or Hide on the new-version bar, the next key reaches the patch without a click: passed, and CI now guards it. The Firefox project passes at the head, locally and on CI, and goes red with the hand-back's second try deleted.

What f13a3fe adds

  • The new commands pass at the head: passed.

    $ pnpm test:browser:firefox
    ✓ [firefox] › focus.spec.ts:172:1 › … new-version bar's Not now or Hide, clicked or pressed (1.2s)
    ✓ [firefox] › focus.spec.ts:228:1 › … a download card's Download, Not now or Dismiss, clicked or pressed (1.2s)
    ✓ [firefox] › focus.spec.ts:274:1 › … the single-key shortcuts dialog closes, by its buttons clicked or pressed, Escape or mid-save (3.7s)
    ✓ [firefox] › focus.spec.ts:385:1 › … Dismiss on an older version's note, clicked or pressed (1.2s)
    … and the file's four earlier tests
    8 passed (43.1s)        # the global setup's build included
    
    $ pnpm exec playwright test -c playwright.tier1.config.ts --project=chromium focus.spec.ts
    8 passed (24.1s)
    
    $ PATCHY_TIER1_SKIP_BUILD=1 pnpm test:browser:firefox --repeat-each=4
    32 passed (1.4m)
    
  • The guard bites: passed. I deleted the second try from hand-back-focus.ts, uncommitted. The Firefox project's global setup rebuilt the served shell, whose dist/hand-back-focus.js then held no setTimeout. Both projects go red:

    $ pnpm test:browser:firefox                       # second try deleted
    ✘ [firefox] › focus.spec.ts:172:1 › … new-version bar's Not now or Hide … › Not now, pressed with Enter
      Error: expect(locator).toBeFocused() failed   Expected: focused   Received: inactive
    1 failed, 3 did not run, 4 passed
    
    $ PATCHY_TIER1_SKIP_BUILD=1 pnpm exec playwright test -c playwright.tier1.config.ts --project=chromium focus.spec.ts
    ✘ [chromium] › focus.spec.ts:172:1 › … › a first try that misses is made again once the press is over
      Error: expect(locator).toBeFocused() failed   Expected: focused   Received: inactive
    1 failed, 3 did not run, 4 passed
    

    I also made the second try unconditional, frame.focus() without its if (nowhere()). Chromium then fails the other new step:

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

    With the file restored and rebuilt, git status --short prints nothing and both projects pass again, 8 and 8.

  • No stray specs run in Firefox: passed.

    $ pnpm exec playwright test -c playwright.tier1.config.ts --project=firefox --list
          8 [firefox] › focus.spec.ts
    Total: 8 tests in 1 file
    
    $ pnpm exec playwright test -c playwright.tier1.config.ts --project=chromium --list
    Total: 177 tests in 27 files
    

    Every caller of the tier 1 config in the repo names its project: test:browser the chromium one, test:browser:firefox the firefox one.

  • CI: passed. CI's browser job on f13a3fe succeeded in 613 s:

    Step Time What it did
    Install Chromium 4 s Cache hit for: playwright-chromium-ubuntu24-X64-1.63.0, the key main already uses
    Exercise tier 1 and 2 pages in Chromium 542 s 177 passed (9.0m), with focus.spec.ts and its forced-miss steps among them
    Install Firefox 8 s Cache not found for input keys: playwright-firefox-ubuntu24-X64-1.63.0, then downloaded Firefox 155.0 (playwright firefox v1543) and Cache saved with key: playwright-firefox-ubuntu24-X64-1.63.0
    Exercise the shell's focus hand-back in Firefox 26 s 8 passed (26.2s), without a rebuild (PATCHY_TIER1_SKIP_BUILD)

    The new Firefox cache entry is 105 MB and holds Firefox alone. Chromium's keeps its key and path. Every other check on the head passes, with attio-live and imap-live skipped.

Golden journeys

  • None touched. The delta changes CI, a test, the tier 1 config and docs, and no served code. The verdict at 6a44579 covered the shell change.

Rollback answers: they still match the diff. The delta adds no migration, API, CLI or infrastructure change, so no one-way label is needed.

Not run

  • A second CI run, so no hit on the new Firefox cache entry has been seen yet. Its restore uses the same key and path as its save.
  • pnpm verify as a whole: this run was limited to focus.spec.ts. I read from the diff that scripts/verify.ts now runs test:browser:firefox after test:browser.
  • Headful Firefox and Safari on macOS, as at 6a44579: not available on this Linux machine.

Notes

  • The earlier verdict's first note, that the Firefox half had no CI guard, is resolved. With the second try deleted, both projects fail, and CI's browser job runs both.
  • A bare playwright test -c playwright.tier1.config.ts, with no --project, now runs the Firefox project too (185 tests). Nothing in the repo runs it that way.
  • ci: the browser tier runs desktop Chromium, where a patch's frame has its own process #1302 is still open and conflicts inside projects: [...], as the body says.
  • No review has been posted on this head yet.

@allisonmahmood
allisonmahmood merged commit 915b495 into main Nov 12, 2026
25 checks passed
@allisonmahmood
allisonmahmood deleted the t3/37255863 branch November 12, 2026 18:00
allisonmahmood added a commit that referenced this pull request Nov 12, 2026
… its own process (#1302)

## 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

- **On CI at this head, `a92a7f1`:** the `browser` job passed twice in a
row. Each time desktop Chromium passed 180 and Firefox 8, with none
failed or skipped. The local-hotkeys test and the tab-switch test ran in
desktop Chromium.
- **Locally:** the local-hotkeys test passed 3 of 3 in desktop Chromium,
and the Firefox project 8 of 8.
- **Earlier heads, stacked on #1412 before it merged:**
- Five passes in a row at its first head, and two or three at each later
one.
  - One failure was the #1377 flake, since fixed on `main` by #1414.
- One `test (bun)` failure was a `Fleet.test.ts` clock-step case, which
passed on rerun.
- The other failures were gaps in #1412's own fix, each fixed in #1412.
- **CI cost.** No new download. `playwright install chromium` without
`--only-shell` already puts both Chromium builds in Chromium's cache
entry, and the action's comment says why it stays that way.
- **Not checked:** headed Chrome on a real display. New headless is the
same browser build and runs the frame out of process, as the target
count shows.

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

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 area:server Touches the server area size:m 100-500 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(serving): Firefox leaves focus outside the patch after the new-version bar is dismissed

1 participant