Skip to content

fix: honour --reconnection-grace-time when the browser closes - #7956

Open
hugodeco wants to merge 1 commit into
coder:mainfrom
hugodeco:fix/honour-reconnection-grace-time
Open

fix: honour --reconnection-grace-time when the browser closes#7956
hugodeco wants to merge 1 commit into
coder:mainfrom
hugodeco:fix/honour-reconnection-grace-time

Conversation

@hugodeco

Copy link
Copy Markdown

Fixes #7955

Summary

--reconnection-grace-time (#7678) cannot currently deliver what it documents, for two independent reasons:

  1. Closing the tab bypasses the grace time. BrowserLifecycleService runs the workbench shutdown on pagehide/beforeunload, disposing the remote connection gracefully. ManagementConnection treats a graceful dispose as a finished client and calls _cleanResources() immediately — the grace time is never consulted, so the session dies with the tab however the flag is set.

  2. A second connection cuts it to 5 minutes. Every new connection calls shortenReconnectionGraceTimeIfNecessary() on all disconnected connections, scheduling ProtocolConstants.ReconnectionShortGraceTime. Opening a second tab is enough to shorten a deliberately long grace time.

This adds patches/session-preservation.diff, which makes the configured grace time authoritative.

Changes

lib/vscode/src/vs/workbench/services/lifecycle/browser/lifecycleService.ts

  • pagehide persists UI state (storageService.flush(WillSaveStateReason.SHUTDOWN)) instead of unloading.
  • A browser-driven unload no longer tears the workbench down. The veto handler is only passed on the browser path, so that is the discriminator: a beforeunload veto is still honoured, and an explicit in-product shutdown (shutdown(), which passes no veto handler) still unloads normally.

lib/vscode/src/vs/server/node/remoteExtensionHostAgentServer.ts

  • The grace time is only shortened when it was left at or below ProtocolConstants.ReconnectionGraceTime. Installations that never set the flag keep Code's stock behaviour; only an operator who deliberately raised it opts into the longer wait.

Also updates the unreleased changelog section.

Test plan

  • quilt pop -a && quilt push -a — full series applies cleanly with the new patch
  • npm run typecheck-client in lib/vscode — passes
  • npm run lint:ts — passes
  • npm run test:unit — 331/332; the one failure (should unlink a socket before listening on the socket, expecting EACCES) is environmental, from running as root, and exercises src/node/app.ts, which this PR does not touch
  • npm run valid-layers-check fails identically with and without this patch (pre-existing, in network.ts / extensionResourceLoader.ts)
  • Behaviour verified in production on 4.128.0: with --reconnection-grace-time 2592000, sessions survive closing the browser and reconnect on return

I was not able to run a full product build on the machine I had available (disk), so a CI build is the remaining check.

🤖 Generated with Claude Code

--reconnection-grace-time lets an operator say how long a disconnected
session should be kept, but two behaviours inherited from Code stop it
from delivering that.

Closing the tab runs the browser workbench's shutdown, which disposes the
remote connection gracefully. The server reads a graceful dispose as "the
client is finished" and cleans up at once, so the grace time is never
consulted -- the session dies with the tab however the flag is set.

Separately, any new connection shortens every disconnected session to
ProtocolConstants.ReconnectionShortGraceTime (5 minutes), so opening a
second tab cuts a deliberately long grace time back down.

Add patches/session-preservation.diff, which makes the configured grace
time authoritative: pagehide persists UI state instead of unloading, a
browser-driven unload no longer tears the workbench down (beforeunload
vetoes are still honoured, and an explicit in-product shutdown still
unloads), and the grace time is only shortened when it was left at or
below the default, so installations that never set the flag keep Code's
stock behaviour.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@hugodeco
hugodeco requested a review from a team as a code owner August 19, 2026 19:04
@code-asher

Copy link
Copy Markdown
Member

Thank you for the PR!

This feels like something we should commit directly to VS Code rather than try to maintain as a patch here. Could we try submitting it upstream?

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.

--reconnection-grace-time does not survive closing the browser tab

2 participants