Skip to content

fix: solve #4384 — guard Cmd+T / new terminal against rapid presses during daemon bootstrap#4385

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
triage/issue-4384-25640142335
Draft

fix: solve #4384 — guard Cmd+T / new terminal against rapid presses during daemon bootstrap#4385
github-actions[bot] wants to merge 1 commit into
mainfrom
triage/issue-4384-25640142335

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented May 10, 2026

Root cause

On cold start, the first terminal.createSession blocks for up to ~5s waiting for the pty daemon to come up (see DaemonSupervisor.waitForSocket(socketPath, 5_000)). Every additional Cmd+T press or "New Terminal" click during that window awaits the same bootstrapPromise. When the socket becomes ready, all queued tRPC calls unblock together and each one creates a terminal — so 5 mashed Cmd+T's during cold start spawn 5 terminals at once.

The two unguarded handlers identified in #4384:

  • useWorkspaceHotkeys.ts NEW_GROUP (Cmd+T)
  • useWorkspacePaneOpeners.ts addTerminalTab (sidebar/menu "New Terminal")

The fix

Mirror the existing isClosingPaneRef pattern used by CLOSE_PANE: drop re-entrant calls while a creation is pending. Extracted as a tiny createInFlightGuard factory next to useV2TerminalLauncher so the lock state is held in a useRef per handler and the logic is unit-testable.

This is fix #2 from the issue's "Proposed fixes" list. Fixes #1 (eager bootstrap) and #3 (optimistic placeholder) are not addressed here.

Tests

  • inFlightGuard.test.ts includes a reproduction test that simulates rapid presses landing on a single deferred bootstrap — without the guard 5 presses produce 5 terminals; with the guard, 1.
  • Also covers lock release on success and on rejection.
bun test src/renderer/routes/_authenticated/_dashboard/v2-workspace/\$workspaceId/hooks/useV2TerminalLauncher/inFlightGuard.test.ts
✓ 4 pass / 0 fail

Typecheck (bun run typecheck in apps/desktop) and bun run lint are clean.

Out of scope

Other launcher consumers (SPLIT_AUTO, SPLIT_RIGHT, SPLIT_DOWN) are not guarded — those aren't typically mashed during cold start and the issue scopes the fix to the two cmd+T paths. Easy to extend if the same concern surfaces for splits.

Closes #4384


Summary by cubic

Prevents multiple terminals from spawning on cold start by dropping re-entrant Cmd+T and “New Terminal” requests while the daemon bootstrap is in-flight. Fixes #4384.

Written for commit 582e08b. Summary will update on new commits.

…ations

Cold-start daemon bootstrap blocks the first terminal.createSession for up
to 5s. Without an in-flight guard at the call sites, every Cmd+T press or
"New Terminal" click during that window awaits the same bootstrap and then
all unblock together, spawning a terminal each.

Mirrors the existing isClosingPaneRef pattern in CLOSE_PANE: a per-handler
ref-held guard drops re-entrant calls while one is pending.

Closes #4384
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.

Desktop: Cmd+T / new terminal blocks on first open, then buffered clicks fire at once

0 participants