Repository navigation
Conversation
renkun-ken
left a comment
There was a problem hiding this comment.
The queued cell reached the new controller in the two-window test. With the editor’s actual control-loss cleanup wired in, the cell already running lost its viewer. I also compared Workspace and adopted-console View() against this PR’s base, exercised a failed restart, and checked arf’s on-disk history. The 82 backend contract tests passed. The inline comments cover the remaining user-visible failures and compatibility with agents that survive an extension update.
| if (message.control === false && this.socket === socket) { | ||
| this.controlRevision++; | ||
| this.control = false; | ||
| this.emit('activity'); |
There was a problem hiding this comment.
Keep the previous listener usable by the cell already running. This activity event calls disposeInteractiveJdvHostOnControlLoss in InteractiveManager.listen(), which closes the listener whose address the running cell captured. I ran the gated handoff test with that production cleanup wired in. After window B took control, the running cell’s View() produced an inline table and opened no panel in A. The queued cell correctly opened its panel in B. The existing test leaves A’s JdvHost alive until teardown. Please retain A’s listener until the cell that captured it finishes and cover the handoff with the manager cleanup enabled.
| address <- .sess_env$attach_jdv[["address"]] | ||
| } | ||
| } | ||
| address <- address %||% .sess_env$attach_jdv[["address"]] |
There was a problem hiding this comment.
Provide the controller’s address for View() outside a dispatched cell. The bridge acknowledges with jdv = NULL, and interactive_execute() restores that value on exit. I compared two entry points against 4f5ac17. Opening a nested table from the Interactive Workspace tree now emits a legacy dataview notification. Calling utils::View(data.frame(a = 1:3)) at the adopted arf console opens no panel. The transcript drops the fallback display because it has no execution ID. Both opened jdv on the base commit. Please make the current controller’s address available between cells as well as preserving the individual cell’s address while it runs.
| } else { | ||
| result = await session.handleEditorRequest(String(data.method), params); | ||
| } | ||
| const result = await session.handleEditorRequest(String(data.method), params); |
There was a problem hiding this comment.
Keep the jdv/address reply for already-running Interactive agents. After an extension update, an existing agent can reconnect with AGENT_PROTOCOL = 1. That agent ignores jdvAddress in the claim and its running R process still sends jdv/address on View(). Forwarding this to handleEditorRequest() now returns Unsupported method: jdv/address, causing every such view to fall back until R is restarted. Keeping the old reply here lets users retain their live session across the update. Newly started agents can continue using the dispatch-time address.
| jdvAddress: () => { | ||
| const lease = this.lease; | ||
| return lease?.jdv && lease.until >= Date.now() && !lease.jdv.socket.destroyed | ||
| ? lease.jdv.address |
There was a problem hiding this comment.
Keep the registered listener live when Restart fails its preflight. Restart disposes the jdv host before checking the configured Node or arf executable. I confirmed Restart with a missing Node path, then ran another cell in the surviving session. Its client was still connected and held control, so this branch returned the exact socket address that Restart had just closed. View() fell back to an inline table. Defer listener disposal until the old session actually stops, or register a live replacement if preparation fails. The existing missing-Node restart test could also assert that the next View() opens a panel.
| throw new DispatchNotSentError('The code was cancelled before it was sent'); | ||
| } | ||
| const address = jdvAddress?.(); | ||
| const code = `sess:::interactive_execute(${rString(submission.id)}, ${rString(submission.code)}, jsonlite::fromJSON(${rString(JSON.stringify(submission.source ?? null))}, simplifyVector=FALSE), ${address ? rString(address) : 'NULL'})`; |
There was a problem hiding this comment.
Keep the listener address out of arf’s command history. Managed dispatch sends this expression through user_input, and arf persists the whole expression. With an empty ARF_HISTORY_DIR, the two-window test left three rows in r.db whose history.command_line contained sess:::interactive_execute(...) and a literal vscr-jdv-… socket path. Both windows’ addresses were still there after R exited. Please pass the address outside the history-recorded command, or suppress history for the wrapper. Checking arf’s history database alongside the agent journal would cover the stated in-memory guarantee.
b6306f3 to
7889495
Compare
renkun-ken
left a comment
There was a problem hiding this comment.
The rebase onto 000310f leaves this PR’s patch identical to the one reviewed at b6306f3. I reproduced the in-flight handoff, Workspace and adopted-console viewer failures, the stale listener after failed Restart, and listener addresses in arf’s SQLite history on 7889495. The legacy jdv/address compatibility issue also remains. #2017 adds a fix for the nested Workspace case in its own diff. I found one additional ordering issue in concurrent Take Control requests. Previous review
| timeout, | ||
| ); | ||
| this.assertConnection(socket); | ||
| claimed = accepted && revision === this.controlRevision; |
There was a problem hiding this comment.
Honor a successful claim that arrives after a control-loss notice. I held window A’s socket reads while B took control and A then successfully claimed it back. A received B’s control: false notice first and its own successful reply second. Because revision was captured before both messages, A returned false and disposed the newly registered listener even though the agent reported A as the controller. A later heartbeat can correct the UI flag while the lease still points to the closed listener. Apply claim results and loss notices in server order, or give both messages an agent-issued lease revision. A two-client test covering this ordering and the reverse would protect both cases.
…ispatched R no longer asks the extension for the jdv listener address with a synchronous jdv/address request while an Interactive cell runs. The editor registers its listener when it claims control, and the agent reads the current lease immediately before writing a cell to arf, for both managed and adopted sessions. A cell queued before Take Control therefore opens its View() in the window that controls the session when the cell starts. A cell already running keeps its original address. Control is still decided per client ID, so a helper connection from the controlling window, such as Stop, keeps that window's control. Moving control to another window notifies the previous one. The address is kept in memory only and is not written to the history or the session manifest.
…anges Instead of embedding the listener address in each dispatched cell, the agent sends the current lease's address to R over SessBridge whenever control moves, the listener disconnects or the lease expires, and resends it when sess reconnects. A queued cell is written to arf only after R has acknowledged the latest route. This keeps the address out of arf's command history and gives View() at the adopted console and nested Workspace opens the controller's address between cells. A cell already running during a handoff uses the new address once R has applied it. Claim replies and control-loss notices now carry an agent-issued lease revision so a stale notice cannot dispose the listener of a later successful claim. Restart keeps the listener until its preflight checks pass, and agents that survived an extension update with protocol 1 still get a reply to jdv/address.
7889495 to
c78811b
Compare
renkun-ken
left a comment
There was a problem hiding this comment.
The new lease revisions fixed the two claim-ordering cases. I also verified the updated handoff behavior, nested Workspace opening, adopted-console View(), and that arf’s SQLite command history no longer contains the listener address. The legacy jdv/address reply is back, and Restart now retains the listener through preflight. Four cases remain. One is reproducible with the existing sized-Arrow test when arrow and nanoarrow are installed.
| @@ -887,7 +880,6 @@ sess::display("display-${cell}", "text/plain"); cat("stderr-${cell}\\n", file=st | |||
| view: params.view, | |||
| generation: params.generation, | |||
| nrow: 3, | |||
There was a problem hiding this comment.
Keep sized-Arrow row-count hints out of the persistent listener-address history. With arrow and nanoarrow installed, this assertion fails because View(arrow::Table$create(data.frame(a = 1:3))) still sends address in jdv/rowCount. I also found the literal listener path in events-000000.jsonl. The live viewer uses that field to match a hint to its peer. Please preserve that matching while keeping the address out of the journal, for example by delivering the hint live or persisting an opaque route ID. A check of the journal after displaying a sized Arrow table would cover this path.
| } | ||
| const inspectionParams = object(params.params ?? {}); | ||
| if (method === 'jdv_open_viewer') { | ||
| delete inspectionParams.address; |
There was a problem hiding this comment.
Honor explicit viewer opens from a protocol-1 client connected to the new agent. An older window can successfully claim this session without a jdvAddress and supplies its listener only on jdv_open_viewer. I tried that client against this agent with a live jdv host and a retained table handle. Deleting the address here made Open Data Viewer return false with no panel. Keep the explicit address for the controlling legacy client, or negotiate this capability before accepting its claim. The compatibility test for a new editor talking to an old agent covers the opposite pairing.
| } | ||
| inspect(request: InspectionRequest): Promise<unknown> { | ||
| async inspect(request: InspectionRequest): Promise<unknown> { | ||
| if (request.method === 'workspace_view') { |
There was a problem hiding this comment.
Wait for the current viewer route when opening a table from a sess list. Both listview_view and listview_navigate can call workspace_show_view() for a table child. Like workspace_view, they can run on arf independently of the sess socket. In a two-window R/arf run, I delayed delivery of the new route, let window B take control, and opened the table child from B. Window A’s listener received List$table, and B received nothing. Both list methods bypassed the wait in a focused backend check. Include these two methods when coordinating viewer opens so clicking a child immediately after Take Control reaches the new window.
| // Workspace opens can run over arf, independently of the sess socket. | ||
| let pending = this.bridge.pendingJdvRoute(); | ||
| while (pending) { | ||
| await pending; |
There was a problem hiding this comment.
Count the route wait against the inspection’s queue deadline. I held a route acknowledgement for seven seconds on a workspace_view with a five-second queue budget. The backend then started the inspection and passed arf a fresh five-second budget. The editor times out at six seconds, so a Workspace click can report failure and open a viewer afterwards. Carry the original start deadline through this wait and drop an expired request before forwarding it to R.
In an Interactive session,
View()asked the extension for the jdv listener address with a synchronousjdv/addressrequest on every call. A request cannot be answered while R is itself answering an extension request, so those views fell back to the sess data viewer.The extension now registers its jdv listener when it claims control of the session. Whenever the lease changes (a claim, a move to another window, a detach, an expiry, or the listener closing), the agent sends the controlling window's address to R over the sess connection, and resends it when sess reconnects. R stores it in the same setting that terminal sessions receive in the attach acknowledgement and no longer sends
jdv/address. This applies to managed and adopted sessions.View()uses the address R currently holds: in a cell, at the adopted arf console, and from a Workspace item.View()during the switch may fall back to the sess data viewer.jdv/address.