Repository navigation
refactor(llc/adapters): extract shared SubprocessLifecycleAdapter base (#9834) - #9835
Merged
Merged
Conversation
#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>
Contributor
✅ SSOT Configuration Compliance: Passing🎉 No hardcoded values detected that have SSOT config equivalents! |
This was referenced Jun 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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) andcopilot_local_adapter(281 lines) —_cancelwas byte-identical bar log strings + claude's session-clear. Filed as #9834; this addresses it.What Changed
New
llc/adapters/subprocess_base.py→SubprocessLifecycleAdapterowns the shared lifecycle:invokewrapper,status/_status,_probe_pid,cancel/_cancel(SIGTERM→grace→SIGKILL),_load_state(path-traversal-guarded),_build_promptresolve_timeout(3-tier) +SIGTERM_GRACE_SECONDS/ADAPTER_TIMEOUT_SECONDS/DEFAULT_*constants_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 sessionCopilotLocalAdapter(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
The existing adapter suite is the behavior contract — 0 failures, all unchanged. New
test_subprocess_base.pycoversresolve_timeouttiers, the_load_statepath-traversal guard, and shared status. Registry wiring verified via the existingTestRegistrytests.Closes #9834.
Model Used
claude-opus-4-8 (1M context)