Skip to content

fix(commands): handle the dashboard link window when a workspace is already open - #1234

Open
EhabY wants to merge 3 commits into
mainfrom
fix/vsc-65-deep-link-window-reuse
Open

EhabY wants to merge 3 commits into
mainfrom
fix/vsc-65-deep-link-window-reuse

Conversation

@EhabY

@EhabY EhabY commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #1229 (VSC-65).

Companion PRs:

Problem

On a cold start, VS Code restores the previous window and sends the dashboard link to it. If that window's workspace is stopped, VS Code holds the link until our "workspace is not running" prompt is answered. If you cancel, the window reloads and the link is lost. The extension never receives the link, so it cannot fix this on its own.

The companion PRs add windowId=_blank to the links Coder builds. VS Code then opens one empty window for the link and, on a cold start, does not restore the previous session. This PR handles the window behavior that follows from that.

Changes

One commit each, so the last one can be dropped on its own:

  1. "Open Without Folder" reuses an empty window. When the "already open in another window" notification shows in a window with no folder, the button uses that window instead of opening another one.

  2. Dev containers share the open path. openWorkspace and openDevContainer use one openRemoteFolder helper, so dev container links also show the "already open" notification.

  3. Close the empty window when the folder is already open elsewhere. sendPong now reports the replying window's opened workspace URI: its workspace file, or its single folder. The field is optional, so older versions still work. closeIfOpenElsewhere runs only when this window asked VS Code to reuse it, and closes the window only if the reply lists the exact target URI and nothing is unsaved. In every other case it falls back to today's notification.

    Why it can't close the wrong window:

    • An exact match means VS Code focuses that window and never loads the folder into this one (the existing-window check in windowsMainService.ts). Without a match, VS Code reloads this window and the close never runs.
    • No reply, an older version (no URI), a different folder, a window that has its own folder, or unsaved changes all leave the window open. Each case has a test, and removing either check makes tests fail.
    • The only remaining gap is a race: the other window would have to close between its reply and the handoff, within milliseconds.

Behavior with old links (no windowId=_blank)

The cold-start bug stays as it is today. Two things change:

  • "Open Without Folder" uses the current window when it has no folder. Today it always opens another window.
  • Dev container links show the "already open" notification. Today they show nothing.

With commit 3, there is one more change. If a link opens in an empty window you left untouched, and another window has exactly that folder open, the empty window closes. Today it stays.

Checks

pnpm typecheck, pnpm lint, pnpm format:check and pnpm test:extension pass. The suite also passes at commit 2, without commit 3. headers.test.ts failed once in a full parallel run and passes on its own. It is unrelated to this change. Not tested on desktop VS Code yet.

Implementation plan and decisions

Root cause

  • On a cold start, the restored remote window runs our activation. remote.setup blocks on the modal start prompt.
  • VS Code's ExtensionUrlHandler.handleURL waits on extensionService.getExtension, which waits until the remote authority resolves. That waits on our activation.
  • Cancel calls closeRemote(), which reloads the window and loses the held link.

Fix

  • Add windowId=_blank only where Coder builds the link, with no generic link matching:
    • coder/coder: getVSCodeHref, the dev container button, and the two coder open vscode link builders;
    • coder/registry: vscode-desktop-core, which every editor module uses.
  • Templates on older module versions, and hand-written coder_app URLs, keep today's behavior until they're updated.
  • VS Code opens a fresh window for the link and, on a cold start, skips session restore. Not restoring is intended: clicking Open B should not reconnect A first.
  • Forks without support pass the parameter through, and the extension ignores unknown parameters.

Behavior after all PRs

  • Cold start, click B: only B opens.
  • VS Code running, the focused window has a folder, click B: B opens in a new window (as today).
  • VS Code running, the focused window is empty, click B: B opens in a new window and the empty window stays.
  • A already open with the same folder, click A: A is focused and the empty link window closes (commit 3). Without proof of the match, the window stays with the notification.

Decisions

  • Ship the extension first, because it updates faster than coderd.
  • Close only on positive proof, without timing heuristics. A failure leaves the window open.
  • No notification when the window auto-closes.
  • Closing an untouched empty window that the user opened is acceptable.
  • Commit 3 is kept separate so it can be dropped if it turns out to be unreliable.

Generated by Coder Agents on behalf of @EhabY.

@linear-code

linear-code Bot commented Dec 1, 2026

Copy link
Copy Markdown

VSC-65

@EhabY
EhabY force-pushed the fix/vsc-65-deep-link-window-reuse branch from d37bb7f to fab40dc Compare December 1, 2026 11:48
@EhabY
EhabY force-pushed the fix/vsc-65-deep-link-window-reuse branch from fab40dc to e2b0755 Compare December 1, 2026 12:32
@EhabY
EhabY marked this pull request as ready for review December 1, 2026 12:46
@EhabY
EhabY force-pushed the fix/vsc-65-deep-link-window-reuse branch 2 times, most recently from b08c6b9 to ec97098 Compare December 1, 2026 22:07
35C4n0r pushed a commit to coder/registry that referenced this pull request Dec 2, 2026
## Description

Adds `windowId=_blank` to the `vscode-desktop-core` app link. This makes
VS Code and its forks open the link in a fresh window, and on a cold
start they skip restoring the previous session, whose remote windows can
block and drop the link. Forks without support ignore the param, and the
Coder extension ignores unknown params.

Templates must update to `vscode-desktop-core` 1.2.2, or a wrapper
module that pins it, to get this.

- Issue: coder/vscode-coder#1229
- coder/coder PR: coder/coder#32847
- Companion vscode-coder PR:
coder/vscode-coder#1234

## Type of Change

- [x] Bug fix

## Module Information

**Path:** `registry/coder/modules/vscode-desktop-core`
**New version:** `v1.2.2`
**Breaking change:** No

## Testing & Validation

- [x] Tests pass (`bun test main.test.ts`, `terraform test`)
- [x] Code formatted (`prettier --check`, `terraform fmt -check`)

<details><summary>Implementation plan</summary>

- Append `&windowId=_blank` after `&token=$SESSION_TOKEN` in the
`coder_app` URL. The coder/coder session token trust check still passes:
every param name is unique, `url` stays a bare origin, and
`token=$SESSION_TOKEN` stays a raw entry.
- Patch bump to 1.2.2 with `.github/scripts/version-bump.sh patch`.
- Wrapper modules (vscode-desktop, cursor, windsurf, kiro, antigravity,
devin-desktop, cytoshahar/positron) pin older core versions, so they are
unchanged here. Each needs its own pin update and version bump to pick
this up.

</details>

_Generated by Coder Agents on behalf of @EhabY._
35C4n0r pushed a commit to coder/registry that referenced this pull request Dec 3, 2026
> **Stacked on #1319: review only the commits after #1319. Merge after
#1319 is merged and vscode-desktop-core 1.2.2 is published.**

## Description

Follow-up to #1319, same shape as #751. Moves the wrapper modules to
`vscode-desktop-core` 1.2.2 so their links carry `windowId=_blank`.

- cursor, windsurf, kiro, antigravity: 1.0.2 to 1.2.2, and they now pass
`config_dir` (`$HOME/.cursor`, `$HOME/.codeium/windsurf`,
`$HOME/.kiro/settings`, `$HOME/.gemini/config`).
- vscode-desktop, devin-desktop: 1.2.0 to 1.2.2.
- Each module is patch bumped, and the tests now expect
`&windowId=_blank`.

Why these four were on 1.0.2: core 1.1.0 (#753) made `config_dir`
required, and no follow-up migrated them. vscode-desktop and
devin-desktop moved to 1.2.0 only for extension pre-install (#1094,
#1089). With defaults, 1.0.2 to 1.2.x adds no resources or behavior for
these wrappers. Their own MCP scripts stay, and core's `mcp_config` is
unused.

`cytoshahar/positron` stays on core 1.0.2. Its maintainer can bump it
and needs to choose a `config_dir`.

## Found, not fixed here

- antigravity's own `mcp` script still writes the legacy
`~/.gemini/antigravity/mcp_config.json`. Antigravity's docs now put the
global MCP config at `~/.gemini/config/mcp_config.json`.
- devin-desktop passes `config_dir = "$HOME/.config/devin"`, but Devin
Desktop is the Windsurf rebrand, and its docs point at
`~/.codeium/windsurf`.

Open PR #1121 also bumps `vscode-desktop-core`, so whichever merges
second must re-bump.

- Issue: coder/vscode-coder#1229
- Core change: #1319
- coder/coder PR: coder/coder#32847
- Companion vscode-coder PR:
coder/vscode-coder#1234

## Type of Change

- [x] Other (dependency update)

## Testing & Validation

- [x] `terraform fmt -check` and `prettier --check` pass
- [x] With the core pinned to the published 1.2.1: `terraform validate`
passes for all six modules
- [x] With the core sourced from the #1319 working tree: `terraform
test` and `bun test` pass for all six modules
- [ ] CI against the published 1.2.2 (fails until #1319 is released)

<details><summary>Implementation plan</summary>

- Branch from #1319 and add one commit.
- In each wrapper's `main.tf`, set the `vscode-desktop-core` pin to
`1.2.2`. In the four wrappers that were on 1.0.2, add `config_dir` set
to each IDE's documented config folder (for Antigravity, the shared
`~/.gemini/config`).
- Run `.github/scripts/version-bump.sh patch` against the #1319 branch,
so only the six wrappers get a patch bump and their README versions
update.
- Update the URL assertions in `main.test.ts` (and kiro's
`kiro.tftest.hcl`) to expect `&windowId=_blank`.
- Verification before 1.2.2 is published: pin 1.2.1 temporarily for
`terraform validate`. Point `source` at the local core temporarily for
`terraform test` / `bun test`, because 1.2.1 has no `windowId`.
- Out of scope: `cytoshahar/positron`. Its maintainer owns the
`config_dir` choice.

</details>

_Generated by Coder Agents on behalf of @EhabY._
@EhabY
EhabY requested a review from code-asher December 4, 2026 14:33
@EhabY
EhabY force-pushed the fix/vsc-65-deep-link-window-reuse branch from ec97098 to 7524c29 Compare December 4, 2026 14:41

This branch has not been deployed

No deployments
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.

1 participant