Repository navigation
fix(terminal): recover sess when VS Code revives an R terminal - #1997
Merged
Merged
Conversation
eitsupi
requested changes
Nov 25, 2026
eitsupi
left a comment
Member
There was a problem hiding this comment.
Reviewed by ChatGPT.
watchTerminalStartupRecords() ignores events without a filename and only logs watcher errors. Since fs.watch() does not guarantee filename availability or reliable event delivery, the R-side retry loop could continue indefinitely without recovering the connection.
Could we add a directory rescan when the filename is unavailable and re-establish the watcher on errors? A recovery mechanism should not depend entirely on successful filesystem notifications.
eitsupi
approved these changes
Nov 26, 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.
VS Code can revive an ordinary terminal after a full application restart by starting a new R process with the old discovery environment. The terminal can reappear before the new extension host is ready, and its restored creation options can omit the discovery file. Its initial connection then fails, disabling Workspace, View(), and plot integration for the new process.
The extension watches the managed startup record, matches it to the live local terminal, and republishes the discovery endpoint for that terminal. The R side retries a failed first connection in the background with backoff. It preserves the requested runtime options, retries an unchanged endpoint that becomes ready later, and cancels stale work when the registration changes. Manual attaches keep their existing behavior.
The integration test fully exits and reopens VS Code, verifies the new R PID and session identity, removes the stale discovery file, and checks Workspace completion, the data viewer, and the plot viewer. The original problem reproduced on main on macOS. Regression tests also cover an interrupted first handshake and a second startup notification arriving while the first is being processed.
Local validation includes all 1,709 sess assertions, 25 extension-host terminal integration tests, build, TypeScript compilation, lint, and formatting.
Fixes #1799