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
Draft
fix: solve #4384 — guard Cmd+T / new terminal against rapid presses during daemon bootstrap#4385github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
…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
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.
Root cause
On cold start, the first
terminal.createSessionblocks for up to ~5s waiting for the pty daemon to come up (seeDaemonSupervisor.waitForSocket(socketPath, 5_000)). Every additional Cmd+T press or "New Terminal" click during that window awaits the samebootstrapPromise. 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.tsNEW_GROUP(Cmd+T)useWorkspacePaneOpeners.tsaddTerminalTab(sidebar/menu "New Terminal")The fix
Mirror the existing
isClosingPaneRefpattern used byCLOSE_PANE: drop re-entrant calls while a creation is pending. Extracted as a tinycreateInFlightGuardfactory next touseV2TerminalLauncherso the lock state is held in auseRefper 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.tsincludes 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.Typecheck (
bun run typecheckinapps/desktop) andbun run lintare 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.
createInFlightGuardand wired it intoNEW_GROUPandaddTerminalTabto coalesce rapid presses into a single terminal creation.Written for commit 582e08b. Summary will update on new commits.