Skip to content

feat(sess)!: return the jdv listener address in an acknowledged attach - #2014

Open
eitsupi wants to merge 4 commits into
mainfrom
feat/sess-attach-jdv-address
Open

eitsupi wants to merge 4 commits into
mainfrom
feat/sess-attach-jdv-address

Conversation

@eitsupi

@eitsupi eitsupi commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

When the data viewer was opened from the Workspace Viewer before any View() in the terminal, sess had to ask VS Code for the jdv listener address with a synchronous jdv/address request. R cannot read that reply while it is answering a socket request, so the first view fell back to the sess data viewer. Navigating from a list to a table hit the same limitation.

sess now sends attach as a JSON-RPC request (protocol version 3) and waits for the matching acknowledgement before starting its runtime. For a terminal session, the extension starts a jdv listener for that connection and returns its address in the acknowledgement, so R already knows where to open views and never sends jdv/address. The first view from the Workspace Viewer and list-to-table navigation now open in jdv.

  • The extension writes the acknowledgement before it publishes the connection, so no editor-initiated request can reach R before the acknowledgement. Terminal lookup and other UI work no longer delay it.
  • The listener belongs to one connection. A reconnect, an attach from another window, or a replaced connection gets a new address, and the old listener is closed. If the listener cannot start within three seconds, the attach still succeeds and reports why jdv is unavailable.
  • R waits up to five seconds for the acknowledgement. Frames that arrive together with it are processed in order after the runtime starts. A timeout or a closed socket retries the same endpoint, as before; an explicit rejection (an unsupported protocol version or invalid metadata) stops automatic retries and prints the reason.
  • The Interactive bridge acknowledges with {"jdv": null}; Interactive sessions still resolve the controller's listener as before.

This is a breaking change to the sess wire protocol: the extension requires the sess package from the same release; the extension rejects an attach from an older sess. The handshake is documented in sess/README.md.

sess now sends attach as a protocol v3 JSON-RPC request and waits up to
five seconds for the matching acknowledgement before starting its runtime.
Frames that arrive with the acknowledgement are handed to the first poll in
order. The extension and the Interactive bridge write the acknowledgement
before publishing the connection, so no editor-initiated RPC can precede it.

A rejection ends automatic retries for the R process; a timeout or an EOF
before the acknowledgement retries the same endpoint as before. Both
receivers acknowledge with a null jdv result for now.
The extension starts a jdv listener for each native sess connection and
returns its address in the attach acknowledgement, so R no longer asks for
it with a synchronous jdv/address request. The first View() from the
Workspace Viewer, or a list navigated to a table while R answers a request,
now opens in jdv instead of falling back to the sess data viewer.

The listener belongs to one connection: a reconnect, an attach from another
window or a replaced connection gets a new address, and the old listener is
closed. If the listener cannot start within three seconds, the attach still
succeeds and reports why jdv is unavailable.
@eitsupi eitsupi changed the title feat/sess attach jdv address feat(sess): return the jdv listener address in an acknowledged attach Nov 30, 2026
@eitsupi eitsupi changed the title feat(sess): return the jdv listener address in an acknowledged attach feat(sess)!: return the jdv listener address in an acknowledged attach Nov 30, 2026
@eitsupi eitsupi added this to the 3.6.0 milestone Nov 30, 2026
@eitsupi
eitsupi added this pull request to stack #2016 November 30, 2026 15:58
@eitsupi
eitsupi marked this pull request as ready for review November 30, 2026 16:00

@renkun-ken renkun-ken 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.

I reproduced two cases where a terminal loses session-watcher functionality during attachment. The five focused R suites passed all 352 assertions, and the six jdv transport tests passed. The inline comments include a fresh R profile case and a VS Code extension-host case for regression coverage.

Comment thread sess/R/server.R Outdated
if (!length(parts) || endsWith(buffer, "\n")) {
return(list(lines = parts, tail = ""))
}
list(lines = head(parts, -1L), tail = parts[[length(parts)]])

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.

Handle a partial frame during R profile startup. The terminal profile calls connect() before R attaches utils. Sending the acknowledgement in two chunks made .await_attach() fail on the first chunk with could not find function "head", leaving the session disconnected. The same branch runs if the first read contains the acknowledgement and part of the next request. parts[-length(parts)] or utils::head(parts, -1L) handles both cases. A fragmented acknowledgement delivered from R_PROFILE_USER reproduces this with the ordinary startup search path.

Comment thread src/session.ts
const superseded = pendingSessionAttachments.get(sessionId);
if (superseded) {
const unpublished = !superseded.socket._sessionId;
cancelSessionAttachment(superseded);

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.

Keep the live attachment’s terminal lookup until its replacement commits. I held the first connection’s terminal.processId lookup open after it received its acknowledgement, then closed a second socket with the same session ID while its jdv listener was starting. The original socket and session reference stayed live, but resolving its exact terminal PID no longer bound or activated the terminal. This cancellation makes isCurrentAttachment() return false. Cancel an unpublished contender immediately and defer cancellation of a published connection’s lookup until the replacement commits. With that ordering, the same extension-host test bound and activated the original terminal.

…erminal lookup

A terminal profile calls connect() before R attaches utils, so splitting a
partially received attach acknowledgement with head() failed and left the
session disconnected. Frame splitting now uses base R only.

A second attach for the same session cancelled the terminal lookup of the
connection already published, even if the new attempt was abandoned before
it committed. The published connection then never bound its terminal. Its
lookup is now cancelled only when the replacement commits; an abandoned
attempt hands the pending lookup back to it.
@eitsupi
eitsupi requested a review from renkun-ken November 30, 2026 16:36

@renkun-ken renkun-ken 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.

Both runtime fixes passed on 000310f. A fragmented acknowledgement now works before utils attaches, and an abandoned replacement leaves the original terminal lookup able to bind and activate. The focused R suites passed 353 assertions locally, and four extension-host tests passed. There is one remaining issue in the new Windows test invocation.

Comment thread sess/inst/tinytest/test-ipc.R Outdated
output <- suppressWarnings(system2(
file.path(R.home("bin"), "Rscript"),
c("--vanilla", "-e", shQuote(code)),
env = c(

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.

Launch the minimal R child portably on Windows. Windows system2() passes these env strings on the command line before --vanilla. Rscript then treats R_DEFAULT_PACKAGES=NULL as its script filename and exits before evaluating the frame-splitting assertion. The Windows job fails here with an empty output. processx::run() can pass the code as a single argument, --default-packages=NULL as an Rscript option, and R_LIBS in the child environment. I checked that invocation returns split-ok. Failing Windows job

system2() on Windows puts env strings on the command line before the
Rscript options, so Rscript took R_DEFAULT_PACKAGES=NULL as its script
name. Use processx::run() with --default-packages=NULL instead, and
assert that utils is not attached in the child.

@renkun-ken renkun-ken 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.

The Windows regression is fixed in f00a354. The child now receives --default-packages=NULL as an Rscript option and R_LIBS through its environment. The test confirms utils is absent before exercising the fragmented frame. All 158 assertions in test-ipc.R passed locally, and all 14 CI checks passed, including Windows Node and Extension. The earlier terminal-lookup and frame-splitting fixes are still in place. Approved.

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.

2 participants