Repository navigation
refactor(agent-server): split claude_code.py into focused modules (#122) - #750
Merged
Merged
Conversation
Extracts the 2137-LOC claude_code.py monolith into six focused services so the chat path, headless task path, parsing, error classification, JSONL recovery, and subprocess teardown each live in their own module: - _runtime_config.py — guardrails config loader (shared by chat + task) - error_classifier.py — exit-code/signal/empty-result diagnosis + recovery - headless_executor.py — execute_headless_task + HeadlessRunContext - jsonl_recovery.py — fallback parsing of ~/.claude/projects/<uuid>.jsonl - stream_parser.py — stream-json line + batch parsers - subprocess_lifecycle.py — pgroup capture/terminate, _drain_bounded (#728) claude_code.py keeps the AgentRuntime adapter, execute_claude_code chat path, and the execution lock; everything else is re-imported from the new modules so the public API is unchanged. Tests updated to follow the new import paths and pin the new module boundaries (chat wallclock timeout, drain bounded, JSONL recovery, signal exit, session-id parser, etc.); test-runner.md catalog updated with the seven new/moved unit suites. Adds TRINITY_DB_PATH default in tests/unit/conftest.py so DatabaseManager() at import doesn't trip on read-only /data on the host. Comment-only update in task_execution_service.py points the cache-token accounting note at the new stream_parser.process_stream_line; comment-only update in process_registry.py reflects that publish_log is now called from both paths. Closes #122 Co-Authored-By: Claude <[email protected]>
vybe
approved these changes
May 10, 2026
vybe
left a comment
Contributor
There was a problem hiding this comment.
Clean module split with no functional regressions. Token-accounting fix is correct and well-tested. All public API callers unaffected. Test isolation improvements are a bonus.
4 tasks
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.
Summary
Splits the 2137-LOC
docker/base-image/agent_server/services/claude_code.pymonolith into six focused services.claude_code.pykeeps theAgentRuntimeadapter,execute_claude_codechat path, and the execution lock; everything else moves out and is re-imported, so the public API is unchanged._runtime_config.pyerror_classifier.pyheadless_executor.pyexecute_headless_task+HeadlessRunContextorchestratorjsonl_recovery.py~/.claude/projects/<uuid>.jsonlstream_parser.pysubprocess_lifecycle.py_drain_boundeddeadlock guard (#728)Net diff is +2466 / -1758 across 26 files; the new module bodies were lifted directly from
claude_code.pyto keep behaviour identical.Why
claude_code.pyhad grown to ~2.1k lines mixing the chat path, headless task path, two parsers, three error-classification surfaces, JSONL recovery, and subprocess lifecycle. Extracting each concern lets future work (#728 drain budget, SESSION_TAB resume path, GUARD-003 runtime config) land in a smaller blast radius.What also changed
tests/unit/conftest.py— pinsTRINITY_DB_PATHtotempfile.gettempdir()soDatabaseManager()at import doesn't trip on read-only/dataon the host.task_execution_service.py— comment-only update redirecting the cache-token accounting note tostream_parser.process_stream_line.process_registry.py— comment-only update reflecting thatpublish_logis now called from both the chat and task paths.Test plan
pytest tests/unit/test_chat_wallclock_timeout.py tests/unit/test_drain_bounded.py tests/unit/test_jsonl_recovery.py tests/unit/test_signal_exit_classification.py tests/unit/test_empty_result_classification.py tests/unit/test_claude_code_result_recovery.py tests/unit/test_claude_code_session_id_parser.py tests/unit/test_session_persistence_flag.py— module-boundary pinspytest tests/unit/— broader unit suite still green after import-path updates./scripts/deploy/build-base-image.sh) and run a chat + a scheduled task against an agent — confirms bothexecute_claude_codeandexecute_headless_taskpaths exercise the re-imported helpersCloses #122
🤖 Generated with Claude Code