Skip to content

refactor(llc/adapters): share pid-probe + SIGTERM/SIGKILL terminate primitives (ProcessAdapter dups subprocess_base) #9839

Description

@mrveiss

Consolidation: share pid-probe + terminate primitives between ProcessAdapter and SubprocessLifecycleAdapter

#9834 (PR #9835) extracted SubprocessLifecycleAdapter for the two CLI adapters. But process_adapter.py (the generic GH#8226 process adapter) still hand-rolls the same two primitives:

  • PID probe — process_adapter.status (lines 58-71) is byte-identical to SubprocessLifecycleAdapter._probe_pid: os.kill(pid, 0) → RUNNING / ProcessLookupError→COMPLETED / PermissionError→RUNNING / OSError→FAILED.
  • Terminate loop — process_adapter.cancel (lines 72-92) is the same SIGTERM → grace-poll → SIGKILL pattern as SubprocessLifecycleAdapter._cancel (only the grace constant differs: 5s vs 10s).

ProcessAdapter can't inherit the full lifecycle base (it has no state file — run_id is a bare PID), but the two pure primitives are genuinely shareable.

Proposed fix

Extract into subprocess_support.py:

  • probe_pid(pid: int) -> AdapterRunStatus
  • async terminate_pid(pid: int, grace_seconds: int, log_name: str) -> None

Then have both SubprocessLifecycleAdapter and ProcessAdapter call them (ProcessAdapter passes grace_seconds=5; the lifecycle base passes 10). Removes the last copy of these primitives.

References

Discovered auditing the merged/under-review #9834 (PR #9835). CodexSubscriptionAdapter is a NotImplementedError stub — correctly excluded (no subprocess). autobot_agent_adapter is in-process and http_adapter is HTTP — neither applies.

Labels: enhancement · backend · agents · priority: low

Activity

  1. mrveiss commented on Jun 11, 2026

    @mrveiss
    OwnerAuthor

    Closed — merged to Dev_new_gui via PR #9979 (squash commit 092a36b51).

    Criteria met:

    • probe_pid(pid) -> AdapterRunStatus and async terminate_pid(pid, grace_seconds, log_name) -> bool extracted into llc/adapters/subprocess_support.py
    • SubprocessLifecycleAdapter (grace 10) and ProcessAdapter (grace 5) both call them — last duplicate copies removed; grep confirms SIGTERM/SIGKILL/os.kill logic exists only in subprocess_support
    • Semantic difference preserved: ProcessAdapter early-returns on already-gone SIGTERM (via return value), lifecycle base always continues to _post_cancel + state-file cleanup
    • 128/128 adapter suite (independently re-run by reviewer); 9 new primitive tests covering every branch; review verdict APPROVE (probe/terminate parity EXACT)

    Discoveries: none (accepted observability delta: SIGTERM/SIGKILL logs now emit under the shared module's logger, adapter identity kept in message text).

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions