Repository navigation
fix(cursor): Stop kills the SDK worker's detached descendants without a systemd scope - #244
nullStack65 wants to merge 1 commit into
Conversation
… a systemd scope Without a systemd scope (macOS, or Linux when the scope wrap is unavailable), Cursor teardown signalled only the worker's own process group. The Cursor SDK starts its shell tools detached, in their own sessions, so a tool and anything it started kept running after Stop. Only the systemd scope stop reaped them. On Linux without a scope, the runner now tracks the worker's descendants by parentage with the ACP runtime's POSIX ownership ledger (the same helper Grok uses), keeps observing so processes whose parent exits first stay owned, and on release terminates the owned tree (SIGTERM, then SIGKILL after the worker exit timeout) before killing the worker group. A close with no live descendant pays no grace. macOS still has no descendant tracking, the same limit as Grok. Two real-process tests spawn a worker with a same-group child and a detached child, each with a sleeping grandchild, and assert all four are gone after session Stop and after runner teardown. Before the fix both failed with the detached child and its grandchild still running. Refs: CLO-1314 (Cursor provider Stop can leave grandchild processes without a systemd scope) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
|
Independent review pass (fresh-context Claude Opus 5.5 subagent, read-only) of the CLO-1314 Cursor Stop descendant fix. No critical or important findings; four nits. {"reviewed_base": "53ae52a745a55ba295151a915132cda2963031ab", "reviewed_head": "df80ec62591b396c6885f2e64fb6d7268c8f52b8", "reviewer": "claude-opus-5-5, Claude Code subagent", "author_session": "379136e3-96f3-43df-ac49-3894db95d4fb", "reviewer_session": "a143643b3b43f93bb", "fresh_context": true, "review_kind": "full", "round_id": "a143643b3b43f93bb", "intent": ["Cursor Stop kills the worker's descendants without a systemd scope, with a real child/grandchild test (CLO-1314)"], "prior_findings": [],
"findings": [
{"id": "F1", "severity": "nit", "summary": "A release with a live descendant always waits the full 2 s grace before SIGKILL, even if SIGTERM was enough; same as Grok's ACP helper", "outcome": "skipped", "file": "packages/provider-acp/src/server/AcpSessionRuntime.ts", "check": "Shared helper behaviour, out of scope; recorded under the PR's known limits"},
{"id": "F2", "severity": "nit", "summary": "Shared worker: a session's detached tools die when the last session releases the worker, not on each session's Stop; same as the systemd-scope path", "outcome": "fixed", "file": "packages/provider-cursor/src/server/CursorAgentSdkProcessRunner.ts", "check": "Documented in the PR body's known limits"},
{"id": "F3", "severity": "nit", "summary": "Ledger only grows between terminations, and the continuous observer polls every 25 ms for the worker's lifetime", "outcome": "skipped", "file": "packages/provider-acp/src/server/AcpSessionRuntime.ts", "check": "Shared helper cost, the same one Grok pays; not a correctness issue"},
{"id": "F4", "severity": "nit", "summary": "Parentage ledger can miss a double-fork that finishes within one observation cycle; macOS has no tracking", "outcome": "skipped", "check": "Known limit, already documented in the ACP code and the PR body"}
]} |
|
Cross-family review pass (Grok 4.7, fresh T3 delegate, read-only) of the CLO-1314 Cursor Stop descendant fix. Verdict clean: one nit, outside the gate's finding map because a second full record must keep the original map. Nit (skipped): on a graceful last-session close, a detached shell the SDK spawns in the final ~25 ms before the worker exits is never sampled and survives reparented to init (CursorAgentSdkProcessRunner.ts:129). Same sampling window as F4; the worker is idle at last-session close. {"reviewed_base": "53ae52a745a55ba295151a915132cda2963031ab", "reviewed_head": "df80ec62591b396c6885f2e64fb6d7268c8f52b8", "reviewer": "grok-4.7, Grok via T3 delegate_task", "reviewer_family": "grok", "author_session": "379136e3-96f3-43df-ac49-3894db95d4fb", "reviewer_session": "thread:delegated-task:command%3Amcp%3Ad601496e-1880-483a-a99f-1e811711c457%3Adelegate-task%3A9fe668b3-e107-41d6-b023-1e43f4b60e6f", "fresh_context": true, "review_kind": "full", "round_id": "a143643b3b43f93bb", "intent": ["Cursor Stop kills the worker's descendants without a systemd scope, with a real child/grandchild test (CLO-1314)"], "prior_findings": [], "findings": [{"id": "F1", "severity": "nit", "summary": "A release with a live descendant always waits the full 2 s grace before SIGKILL, even if SIGTERM was enough; same as Grok's ACP helper", "outcome": "skipped", "file": "packages/provider-acp/src/server/AcpSessionRuntime.ts", "check": "Shared helper behaviour, out of scope; recorded under the PR's known limits"}, {"id": "F2", "severity": "nit", "summary": "Shared worker: a session's detached tools die when the last session releases the worker, not on each session's Stop; same as the systemd-scope path", "outcome": "fixed", "file": "packages/provider-cursor/src/server/CursorAgentSdkProcessRunner.ts", "check": "Documented in the PR body's known limits"}, {"id": "F3", "severity": "nit", "summary": "Ledger only grows between terminations, and the continuous observer polls every 25 ms for the worker's lifetime", "outcome": "skipped", "file": "packages/provider-acp/src/server/AcpSessionRuntime.ts", "check": "Shared helper cost, the same one Grok pays; not a correctness issue"}, {"id": "F4", "severity": "nit", "summary": "Parentage ledger can miss a double-fork that finishes within one observation cycle; macOS has no tracking", "outcome": "skipped", "check": "Known limit, already documented in the ACP code and the PR body"}]} |
Problem
When the Cursor SDK worker runs without a systemd scope (macOS, or Linux when the scope wrap is unavailable), Stop and runner teardown signal only the worker's own process group. The Cursor SDK starts its shell tools with
detached: true, so each one gets its own session and group. That means a running shell tool, and anything it started, outlives Stop. OnlyagentScope.stop(unit)was reaping them. Tracked as CLO-1314 (Cursor provider Stop can leave grandchild processes without a systemd scope, a follow-up to the T2a-01 Stop audit).The issue said only the worker PID was signalled. That is half right: the Effect spawner already starts the worker detached and kills its whole group, so grandchildren in the same group already died. Grandchildren in detached groups did not.
Change
CursorAgentSdkProcessRunner: whenagentScope.wrapreturns no unit and the host is Linux, the runner tracks the worker's descendants by parentage with the ACP runtime's POSIX ownership ledger, the same helper Grok uses. It takes one observation at spawn and then keeps observing in the worker scope, so processes whose parent exits first stay owned. On release it terminates the owned tree (SIGTERM, then SIGKILL afterWORKER_EXIT_TIMEOUT) before the existing group kill and scope stop. A close with no live descendant skips the grace period. If tracking can't start, it logs a warning and falls back to the old behaviour.provider-acp: exportsobservePosixOwnershipLedgerContinuously.provider-cursornow depends on@t3tools/provider-acp.Scope
Bug fix for CLO-1314. A systemd-scoped Linux worker is unchanged: the scope still reaps the tree, and no ledger is created.
Known limits:
Detached ACP descendant ownership is unsupported on darwin).Prior art
Searched: 2026-11-27, repository code and Effect/Node platform docs.
AgentScope): already used when available; not available on macOS or scope-less Linux. Kept.NodeChildProcessSpawnerdetached group plus group kill: already in effect. It misses SDK tools in their own sessions, so on its own it is not enough.provider-core/processGroup.ts): can't find detached sessions without a ledger.terminatePosixOwnedProcessTree): reused here, so no new process-tree code.tree-kill/ps-treenpm packages: they walk the tree only at kill time, so they lose processes reparented to init after their parent exits. The continuous ledger keeps them. Not adopted.Verification
it.livetests on Linux, using real processes: a fake worker spawns a same-group child and adetached: truechild, each with asleep 600grandchild. The tests assert all four PIDs are gone (zombies count as dead) after session Stop and after runner-scope teardown, with no systemd unit. Before the fix, both failed with the detached child and its grandchild still running. After the fix, both pass.packages/provider-cursortests: 190 of 190 passed, 5 consecutive runs.apps/serverAcpSessionRuntime.processTree.test.ts: 18 of 18 passed.effect-tsgo tsrs --noEmitpasses for provider-cursor and provider-acp.vp lint(Node 26.13.1) andvp fmt --checkare clean on both packages.Browser proof
Not applicable: server process teardown only, no UI change.
Deploy: fleet
Model and harness: Claude Opus 5.5 in Claude Code via T3.
Model-family: claude
🤖 Generated with Claude Code