Repository navigation
fix session shutdown wedge with an active posit assistant - #18417
Conversation
…ents at shutdown The assistant/chat shutdown waits pumped the full background-processing pass (every module's background handlers plus scheduled commands) and the R event loop on each poll. Dispatching arbitrary work mid-rCleanup means any one blocking item wedges the session's exit permanently -- and with it the desktop relaunch (driven by the child exit event) or the server session proxy (whose connect() to the still-held listening socket succeeds, so session-unavailable recovery never launches a replacement). The supervisor poll alone drains the child pipes, flushes the queued shutdown request, and fires the exit callbacks these waits watch; agent I/O handlers already early-return during shutdown, so the full pump delivered nothing else on this path. Also escalate to SIGKILL on the agent's detached process group when it survives the grace waits: terminateProcess() is a single-pid SIGTERM, terminateAllChildProcesses() is off by default in the session, and exitWithParent is compiled out on macOS, so a surviving agent was otherwise orphaned forever. The did-not-exit paths now log at WARN so a recurrence localizes itself in session logs (everything on this path was previously DLOG-only). Addresses #18394.
…s at startup launchNextSession never cleared workbenchInitialized (only the desktop_launch_session IPC path through MainWindow.launchSession did), so a replacement session that died during startup after a project switch was misread as a crash of a running workbench: the launch error page was suppressed and the window hung silently on the old, dead frame. Addresses #18394.
The assistant and chat_provider prefs default to "posit", so once a @chat suite installs the Posit Assistant backend into a worker's data home, every later session start in that worker launches the chat backend and NES agent -- and every project open/close/restart in unrelated suites then shuts them down seconds after startup. That churn is the window for the session-shutdown wedge that has been killing whole CI shards via the run-with-heartbeat watchdog. Start desktop workers with both prefs at "none" via base-prefs.jsonc, and flip leaked provider prefs back to "none" from the per-test fixture for tests not tagged @ai/@chat. Desktop only: server mode shares one config/data home across workers, so a per-test pref flip there would race a @chat suite running concurrently in another worker. Addresses #18394.
Loop project open/close cycles with the Posit Assistant chat backend and NES agent running -- the exact workload that wedged CI shards. The @chat suites only hit this incidentally when the tests/projects region shared their worker; this makes the workload deliberate so a recurrence fails here, visibly, instead of killing whatever unrelated shard inherited the leaked provider state. Gated on the backend actually starting (positai.log appears) so it cannot silently degrade into testing plain restarts. Addresses #18394.
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Two rsession-scope tests for the #18394 shutdown-pump change: processSupervisor().poll() alone must reap an exited child and fire its exit callback, and it must NOT dispatch scheduled commands (while onBackgroundProcessing(false) does). A supervisor or scheduling refactor that breaks either assumption fails here instead of resurfacing as a silent CI shard hang. Addresses #18394.
|
Since the supervisor-only pump touches sensitive shutdown code, here is the verification that went beyond "existing tests still pass": 1. Unit tests pinning the load-bearing semantics (added in 97b07fd, rsession scope): 2. Adversarial A/B experiment reproducing the wedge mechanism locally (throwaway spec, not committed). Setup: assistant enabled, then
So the pre-fix shutdown wait demonstrably dispatches arbitrary pending R callbacks mid-teardown (a blocking one wedges rsession's exit exactly as diagnosed in #18394), and the patched wait dispatches none while the restart still completes and the stuck agent still gets cleaned up. Two earlier runs also confirmed the graceful path is unaffected: with healthy (unfrozen) agents both builds close in ~4.5s, because the agents exit on the first poll iterations and the pump window never opens. One incidental finding from a false start: the first experiment runs showed no live agents at all mid-test -- the new per-test fixture guard had flipped the provider prefs to 3. Why the risky branch is narrower than it looks: it is gated to |
… pane uninstall-posit-ai and deprecate-pai-blocking opened the chat pane relying on the chat_provider default of "posit"; with base-prefs now seeding "none" the pane has no provider and waitForChatReady times out (seen on the macOS shard for uninstall-posit-ai; deprecate-pai-blocking has the same latent dependence on suite ordering). chat-guardrails-paths is console-driven and unaffected. Addresses #18394.
RStudio E2E - all platformsAll tests passed!
View / download the full reportView report online -- opens in the browser, no download needed. Available for 14 days. Download playwright-report.zip -- extract and open
All platforms - commit |
Code review findingsActionable items from an automated multi-agent review. Verified against source; the C++ was not built or run. Critical
Important
Suggestions
|
The chat module's suspend handler still pumped the full background-processing pass and cleared the backend pid unconditionally, which both preserved the wedge on server idle-timeout suspends / suspend-for-restart and made the onShutdown escalation dead code on that leg. Factor the request/wait/escalate sequence into stopChatBackendForSessionExit() and use it from both handlers. Also from review: skip the grace wait when the shutdown request was never sent (older backends without lifecycle/requestShutdown), log SIGKILL failures other than ESRCH, snapshot pids and guard with > 1 before signaling the process group, pin callbacksRequireMainThread in the supervisor-pump test, and correct the comments on exitWithParent and supervisor-poll semantics.
From review: the comment claimed parity with MainWindow.launchSession, which clears the flag unconditionally -- state the reload gating rationale instead, and pin both branches with unit tests.
From review: baseline positai.log before enabling the provider so a stale log from an earlier @chat suite can't satisfy the started-backend guard; make the afterAll steps independently non-fatal and logged instead of swallowed; drop the unreachable assertions after createAndOpenProject; warn when the leak guard cannot read the provider prefs; make chat-user-skills' backend stop conditional on a leaked-on provider; extract selectPositChatProvider; and correct the server-mode config-home and backend-start comments.
From review: terminate the chat backend through its retained process handle, which signals the detached child's whole process group instead of the single pid, and cut the assistant's shutdown reap wait from 10s to 2s -- the SIGKILL escalation is the backstop, and session exit should stay fast even when the agent ignores SIGTERM. Non-exit callers keep the patient 10s default.
|
Thanks -- this was a genuinely useful review. All items are addressed in bf6ab6c (session), 2e5e345 (desktop), 3c4c318 (e2e), and 2bd6081 (items 10/23), with the following notes: 1: Confirmed, including the ordering (suspend hook -> 2: The premise doesn't hold: 7/24: Fixed via direct 10: Applied for chat (2bd6081): the force-terminate now goes through the retained 23: Applied (2bd6081): 16: Kept the stop but made it conditional -- it's not always a no-op: an earlier @chat suite can leak 3: Stale-log hole fixed with a size baseline. The NES agent half is documented rather than guarded: the agent has no bridge-observable startup artifact today (runtime status only lands in SessionInfo at client init). Exposing it on the automation bridge would make a good follow-up. 22: Fixed the diverged/overstrong wording (the test header now says poll still fires I/O/exit callbacks of other supervised children), and the chat helper collapses one C++ copy. I've left the remaining copies in place -- each addresses a different audience and they all point at #18394 as canonical. 14's parenthetical: confirmed, Everything else applied as suggested. Verification: full build, 407 rsession gtests, 449 desktop unit tests (2 new for |
Addresses #18394.
CI shards have been dying with 300 seconds of output silence (
run-with-heartbeatexit 124) at session-restart boundaries in thetests/projectsregion. The investigation (see the issue comment) traced it to session shutdowns that never complete when the Posit Assistant chat backend / NES agent are running: the desktop relaunch is driven purely by the rsession child'sexitevent, and the server session proxy only launches a replacement whenconnect()to the session's socket fails -- so an rsession that never finishesrCleanup()wedges the whole IDE, silently, in both modes.Every wait in the shutdown sequence is bounded except one thing: the assistant/chat stop loops pumped the full
module_context::onBackgroundProcessing()pass (every module's background handlers plus scheduled commands) andr::session::event_loop::processEvents()(arbitrary R callbacks) on every poll, mid-teardown. Any blocking item dispatched there wedges the exit permanently, with nothing logged (the whole path was DLOG-only).Changes:
SessionAssistant.cpp/SessionChat.cpp: during session shutdown, the stop waits pump onlyprocessSupervisor().poll()-- which drains the child pipes, flushes the queued shutdown request, and fires the exit callbacks these waits are watching. (Agent I/O handlers already early-return during shutdown, so the full pump delivered nothing else on this path.) If the agent/backend survives SIGTERM plus the grace wait, escalate with SIGKILL to its detached process group --terminateProcess()is a single-pid SIGTERM,terminateAllChildProcesses()is off by default in the session, andexitWithParentis compiled out on macOS, so a surviving agent was otherwise orphaned forever. The did-not-exit paths now log at WARN so any recurrence localizes itself in the session logs CI already attaches.session-launcher.ts(desktop):launchNextSession()now clearsworkbenchInitializedon reload, as thedesktop_launch_sessionIPC path already did. Without this, a replacement session dying during startup after a project switch was misread as a crash of a running workbench, the launch error page was suppressed, and the window hung silently on the old dead frame.assistant/chat_providerat"none"(both default to"posit", so once a @chat suite installed the backend into a worker's data home, every unrelated suite in that worker ran -- and tore down -- the agents on every restart). A per-test fixture guard flips leaked provider prefs back to"none"for tests not tagged@ai/@chat. Desktop-only: server mode shares one config across workers, so a per-test flip there would race concurrently-running @chat suites.restart-under-agent.test.tsstress test (@chat lane, desktop-only) that enables the assistant and loops project open/close cycles with the agents live -- the exact workload that wedged CI -- so a recurrence fails visibly in this test instead of killing whatever shard happened to inherit the leaked provider state.Verification: rsession + core C++ suites pass; desktop typecheck/lint/unit tests pass (one pre-existing environmental failure:
findComponentsneeds a built rsession); e2e typecheck passes; the new stress test passes locally against this branch's build. The wedge mechanism is the only unbounded path found in the shutdown sequence, but no stack was ever captured from a wedged CI runner, so the WARN logging is there to confirm or refute recurrence from CI artifacts.Follow-ups deliberately not in this PR (noted on the issue): the server session proxy has no request deadline; the local-stream acceptor lacks
FD_CLOEXEC(and the Windows acceptor handle is inheritable), so a non-ChildProcessfork can starve session relaunch indefinitely.