Skip to content

fix(interactive): interrupt and stop arf through IPC instead of signals - #1950

Merged
eitsupi merged 21 commits into
mainfrom
feat/interactive-arf-ipc
Nov 16, 2026
Merged

eitsupi merged 21 commits into
mainfrom
feat/interactive-arf-ipc

Conversation

@eitsupi

@eitsupi eitsupi commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Summary

Interrupting an R Interactive submission sends SIGINT to arf. When R is idle, headless arf ends the session on SIGINT, so an interrupt that races with the start or end of an evaluation kills it. This is why adopts an existing arf process without losing its objects fails intermittently on Linux and macOS (left out of #1943).

This PR moves Interactive to arf 0.7 IPC. Interrupt and Stop no longer signal the process, and inspection runs as arf handler calls, because under arf 0.7 a slow inspection on the sess socket cannot be interrupted.

Changes

  • arf version: requires arf 0.7.2-rc.1 or later, checked against the session's arf_version with SemVer precedence. A TODO moves the minimum to 0.7.2 once released.
  • Interrupt: an arf interrupt for the running execution's ID, which arf attaches to an event sess publishes before running the submission. A request made before the ID is known is held, and dropped once the submission finishes.
  • Stop: arf shutdown, then kill after a deadline. Only an interactive arf, which rejects shutdown, falls back to SIGTERM/SIGKILL.
  • Inspection: managed arf publishes sess's ten inspection methods with --ipc-expose (vscode-r.inspect.json/<method>). The request timeout is the call's execution deadline, so arf interrupts a slow inspection. Hover and completion use the resolver from feat(sess): resolve hover and completion targets without evaluating them #1949 and never evaluate the request. Startup fails if managed arf does not report every handler as published; an adopted arf keeps the sess socket unless it publishes them all.
  • Errors: JSON-RPC error codes are kept, so timeouts and other failures are told apart by code rather than by message.
  • CI: arf is installed with mise (src/test/node/mise.toml and mise.lock).

Notes for reviewers

  • an interrupt between executions does not end the session fails when interrupts are sent as SIGINT, so it covers the race behind the flaky test.
  • The slow inspection test now hovers a slow active binding and checks that the deadline stops it. It fails if inspection goes back to the sess socket.
  • An interrupt request no longer stops a running inspection; the deadline does.

arfRequest now rejects with an ArfRpcError that keeps the error code and data,
and with ArfTransportTimeoutError when the client stops waiting, so callers
can tell a server timeout from other failures without matching messages.

Add the version check for Interactive sessions: arf 0.7.1 or later, with
execution deadlines for handler calls. Prereleases count as older than their
release. A TODO records that the minimum should move to 0.7.2 once it is
released.
ArfAttachConnection attaches to arf over newline-delimited JSON-RPC, matches
responses by ID, and delivers events to a listener registered before
attaching, so an event in the same chunk as the attach response is not lost.
A request that times out or is aborted locally may still run in R; its late
response is ignored and its ID is not reused. The connection closes once and
rejects every pending request with the same reason; it never reconnects.
Interrupting an Interactive submission sent SIGINT to the arf process. When
the signal reached headless arf while R was idle, for example just before
evaluation started or after it finished, it ended the whole session; this made
the adopted-session interrupt test fail intermittently.

The backend now attaches to arf before submitting code, and sess publishes an
event with the submission ID before running it, so the event's arf execution
ID identifies the submission (a managed user_input acknowledgement reports the
same ID). An interrupt is sent as an arf IPC interrupt for that ID, held until
the ID is known and dropped once sess reports completion. With nothing
running, interrupt now fails instead of signalling R.

Stop sends arf shutdown, waits for the process to exit and kills it after a
deadline. An interactive arf rejects shutdown as an unknown method, and only
that answer falls back to SIGTERM and then SIGKILL. The bootstrap evaluation
must report status "ok".

Interrupting slow inspection is not supported yet; it will use execution
deadlines of handler calls.
mise.toml pins arf, and mise.lock records the download and checksum for each
platform, replacing the hand-written download and checksum script. arf is
still not installed on Windows. ARF_PATH points at the installed binary.
Also suppress Arity's routine-registration rule where sess calls the arf
routines: they are registered by the embedding host, so there is no package
symbol to bind.
Move mise.toml and mise.lock from the repository root to src/test/node,
next to the Interactive runtime tests that use arf, and run mise there in CI.
The release candidate includes the fix that keeps forked R workers from
crashing on macOS. The minimum supported version stays 0.7.1 until 0.7.2 is
released.
Managed arf publishes the sess inspection handlers at startup, and inspection
uses arf call with the request timeout as its execution deadline, so a slow
inspection is interrupted instead of blocking R. Errors keep their cause:
queue timeout, execution deadline, transport timeout, R error, interrupt, or
an unpublished handler. Requests go out one at a time over the attach
connection; identical read-only ones share a call and a newer hover or
completion replaces one that has not started.

An adopted arf uses calls only when it publishes every handler; otherwise
inspection stays on the sess socket. The inspectionDeadline capability reports
which applies. The slow inspection test now hovers a slow active binding and
checks that the deadline stops it.
Add a fixed table of the ten Interactive inspection methods that arf can
publish with --ipc-expose under the vscode-r.inspect.json namespace. Each
handler takes the request parameters as one JSON string, validates them in R,
and returns the result as one JSON string encoded like a socket reply, so the
call's execution deadline covers decoding, the handler and encoding.

Hover and completion resolve names and $/@ chains without evaluating the
request. The per-method logic is shared with the socket handler table, whose
behavior is unchanged. The published functions look up the private sess only
when called, because arf evaluates the expression before the bootstrap loads
it.
…f-ipc

# Conflicts:
#	src/test/node/interactiveRuntime.test.ts
The socket path no longer evaluates hover and completion requests; it differs
from handler calls only in turning errors into no result.
macOS limits Unix socket paths to 104 bytes, and a UUID file name under its
long temporary directory exceeded that, so the inspection routing tests could
not listen.
@eitsupi
eitsupi requested a review from renkun-ken November 16, 2026 09:05
Inspection requests reach the agent from every client, so a newer hover or
completion is not necessarily a replacement for an older one. Replacing them by
method answered another client's request with no result. Keep sharing calls
only between identical requests.
…andler

A managed session used handler calls without checking what arf reported, so a
mismatch between the selectors in TypeScript and the table installed with sess
would only show up as failing inspections. Check the handler list for managed
sessions as for adopted ones, and fail startup when it is incomplete.
The release candidate fixes forked R workers crashing on macOS and the status
of an R error after a caught interrupt. Compare prerelease versions with
SemVer precedence so that a prerelease minimum rejects earlier prereleases.
@eitsupi
eitsupi marked this pull request as ready for review November 16, 2026 09:27

@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 at 7e876b3. No blocking correctness issues found in the execution-ID interrupt handling, managed/adopted Stop paths, attach lifecycle, or R inspection handlers. One non-blocking queue-timeout budget discrepancy is noted inline.

Validation:

  • Local build, TypeScript compilation/typecheck, oxlint, formatting, and diff whitespace checks passed.
  • Node suite: 464 tests passed initially; the remaining renv-isolation test passed on its focused rerun after installing the missing local renv dependency (465 tests passed across those runs), using arf 0.7.2-rc.1.
  • Private bundled sess: all 1,687 tinytest checks passed, including the 189 new inspection-call checks.
  • Latest hosted checks: 14 passed, with the Pages deployment skipped. The macOS extension job passed on rerun after its initial R language-server ECONNRESET assertion failure.

A request that waited behind earlier inspection requests was still given its
full timeout as the arf queue limit, so it could wait almost twice as long as
documented before starting. Send arf only what is left of the wait.

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

Re-reviewed the changes since 7e876b3 at e085dc7. The previous P3 queue-budget issue is fixed: local waiting is deducted from arf's remaining queue timeout, expired requests are rejected before transport, and the execution deadline is preserved. No new findings.

Validation: local build, TypeScript compilation/typecheck, lint, formatting, and diff whitespace checks passed; all 41 affected arf IPC/inspection/backend tests passed, including the new regression test. The original timing repro now gives the second request only 19 ms of arf queue budget after 82 ms of local waiting, rather than another 100 ms; exact-deadline and already-expired cases were also checked.

Current hosted checks: 12 passed, one Pages deployment skipped, and the two macOS Node/Extension jobs are still running. This approval covers the reviewed code; those remaining CI results are pending.

@eitsupi
eitsupi merged commit 621c3c1 into main Nov 16, 2026
15 checks passed
@eitsupi
eitsupi deleted the feat/interactive-arf-ipc branch November 16, 2026 09:56
eitsupi added a commit that referenced this pull request Nov 17, 2026
## Summary

R Interactive refused to start on Windows. The obstacle was not R or arf IPC but the Session Agent: its endpoints, launch and liveness checks assumed Unix sockets, chmod and POSIX processes. Since interrupt and Stop now go through arf IPC (#1950), Windows no longer needs signals for them.

This PR enables managed Interactive sessions on Windows and keeps the Unix behavior unchanged. Discovering and adopting an existing arf process on Windows is left for a follow-up.

## Changes

- **Transport**: a new `transport.ts` creates and listens on local endpoints for the agent control channel and the sess bridge. Windows uses named pipes; Unix keeps sockets with mode 0600.
- **Supervision**: Windows uses detached supervision for `auto` and `detached`; `tmux` and `systemd` are rejected with an actionable error. The agent is spawned detached and hidden, without editor-owned stdio, logging to `agent.log`.
- **Readiness and liveness**: a launch waits until the agent answers an authenticated probe for the expected session, not just until its manifest appears. The registry pre-filter still rejects stale entries by agent PID and, on Unix, by the socket file; on Windows it does not touch the pipe.
- **Storage**: the default registry on Windows is `%LOCALAPPDATA%\vscode-r\interactive`.
- **Process control**: Interrupt is available on Windows through arf IPC. Stop's fallback force-terminates on Windows, where Node signals already mean termination.
- **Line endings**: code submitted from a CRLF editor document is normalized to LF before R parses it, since R rejects CR in source; history keeps the submitted text.
- **CI**: Windows installs arf through mise, and the managed runtime, backend and protocol tests run there. Adopting an existing arf stays skipped on Windows.

## Notes for reviewers

- Security on Windows relies on the existing token authentication of the control and sess endpoints and on the user-profile ACL inherited by `%LOCALAPPDATA%` and the per-user `%TEMP%`. The extension does not rewrite ACLs. Named pipes keep their default security descriptor, under which other users cannot open them for writing. Securing a custom or shared storage path is documented as the user's responsibility.
- The detached-supervision runtime test checks that a session survives the termination of the process that launched it and keeps its objects. On Windows it does not walk the process tree.

## Follow-ups

- **Editor tests on Windows**: some Interactive editor tests are skipped on Windows because their fake `node`/`arf` executables are POSIX shell scripts. The product spawns executables without a shell, so `.cmd` wrappers cannot replace them either; they need a Node-based fake that Windows can launch as an `.exe`.
- **Multiplexer supervision on Windows**: Windows currently supports only detached supervision. A multiplexer with Windows builds, such as zellij, could be evaluated as an additional supervisor, which would also let the supervisor-specific tests run there.
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