Skip to content

fix(chat): bound the /-menu slash-command fetch so a slow gateway fails visibly - #7418

Merged
bolichen97 merged 1 commit into
kirodotdev:mainfrom
rnoack1:fix/slash-commands-fetch-timeout
Sep 2, 2026
Merged

bolichen97 merged 1 commit into
kirodotdev:mainfrom
rnoack1:fix/slash-commands-fetch-timeout

Conversation

@rnoack1

@rnoack1 rnoack1 commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

At 78cc85a83 the /-menu's command fetch has no deadline and no AbortSignal:

// website/src/api/client.ts:2424
slashCommands: () => fetch('/api/slash-commands').then(j),

// website/src/components/SlashCommandMenu.tsx:148
queryFn: () => api.slashCommands(),

A wedged /api/slash-commands therefore never settles, and isFetching never
clears. That matters because the menu's key-release gate reads it:

const releaseKeysWhenEmpty = !isFetching && filtered.length === 0

So on a slash prefix that matches nothing yet — /xyz, or any server-only
command the offline fallback does not list — the menu takes the
displayed.length === 0 && !releaseKeysWhenEmpty branch and renders null
while useListKeyboardNav's document listener stays attached. Enter is
preventDefaulted by an element that is not on screen. The user cannot send,
and there is nothing to explain why.

This is the same defect class as the $-skills menu, fixed in #7062
(62c20a17e). That PR is the template here; this is the next menu along.

Why it matters

The failure is a composer deadlock, and it is silent. The $-menu at least
held a visible "Loading skills…" up; this menu rendered nothing at all, so the
only symptom was that Enter stopped working — indistinguishable, from the user's
side, from the app having frozen. The one escape was to backspace out of the
slash prefix, which is not discoverable. This PR closes that gap as well as
bounding the fetch: the in-flight window now names itself.

It also mis-reports once the fetch does fail. data defaults to
FALLBACK_COMMANDS, so a settled error still shows the offline list, and a
zero-match against that list rendered "No matching commands". That asserts the
live list was read and did not hold the prefix. It was never read, and the
served list is provider-aware, so a command it would have offered may simply
never have arrived.

What changed

Bound inside api.slashCommands, not at the call site. One
react-query initiator exists today (verified by grep with a fabricated-token
control), so this is not yet about losing a dedupe race — it is about the next
caller of ['slash-commands'] inheriting the bound rather than having to
remember it. Reuses lib/withDeadline.ts as shipped by #7062; no second helper.

export const SLASH_COMMANDS_TIMEOUT_MS = 15_000

slashCommands: (signal?: AbortSignal) =>
  withDeadline(SLASH_COMMANDS_TIMEOUT_MS, signal, s =>
    fetch('/api/slash-commands', { signal: s }).then(j)),

fetch is kept rather than switched to the get helper deliberately: get
adds the X-Session-Key placeholder header, and this endpoint is
provider-aware, so that would be a behaviour change smuggled in beside a
timeout fix.

The in-flight window is named, not merely bounded. The zero-match branch
rendered null while the fetch was outstanding, so for up to 15s the composer
looked frozen with Enter held. It now renders a Loading commands… row — new
key loading_commands across 13 catalogs — mirroring SkillPickerMenu.tsx:237.
Enter is still held there on purpose: a half-typed command must not send.

On the 15s value, stated plainly: it is the sibling constant's value, chosen
for consistency. I did not measure this endpoint, so the comment on the constant
claims no measurement of its own — the two menus are the same kind of composer
affordance blocking Enter on the same gateway, and a second, differently-derived
number here would only be another thing to explain.

No per-query retry:. #7062 folded isDeadlineError into the app-wide
retryPolicy (queryClient.ts:37), and this component sets no retry, so it
already inherits "never retry a deadline". Adding one here would re-introduce
exactly the per-site threading that PR removed. Pinned by test, not by comment.

Failure rendered as failure. SlashCommandMenu.tsx now threads
({ signal }) through and reads isError, and the zero-row copy branches on it
ahead of the empty-state text:

const emptyKey = isError
  ? (… 'commands_load_failed_ctrl_enter_sends' : 'commands_load_failed_enter_sends')
  : (… 'no_matching_commands_ctrl_enter_sends' : 'no_matching_commands_enter_sends')

Two points a reviewer comparing against #7062 will want:

  • Two keys, not three. fix(chat): bound the $-menu skills fetch so a slow gateway fails visibly #7062 ships skills_load_failed plus the two
    send-binding variants because its menu renders an empty state while still
    unreleased. Here a settled error with zero rows ALWAYS releases Enter —
    releaseKeysWhenEmpty is !isFetching && filtered.length === 0, and isError
    implies !isFetching — so the bare variant is structurally unreachable and
    would be dead copy for 13 translators. The existing no_matching_commands_*
    pair omits it for the same reason.
  • Scoped to the zero-row state, matching fix(chat): bound the $-menu skills fetch so a slow gateway fails visibly #7062's isError && items.length === 0.
    When the fallback does yield rows they stay listed and usable; the failure copy
    is for the case where the menu would otherwise have made a false claim.

Real per-locale translations across all 13 catalogs, each composed from that
locale's own shipped halves — its skills_load_failed verb phrase and its
no_matching_commands_* send clause — so separator (— / : / ——), key
naming (Enter vs Invio) and register match what already ships there.
en-XA regenerated with npm run i18n:pseudo.

Two call-site consequences, both deliberate:

  • slashCommands joins HAND_TESTED in ApiClient.coverage.test.tsx. That
    sweep passes positional junk, which now lands on the signal parameter and
    would throw inside withDeadline — the same reason skills was excluded.
    The URL/no-body coverage it provided is re-asserted directly in the new
    api test.
  • One existing assertion changes copy. filtering to /tan … drove the error
    path and expected "No matching commands"; it now expects the failed-load
    copy. Its actual intent — never render an inert /tangent row — is unchanged
    and still asserted.

Deferred, and named here because leaving it unnamed is the real defect.
api.fileSearch is the same class and is not bounded by this PR. It accepts and
forwards an AbortSignal (client.ts:3167) but carries no deadline, and
FilePickerMenu sits behind the same !isFetching release gate
(FilePickerMenu.tsx:160), so the @-menu can swallow Enter exactly as the /-menu
did. It is deliberately not touched here because #7068 already implements it: that PR
is open and non-draft, and carries its own website/src/lib/fileSearchDeadline.ts, a
bounded FolderPanel, and a 240-line timeout suite. Bounding it here would duplicate a
live sibling and collide in FilePickerMenu.tsx, queryClient.ts and these same
locale catalogs. If #7068 is abandoned, this is the follow-up to pick up.

Tests

src/test/apiSlashCommandsDeadline.test.ts (new, 5 tests) — the client-layer
bound, against a gateway that settles only if the signal aborts: rejects with
TimeoutError given no signal (the pre-fix shape); relays an outer signal so
react-query unmount/cancel still aborts; asks for SLASH_COMMANDS_TIMEOUT_MS;
and the two that must pass either way — a healthy fetch resolves untouched, and
the URL is exactly /api/slash-commands with no body.

src/test/SlashCommandMenu.timeout.test.tsx (new, 6 tests) — what the menu
owes: the AbortSignal reaches api.slashCommands; a timeout names the failure
and Enter passes through un-prevented (fireEvent.keyDown returns true) with
onSelect untouched; it does not claim "no matching commands"; ctrl-enter
mode names Ctrl+Enter; the fetch runs once under the production
retryPolicy; and, as the negative control on the copy's scope, a bare /
still lists the fallback with no failure text.

Negative controls, run in two stages rather than asserted. With only
SlashCommandMenu.tsx reverted to main, 6 tests fail — 5 on the absent
failure copy and one on expected undefined to be an instance of AbortSignal —
while the fallback-rows control still passes. With only the withDeadline wrap
removed from client.ts (the constant left in place, so the failure is
behavioural and not a missing symbol), the 3 deadline tests hang and time out at
15000ms, which is the defect itself; the healthy-resolve and URL tests still
pass. Both files were restored and re-diffed byte-identical afterwards.

Local gates, all green: npx tsc -b; npx eslint src/ --max-warnings 659
(0 errors, 657 warnings — the same count a clean 78cc85a83 tree produces,
measured by stashing this change and re-running, so the diff adds none);
npx jscpd . (0 clones); node scripts/i18n-check.mjs with
I18N_BASE_REF=78cc85a83… — including check-unit-literals reporting 0
number+unit literals on added lines, check-i18n-keys resolving the new ternary
statically with no new dynamic site, and check-untranslated-values flagging
none of the 26 new values as passthrough; and npx vitest run src/.

Screenshot evidence

Captured against the REAL built SPA by website/scripts/capture-slash-command-fetch-timeout.mjs,
which asserts as well as photographs: the two timeout scenes let /api/slash-commands HANG, so the
production withDeadline timer is what fires rather than a simulated rejection, and the script
exits non-zero unless the expected copy rendered inside a role="status" live region. Nothing in
CI runs that file — the CI-enforced half is SlashCommandMenu.timeout.test.tsx and
apiSlashCommandsDeadline.test.ts.

Healthy gateway: typing a slash lists the served commands. Unchanged by this PR, included so the failure frames below are read against a known-good baseline

Fetch in flight on a zero-match prefix: the menu NAMES the wait with "Loading commands…" instead of rendering nothing, and Enter stays held so a half-typed command cannot send

The same scene once the deadline fires: "Couldn't load commands — Enter sends the message" in a live region, so the failure names itself and Enter is handed back, instead of the menu claiming "No matching commands" about a list it never read

Same timeout under a ctrl-enter send binding: the copy names Ctrl+Enter and never promises bare Enter, which is a newline in that mode

Pattern harvest

Rule candidate: semgrep
Pattern: a react-query queryFn that drops the injected signal — queryFn: () => api.foo() instead of queryFn: ({ signal }) => api.foo(..., signal) — leaving the fetch unbounded, so a wedged gateway latches the component's in-flight state forever.

Third instance of this class here, which is what makes it a candidate rather than a one-off: #7062 (api.skills, the $-menu, merged), #7068 (file search, the @-menu, open), and this one (api.slashCommands, the /-menu). All three are composer menus whose in-flight state gates a key binding, so an unbounded fetch does not merely spin — it swallows Enter and the message cannot be sent.

Only the dropped-signal half is mechanically detectable. The other half belongs in a review prompt rather than a rule: a settled error must not render as a confident empty state. Here data defaulted to an offline fallback list, so a failed load was indistinguishable from a successful one, and a zero-match against that fallback still claimed "No matching commands".

@rnoack1
rnoack1 requested review from a team and hoang-phan98 September 1, 2026 01:29
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 1, 2026
@rnoack1
rnoack1 force-pushed the fix/slash-commands-fetch-timeout branch from 7c51ea9 to 1af3bab Compare September 1, 2026 01:43
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 1, 2026
@github-actions

github-actions Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings

Reviewed f25073694a96e6d09828f0c6a1828e9a7d2fef90 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] f250736

@github-actions

github-actions Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — ✅ PASS

Design-level review of f25073694a96e6d09828f0c6a1828e9a7d2fef90 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

All claims verified against the base tree: withDeadline and the deadline-aware retryPolicy ship as described, the SkillPickerMenu precedent matches, temp-screenshots/ and capture-*.mjs are established repo conventions, and the render-branch rewrite covers every state (in-flight zero-match, settled error, cached-rows refetch) coherently.

Design-Verdict: PASS

Faithfully extends the proven #7062 pattern to the next composer menu; every trade-off (fallback-row scoping, two keys, deferred fileSearch) is deliberate and verified.

[DESIGN-REVIEWED] f250736

@github-actions

github-actions Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — ✅ PASS

Premise-level review of f25073694a96e6d09828f0c6a1828e9a7d2fef90 via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

All claims verified against the base. The pre-state matches (client.ts:2430 bare fetch, SlashCommandMenu.tsx:223 renders null in-flight), withDeadline/retryPolicy/SKILLS_TIMEOUT_MS exist as #7062 shipped them, the production consumer count of api.slashCommands is exactly 1, the 13-catalog set is correct (en.json is generated and never hand-edited), and the one unfixed sibling (fileSearch at client.ts:3188 behind FilePickerMenu.tsx:160's gate) is named and deferred by the author. Final review:

First-Principles-Verdict: PASS

A real composer deadlock gets a bound, a named wait, and honest failure copy — every item traces to the reported defect or a documented invariant.

What this change ships

Intent: stop a wedged /api/slash-commands from silently swallowing Enter in the composer — a FIX.

  1. /-menu fetch now fails after 15s instead of hanging forever — justified (reported defect; fix(chat): bound the $-menu skills fetch so a slow gateway fails visibly #7062 fixed the same class).
  2. In-flight zero-match shows "Loading commands…" instead of an invisible Enter-swallowing menu — declared, justified.
  3. Settled failure reads "Couldn't load commands" instead of the false "No matching commands" — declared, justified.
  4. api.slashCommands gains an optional AbortSignal — one consumer, not generalized beyond it.
  5. Exported SLASH_COMMANDS_TIMEOUT_MS — mirrors the recorded SKILLS_TIMEOUT_MS precedent.
  6. Three keys × 13 catalogs — mandated by the i18n invariant; catalog set verified complete.
  7. Capture script + 4 screenshots — rides along, but matches recorded repo practice (339 capture-*.mjs, 601 tracked screenshots).
  8. Test moves (HAND_TESTED, one copy assertion) — declared, intent preserved.

Watch

[FIRST-PRINCIPLES-REVIEWED] f250736

@github-actions

github-actions Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review (fork) — ✅ no blocking findings

Reviewed f25073694a96e6d09828f0c6a1828e9a7d2fef90 via the fork AI-review pipeline; updated in place on each push.

Review details

I've traced the full component logic and the diff. Let me evaluate the single candidate.

Candidate 1 — the in-flight "Loading commands…" <div> omits role="status" that the settled-empty/error sibling carries.

Verifying against the render code (SlashCommandMenu.tsx:233–239, new lines 292–294):

  • (a) input: a screen-reader user types a server-only zero-match prefix while the fetch is in flight — plausible, occurs in practice.
  • (b) path: displayed.length === 0 && isFetching → renders <div className="px-3 py-3 …">{loading_commands}</div> with no role="status", unlike the role="status" on the settled-empty/error branch. Grounded.
  • (c) outcome: this is where it fails the bar. During the loading window Enter is still deliberately swallowed (releaseKeysWhenEmpty = !isFetching && … is false) — there is no "flip" to announce yet, which is exactly what the sibling's role="status" comment exists to voice. The state is transient and resolves within the 15s deadline to either the role="status" error row (which is announced) or navigable role="option" rows. The "wrong outcome" is at most that "Loading commands…" isn't auto-spoken — and it's genuinely unclear this is undesired rather than deliberate (the discovery pass itself couldn't confirm it, rating it "low").

This is a minor a11y polish item, ambiguous as to whether it's even a defect, and does not reach the 80+ bar for a concrete wrong outcome. Dropped.

Step 2: I traced the surrounding logic for new defects — the release-gate (releaseKeysWhenEmpty) is unchanged from base; the isError→FALLBACK_COMMANDS default, the zero-row emptyKey selection, the cached-refetch path, and the deadline/retry behavior all resolve correctly and match the tests. No grounded finding at 80+.

No findings.

[OPUS-REVIEWED] f250736

@github-actions

github-actions Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Fable 5, fork) — ✅ PASS

UX-level review of f25073694a96e6d09828f0c6a1828e9a7d2fef90 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

UX-Verdict: PASS

The failure now names itself in the user's vocabulary, the wait is visible, and every string mirrors the shipped $-menu pattern per locale — the experience holds.

Suggestions

  • The Loading commands… row (SlashCommandMenu.tsx) renders without role="status" while the error/empty row has it — a screen-reader user typing /xyz gets up to 15s of silence with Enter swallowed, the exact opacity this PR fixes for sighted users; add role="status" (or aria-live="polite") to the loading row.

[UX-REVIEWED] f250736

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision readiness: action required A blocking check or review needs attention labels Sep 1, 2026
@rnoack1
rnoack1 force-pushed the fix/slash-commands-fetch-timeout branch from 1af3bab to e6b9192 Compare September 1, 2026 03:06
@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Sep 1, 2026
@rnoack1
rnoack1 force-pushed the fix/slash-commands-fetch-timeout branch 3 times, most recently from 019b352 to a4e2acc Compare September 2, 2026 00:41
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 2, 2026
@rnoack1
rnoack1 force-pushed the fix/slash-commands-fetch-timeout branch 2 times, most recently from a7487ea to c78c8b2 Compare September 2, 2026 02:20
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Sep 2, 2026
…ls visibly

Give api.slashCommands an AbortSignal and a 15s deadline, and render a failed
load as a failure so a wedged gateway stops swallowing Enter in the composer.
@rnoack1
rnoack1 force-pushed the fix/slash-commands-fetch-timeout branch from c78c8b2 to f250736 Compare September 2, 2026 04:00
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: passed Eligible automated validation passed for the current revision readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 2, 2026
// a newline); role="status" so screen-reader users hear the flip too.
? <div role="status" className="px-3 py-3 text-[12px] text-muted">{i18nT(sendOnEnter === 'ctrl-enter' ? 'components.slashCommandMenu.no_matching_commands_ctrl_enter_sends' : 'components.slashCommandMenu.no_matching_commands_enter_sends')}</div>
? (isFetching
? <div className="px-3 py-3 text-[12px] text-muted">{i18nT('components.slashCommandMenu.loading_commands')}</div>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 The new loading row is silent to screen readers, while your own open sibling PR #7668 exists precisely to announce the $-picker's loading hold.

? <div className="px-3 py-3 text-[12px] text-muted">{i18nT('components.slashCommandMenu.loading_commands')}</div>

Cause → mechanism → consequence: the loading row carries no role="status"/live-region semantics → a screen-reader user typing /xyz hears nothing while Enter stays preventDefaulted for up to 15s → the exact silent-held-Enter confusion this PR fixes visually persists aurally. Today this mirrors SkillPickerMenu's shipped loading row exactly (verified at head), so it is consistent — but #7668 ("announce that Enter is held while the $skill picker loads") will make that sibling announce, leaving this menu the odd one out the day it merges.

Suggestion: either add role="status" here now (matching the settled-empty row two lines down), or note in the PR that this row inherits whatever announcement pattern #7668 lands, as a named follow-up. Non-blocking either way.

[code-review-sage]

@bolichen97
bolichen97 enabled auto-merge (squash) September 2, 2026 09:27

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving on the strength of a full readiness audit of every open PR against main, not a
line-by-line reading of this diff — recording that plainly so the next reader knows what this
stamp does and does not cover.

Verified against this exact head SHA:

  • readiness: passed present, and PR Readiness — the one required status context on main
    (ruleset protected-branches) — is success on this head.
  • No check run on this head is failure, cancelled, timed_out or still in flight. Skipped
    jobs are path-filtered conditionals, none of them required.
  • mergeable: true, and the head is not far enough behind main for its green CI to describe a
    base that no longer exists.
  • No surviving reviewer CHANGES_REQUESTED: any such review is on an older commit and therefore
    already dismissed by dismiss_stale_reviews_on_push.
  • Every issue comment, inline review comment and review thread was read and classified. Nothing
    left is an unresolved human change request — the remainder is bot review-lane output, resolved
    or outdated threads, explicitly non-blocking suggestions, and author status notes.

Auto-merge (squash) is armed, so this lands once every other ruleset requirement is met.

@bolichen97
bolichen97 merged commit 6bb79b0 into kirodotdev:main Sep 2, 2026
72 checks passed
@rnoack1
rnoack1 deleted the fix/slash-commands-fetch-timeout branch September 2, 2026 18:25
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants