Skip to content

Fix terminal stealing new thread focus - #1278

Merged
ymichael merged 2 commits into
mainfrom
bb/investigate-reported-github-issue-thr_bv7p6mpn3y
Aug 10, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/investigate-reported-github-issue-thr_bv7p6mpn3y

Conversation

@ymichael

@ymichael ymichael commented Aug 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • distinguish passive terminal and new-tab panel remounts from explicit focus requests
  • preserve composer or newer user focus while xterm initializes asynchronously
  • retain autofocus for explicit terminal creation, terminal tab activation, and new-tab opens
  • consume new-tab autofocus requests so later passive remounts stay inert
  • cover both terminal focus race orderings plus passive and explicit new-tab focus behavior

Testing

  • pnpm exec turbo run test --filter=@bb/app --force -- src/components/secondary-panel/NewTabFileSearch.test.tsx src/components/secondary-panel/NewTabPage.test.tsx src/components/thread/terminal/ThreadTerminalView.test.ts src/components/thread/terminal/ThreadTerminalContent.test.tsx
  • pnpm exec turbo run typecheck --filter=@bb/app --force
  • pnpm exec turbo run lint --filter=@bb/app --force (0 errors; 141 existing warnings)

Fixes #1160

@SawyerHood

Copy link
Copy Markdown
Collaborator

🚨 SLOP COP 🚨 · review

I am SlopCop. I am reviewing this pull request now.

I will check security, code quality, performance, architecture, and the user flow.

})
) {
terminal.focus();
onAutoFocusHandledRef.current?.();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🚨 slopcop/review — Consume a denied focus request so it cannot affect a later mount.

If focus moves during the asynchronous load, this condition rejects terminal focus. The callback then does not run. Both parents keep the request true. A later terminal mount can reuse that old request and steal focus. Another set to true also cannot start a new request. Consume each request after this decision. Use a request ID and terminal ID to stop an old mount from clearing a new request. Add a lifecycle test for a denied request and a later mount.

@SawyerHood SawyerHood left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🚨 SLOP COP 🚨 · review

ELI5

The terminal loads after the page changes. This patch checks whether another input gained focus. It then leaves that input alone.

Finding

  • P2: A denied focus request stays active. A later terminal mount can reuse it and steal focus. A later terminal action also cannot start a new request. Consume every request after the focus decision. Use a request ID with the terminal ID. Add a lifecycle test for the rejected request and later mount.

Other review results

  • I found no second security issue.
  • I found no performance regression. The new checks use constant time.
  • The two parent views duplicate the new request state. A shared hook can own the request ID and consume rules. This refactor is optional.
  • The type check passed. The focused tests passed all 16 tests. The lint task passed with zero errors and 141 existing warnings.
  • The full app suite passed 2,463 of 2,464 tests. One prompt-box test outside this diff failed.
  • The browser smoke test loaded the real app. It did not complete the terminal-to-new-thread focus sequence.
  • The final GPT-5.6 review confirmed the P2 finding.

I used a comment-only review. I did not approve the pull request or request changes.

@ymichael
ymichael merged commit c81683b into main Aug 10, 2026
10 checks passed
@ymichael
ymichael deleted the bb/investigate-reported-github-issue-thr_bv7p6mpn3y branch August 10, 2026 19:48
amadad pushed a commit to amadad/bb that referenced this pull request Aug 14, 2026
## Summary

- distinguish passive terminal and new-tab panel remounts from explicit
focus requests
- preserve composer or newer user focus while xterm initializes
asynchronously
- retain autofocus for explicit terminal creation, terminal tab
activation, and new-tab opens
- consume new-tab autofocus requests so later passive remounts stay
inert
- cover both terminal focus race orderings plus passive and explicit
new-tab focus behavior

## Testing

- `pnpm exec turbo run test --filter=@bb/app --force --
src/components/secondary-panel/NewTabFileSearch.test.tsx
src/components/secondary-panel/NewTabPage.test.tsx
src/components/thread/terminal/ThreadTerminalView.test.ts
src/components/thread/terminal/ThreadTerminalContent.test.tsx`
- `pnpm exec turbo run typecheck --filter=@bb/app --force`
- `pnpm exec turbo run lint --filter=@bb/app --force` (0 errors; 141
existing warnings)

Fixes get-bb#1160
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.

Focus is stolen by right panel when creating a new session

2 participants