Skip to content

feat(sess)!: stabilize attach identity and endpoint contract - #1764

Merged
eitsupi merged 32 commits into
REditorSupport:masterfrom
eitsupi:feat/sess-protocol-stabilization
Sep 26, 2026
Merged

eitsupi merged 32 commits into
REditorSupport:masterfrom
eitsupi:feat/sess-protocol-stabilization

Conversation

@eitsupi

@eitsupi eitsupi commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Summary

On master, sess identity and discovery depend on local PIDs and ~/.vscode-R/sessions/<PID>.json. Reloading VS Code leaves surviving R processes disconnected, and restoring one terminal can prevent manual recovery of another. This PR establishes the session contract before the first stable 3.x release (#1763).

  • Add a versioned attach handshake and process-lifetime session_id. Use socket ownership for cleanup so a late close cannot remove a replacement connection; defer workspace and plot notifications until task callbacks return, with generation guards across disconnects.
  • Standardize sess::connect(endpoint = ...), SESS_ENDPOINT, and SESS_DISCOVERY_FILE. Store managed discovery files and attach scripts in extension storage, without making its directory layout part of the contract.
  • Automatically reconnect each surviving managed terminal after reload, preserving identity and runtime options, restoring the selected terminal’s session, and refreshing the JGD renderer endpoint. Failed runtime startup closes the transport so reconnect can retry. Manual recovery prioritizes the selected terminal based on discovery ownership, not its name.
  • Expose connection metadata and activation by session ID to downstream extensions. Share server startup so concurrent terminal and API clients receive the same endpoint. Clean up failed initialization and wait for startup before shutdown.
  • Keep discovery extensible: version 1 requires only version and endpoint, ignores unknown fields, and permits optional backend fields such as jgdSocket without a version bump.

Breaking pre-release changes: replace pipe_path, SESS_PIPE, the pipe discovery field, and the PID-based home-directory fallback. Transport remains local Unix-domain sockets / Windows named pipes.

@eitsupi eitsupi changed the title feat(sess): stabilize attach identity and endpoint contract feat(sess)!: stabilize attach identity and endpoint contract Sep 23, 2026
@eitsupi
eitsupi marked this pull request as draft September 23, 2026 17:42
@eitsupi
eitsupi marked this pull request as ready for review September 23, 2026 17:45
@eitsupi eitsupi added this to the 3.0.0 milestone Sep 23, 2026
@eitsupi
eitsupi marked this pull request as draft September 23, 2026 17:54
@eitsupi
eitsupi marked this pull request as ready for review September 23, 2026 18:02
@eitsupi
eitsupi marked this pull request as draft September 23, 2026 18:03
@eitsupi
eitsupi marked this pull request as ready for review September 23, 2026 18:29
@eitsupi
eitsupi marked this pull request as draft September 23, 2026 18:36
@Fred-Wu

Fred-Wu commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Given the recent large sess refactor, I may take the opportunity to ask whether you would consider supporting pseudo-terminal console applications. The only APIs that may be needed by downstream applications, such as my R Console, are:

  1. Expose the connection details, such as the connection endpoint, protocol version, and plot backend address.
  2. Allow activation of the connected session using its sess session ID.

In addition, during the review, there appears a bug. A VS Code reload may clean up the workspace callback while it is still sending notifications, which could crash R. It has been suggested to use later() around notify_client() so that the notification is sent after the workspace callback has finished.

@eitsupi
eitsupi marked this pull request as draft September 24, 2026 08:31
@eitsupi
eitsupi marked this pull request as ready for review September 24, 2026 09:16
@eitsupi

eitsupi commented Sep 24, 2026 •

Copy link
Copy Markdown
Member Author

@Fred-Wu Could you please take another look?
I believe I've prepared the necessary APIs for https://github.com/Fred-Wu/vscode-R-console.

@eitsupi
eitsupi marked this pull request as draft September 25, 2026 23:54
@eitsupi

This comment was marked as outdated.

@Fred-Wu

Fred-Wu commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for supporting the downstream applications. This might be another bug for native R terminals.

When VS Code is reloaded, R process survives, but sess connection is gone. I could restore the connection by clicking on R:(not attached). However if I have two R terminals opened, after reload, only one could be restored even both R processes survive. Click on R :(not attached) would switch to the other restored one.

Here is a small demo.

R.restore.mp4

@eitsupi
eitsupi marked this pull request as ready for review September 26, 2026 02:36
@eitsupi
eitsupi marked this pull request as draft September 26, 2026 02:43
@eitsupi

eitsupi commented Sep 26, 2026

Copy link
Copy Markdown
Member Author

@Fred-Wu I believe I've fixed the bug you pointed out, so could you please check it again?

@eitsupi
eitsupi marked this pull request as ready for review September 26, 2026 03:46
@Fred-Wu

Fred-Wu commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Connections are now correctly restored automatically after VS Code reload.

But R Plot: commands are obsolete now. And they are not session aware at the moment.

Remove or fix in the next release?

@eitsupi

eitsupi commented Sep 26, 2026

Copy link
Copy Markdown
Member Author

But R Plot: commands are obsolete now. And they are not session aware at the moment.

Remove or fix in the next release?

Thanks for pointing that out!
I will take a look in #1762

@eitsupi
eitsupi merged commit a1ab3d6 into REditorSupport:master Sep 26, 2026
5 checks passed
@eitsupi
eitsupi deleted the feat/sess-protocol-stabilization branch September 26, 2026 09:02
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.

2 participants