feat: detect when multiple windows open the same workspace#918
Merged
Conversation
2d482fc to
95ba149
Compare
53448a5 to
b07d0c6
Compare
mtojek
reviewed
Apr 28, 2026
Add WindowBroadcast<T>, a generic typed pub/sub channel over SecretStorage.onDidChange for transient cross-window messaging. Build WindowIpc on top of two broadcast channels to detect when multiple windows are connected to the same Coder workspace. When a user clicks Connect and another window responds to the PING, a non-blocking notification offers Duplicate Window or Open Without Folder. The entire chain is fire-and-forget; openWorkspace() never blocks on it. Closes #783 Closes #548
Address review feedback: - Move OAuthCallback out of SecretsManager into src/oauth/oauthCallback.ts - Move WindowBroadcast (the generic primitive) into src/ipc/ - Rename WindowIpc to DuplicateWorkspaceIpc and move it into src/workspace/, since it covers a single workspace-coordination feature, not all window IPC - Use Zod schemas in both DuplicateWorkspaceIpc and OAuthCallback for consistent validation - Tighten tests: the broadcast key-isolation test now also asserts delivery on the matching key, and the stale-request test asserts delivery of fresh requests
b07d0c6 to
c0807b4
Compare
c0807b4 to
2f53028
Compare
mtojek
approved these changes
Apr 28, 2026
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.
Summary
Adds
WindowBroadcast<T>, a generic typed pub/sub channel built on top ofSecretStorage.onDidChange, and uses it to detect when more than one VS Code window is connected to the same Coder workspace.Closes #783, #548
How it works
When a user clicks Connect, the extension fires
openFolder()immediately and sends a PING throughSecretStoragein parallel. If another window responds with a PONG, the clicking window shows a non-blocking notification with two choices:duplicateWorkspaceInNewWindow, preserving its tabs, panels, and remote connection.The whole chain is fire-and-forget.
openWorkspace()never blocks on it, so if no other window is listening the behavior is identical to before.Layout
src/ipc/windowBroadcast.tssrc/workspace/duplicateWorkspaceIpc.tssrc/oauth/oauthCallback.tsWindowBroadcastsrc/commands.tsopenFolder()and shows the notificationsrc/extension.tsduplicateWorkspaceInNewWindowwhen targetedEach consumer of
WindowBroadcastdefines its message shape with a Zod schema, so invalid or stale data on the storage key is dropped before reaching handlers.Notes
WindowBroadcastis the only generic piece. Specializations live with their feature (OAuth signal inoauth/, workspace duplicate detection inworkspace/) rather than in a shared IPC bucket.showInformationMessage, which VS Code may dismiss without resolving, so the chain must not be awaited from the open path.