Repository navigation
fix(chat): bound the $-menu skills fetch so a slow gateway fails visibly - #7062
Conversation
3ae889e to
885e622
Compare
GPT 5.6 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Design Review (Fable 5, fork) — ✅ PASSDesign-level review of The patch is fully covered: client-layer deadline ( Design-Verdict: PASS Bounding once inside Suggestions
[DESIGN-REVIEWED] dc1c01a |
UX Review (Fable 5, fork) — ✅ PASSUX-level review of All evidence reviewed: the patch, the SkillPickerMenu base component, and the sibling consumers of UX-Verdict: PASS A hang becomes a bounded, truthfully-worded failure that hands Enter back — copy, locales, and keyboard behavior all match the picker's established pattern. [UX-REVIEWED] dc1c01a |
Opus 4.8 Review (fork) — ✅ no blocking findingsReviewed Review detailsThe candidate list is empty (the discovery pass found nothing), so there is nothing to falsify in Step 1. I've independently verified the load-bearing logic myself:
No grounded defect (a/b/c at 80+) survives, and none is newly derivable. This is a successful clean review. No findings. [OPUS-REVIEWED] dc1c01a |
First Principles Review (Fable 5, fork) — ✅ PASSPremise-level review of All description claims check out against the base tree: the six First-Principles-Verdict: PASS A measured defect fixed at the mechanism level, the true cause named and handled elsewhere, and every rider serves the same "fail visibly" job. What this change shipsIntent: stop the
Watch
[FIRST-PRINCIPLES-REVIEWED] dc1c01a |
885e622 to
d9acfe0
Compare
d9acfe0 to
45504a5
Compare
0512acf to
645b96f
Compare
645b96f to
1600b11
Compare
Give api.skills an AbortSignal and wrap the SkillPickerMenu queryFn in a 15s deadline, so an unsettled fetch stops showing "Loading skills…" forever.
1600b11 to
dc1c01a
Compare
Open PR relationship auditThis is a consolidated, point-in-time code-level audit note. It compares complete merge-base diffs and current/merged code; it does not treat a shared topic as duplication or partial coverage as completion. Relationship findings
No PR, Issue, label, branch, or review state was changed by the relationship-note portion of this audit. |
Problem / Motivation
SkillPickerMenucomputesconst loading = isLoading && open, and react-query'sisLoadingclears only when the query resolves or rejects.api.skillspassed noAbortSignal, so a response that never arrives never settles, and the$-trigger menu showsLoading skills…indefinitely — indistinguishable from a hang.skillswas the outlier in its own file. Its siblingschatSlotDetail,sendChatandfileSearchall already accept anAbortSignal.The latency that exposes it is real and measured.
GET /api/skillson one host inside twenty minutes:Byte-identical each time, so the variance is not the skills scan (~0.6s) — it is event-loop contention in the gateway. That cause is being addressed separately by #7031 (a 3s server-side memo for this endpoint), which reduces exposure but does not fix this: any future slow path still spins forever, because the client has no deadline at all. This PR is the client-side half and does not overlap #7031.
Why it matters
A spinner that never resolves is worse than an error. The user cannot tell "slow" from "broken", so the only recovery is a reload — and the menu is on the composer's typing path, so it is hit often.
There is a second, sharper consequence. The menu's
releaseKeysWhenEmptygate is!isFetching && (data !== undefined || isError) && matched.length === 0. While the query is pending it isfalse, which is correct — it deliberately swallows Enter so a draft mid-$tokenis not sent by accident. But an unbounded pending state means Enter is swallowed forever: the composer cannot send at all until the page is reloaded. Verified in source rather than assumed: that gate already admitsisError, so a settled rejection is enough to release the keys, and an existing test (after the skills fetch settles in an ERROR, Enter is released) pins it. A timeout therefore needs no downstream change — it just has to make the query settle.What changed
Four small pieces.
website/src/lib/withDeadline.ts(new, 40 lines) — runs an attempt under a deadline, relays the caller's signal, and releases both the timer and the relay listener on settle.website/src/api/client.ts—skillsgains an optional trailingsignal(threaded through the sharedget()helper, also a new optional trailing parameter, so every other caller is unaffected) and the deadline is applied here, once:Each of the three
queryFns that had been wrapping the call individually now just passes react-query's signal straight through —({ signal }) => api.skills(slotKey, agent, signal)— and thewithDeadline/SKILLS_TIMEOUT_MSimports are gone from all three components.The deadline is not retried — bound once, app-wide.
api/queryClient.tsgainsisDeadlineErrorand folds it into the existing defaultretryPolicyas a first clause. Without it the default retries any non-throttle failure once, so a 15s bound settled at ~31s with its backoff — and becauseisLoading/releaseKeysWhenEmptyonly settle when retries exhaust, the composer stayed un-sendable for twice the advertised window.An earlier revision threaded
retry:per query at three sites. That repeated, for retry, the same weakness this PR argues against for the deadline: react-query dedupes on the key, so a per-initiator rule is only as strong as the weakest initiator sharing that key. Binding it in the default policy every query inherits closes all of them and is strictly smaller — three imports and three option lines deleted. It stays narrower thanretry: false: an ordinary failure keeps its single retry and a throttle keeps the full 429 ladder, both pinned by assertion. ATimeoutErroronly ever originates fromlib/withDeadline, so no other query's behaviour changes today.A failed load no longer renders as an empty catalog — a new
isErrorbranch selectsskills_load_failed{,_enter_sends,_ctrl_enter_sends}instead of theno_matching_skills*copy, with all 14 catalogs updated (en-XAregenerated vianpm run i18n:pseudo). The key-release behaviour is unchanged: returning Enter to the composer was already correct.Why the deadline binds inside
api.skillsrather than at each initiatorAn earlier revision of this PR threaded the deadline at three call sites, and this description argued for that. Both were wrong, and the reason is worth stating because it is the whole shape of the fix.
React-query dedupes on the query key, so per-initiator binding is only as strong as the weakest initiator of that key. Measured at source, there are two shared keys and six non-test call sites:
['skills', slot, project, agent]ChatInput.tsx:1337(focus prefetch),SkillPickerMenu.tsx:97['skills']HookSkillsSelect.tsx:30,skillsProvider.ts:206,SkillsTab.tsx:90['skills-catalog']AgentSkillsEditor.tsx:56Whichever initiator wins the race is the one that actually fetches; the others reuse its promise and never run their own
queryFn. So threading three of six left two live holes — the$-menu could dedupe ontoChatInput's prefetch, and the command palette ontoSkillsTaborHookSkillsSelect— and any initiator added later would silently reopen one. Wrapping once insideapi.skillsmakes the hole structurally unreachable: every one of the six goes through the same bounded function, including the three (AgentSkillsEditor,HookSkillsSelect,SkillsTab) that this PR previously declared unbounded-and-deferred. It is also strictly smaller — three wraps and four import lines deleted.Measured at source, there are six react-query initiators of
api.skills, not five — the review notes nameSkillsTabandAgentSkillsEditoras the unfixed pair but missHookSkillsSelect.tsx:32, which also uses the bare['skills']key. So per-site threading had left three holes, two of them on the key the command palette dedupes onto. Folding the rule into the default policy closes all three, and the retry test carries one case per initiator.One correction to the First Principles note, verified at source: its
client.ts:2770,2862,3091andSkillPickerMenu.tsx:158coordinates have drifted by a rebase (the siblings are now at:2772/:2864/:3093and theisErrorgate at:162). Both underlying claims hold —chatSlotDetail/sendChat/fileSearchdo take anAbortSignal, and theisErrorrelease gate does exist.Both sibling pickers are untouched, each deferred for a named reason:
FilePickerMenu.tsx:111—#7068's work; touching it here would collide.SlashCommandMenu.tsx:189— carries the identical Enter-swallowing gate (!isFetching && filtered.length === 0) overapi.slashCommands()(client.ts:2396, which takes no signal), so a wedged fetch swallows Enter on an unmatched/xyz. Same root cause, different endpoint and different cache key, so it needs its own bound, its own tests and its own measured latency evidence — none of which this diff carries. Deferred to a follow-up PR of its own, in the same shape as this one; widening the diff to a third picker now would invite fresh findings on a change that is otherwise ready.Why not
AbortSignal.any([signal, AbortSignal.timeout(N)])That is the direct expression of this and was the first implementation. Two things pushed it out, one of them measured:
AbortSignal.timeoutexposes no handle, so its timer cannot be cancelled. It therefore leaves a live 15s timer behind every successful menu open. That is a leak on its own terms, and it is observable: it stalled the teardown of an unrelated suite (ChatInput.skillTrigger.test.tsx) by 10s, because the shared test setup drains the DOM task queue before shutting its mock server down — 3.69s baseline to a 10,283ms suite failure. AnAbortControllerplus an explicitclearTimeouton settle has neither problem.browserslistand no vite/esbuild target override;tsconfig.app.jsonistarget: ES2020,lib: ["ES2023", "DOM", "DOM.Iterable"].AbortSignal.timeoutalready ships in-tree (src/pages/DevFleetPage.tsx, twice), floor Chrome 103 / Firefox 100 / Safari 16.AbortSignal.anyhas no existing use and a materially higher floor: Chrome 116 / Firefox 124 / Safari 17.4. A missinganythrows synchronously insidequeryFn, which react-query catches — turning "slow sometimes" into "the menu is empty every time it opens" on an older engine. TheAbortControllerform needs no feature detection, so the question does not arise.Why the abort reason is an
Error, not aDOMExceptionThe timeout reason would naturally be
new DOMException('…', 'TimeoutError')— that is whatAbortSignal.timeoutitself produces. Two i18n gates inFrontend Lint & Type Checkrefuse it, and both are zero-tolerance on added lines with no ceiling to raise:check-i18n-strings.mjsdrives a second eslint pass whosecallees.excludecarries'^(Type)?Error$'under the heading "Diagnostics and dev-only output" — but notDOMException, so both the message and the'TimeoutError'name argument were reported (2 findings on one line). Note it runs withallowInlineConfig: false, so aneslint-disablecomment cannot dispose of this.check-unit-literals.mjsis a separate TypeScript-AST scan that never consults eslint's exclusions, and flagged${ms}msas a number+unit literal on its own. Its documented dispositions are thesrc/i18n/format.tshelpers or aROUND_TRIPparser entry — neither applies to an internal abort reason that nothing renders and nothing parses.So the reason is built with
Error(the exemption the repo already grants diagnostics) and the interpolated duration is dropped rather than reformatted — importing an i18n formatter into a leaf utility to translate a string no one reads would be the wrong trade..nameis still'TimeoutError', which is what the tests assert and what the web standard uses.Choice of N = 15s
Both bounds are pinned by assertion (
> 9_760,< 41_410), so moving the constant outside the measured window fails the suite rather than drifting silently.Noted, not changed
skillsCacheStaleTime()inwebsite/src/lib/skillsCache.ts(a file this PR no longer touches) returns0whenprojectisundefined, so on a project-less slot every reopen refetches — which is what makes this endpoint's latency user-visible as often as it is. I left it alone on purpose: the0is deliberate and load-bearing. Its own comment explains that without project identity the query key cannot observe a same-slot project switch, so caching would serve another project's catalog. That is a correctness trade, not an oversight, and narrowing it is a separate change with a separate argument.Tests
The deadline is now a client-layer guarantee, so it is pinned at that layer:
website/src/test/apiSkillsDeadline.test.ts(new) drives the realapi.skillsagainst a stubbedfetchthat only settles on abort. Its first case passes no signal at all — the exact shapeAgentSkillsEditor,HookSkillsSelectandSkillsTabuse — which is what proves those three are bounded now. The component suites keep what the components actually owe: passing react-query's signal through, rendering a settled failure as a failure, and — under the app's own default retry policy rather than aretry: falseclient — running the fetch exactly once.Three existing arity assertions in
SkillPickerMenu.test.tsxwere updated for the new third argument.Counts
apiSkillsDeadline.test.tsskillsRetryPolicy.test.tswithDeadline.test.tsSkillPickerMenu.timeout.test.tsxSkillPickerMenu.dedupe.test.tsxChatInput.skillsPrefetchDeadline.test.tsxSkillPickerMenu.test.tsxApiClient.coverage.test.tsxvitest run src/npx tsc -bnpx eslint src/ --max-warnings 659npx jscpd .node scripts/i18n-check.mjsOne upstream baseline refresh, not mine
Rebasing onto
bb3d4943952abrought in20b3710c054a, after whichtest/test_agent_sdk_boundary.py::test_every_recorded_violation_still_existsfails with{'src/kiro_crew/subagent.py': (9, 8)}: the baseline records 9 imports for that file while the tree has 8. Applied the refresh the gate itself prescribes (--update-baseline). The rule is unchanged and no exemption was added.Narrowed to exactly the one prescribed line: the script also regenerates its own header comment, which would have rewritten an unrelated line of prose, so that line is left at upstream's text. The committed diff is the single count line and nothing else; the boundary suite then passes 25/25.
Negative controls
A passing test proves nothing on its own, so each claim was checked by reverting the thing it asserts.
withDeadlinewrap insideapi.skillsclearTimeout(timer)removed fromrelease()outer.abortedup-front check removedisErrorcopy branch removedisDeadlineErrorclause removed from the defaultretryPolicyretry: falseA harness collision, and where the tolerance belongs
Moving the wrap into
api.skillsmade an existing test fail —ApiClient.coverage.test.tsx's "every api method issues one well-formed /api request", which drives every method with uniform positional junk ('sw-1'…'sw-4'). The other signal-taking methods survive that because they only ever forward the signal tofetch, which the mock ignores;withDeadlinewas the first code to actually use it, so a string in the signal position threwTypeError: outer?.addEventListener is not a function.An earlier revision absorbed this with a
typeof outer?.addEventListener === 'function'guard inwithDeadline. That was the wrong layer: production has zero non-signal producers across all six call sites, so the guard defended only against the harness. The guard is gone, and the tolerance now sits where the non-signal actually originates —skillsjoins the harness's ownHAND_TESTEDescape hatch (alongside the four methods already there for needing real fixtures), and that sweep's URL assertions are replicated verbatim againstapi.skillsinapiSkillsDeadline.test.ts, so excluding it costs no coverage. Verified by the full suite passing with the guard removed: had anything outside the harness depended on it, that would have shown up here.Why no screenshot: No layout, theme, or component change — no new markup and no styling. The change is behavioural (a stuck
Loading skills…now settles) plus one string swap in the picker's existingrole="status"empty-state slot:No matching skills — Enter sends the messagebecomesCouldn't load skills — Enter sends the messageon the error path only. Both the old and new strings are in the diff verbatim, in the same element, so the visual result is fully judgeable from the diff and the catalog entries; a screenshot would show pre-existing chrome around one line of text.