Skip to content

fix(cursor): Stop kills the SDK worker's detached descendants without a systemd scope - #244

Open
nullStack65 wants to merge 1 commit into
release/native-0.1.10from
t3/clo-1314-cursor-stop-tree
Open

nullStack65 wants to merge 1 commit into
release/native-0.1.10from
t3/clo-1314-cursor-stop-tree

Conversation

@nullStack65

@nullStack65 nullStack65 commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

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. Only agentScope.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: when agentScope.wrap returns 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 after WORKER_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: exports observePosixOwnershipLedgerContinuously. provider-cursor now 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:

  1. macOS has no descendant tracking. It still uses the worker group kill only, the same limit as Grok's ACP runtime (Detached ACP descendant ownership is unsupported on darwin).
  2. A parentage ledger can miss a double-fork that finishes between two observations.
  3. The worker is shared across sessions, so descendants die when the last session releases the worker or the runner shuts down, not on each session's Stop. The systemd-scope path has the same behaviour.
  4. A release with a live descendant waits the full 2 s grace before SIGKILL, the same as Grok.
  5. The issue also asked for a matching Grok child/grandchild Stop test with real processes. That is not in this PR; it stays a follow-up on the issue.

Prior art

Searched: 2026-11-27, repository code and Effect/Node platform docs.

  • systemd scope (AgentScope): already used when available; not available on macOS or scope-less Linux. Kept.
  • Effect NodeChildProcessSpawner detached group plus group kill: already in effect. It misses SDK tools in their own sessions, so on its own it is not enough.
  • Process-group kill of every observed pgid (provider-core/processGroup.ts): can't find detached sessions without a ledger.
  • ACP runtime POSIX ownership ledger (terminatePosixOwnedProcessTree): reused here, so no new process-tree code.
  • tree-kill / ps-tree npm 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

  • Two new it.live tests on Linux, using real processes: a fake worker spawns a same-group child and a detached: true child, each with a sleep 600 grandchild. 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-cursor tests: 190 of 190 passed, 5 consecutive runs.
  • apps/server AcpSessionRuntime.processTree.test.ts: 18 of 18 passed.
  • effect-tsgo tsrs --noEmit passes for provider-cursor and provider-acp. vp lint (Node 26.13.1) and vp fmt --check are clean on both packages.
  • Not checked: macOS (unchanged path), a live Cursor session with a real shell tool.

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

… 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>
@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@nullStack65

Copy link
Copy Markdown
Owner Author

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"}
 ]}

@nullStack65

nullStack65 commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner Author

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"}]}

This branch has not been deployed

No deployments
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.

1 participant