Skip to content

refactor(llc/adapters): extract shared SubprocessLifecycleAdapter base (#9834) - #9835

Merged
mrveiss merged 1 commit into
Dev_new_guifrom
issue-9834
Jun 9, 2026
Merged

mrveiss merged 1 commit into
Dev_new_guifrom
issue-9834

Conversation

@mrveiss

@mrveiss mrveiss commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Thinking Path

The post-merge audit (after #9811 shared the prompt/credential layer) found the subprocess lifecycle still duplicated near-verbatim across claude_code_adapter (355 lines) and copilot_local_adapter (281 lines) — _cancel was byte-identical bar log strings + claude's session-clear. Filed as #9834; this addresses it.

What Changed

New llc/adapters/subprocess_base.py → SubprocessLifecycleAdapter owns the shared lifecycle:

  • invoke wrapper, status/_status, _probe_pid, cancel/_cancel (SIGTERM→grace→SIGKILL), _load_state (path-traversal-guarded), _build_prompt
  • shared resolve_timeout (3-tier) + SIGTERM_GRACE_SECONDS / ADAPTER_TIMEOUT_SECONDS / DEFAULT_* constants
  • a _post_cancel(agent_config, run_id) hook (default no-op)

Subclasses now only carry what actually differs:

  • ClaudeCodeAdapter (355→234): _invoke (resume-session + stream-json), Redis session methods, _post_cancel → clear session
  • CopilotLocalAdapter (281→156): _invoke (gh copilot suggest)

The legacy module-level symbols (_output_path/_state_path/_resolve_claude_cli/_resolve_gh_cli/_resolve_timeout/_SIGTERM_GRACE_SECONDS) are kept as re-exports, so the subscription adapters' imports and the existing test suite's import-contract are unchanged. The subscription subclasses inherit the shared lifecycle automatically.

Net: −246 duplicated lines for a 197-line single source of truth.

Verification

$ python3 -m pytest llc/adapters/tests/ llc/tests/test_heartbeat_scheduler.py llc/tests/test_heartbeat_context.py -q
154 passed

The existing adapter suite is the behavior contract — 0 failures, all unchanged. New test_subprocess_base.py covers resolve_timeout tiers, the _load_state path-traversal guard, and shared status. Registry wiring verified via the existing TestRegistry tests.

Closes #9834.

Model Used

claude-opus-4-8 (1M context)

#9834)

The two base subprocess adapters duplicated their entire CLI lifecycle —
state-file management, PID probe, timeout resolution, status polling, and
SIGTERM→SIGKILL cancel — differing only in log name, file-name prefix, and a
claude-only post-cancel session clear.

New llc/adapters/subprocess_base.py:SubprocessLifecycleAdapter owns
invoke-wrapper, status/_status, _probe_pid, cancel/_cancel, _load_state,
_build_prompt, and the shared resolve_timeout / SIGTERM_GRACE_SECONDS /
DEFAULT_* constants. Subclasses provide _LOG_NAME, a _state_path staticmethod,
_invoke, and an optional _post_cancel hook (ClaudeCodeAdapter clears its Redis
resume session there).

claude_code_adapter 355→234 lines, copilot_local_adapter 281→156 (−246 dup
lines for a 197-line shared base). The legacy module-level symbols
(_output_path/_state_path/_resolve_*/_resolve_timeout/_SIGTERM_GRACE_SECONDS)
are preserved as re-exports so the subscription adapters and the existing test
suite import-contract is unchanged.

Verification: full adapter + scheduler + context suite = 154 passed, 0
failures (behavior contract preserved). New test_subprocess_base.py covers
resolve_timeout tiers, the _load_state path-traversal guard, and shared status.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

✅ SSOT Configuration Compliance: Passing

🎉 No hardcoded values detected that have SSOT config equivalents!

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