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
Consolidation: share pid-probe + terminate primitives between ProcessAdapter and SubprocessLifecycleAdapter
#9834 (PR #9835) extracted
SubprocessLifecycleAdapterfor the two CLI adapters. Butprocess_adapter.py(the generic GH#8226 process adapter) still hand-rolls the same two primitives:process_adapter.status(lines 58-71) is byte-identical toSubprocessLifecycleAdapter._probe_pid:os.kill(pid, 0)→ RUNNING /ProcessLookupError→COMPLETED /PermissionError→RUNNING /OSError→FAILED.process_adapter.cancel(lines 72-92) is the same SIGTERM → grace-poll → SIGKILL pattern asSubprocessLifecycleAdapter._cancel(only the grace constant differs: 5s vs 10s).ProcessAdapter can't inherit the full lifecycle base (it has no state file —
run_idis a bare PID), but the two pure primitives are genuinely shareable.Proposed fix
Extract into
subprocess_support.py:probe_pid(pid: int) -> AdapterRunStatusasync terminate_pid(pid: int, grace_seconds: int, log_name: str) -> NoneThen have both
SubprocessLifecycleAdapterandProcessAdaptercall them (ProcessAdapter passesgrace_seconds=5; the lifecycle base passes 10). Removes the last copy of these primitives.References
Discovered auditing the merged/under-review #9834 (PR #9835).
CodexSubscriptionAdapteris a NotImplementedError stub — correctly excluded (no subprocess).autobot_agent_adapteris in-process andhttp_adapteris HTTP — neither applies.Labels: enhancement · backend · agents · priority: low