Skip to content

fix(terminal): recover sess when VS Code revives an R terminal - #1997

Merged
renkun-ken merged 3 commits into
mainfrom
codex/revive-r-terminal
Nov 26, 2026
Merged

renkun-ken merged 3 commits into
mainfrom
codex/revive-r-terminal

Conversation

@renkun-ken

Copy link
Copy Markdown
Member

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

@renkun-ken
renkun-ken requested a review from eitsupi November 25, 2026 09:50

@eitsupi eitsupi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@renkun-ken
renkun-ken requested a review from eitsupi November 25, 2026 16:51
@renkun-ken
renkun-ken merged commit ff7a535 into main Nov 26, 2026
14 checks passed
@renkun-ken
renkun-ken deleted the codex/revive-r-terminal branch November 26, 2026 11:52
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.

sess integration lost when VS Code restores an R terminal

2 participants