fix(agent): guard undefined availableCommands in useAcpSlashCommands - #165
Merged
Conversation
The cached-meta response can omit `availableCommands` entirely (a live ACP session entry that hasn't populated the field yet is serialized without the key), even though the response type declares it non-optional. `setCommands(response.availableCommands)` then set `commands` to `undefined`, and a later `.length` read crashed CanvasPage with an uncaught TypeError and no error boundary, making the whole Space unopenable. Default to `[]` when the field is missing, and add a regression test covering a response without `availableCommands`. Fixes #164 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #164
Root cause
useAcpSlashCommands.tscalledsetCommands(response.availableCommands)without a fallback.GET /threads/:threadId/cached-metacan return a body whereavailableCommandsis entirely absent (a live ACP session entry that hasn't populated it yet serializes without the key), socommandsbecameundefinedand a later.lengthread crashedCanvasPagewith an uncaughtTypeError. No route-level error boundary exists, so the whole Space became unopenable.Fix
Default to
[]when the field is missing:setCommands(response.availableCommands ?? []).Testing
useAcpSlashCommands.test.tsxcovering a cached-meta response withoutavailableCommands.pnpm --dir apps/web exec vitest run src/hooks/useAcpSlashCommands.test.tsx— 3/3 pass.pnpm typecheck— clean.pnpm format/pnpm lint:fix— no changes beyond the fix itself.