From ff5a83bc5a88772b2f5f7e60c23c5b90b282d467 Mon Sep 17 00:00:00 2001 From: "paseo-bot[bot]" <266920839+paseo-bot[bot]@users.noreply.github.com> Date: Sun, 22 Nov 2026 05:50:48 +0000 Subject: [PATCH] Keep stale slash menu choices from archiving agents (#10484) * fix(app): ignore slash menu picks made before the menu filters On web the cursor reaches the autocomplete after paint. A Tab or Enter pressed right after typing could pick from the unfiltered list, where /exit is the default highlight, and archive the agent. Skip the pick when the typed command no longer matches the query the menu was built for. Co-Authored-By: Claude Opus 5.5 * fix(app): limit the stale slash menu guard to key presses Clicks also pass the live input snapshot, so the guard could drop a click on a visible option while the cursor update was still pending. A click picks what the user sees. Check for a stale menu only when Tab or Enter selects. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: 3ae3ae Co-authored-by: Claude Opus 5.5 Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com> Co-authored-by: Bae Seongmin <83870598+3ae3ae@users.noreply.github.com> --- .../e2e/browser/client-slash-commands.spec.ts | 39 +++++++++++++++++++ .../app/src/hooks/use-agent-autocomplete.ts | 26 +++++++++++-- 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/packages/app/e2e/browser/client-slash-commands.spec.ts b/packages/app/e2e/browser/client-slash-commands.spec.ts index a3b5a658b..a16d46818 100644 --- a/packages/app/e2e/browser/client-slash-commands.spec.ts +++ b/packages/app/e2e/browser/client-slash-commands.spec.ts @@ -59,6 +59,35 @@ async function selectClientSlashCommand(page: Page, query: string, label: string await input.press("Enter"); } +async function typeBeforeMenuFilters( + page: Page, + input: { text: string; key: "Tab" | "Enter" }, +): Promise { + await composerLocator(page).evaluate(async (element, { text, key }) => { + if (!(element instanceof HTMLTextAreaElement)) { + throw new Error("Composer input is not a textarea"); + } + const setValue = Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, "value")?.set; + if (!setValue) throw new Error("Textarea value setter is unavailable"); + setValue.call(element, text); + element.setSelectionRange(text.length, text.length); + element.dispatchEvent(new Event("input", { bubbles: true })); + await Promise.resolve(); + element.dispatchEvent(new KeyboardEvent("keydown", { key, bubbles: true, cancelable: true })); + await new Promise((resolve) => requestAnimationFrame(() => setTimeout(resolve, 0))); + }, input); +} + +async function showExitSuggestion(page: Page, query: string): Promise { + await composerLocator(page).fill(query); + await expect(page.getByText("/exit", { exact: true }).first()).toBeVisible(); +} + +async function expectOpenAgentWithInput(page: Page, agentId: string, text: string): Promise { + await expect(composerLocator(page)).toHaveValue(text); + await expectWorkspaceTabVisible(page, agentId); +} + async function expectAgentArchivedInSessions(page: Page, title: string): Promise { await openSessions(page); await expectSessionRowArchived(page, title); @@ -131,6 +160,16 @@ test.describe("Client slash commands", () => { ); }); + for (const key of ["Tab", "Enter"] as const) { + test(`${key} ignores an exit suggestion for an earlier query`, async ({ page }) => { + await withOpenReadyMockAgent(page, { title: "Stale slash command" }, async ({ agentId }) => { + await showExitSuggestion(page, "/e"); + await typeBeforeMenuFilters(page, { text: "/co", key }); + await expectOpenAgentWithInput(page, agentId, "/co"); + }); + }); + } + test("slash clear replaces the active agent with a matching draft", async ({ page }) => { await withOpenReadyMockAgent( page, diff --git a/packages/app/src/hooks/use-agent-autocomplete.ts b/packages/app/src/hooks/use-agent-autocomplete.ts index f08a69c32..4ff69492e 100644 --- a/packages/app/src/hooks/use-agent-autocomplete.ts +++ b/packages/app/src/hooks/use-agent-autocomplete.ts @@ -110,6 +110,10 @@ function resolveAgentAutocompleteSnapshot(input: { }; } +function isSameSlashCommand(a: SlashCommandRange | null, b: SlashCommandRange | null): boolean { + return a?.start === b?.start && a?.query === b?.query; +} + interface DirectorySuggestionEntry { path: string; kind: "file" | "directory"; @@ -746,9 +750,25 @@ export function useAgentAutocomplete(input: UseAgentAutocompleteInput): AgentAut ); const selectOptionFromKeyPress = useCallback( - (option: AutocompleteOption, event?: AgentAutocompleteKeyPressEvent) => - onSelectOption(option, event?.input), - [onSelectOption], + (option: AutocompleteOption, event?: AgentAutocompleteKeyPressEvent) => { + // The cursor reaches the menu after paint, so a key can land while the options still + // belong to an older query. Never pick from that list. A click picks what the user sees. + if ( + mode === "command" && + event && + !isSameSlashCommand( + findActiveSlashCommand({ + text: event.input.text, + cursorIndex: event.input.selection.start, + }), + activeSlashCommand, + ) + ) { + return; + } + onSelectOption(option, event?.input); + }, + [activeSlashCommand, mode, onSelectOption], ); const { selectedIndex, onKeyPress } = useAutocomplete({