Skip to content

fix: fix workspace actions for explicitly bound downstream terminals - #1837

Merged
eitsupi merged 13 commits into
REditorSupport:mainfrom
eitsupi:fix/session-terminal-binding
Oct 7, 2026
Merged

eitsupi merged 13 commits into
REditorSupport:mainfrom
eitsupi:fix/session-terminal-binding

Conversation

@eitsupi

@eitsupi eitsupi commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Fixes #1836.

#1764 introduced the public session API with pseudoterminal downstream clients in mind. #1805 made Workspace actions execute in their owning session, but terminal dispatch only resolves native PID associations, leaving extension-owned pseudoterminals without an execution target.

Add backward-compatible session.activate(sessionId, { terminal }) to explicitly bind a terminal. Interactive execution retains priority; terminal execution uses the session's current explicit or native association. Unassociated background sessions still reject terminal execution.

Execution, readiness and terminal selection share a registry with at most one terminal per session and one session per terminal. Explicit binding replaces either endpoint's previous association, so a superseded native terminal cannot return as a fallback when the explicit terminal closes. Live explicit bindings take priority over native attach. Close and connection replacement invalidate associations; queued sends validate the exact association, and delayed native discovery cannot overwrite intervening ownership changes or a newer connection. Reconnect refreshes the selected session's connection even after same-session reselection, while preserving a newer selection of a different session; old Workspace nodes still reject execution.

Downstream follow-up: vscode-R-console needs to pass its VS Code Terminal when activating a sess session, and repeat registration after reconnecting. Older vscode-R implementations ignore the extra argument, so downstream can retain compatibility with their existing activation API. No vscode-R-console sources or sess wire protocol are changed here.

@eitsupi eitsupi changed the title Fix Workspace actions for explicitly bound downstream terminals fix: Fix Workspace actions for explicitly bound downstream terminals Oct 6, 2026
@eitsupi
eitsupi requested review from Fred-Wu and renkun-ken October 6, 2026 16:51
@eitsupi
eitsupi marked this pull request as draft October 6, 2026 16:55
@eitsupi
eitsupi marked this pull request as ready for review October 6, 2026 16:58

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

Reviewed the latest revision, 4fca874. The explicit pseudoterminal binding path and its close/reconnect coverage look good, but two ownership edge cases below should be fixed before merging.

Validation: TypeScript compilation, extension build, and oxlint passed. The 105 tests in Session Terminal Binding, Session Communication, Workspace Viewer, and R Terminal passed in VS Code 1.140.0 on macOS. Additional targeted tests reproduced stale native fallback after an explicit owner's disconnect and an older terminal-selection callback overwriting a newer public API activation.

Comment thread src/session.ts Outdated
Comment thread src/session.ts Outdated
@eitsupi
eitsupi marked this pull request as draft October 6, 2026 17:08
@eitsupi
eitsupi marked this pull request as ready for review October 6, 2026 17:18
@eitsupi
eitsupi requested a review from renkun-ken October 6, 2026 17:18

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

Follow-up review of 4371af1: both findings from my previous review are addressed. I reran the original stale-native-disconnect and pending-selection reproductions; both now pass. The revision-based retirement also correctly requires a fresh native attach before an unbound terminal can resume PID routing.

One new readiness regression is described inline: a live explicit binding is ignored when deciding whether a managed terminal can accept its first source command.

Validation: TypeScript compilation, extension build, and oxlint passed. All 112 tests in Session Terminal Binding, Session Communication, Workspace Viewer, and R Terminal passed in VS Code 1.140.0 on macOS; all five GitHub CI checks are green. A targeted source-command comparison passes without explicit binding and fails after binding the same connected session to the same terminal.

Comment thread src/session.ts Outdated
@eitsupi
eitsupi requested a review from renkun-ken October 6, 2026 23:02
@eitsupi
eitsupi marked this pull request as draft October 6, 2026 23:06
@eitsupi eitsupi added this to the 3.2.0 milestone Oct 6, 2026
@eitsupi
eitsupi marked this pull request as ready for review October 6, 2026 23:45

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

Reviewed the latest revision, 33664fe, including the shared terminal registry, exclusive associations, and reconnect/discovery guards. All three findings from my earlier reviews are fixed: stale native fallback stays removed, older terminal selection no longer overrides newer activation, and a managed terminal accepts its first source command after explicit binding. I reran those reproductions successfully.

One reconnect selection regression remains, described inline: selecting the same session while its replacement handshake is resolving leaves the Workspace attached to the destroyed previous Session object.

Validation: TypeScript compilation, extension build, and oxlint passed. All 130 relevant extension tests and all 17 terminal-registry Node tests passed in the local macOS setup with VS Code 1.140.0; all five GitHub CI checks are green. An additional reconnect comparison passes without an intervening selection and fails when the same terminal is reselected during discovery. A recovery check confirms that Workspace execution rejects until the terminal is selected again after reconnect.

Comment thread src/session.ts Outdated
@eitsupi
eitsupi requested a review from renkun-ken October 7, 2026 00:58
@eitsupi eitsupi changed the title fix: Fix Workspace actions for explicitly bound downstream terminals fix: fix workspace actions for explicitly bound downstream terminals Oct 7, 2026

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

Reviewed the latest revision, 0a224be. All findings from my earlier reviews are addressed, and I found no new actionable issues.

The reconnect change now carries the selected logical session to its replacement connection even after same-session reselection, while preserving a newer selection of a different session. Old Workspace nodes still reject execution rather than redirecting to the replacement. The final naming refactor preserves that behavior.

Validation: TypeScript compilation, extension build, oxlint, all 137 relevant extension tests, and all 17 terminal-registry Node tests passed locally with VS Code 1.140.0 on macOS. The seven independent reproductions covering the earlier ownership, readiness, and reconnect findings passed on 4fde676; the final commit only names the existing preservation condition, and the full relevant suite was rerun on 0a224be. CI for the latest commit is still running.

@eitsupi
eitsupi merged commit 1b3371a into REditorSupport:main Oct 7, 2026
5 checks passed
@eitsupi
eitsupi deleted the fix/session-terminal-binding branch October 7, 2026 01:12
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.

[Bug]: Not able to send code to third party terminal with development version from R: Workspace.

2 participants