Skip to content

fix(command-center): guard ActionSelector Enter against empty/stale options#3438

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/fix-action-selector-enter-crash
Draft

fix(command-center): guard ActionSelector Enter against empty/stale options#3438
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/fix-action-selector-enter-crash

Conversation

@posthog

@posthog posthog Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Problem

Users in command center hit a full-screen crash when pressing Enter to approve an agent permission or switch mode (accept edits / plan / default), forcing an app restart or navigating away and back.

The root cause: selectCurrent() in useActionSelectorState.ts read allOptions[selectedIndex] and dereferenced selected.id with no bounds check — unlike its siblings selectByIndex and handleClick, which already guard. When the options change mid-render (a permission gets resolved or superseded, a step/mode transition fires, or the clamping effect hasn't run before the keydown), selected is undefined and selected.id throws a TypeError.

This took down the entire screen, not just the one prompt: command center mounts one ActionSelector per grid cell, and there was no error boundary around individual cells — the only boundary was the app-root one, so a single throw unmounted the whole router tree and showed "Something went wrong."

Why: approving agent permissions / switching mode is a core, high-frequency interaction, so a full-screen crash there is disruptive enough that recovery required restarting the app or navigating away.

Changes

  • Add the missing if (!selected) return; guard to selectCurrent, matching the guards selectByIndex and handleClick already have.
  • As defense in depth, wrap each command-center grid cell in its own ErrorBoundary so one cell's failure can no longer take down the whole screen (resets when the cell's task/terminal changes).
  • Add regression tests covering the empty-options and stale-index cases, plus a happy-path assertion.

How did you test this?

  • Added useActionSelectorState.test.ts (3 cases) — all pass via vitest run.
  • pnpm --filter @posthog/ui typecheck — clean.
  • biome check on the changed files — clean.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Created with PostHog Code from an inbox report.

…ptions

Pressing Enter on a permission prompt or mode switch could crash the whole
command-center screen. selectCurrent() read allOptions[selectedIndex] and
dereferenced selected.id with no bounds check, unlike its siblings
selectByIndex and handleClick which already guard. When options change
mid-render (a permission resolves/supersedes, a step/mode transition fires,
or the clamping effect hasn't run before the keydown) selected is undefined
and selected.id throws a TypeError.

Because command center mounts one ActionSelector per grid cell with no
per-cell error boundary, a single throw unmounts the whole router tree via
the app-root boundary and shows "Something went wrong".

- Add the missing `if (!selected) return;` guard to selectCurrent.
- Wrap each command-center grid cell in its own ErrorBoundary so one cell's
  failure can no longer take down the entire screen.
- Add regression tests for the empty and stale-index cases.

Generated-By: PostHog Code
Task-Id: 64856792-d5b4-4990-ac32-0c102f9884ec
@trunk-io

trunk-io Bot commented Jul 14, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit ec46443.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants