Repository navigation
fix(ui-kit,ui-react): close non-modal panels on Android back (#2577) - #4194
Conversation
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>
|
No uploads on this PR yet This PR changes UI files (
Tips for agentsLabel each shot so reviewers know what they're seeing. Labels apply to every file in a call, so run one 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 afterNo CLI? With the Uploads MCP, call 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 Workspace admins can turn this comment off in Settings → GitHub · docs |
Independent reviewReviewed 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>
Independent reviewReviewed 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>
Independent reviewReviewed 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>
Independent reviewReviewed 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"
}
]
} |
Independent reviewReviewed 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>
Independent reviewReviewed 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"
}
]
} |
Independent reviewReviewed 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>
Independent reviewReviewed 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"
}
]
} |
Independent reviewReviewed 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>
Independent reviewReviewed 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"
}
]
} |
Independent reviewReviewed 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>
Independent reviewReviewed 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"
}
]
} |
Independent reviewReviewed 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>
Independent reviewReviewed 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"
}
]
} |
Independent reviewReviewed 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": []
} |
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.watchCloseRequests(document, request, { escape?, armed? })inpackages/ui-kit/src/internal/close-request.ts, shared through@schlessera/brain-ui-kit/internal. It is not supported API.CloseWatcherand hands itsclosetorequest.requestreturns 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.CloseWatcher("CloseWatcher" in windowis 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.arm()anddisarm()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.ts):escapereports whether the overlay closed, soclosedBy="none"and a covered overlay stay open and re-arm.<dialog>handles itself.SlidePanelin pane mode), the Files panes, the dictation field and its gate notices (consent, a blocked take) drop their hand-written listeners for a smalluseCloseRequesthook over the helper.openModal()guard stays. A pane withclosedBy="none"(Settings while its navigation is protected) now holds a watcher and refuses, so Android back no longer leaves the app there.ShareMenustopped the Escape but didn't prevent it, so under a watcher the panel closed along with the menu. It now does both.grep -rn '"Escape"'already prevent, or sit outside any panel (the chat Composer, the palette).Citation drift: #3772 replaced
dictation-sheet.tsxwith the voice field (DictationCapture). It mounts only while a take is live, Escape cancels the take, and D5 is the olddraining. The scope maps one-to-one; see the drift comment.Acceptance criteria
overlay-stack.ts,slide-panel.tsx,file-panel.tsxanddictation-field.tsxall go throughwatchCloseRequests. Their own keydown listeners are removedCloseWatcher: the topmost non-modal panel, pane or dictation field closes once, focus returns (D52 N2),history.lengthandlocationare unchangedclose-requests.pointer.tsxfor the Sessions drawer (390px), the Settings pane and the Files pane (1024px):CLOSE_WATCHER_ARMED, onecloseevent, focus back on the opener, and{history.length, location.href}equal to before opening. A second Escape closes nothingpopstate, 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: adisarm()that keeps the watcher, and anarm()that creates none, each fail it. "a disarmed surface with the Escape fallback…": Escape closes it and the page does not also take itclosedBy="none"and a finishing take survive and re-armDictationCapturefrom 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 pathCloseWatcher, Escape still closes each surface oncepreventDefault()PREVENTED_INNER_ESCAPEin the share-menu and passkey-rename tests: the menu closes or the rename cancels, and the pane stays.changeset/2577-android-back-close-requests.mdProof
Real Chromium (
../ui-react/tests/browser/close-requests.pointer.tsx, added to the rail projects): 24/24 on each ofrail-fine,rail-coarseandrail-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):
Watcher = null): the same 6 fail, onCLOSE_WATCHER_ARMEDand the watcher-event assertions.preventDefault(): failsPREVENTED_INNER_ESCAPE: the pane stays open.DictationNotices' own Escape listener: fails "the notice holds a close watcher".closedBy !== "none"again: fails "a closedBy=none pane still holds a close watcher".[0, 1]for[1, 0]).[0, 1]for[1, 0]).FilePanel'sopenModal()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 withoutCloseWatcher, 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.tsx160/160,phone-navigation.pointer.tsx217/217,desktop-navigation.pointer.tsx118/118. One earlieroverlay-stackingrun, 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 areapi-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.tspasses with its callbacks returning whether they closed.Not run locally: the issue's
scripts/visual.mjscommands (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:prpass.Contract impact
None. The helper ships on the unsupported
/internalentry (public-export-boundary).Collisions
bun scripts/collisions.ts --json --pr 4194at head 235ea33: one textual collision with #3059 (draft) onpackages/ui-kit/vitest.config.ts. This PR adds one entry to the rail projects'includelist 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