Skip to content

fix(ui-kit,ui-react): close non-modal panels on Android back (#2577) - #4194

Merged
schlessera merged 11 commits into
mainfrom
fix/2577-android-back-close-watcher
Nov 17, 2026
Merged

schlessera merged 11 commits into
mainfrom
fix/2577-android-back-close-watcher

Conversation

@schlessera

@schlessera schlessera commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Closes #2577.

What this does

A native modal <dialog> receives Android back as a close request. The non-modal surfaces listened for an Escape keydown only, so on an installed Android PWA the back gesture skipped the open panel and left the app. That covered the phone destination drawers, the ≥900px Settings and Files panes and the dictation field.

  • One helper owns close requests for a non-modal surface: watchCloseRequests(document, request, { escape?, armed? }) in packages/ui-kit/src/internal/close-request.ts, shared through @schlessera/brain-ui-kit/internal. It is not supported API.
    • While armed, it keeps one CloseWatcher and hands its close to request. request returns whether the surface closed. When the surface stays open (closedBy="none", a finishing take), the helper arms a fresh watcher, so the next close request reaches it again.
    • Without CloseWatcher ("CloseWatcher" in window is false), or while disarmed, an Escape keydown stands in. It handles only an Escape that is unprevented and not composing, and only for the topmost open surface: a surface disarmed beneath an armed one leaves the Escape to it. It prevents the keydown only when the surface closed, so a modal above a refusing pane still gets its cancel.
    • Only the topmost open surface holds a platform watcher. A surface opened above another takes it: the one beneath releases its own and stays armed, and arms again once the surfaces above it close. A close request therefore reaches the topmost surface or, when that surface is disarmed (drilled in), the page, and never a surface beneath.
    • arm() and disarm() are the control ui-react: Back has no in-app history because every route write replaces the entry #2582's history helper drives. A disarmed surface lets the close request reach the page (popstate). Its Escape fallback still closes it, so Escape keeps its D52 N2 meaning at every depth.
  • Overlay stack (overlay-stack.ts):
    • Each non-modal entry (the phone destination drawers) gets a watcher.
    • The document Escape listener now steps aside while the top entry is watching, so one Escape never closes twice. It also steps aside when another surface has opened above that entry (a dictation notice over a drawer), so the Escape is that surface's.
    • escape reports whether the overlay closed, so closedBy="none" and a covered overlay stay open and re-arm.
    • Modal entries are unchanged; the <dialog> handles itself.
  • ui-react surfaces: the Settings pane (SlidePanel in pane mode), the Files panes, the dictation field and its gate notices (consent, a blocked take) drop their hand-written listeners for a small useCloseRequest hook over the helper.
    • The openModal() guard stays. A pane with closedBy="none" (Settings while its navigation is protected) now holds a watcher and refuses, so Android back no longer leaves the app there.
    • A finishing take (D5) refuses and re-arms.
  • Escape audit (Chromium raises the close request unless the keydown was prevented):
    • ShareMenu stopped the Escape but didn't prevent it, so under a watcher the panel closed along with the menu. It now does both.
    • The passkey rename field did neither. It now prevents and stops.
    • The graph node list's two handlers now prevent too.
    • The remaining handlers from grep -rn '"Escape"' already prevent, or sit outside any panel (the chat Composer, the palette).

Citation drift: #3772 replaced dictation-sheet.tsx with the voice field (DictationCapture). It mounts only while a take is live, Escape cancels the take, and D5 is the old draining. The scope maps one-to-one; see the drift comment.

Acceptance criteria

Criterion Proof
One helper owns close-request wiring; no second Escape listener per surface overlay-stack.ts, slide-panel.tsx, file-panel.tsx and dictation-field.tsx all go through watchCloseRequests. Their own keydown listeners are removed
With CloseWatcher: the topmost non-modal panel, pane or dictation field closes once, focus returns (D52 N2), history.length and location are unchanged close-requests.pointer.tsx for the Sessions drawer (390px), the Settings pane and the Files pane (1024px): CLOSE_WATCHER_ARMED, one close event, focus back on the opener, and {history.length, location.href} equal to before opening. A second Escape closes nothing
Arm and disarm: a disarmed surface ignores the request (it reaches the page), Escape still closes it, and re-arming restores exactly once "arm and disarm…": the page beneath re-arms itself in its own close handler with no user activation, as #2582 will from popstate, and stays armed throughout. A disarmed surface (opened from a real press) ignores the request, and the page takes it. The surface then re-arms from script, also without activation. The next two requests give one dismissal each, and the page sees neither, so nothing was grouped. Disarmed again, the page takes the next request alone. Mutations: a disarm() that keeps the watcher, and an arm() that creates none, each fail it. "a disarmed surface with the Escape fallback…": Escape closes it and the page does not also take it
A modal over a destination panel closes first "a modal over a destination panel…": Files → More. The first Escape closes More (no panel watcher event); the next closes Files through its watcher
closedBy="none" and a finishing take survive and re-arm The dictation test mounts DictationCapture from a press while D5 shows. The close request reaches the watcher and cancels nothing. Once D5 ends, the next request cancels once. The arm/disarm test's surface stays open on every request, which exercises the re-arm path
Without CloseWatcher, Escape still closes each surface once "…without CloseWatcher" for each of the three surfaces (the full descriptor is deleted and restored)
Inner Escape consumers call preventDefault() PREVENTED_INNER_ESCAPE in the share-menu and passkey-rename tests: the menu closes or the rename cancels, and the pane stays
Real-Chromium test fails on the current tree for the watcher assertion, passes after, and a mutation that skips the watcher fails again Below
Changeset for ui-kit and ui-react (patch) .changeset/2577-android-back-close-requests.md

Proof

  • Real Chromium (../ui-react/tests/browser/close-requests.pointer.tsx, added to the rail projects): 24/24 on each of rail-fine, rail-coarse and rail-mixed.

  • Failing first (product changes reverted, the helper file kept so the test still loads, workspace rebuilt): 6 fail on the named assertions:

    • CLOSE_WATCHER_ARMED … expected 0 to be greater than 0 (Sessions, Settings, Files);
    • through the panel's watcher: expected +0 to be 1 (modal over panel);
    • the close request reached the field's watcher: expected +0 to be 1 (dictation);
    • PREVENTED_INNER_ESCAPE (passkey rename closed the pane).

    The share-menu case passes on the old tree, where the pane only listened for a bubbling keydown, so its fix is proven by mutation instead.

  • Mutations (each restored, workspace rebuilt):

    • Skip creating the watcher (Watcher = null): the same 6 fail, on CLOSE_WATCHER_ARMED and the watcher-event assertions.
    • Drop the share menu's preventDefault(): fails PREVENTED_INNER_ESCAPE: the pane stays open.
    • Put back DictationNotices' own Escape listener: fails "the notice holds a close watcher".
    • Prevent the fallback's keydown before asking the surface: fails "a modal opened over a pane takes Escape first (without CloseWatcher)" on "the modal closed first".
    • Gate the pane watcher on closedBy !== "none" again: fails "a closedBy=none pane still holds a close watcher".
    • Let every surface's fallback act, not only the topmost: fails "a disarmed surface beneath an armed one leaves Escape to the surface above" ([0, 1] for [1, 0]).
    • Let the overlay stack take Escape for a drawer with a surface above it: fails both "a surface opened over a phone drawer takes Escape…" cases ([0, 1] for [1, 0]).
    • Keep the lower surface's watcher when another opens above: fails "a disarmed surface above an armed one lets the close request reach the page" on "only the topmost surface holds a watcher".
    • Arm a watcher whatever the surface's place: fails "re-arming a surface beneath another waits until the upper one closes" ("the pane's arming waits beneath the take").
    • Drop the dictation field's D5 refusal: fails "D5 refuses the fallback's Escape".
    • Drop FilePanel's openModal() refusal: fails overlay-stacking's "document Escape under modal keeps pane open".
  • overlay-stacking's pane-guard test (files/settings pane: Escape respects inner prevention and modal stacking) dispatches synthetic Escapes. Those never raise a close request, so with armed panes it could no longer fail. It now runs without CloseWatcher, where its guards are the fallback's.

  • Repeated refusals do not group: a surface that refuses eight requests in a row (re-arming each time, with no new user activation) is the only one each request reaches. Once it closes, the next request reaches the surface beneath.

  • Existing browser suites (rail-fine, at the final head): overlay-stacking.pointer.tsx 160/160, phone-navigation.pointer.tsx 217/217, desktop-navigation.pointer.tsx 118/118. One earlier overlay-stacking run, the first after a rebuild, failed 8 cases. Four of them were diagram cases timing out at 15 s, and the four Escape and stacking cases passed when run alone. The next three full runs passed 160/160, and main passed 160/160 once. I can't attribute that run; heavy browser proof runs on the squash's main run.

  • Unit: bun run test packages/ui-kit packages/ui-react: 3786 pass, 7 fail. The 7 are api-client-sync.test.ts's "published sync helper" cases, which fail the same on an unmodified checkout on this host ("Sync fixture did not start"). overlay-stack.test.ts passes with its callbacks returning whether they closed.

  • Not run locally: the issue's scripts/visual.mjs commands (pinned container). This changes no visual output; the hosted browser and layout categories run them.

  • Typecheck, lint, the API surface report (two new internal exports) and check:pr pass.

Contract impact

None. The helper ships on the unsupported /internal entry (public-export-boundary).

Collisions

bun scripts/collisions.ts --json --pr 4194 at head 235ea33: one textual collision with #3059 (draft) on packages/ui-kit/vitest.config.ts. This PR adds one entry to the rail projects' include list there. Closure reports only (shared test categories and workspaces) with #3054, #3056, #3069, #3581, #3622, #4002, #4151, #4168, #4173, #4175, #4177, #4179 and #4193. No other PR edits the changed source files.

{"version":1,"kind":"brain-check-pr-receipt","head":"8f5147225d8723cf9037facc57f3800b06eac06e","base":"origin/main","mode":"focused","startedAt":"2026-11-17T18:20:23.404Z","finishedAt":"2026-11-17T18:21:55.628Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":17885.763336000004},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":158.11494200000016},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":134.67587400000048},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":29.864346999995178},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":73996.261122}]}

🤖 Generated with Claude Code

A native modal dialog receives Android back as a close request; the
non-modal surfaces listened for an Escape keydown only, so on an
installed Android PWA the back gesture skipped the open panel and left
the app. One helper (`watchCloseRequests`, ui-kit internal) now owns
close requests for a non-modal surface: while armed it keeps a
CloseWatcher and hands its close to the surface, re-arming when the
surface stays open; without CloseWatcher, or while disarmed for #2582's
drill-in history, an Escape keydown stands in.

- Non-modal Overlay entries (the phone destination drawers) get a
  watcher from the overlay stack, whose document Escape now steps aside
  for a watching top entry, so one Escape never closes twice.
- The Settings and Files panes and the dictation field use it in place
  of their own listeners. A modal over them still closes first; a
  finishing take (D5) and closedBy="none" survive and re-arm.
- Inner Escape consumers inside panels now prevent the keydown as well
  as stopping it (share menu, passkey rename, the graph node list), since
  Chromium raises the close request unless the keydown was prevented.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera schlessera added this to the 0.45.0 milestone Nov 17, 2026
@uploads-sh

uploads-sh Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

No uploads on this PR yet

This PR changes UI files (packages/ui-kit/src/chrome/Overlay.tsx, packages/ui-react/src/components/files/file-panel.tsx, packages/ui-react/src/components/graph/graph-scene.tsx and 6 more). Screenshots help reviewers see what changed.

  • From the CLI: uploads put before.png after.png --pr 4194
  • From an agent: ask it to attach screenshots with uploads.sh
  • By hand: drag images into the PR description and they're imported automatically
Tips for agents

Label each shot so reviewers know what they're seeing. Labels apply to every file in a call, so run one put per shot:

uploads put after.png --pr 4194 --meta path=/settings --state after --caption "Saved settings toast"
uploads put chat.png --pr 4194 --app ios --screen "Chat" --state after

No CLI? With the Uploads MCP, call sign_upload_url for files on disk (or put) with repo, pr: 4194 and the same screen, state and caption fields.

This comment updates with each upload, so you don't need to post the images yourself. A shot or two in the PR description is still welcome. Check what's attached with uploads list --pr 4194. More in the github-screenshots skill or the agent docs.

Workspace admins can turn this comment off in Settings → GitHub · docs

@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head 235ea33 against base d6cc842. Reviewer: agent. 2 findings: 0 fixed, 0 filed, 0 rejected, 2 without a disposition.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4194,
  "head": "235ea3323a4deba1cd75cd5846f0f2025a82302c",
  "base": "d6cc842bca8d3ce3ef433978c7b5e09babe49ce6",
  "reviewer": "agent",
  "outcome": "findings",
  "findings": [
    {
      "summary": "packages/ui-react/src/components/voice/dictation-field.tsx:126-136: DictationNotices (D0 consent, Dx0/Dx1/Dx2 blocked take) keeps its own document Escape keydown listener and bypasses the close-request helper. The deleted dictation-sheet.tsx handled Escape in these gate states too, so the 1:1 mapping misses them: Android back on a D0/Dx notice leaves the app, and the surface keeps a hand-written Escape listener, against the first two criteria."
    },
    {
      "summary": "packages/ui-kit/src/internal/close-request.ts:79: a refused request (D5, closedBy=\"none\") re-arms with a new CloseWatcher made without user activation. The spec lowers the allowed group count after each close request, so after repeated refusals the new watcher joins the group beneath (e.g. a pane under a dictation take), and the next Back cancels the take and closes the pane at once. The arm/disarm test inherits activation credit and sends only two requests, so it cannot catch this."
    }
  ]
}

The dictation sheet these notices replaced closed on Escape in its gate
states as well (consent, a blocked take). DictationNotices kept its own
Escape listener, so Android back on a gate notice still left the app.
It now goes through the shared close-request helper, as the capture
field does.

The browser test also proves that a surface refusing request after
request (a finishing take, closedBy="none") re-arms without joining the
surface beneath it: eight refusals reach only the upper surface, and
once it closes, the next request reaches the one beneath.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head 235ea33 against base d6cc842. Reviewer: agent. 2 findings: 1 fixed, 0 filed, 1 rejected, 0 without a disposition.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4194,
  "head": "235ea3323a4deba1cd75cd5846f0f2025a82302c",
  "base": "d6cc842bca8d3ce3ef433978c7b5e09babe49ce6",
  "reviewer": "agent",
  "outcome": "findings",
  "findings": [
    {
      "summary": "packages/ui-react/src/components/voice/dictation-field.tsx:126-136: DictationNotices (D0 consent, Dx0/Dx1/Dx2 blocked take) keeps its own document Escape keydown listener and bypasses the close-request helper. The deleted dictation-sheet.tsx handled Escape in these gate states too, so the 1:1 mapping misses them: Android back on a D0/Dx notice leaves the app, and the surface keeps a hand-written Escape listener, against the first two criteria.",
      "disposition": "fixed",
      "commit": "3611ae547a38cb8b5c9fa01809de6305cf9fd800"
    },
    {
      "summary": "packages/ui-kit/src/internal/close-request.ts:79: a refused request (D5, closedBy=\"none\") re-arms with a new CloseWatcher made without user activation. The spec lowers the allowed group count after each close request, so after repeated refusals the new watcher joins the group beneath (e.g. a pane under a dictation take), and the next Back cancels the take and closes the pane at once. The arm/disarm test inherits activation credit and sends only two requests, so it cannot catch this.",
      "disposition": "rejected",
      "reason": "Tested in real Chromium rather than inferred: a surface opened over another refuses eight close requests in a row, re-arming inside each close event with no new activation, and every request reaches only the upper surface; once it closes, the next reaches the one beneath. That case is now the test 'repeated refusals re-arm without joining the surface beneath' in close-requests.pointer.tsx."
    }
  ]
}

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head d783e90 against base d6cc842. Reviewer: agent. 2 findings: 0 fixed, 0 filed, 0 rejected, 2 without a disposition.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4194,
  "head": "d783e90be09b7419384792a660b5ab7797768f9a",
  "base": "d6cc842bca8d3ce3ef433978c7b5e09babe49ce6",
  "reviewer": "agent",
  "outcome": "findings",
  "findings": [
    {
      "summary": "packages/ui-kit/src/internal/close-request.ts:95 - the Escape fallback calls event.preventDefault() before request(), even when request() refuses. SlidePanel (slide-panel.tsx:46) and FilePanel (file-panel.tsx:79) refuse via openModal() only after that; the removed listeners checked openModal() first. Without CloseWatcher (Firefox Android <149) or while disarmed, Escape on a modal over a Settings/Files pane (More, Search) is prevented, the dialog gets no cancel and stays open."
    },
    {
      "summary": "packages/ui-react/src/components/layout/slide-panel.tsx:46 - useCloseRequest is enabled only when closedBy !== \"none\", so a pane-mode SlidePanel that cannot be dismissed has no watcher. Settings in pane mode sets closedBy=\"none\" while settingsNavigationProtected (settings-panel.tsx:53), and then Android back goes to the page and leaves the app. This misses the criterion that a closedBy=\"none\" surface survives the request with its watcher re-armed; the Overlay drawer path does refuse and re-arm."
    }
  ]
}

… undismissable panes (#2577)

- The Escape fallback now prevents the keydown only when the surface
  closed. It prevented before asking, so without CloseWatcher (or while
  disarmed) a modal opened over a Settings or Files pane never got its
  cancel and stayed open.
- A pane that cannot be dismissed (closedBy="none", Settings while its
  navigation is protected) now holds a close watcher and refuses each
  request, re-armed, instead of letting Android back leave the app.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head d783e90 against base d6cc842. Reviewer: agent. 2 findings: 2 fixed, 0 filed, 0 rejected, 0 without a disposition.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4194,
  "head": "d783e90be09b7419384792a660b5ab7797768f9a",
  "base": "d6cc842bca8d3ce3ef433978c7b5e09babe49ce6",
  "reviewer": "agent",
  "outcome": "findings",
  "findings": [
    {
      "summary": "packages/ui-kit/src/internal/close-request.ts:95 - the Escape fallback calls event.preventDefault() before request(), even when request() refuses. SlidePanel (slide-panel.tsx:46) and FilePanel (file-panel.tsx:79) refuse via openModal() only after that; the removed listeners checked openModal() first. Without CloseWatcher (Firefox Android <149) or while disarmed, Escape on a modal over a Settings/Files pane (More, Search) is prevented, the dialog gets no cancel and stays open.",
      "disposition": "fixed",
      "commit": "f1c11cd636d6831e174a8404447fd489cb8c6939"
    },
    {
      "summary": "packages/ui-react/src/components/layout/slide-panel.tsx:46 - useCloseRequest is enabled only when closedBy !== \"none\", so a pane-mode SlidePanel that cannot be dismissed has no watcher. Settings in pane mode sets closedBy=\"none\" while settingsNavigationProtected (settings-panel.tsx:53), and then Android back goes to the page and leaves the app. This misses the criterion that a closedBy=\"none\" surface survives the request with its watcher re-armed; the Overlay drawer path does refuse and re-arm.",
      "disposition": "fixed",
      "commit": "f1c11cd636d6831e174a8404447fd489cb8c6939"
    }
  ]
}

@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head f1c11cd against base d6cc842. Reviewer: agent. 1 finding: 0 fixed, 0 filed, 0 rejected, 1 without a disposition.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4194,
  "head": "f1c11cd636d6831e174a8404447fd489cb8c6939",
  "base": "d6cc842bca8d3ce3ef433978c7b5e09babe49ce6",
  "reviewer": "agent",
  "outcome": "findings",
  "findings": [
    {
      "summary": "packages/ui-react/tests/browser/close-requests.pointer.tsx:334-347: the arm/disarm test cannot detect the grouping the issue requires it to rule out. The page's sentinel watcher (line 311) is spent by the disarmed request at line 330, so after re-arming nothing sits beneath the surface to group with, and 'the page saw neither' (line 347) passes whatever the helper does. The re-arm also runs from a fresh click (lines 336-341), which grants user activation; #2582 re-arms from popstate with none."
    }
  ]
}

…2577)

The page beneath the surface now arms itself again in its own close
handler, with no user activation, as #2582's history helper will from
popstate, and the surface re-arms from script, not from a press. A
re-armed watcher that joined the page's group would now show: two
requests after re-arming reach the surface only, and the page takes
the next request alone once the surface is disarmed again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head f1c11cd against base d6cc842. Reviewer: agent. 1 finding: 1 fixed, 0 filed, 0 rejected, 0 without a disposition.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4194,
  "head": "f1c11cd636d6831e174a8404447fd489cb8c6939",
  "base": "d6cc842bca8d3ce3ef433978c7b5e09babe49ce6",
  "reviewer": "agent",
  "outcome": "findings",
  "findings": [
    {
      "summary": "packages/ui-react/tests/browser/close-requests.pointer.tsx:334-347: the arm/disarm test cannot detect the grouping the issue requires it to rule out. The page's sentinel watcher (line 311) is spent by the disarmed request at line 330, so after re-arming nothing sits beneath the surface to group with, and 'the page saw neither' (line 347) passes whatever the helper does. The re-arm also runs from a fresh click (lines 336-341), which grants user activation; #2582 re-arms from popstate with none.",
      "disposition": "fixed",
      "commit": "0ef0d7ad7d43c37ed3c7a958a9227d2b572f80f1"
    }
  ]
}

@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head 0ef0d7a against base d6cc842. Reviewer: agent. 3 findings: 0 fixed, 0 filed, 0 rejected, 3 without a disposition.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4194,
  "head": "0ef0d7ad7d43c37ed3c7a958a9227d2b572f80f1",
  "base": "d6cc842bca8d3ce3ef433978c7b5e09babe49ce6",
  "reviewer": "agent",
  "outcome": "findings",
  "findings": [
    {
      "summary": "packages/ui-react/tests/browser/overlay-stacking.pointer.tsx:354-371 can no longer fail: the Files and Settings panes now hold an armed CloseWatcher, so close-request.ts:94 returns early and a synthetic, untrusted Escape raises no close request. Its prevented-Escape, protected-Settings and modal-over-pane assertions pass with the defaultPrevented, closedBy or openModal() guard removed, which leaves FilePanel's openModal() refusal (file-panel.tsx:80) untested."
    },
    {
      "summary": "packages/ui-kit/src/internal/close-request.ts:94: a disarmed surface's Escape fallback runs even with an armed surface above it. The armed one's listener returns without preventing, so the disarmed one runs request() and preventDefault(): the lower surface closes, the close request is suppressed and the topmost stays open. E.g. a Files pane disarmed by #2582 under a dictation take: Escape closes the pane, not the take, breaking one-gesture/one-action and topmost-first."
    },
    {
      "summary": "packages/ui-react/tests/browser/close-requests.pointer.tsx:147-156 and 222-223: the no-CloseWatcher criterion ('Escape still closes each surface once') is tested only for the Sessions drawer, the Settings and Files panes, and a SlidePanel under a modal. Nothing tests the dictation field (DictationCapture, DictationNotices, dictation-field.tsx:63-67 and 128-131) without CloseWatcher, so its keydown fallback, including the D5 refusal, is unproven although the issue names that surface."
    }
  ]
}

- A surface disarmed beneath an armed one (a drilled-in pane under a
  dictation take, once #2582 disarms) ran its Escape fallback and closed
  itself, suppressing the close request the surface above was armed
  for. The helper keeps each document's open surfaces in opening order,
  and only the topmost one's fallback acts.
- overlay-stacking's pane-guard test dispatches synthetic Escapes, which
  never raise a close request; with the panes now armed it could no
  longer fail. It now runs where the keydown fallback is the path
  (without CloseWatcher), so the defaultPrevented, closedBy="none" and
  openModal() guards are each proven again.
- The dictation field and its gate notices are now tested without
  CloseWatcher too, a finishing take included.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head 0ef0d7a against base d6cc842. Reviewer: agent. 3 findings: 3 fixed, 0 filed, 0 rejected, 0 without a disposition.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4194,
  "head": "0ef0d7ad7d43c37ed3c7a958a9227d2b572f80f1",
  "base": "d6cc842bca8d3ce3ef433978c7b5e09babe49ce6",
  "reviewer": "agent",
  "outcome": "findings",
  "findings": [
    {
      "summary": "packages/ui-react/tests/browser/overlay-stacking.pointer.tsx:354-371 can no longer fail: the Files and Settings panes now hold an armed CloseWatcher, so close-request.ts:94 returns early and a synthetic, untrusted Escape raises no close request. Its prevented-Escape, protected-Settings and modal-over-pane assertions pass with the defaultPrevented, closedBy or openModal() guard removed, which leaves FilePanel's openModal() refusal (file-panel.tsx:80) untested.",
      "disposition": "fixed",
      "commit": "5b28147989fd60b4fe074947296c4064d06b39b4"
    },
    {
      "summary": "packages/ui-kit/src/internal/close-request.ts:94: a disarmed surface's Escape fallback runs even with an armed surface above it. The armed one's listener returns without preventing, so the disarmed one runs request() and preventDefault(): the lower surface closes, the close request is suppressed and the topmost stays open. E.g. a Files pane disarmed by #2582 under a dictation take: Escape closes the pane, not the take, breaking one-gesture/one-action and topmost-first.",
      "disposition": "fixed",
      "commit": "5b28147989fd60b4fe074947296c4064d06b39b4"
    },
    {
      "summary": "packages/ui-react/tests/browser/close-requests.pointer.tsx:147-156 and 222-223: the no-CloseWatcher criterion ('Escape still closes each surface once') is tested only for the Sessions drawer, the Settings and Files panes, and a SlidePanel under a modal. Nothing tests the dictation field (DictationCapture, DictationNotices, dictation-field.tsx:63-67 and 128-131) without CloseWatcher, so its keydown fallback, including the D5 refusal, is unproven although the issue names that surface.",
      "disposition": "fixed",
      "commit": "5b28147989fd60b4fe074947296c4064d06b39b4"
    }
  ]
}

@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head 5b28147 against base d6cc842. Reviewer: agent. 1 finding: 0 fixed, 0 filed, 0 rejected, 1 without a disposition.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4194,
  "head": "5b28147989fd60b4fe074947296c4064d06b39b4",
  "base": "d6cc842bca8d3ce3ef433978c7b5e09babe49ce6",
  "reviewer": "agent",
  "outcome": "findings",
  "findings": [
    {
      "summary": "packages/ui-kit/src/internal/close-request.ts:115-118: arm() always makes a new CloseWatcher, which goes on top of the platform stack, but the `opened` order (lines 76-78) does not move. A surface re-armed beneath another armed one (a pane back at its drill-in root under a live dictation take) takes the next Android back first, while its Escape fallback still treats it as beneath. That skips a Back step, which the arm/disarm criterion forbids. Latent until #2582 calls arm()."
    }
  ]
}

…2577)

A new CloseWatcher goes on top of the platform's stack. Re-arming a
surface beneath another open one (a pane back at its drill-in root under
a live dictation take, once #2582 drives arm()) would let it take the
next Back before the surface above. A surface now arms only while it is
topmost; an arming beneath waits, and runs when the surfaces above it
close.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head 5b28147 against base d6cc842. Reviewer: agent. 1 finding: 1 fixed, 0 filed, 0 rejected, 0 without a disposition.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4194,
  "head": "5b28147989fd60b4fe074947296c4064d06b39b4",
  "base": "d6cc842bca8d3ce3ef433978c7b5e09babe49ce6",
  "reviewer": "agent",
  "outcome": "findings",
  "findings": [
    {
      "summary": "packages/ui-kit/src/internal/close-request.ts:115-118: arm() always makes a new CloseWatcher, which goes on top of the platform stack, but the `opened` order (lines 76-78) does not move. A surface re-armed beneath another armed one (a pane back at its drill-in root under a live dictation take) takes the next Android back first, while its Escape fallback still treats it as beneath. That skips a Back step, which the arm/disarm criterion forbids. Latent until #2582 calls arm().",
      "disposition": "fixed",
      "commit": "ca679af05ec8b41efcc26050849e9a3606d97180"
    }
  ]
}

@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head ca679af against base d6cc842. Reviewer: agent. 1 finding: 0 fixed, 0 filed, 0 rejected, 1 without a disposition.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4194,
  "head": "ca679af05ec8b41efcc26050849e9a3606d97180",
  "base": "d6cc842bca8d3ce3ef433978c7b5e09babe49ce6",
  "reviewer": "agent",
  "outcome": "findings",
  "findings": [
    {
      "summary": "packages/ui-kit/src/internal/close-request.ts:128-131: disarm() releases only the topmost surface's watcher; a lower surface armed earlier keeps its own, so Android back reaches it instead of the page. E.g. a live dictation take, then a Files pane opened above and drilled in (#2582 disarms it): Back cancels the take while the pane stays drilled in. Misses the arm/disarm criterion and innermost-first ruling; no test disarms above an armed surface."
    }
  ]
}

Disarming the topmost surface released only its own watcher, so a
surface beneath that had armed earlier kept one, and Android back
reached it instead of the page: a dictation take with a drilled-in pane
above it (#2582) would be cancelled while the pane stayed drilled in.
A surface opened above another now takes the watcher: the one beneath
releases its own and stays armed, and arms again once the surfaces above
it close. A close request therefore reaches the topmost surface or, when
that is disarmed, the page, and never a surface beneath.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head ca679af against base d6cc842. Reviewer: agent. 1 finding: 1 fixed, 0 filed, 0 rejected, 0 without a disposition.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4194,
  "head": "ca679af05ec8b41efcc26050849e9a3606d97180",
  "base": "d6cc842bca8d3ce3ef433978c7b5e09babe49ce6",
  "reviewer": "agent",
  "outcome": "findings",
  "findings": [
    {
      "summary": "packages/ui-kit/src/internal/close-request.ts:128-131: disarm() releases only the topmost surface's watcher; a lower surface armed earlier keeps its own, so Android back reaches it instead of the page. E.g. a live dictation take, then a Files pane opened above and drilled in (#2582 disarms it): Back cancels the take while the pane stays drilled in. Misses the arm/disarm criterion and innermost-first ruling; no test disarms above an armed surface.",
      "disposition": "fixed",
      "commit": "7a23304a9dbf43b8e6fae0bab4252f0f4f123937"
    }
  ]
}

@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head 7a23304 against base d6cc842. Reviewer: agent. 1 finding: 0 fixed, 0 filed, 0 rejected, 1 without a disposition.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4194,
  "head": "7a23304a9dbf43b8e6fae0bab4252f0f4f123937",
  "base": "d6cc842bca8d3ce3ef433978c7b5e09babe49ce6",
  "reviewer": "agent",
  "outcome": "findings",
  "findings": [
    {
      "summary": "packages/ui-kit/src/internal/overlay-stack.ts:27: the document Escape listener steps aside only while its top drawer is watching. A ui-react surface opened after a phone drawer (dictation field or notice) takes the drawer's watcher, so the stack still treats the drawer as top: Escape is prevented and closes the drawer beneath, while Android back closes the surface above. This breaks the helper's rule that a lower surface never takes the upper one's Escape."
    }
  ]
}

The overlay stack's document Escape listener stepped aside only while
its top drawer was watching. A surface opened after a phone drawer (a
dictation field or notice) takes the drawer's watcher, so the stack
still took Escape for the drawer and closed it beneath, while Android
back closed the surface above. The watch now reports whether its
surface is the topmost, and the stack leaves Escape to the surface
above when its drawer is not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head 7a23304 against base d6cc842. Reviewer: agent. 1 finding: 1 fixed, 0 filed, 0 rejected, 0 without a disposition.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4194,
  "head": "7a23304a9dbf43b8e6fae0bab4252f0f4f123937",
  "base": "d6cc842bca8d3ce3ef433978c7b5e09babe49ce6",
  "reviewer": "agent",
  "outcome": "findings",
  "findings": [
    {
      "summary": "packages/ui-kit/src/internal/overlay-stack.ts:27: the document Escape listener steps aside only while its top drawer is watching. A ui-react surface opened after a phone drawer (dictation field or notice) takes the drawer's watcher, so the stack still treats the drawer as top: Escape is prevented and closes the drawer beneath, while Android back closes the surface above. This breaks the helper's rule that a lower surface never takes the upper one's Escape.",
      "disposition": "fixed",
      "commit": "0aa7cd2083003e018bd463279f3cf643e6eb33fa"
    }
  ]
}

@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed head 0aa7cd2 against base d6cc842. Reviewer: agent. No findings.

{
  "version": 1,
  "kind": "brain-review-receipt",
  "pr": 4194,
  "head": "0aa7cd2083003e018bd463279f3cf643e6eb33fa",
  "base": "d6cc842bca8d3ce3ef433978c7b5e09babe49ce6",
  "reviewer": "agent",
  "outcome": "no-findings",
  "findings": []
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ui-kit: Android back leaves the app instead of closing an open destination panel or pane

1 participant