Skip to content

studio: stop a menu dismissal deleting a chat message - #9243

Merged
Etherll merged 8 commits into
unslothai:mainfrom
mahiatlinux:fix/studio-action-bar-dismiss-delete
Aug 21, 2026
Merged

Etherll merged 8 commits into
unslothai:mainfrom
mahiatlinux:fix/studio-action-bar-dismiss-delete

Conversation

@mahiatlinux

Copy link
Copy Markdown
Contributor

The bug

Dismissing the chat action bar's "More" menu can delete a message, with no confirmation.

#8992 set modal={false} on ActionBarMorePrimitive.Root in studio/frontend/src/components/assistant-ui/thread.tsx. That was the right call and this PR keeps it: a modal Radix layer parks pointer-events: none on <body>, which is an inherited property, so every open invalidates computed style for the whole thread. studio/frontend/tests/action-menu-modal-layer.test.ts pins the menu non-modal and carries the numbers.

What that shield was also doing is absorbing the press that dismisses the menu. Radix's outside handler closes the layer but never cancels the event, so one press on a control beside the menu both closes it and fires that control. Two buttons from the trigger sits DeleteMessageButton (thread.tsx:7033), which deletes on onClick with no confirmation.

Measured with tests/studio/probe_dismiss_guard.py against a seeded thread of 10 assistant messages:

tree chromium webkit
origin/main (6e5360c) 11 gestures deleted a message 9 gestures deleted a message
this branch none none

The gestures that reach it include a quick click, a press held past any fixed deadline, a press while the main thread is busy, a touch tap, a press with a modifier, Enter or Space pressed mid-press, and Space pressed after the menu was already dismissed.

The fix

studio/frontend/src/lib/menu-dismiss.ts swallows exactly the click that dismissed the menu.

It arms from pointerdown on document in the capture phase, not from Radix's onPointerDownOutside. Two reasons, both measured rather than assumed. A guard armed from that callback and retired by a fixed timer is gone before the browser synthesises click on release, and a press can be held for as long as the user likes. And usePointerDownOutside in @radix-ui/react-dismissable-layer 1.1.11 defers to the resulting click for pointerType === "touch", listening on ownerDocument in the bubble phase, while React 19 delegates to the root container inside document, so the control's own onClick has already run by the time Radix calls back.

The upper bound is anchored at pointerup, not at the press, so a gesture that never becomes a click cannot leave the swallower waiting for an unrelated one. A non-primary button never arms it at all, since a right click raises contextmenu and no click.

Throwing the click away is only half of undoing the press. The press also focuses what it landed on, and a focused button is one Space away from firing, so the swallow releases the focus it took unless the target takes text.

studio/frontend/src/lib/menu-dismiss-guard.tsx exposes <MenuDismissGuard />, mounted inside ActionBarMorePrimitive.Content. Radix mounts content on open and unmounts it on close, so the guard's lifetime is the menu's with no onOpenChange wiring.

The sidebar's "More" destinations flyout stays non-modal and unguarded. It opens on pointer enter, so an unconditional swallow there would eat an ordinary click on the nav row the pointer was heading for. nonmodal-menu-dismiss-guard.test.ts records that as an explicit exception and fails on any other unguarded modal={false} menu.

Before and after

Same fixture, same viewport, same gesture: open the last reply's "More" menu, press and hold its "Delete message" button for 600ms, release. Captured at 6e5360c and at this branch's head.

On main, reply 9 is gone and the thread ends at the prompt that produced it:

one dismissing press on main deletes the reply

On this branch the menu closes and the reply is still there:

the same press on this branch only closes the menu

Tests

tests/studio/probe_dismiss_guard.py drives the real menu on the heavy-thread smoke page through 19 cases and is wired into studio-frontend-ci.yml as a gate. It watches both directions: the dismissing press must not reach the control underneath, and a click inside the menu, a second click after a dismissal, and the click after a right-click dismissal must all still land.

nonmodal-menu-second-pointer.test.ts drives the arm/disarm state machine against a fake document, where the clock can be advanced by hand rather than slept through.

nonmodal-menu-dismiss-guard.test.ts sweeps every .tsx under src/ for modal={false} and requires the guard or a listed exception.

Checks

  • probe_dismiss_guard.py: passes on chromium and webkit, fails on both at the merge base
  • npm test: 3800 of 3801. The one failure, queued-model-capabilities.test.ts, is pre-existing on main (image-input-support.ts:7 imports ./mmproj-fallback without an extension)
  • npm run typecheck, npm run build, npm run bundle:check: clean, and the bundle stays within budget
  • eslint: no new findings, the 55 in thread.tsx and app-sidebar.tsx are unchanged from main
  • ruff check, ruff format, biome check on the new files: clean
  • six mutations applied to the fix: five caught by the node tests, and removing the branch that handles a keyboard-generated click mid-press is caught by the probe's held_enter case

@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

Frontend unit tests (Windows) is red on one test that this branch does not touch: tests/queued-model-capabilities.test.ts. Everything else in that job passes, 3801 of 3802.

studio/frontend/src/features/chat/utils/image-input-support.ts:7 imports ./mmproj-fallback without an extension, which node's --experimental-strip-types runner cannot resolve. It reproduces on a clean checkout of the merge base 6e5360c with none of this branch applied:

ERR_MODULE_NOT_FOUND: Cannot find module '.../src/features/chat/utils/mmproj-fallback'
  imported from .../src/features/chat/utils/image-input-support.ts
tests 1, pass 0, fail 1

It arrived with #9173. Leaving it alone rather than folding an unrelated fix into this PR, but happy to send it separately.

The first Windows run also failed the new guard sweep, which was mine: path.relative returns backslashes there, so the exception keys in nonmodal-menu-dismiss-guard.test.ts matched nothing and the listed exception read as an offender. Fixed in c638b26, which builds the ids with posix separators and adds a test that fails if a host separator reaches one.

@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

1 similar comment
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed this hits the path in studio/frontend/src/components/assistant-ui/thread.tsx where the non-modal More menu sits beside an unconfirmed Delete message on line 7034, so a dismissing press can still remove a message. Could you get the Frontend build and bundle sanity job green so I can review it properly?

@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@mahiatlinux
mahiatlinux force-pushed the fix/studio-action-bar-dismiss-delete branch from c638b26 to a090b7b Compare August 19, 2026 05:47
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@mahiatlinux

Copy link
Copy Markdown
Contributor Author

@codex review

@Etherll

Etherll commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7ec0d5f140

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +407 to +408
export function useDismissingClickGuard(): void {
useEffect(installDismissingClickGuard, []);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Stop guarding as soon as the menu closes

When an item closes the menu, Radix Presence can keep the content—and therefore this effect—mounted during its exit animation. A click during that interval is unrelated to any open menu, but onPointerDown still arms swallowClick, causing the click to be discarded. The newly added select_then_quick_click probe documents that the current action-menu content remains mounted for roughly 126 ms and deliberately clicks after 40 ms, so this also makes the new CI probe fail; drive the guard from the menu's open state rather than the content's mount lifetime.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rejected on exact head: this content has no exit animation, Radix unmounts immediately when animationName is none, and select_then_quick_click returned neutralClicks=1 on Chromium, WebKit, and Firefox. The probe comments describe a class this menu does not have.

Etherll pushed a commit to Etherll/unsloth that referenced this pull request Aug 21, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Etherll pushed a commit to Etherll/unsloth that referenced this pull request Aug 21, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 36f3b0bdb8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Etherll pushed a commit to Etherll/unsloth that referenced this pull request Aug 21, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: bde629ac01

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Etherll

Etherll commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

@codex review

Etherll pushed a commit to Etherll/unsloth that referenced this pull request Aug 21, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f28d94e68a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +42 to +44
if (isActivationKey(event)) {
activationKeyIsDown = true;
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Disarm when Space starts a new gesture

When the dismissing press produces no click—for example, pointerdown/up on a disabled native composer control—the guard remains armed for 500 ms after pointerup. If the user presses Space during that window, this branch marks it as part of the old gesture even though the guarded pointer is no longer down; the button's keyup-generated click fires before the zero-delay disarm timer and is swallowed. This prevents a distinct keyboard action, such as using Space on the still-focused More trigger to reopen the menu, so Space keydown should disarm when pointerIsDown is already false while preserving the held-Space-before-pointerup case.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rejected after strict product-path validation on exact head 6155946. In the real Studio heavy-thread UI, the Search pill was put in the same native disabled state and tested in Chromium, Firefox, and WebKit with the menu opened by both mouse and keyboard. The disabled press emitted no click, but activeElement became BODY in all six runs; Space then targeted BODY and produced no activation click to swallow. When More was artificially refocused, Radix reopened the menu on keydown and this guard did not prevent it. The synthetic failing sequence manually dispatches a detail=0 click without a focused activatable control, which browsers do not synthesize. No legitimate production path reproduced, so no code change is warranted.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 21, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 6155946aca

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Etherll Etherll left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Etherll
Etherll merged commit 746ad08 into unslothai:main Aug 21, 2026
32 of 34 checks passed
danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Sep 6, 2026
The AST tests pin which menus use NonModalDropdownMenu. What the wrapper then does is
only answerable in a browser, and it is where this has gone wrong before: a dismissal
deleting a chat message (unslothai#9243), a lost trigger focus (unslothai#9772), a guard that outlived the
exit animation, and a menu left anchored to a row that had scrolled away.

smoke-nonmodal-menus.html mounts the real component on a 60 row overflowing list, with a
submenu, a menu whose own viewport scrolls, an unrelated scroller, and one still-modal
menu as a control. The control is the shape every converted menu had before, so a case
that behaves the same on both is Radix rather than this wrapper, and the lock it still
writes to <body> is what proves the probe can see a lock at all.

34 checks, passing on chromium, firefox and webkit. Frontend CI runs the chromium leg
next to the existing dismiss-guard probe; PW_ENGINE picks the other two.
danielhanchen added a commit that referenced this pull request Sep 7, 2026
#10262)

* Studio: take the chat and sidebar menus off the body modal layer

* Studio: gate the menu dismiss guard on the open state

* Studio: check every occurrence of each menu marker

* Studio: close a non-modal menu when the list behind it scrolls

* Studio: cover the non-modal dropdown wrapper in a browser

The AST tests pin which menus use NonModalDropdownMenu. What the wrapper then does is
only answerable in a browser, and it is where this has gone wrong before: a dismissal
deleting a chat message (#9243), a lost trigger focus (#9772), a guard that outlived the
exit animation, and a menu left anchored to a row that had scrolled away.

smoke-nonmodal-menus.html mounts the real component on a 60 row overflowing list, with a
submenu, a menu whose own viewport scrolls, an unrelated scroller, and one still-modal
menu as a control. The control is the shape every converted menu had before, so a case
that behaves the same on both is Radix rather than this wrapper, and the lock it still
writes to <body> is what proves the probe can see a lock at all.

34 checks, passing on chromium, firefox and webkit. Frontend CI runs the chromium leg
next to the existing dismiss-guard probe; PW_ENGINE picks the other two.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Hold the invariant, not the race, when a menu is reopened mid-animation

Whether the reopening click lands while Radix still has the closing content mounted
is a race, and the converted menu and the unconverted control each win it about as
often on Windows Firefox, which made the comparison red for no defect. Assert the
part that is not a race: neither may end up with two menus open.

* Tighten the comments this branch adds

Comments only, no code. The paragraphs that restated the code are gone and the
rest collapse to a line each. Every fact that names a defect somebody could
reintroduce is kept, which is what keeps this a modest sweep rather than a large
one.

* Wire the new browser check into the paths filter and the failure upload

Two things the driver needed and did not have. tests/studio/playwright_nonmodal_menus.py
was missing from the workflow's pull_request paths, where every other driver this job
invokes is listed, so a PR touching only the harness would never run it. And its report
was not in the failure upload, which test_every_smoke_report_is_covered_by_the_failure_upload
rejects by design, so the required workflow-trigger-lint job was red.

* Press the visible sliver instead of forcing the click

tests/studio/test_click_forced.py rejects a forced click that does not scroll
first, and it is right to: force turns the scroll off and Playwright will not
click a point it cannot reach. The sanctioned helper scrolls into view, which is
the one thing this case must not do, since it is about a trigger the scroller
clips. A real pointer press on the intersection of the trigger and the scroller
keeps the case and needs no force at all. Still 34/34 on chromium, firefox and
webkit.

* Do not take focus back from whatever the user clicked while the menu closed

The content is held mounted for its exit animation, so a scroll close can be
followed by a click into an input before onCloseAutoFocus runs. Radix's own
restore checks for that interaction, but the scroll-close path calls
preventDefault, which skips the check, so the trigger pulled the caret straight
back out of the input. Measured on chromium, firefox and webkit: with the menu
scroll-closed and the input clicked 0 to 90ms later, focus ended on the trigger
every time, against the input on an ordinary close.

Make the same check before taking focus. The case the path exists for is
unchanged: with nothing else claiming focus, a scroll close still lands on the
trigger and still keeps the scroll, 600px in all three engines.

The regression case fails without this and passes with it.

---------

Co-authored-by: danielhanchen <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@mahiatlinux
mahiatlinux deleted the fix/studio-action-bar-dismiss-delete branch September 25, 2026 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants