Skip to content

LLC adapters: agent cancel/timeout orphans the whole subprocess tree #13097

Closed

Description

@mrveiss

Problem

terminate_pid() signals a single PID. None of the LLC CLI adapters spawn
their child in its own process group, so cancelling or timing out an agent run
kills the CLI process and orphans every descendant it spawned.

Agent CLIs are process trees, not single processes: the Claude Code CLI spawns
Bash-tool children, MCP servers, and npx/node chains. Those keep running after
the parent is killed — holding file handles, ports, and workspace locks, and in
the worst case continuing to mutate a workspace that the scheduler believes is
released.

Evidence

autobot-backend/llc/adapters/subprocess_support.py:302-335 — terminate_pid()
uses os.kill(pid, signal.SIGTERM) then os.kill(pid, signal.SIGKILL) on one PID.

All 8 spawn sites use bare asyncio.create_subprocess_exec with no
start_new_session:

  • llc/adapters/claude_code_adapter.py:258,273
  • llc/adapters/claude_code_subscription_adapter.py:99,118
  • llc/adapters/copilot_local_adapter.py:117,133
  • llc/adapters/copilot_subscription_adapter.py:113,132
$ grep -rn --include=*.py "killpg\|getpgid\|start_new_session" autobot-backend/llc/
(no output)

Prior art already in this repo

The correct pattern is already used elsewhere and should simply be reused:

  • autobot-backend/services/mcp_isolated_runtime.py:83 — start_new_session=True
  • autobot-backend/services/simple_pty.py:298,311 — os.killpg(os.getpgid(pid), sig)

Proposed fix

  1. Add start_new_session=True to all 8 create_subprocess_exec calls.
  2. terminate_pid() → signal the process group via os.killpg(os.getpgid(pid), …),
    falling back to the current single-PID path on ProcessLookupError /
    PermissionError (a child that already changed its own pgid, or a
    non-signallable group).
  3. Preserve the existing return contract: True when the process was already gone
    on the initial signal.

Acceptance criteria

  • All 8 spawn sites create a new session/process group
  • terminate_pid() kills the group, with documented single-PID fallback
  • Test: spawn a parent that forks a long-lived child; assert the grandchild is
    gone after terminate_pid()
  • Test: already-dead PID still returns True (no regression)
  • SIGTERM→SIGKILL grace behaviour unchanged

Notes

Found during a capability audit of the LLC adapter layer. This is a live
correctness bug, not a feature request.

Activity

  1. mrveiss commented on Jul 31, 2026

    @mrveiss
    OwnerAuthor

    Parent: #13096 (capability audit umbrella).

  2. 2 remaining items

  3. added this to the v0.9.0 milestone on Sep 12, 2026
  4. mrveiss commented on Sep 14, 2026

    @mrveiss
    OwnerAuthor

    Closure audit against origin/main (vehicle merge #16702, closing PR #16284).

    AC Verdict Evidence
    All 8 spawn sites create new session/process group met Every LLC adapter routes through autobot-backend/llc/adapters/subprocess_support.py:spawn_detached() (start_new_session=True); tests/test_process_group_kill_13097.py::TestSpawnSitesCreateNewSession::test_every_call_site_sets_start_new_session is an AST-based guard over every call site
    terminate_pid() kills the group, documented single-PID fallback met subprocess_support.py:terminate_pid() uses _process_group_id()/_signal_target(); falls back to os.kill(pid, sig) on ProcessLookupError/PermissionError or when pid isn't its own group leader (docstring at line ~498)
    Test: grandchild gone after terminate_pid() met tests/test_process_group_kill_13097.py::TestGrandchildSurvival::test_terminate_pid_kills_the_grandchild
    Test: already-dead PID still returns True met tests/test_process_group_kill_13097.py::TestTerminatePidRealProcesses::test_already_dead_pid_returns_true
    SIGTERM→SIGKILL grace behaviour unchanged met tests/test_process_group_kill_13097.py::test_sigterm_then_sigkill_after_grace; terminate_pid() retains the same grace-poll-then-SIGKILL shape, now targeting the group

    All 5 criteria met. Kept closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions