refactor: AutoModeService decomposition (Phases 1-6) #733 + fixes#771
refactor: AutoModeService decomposition (Phases 1-6) #733 + fixes#771gsxdsm wants to merge 61 commits intoAutoMaker-Org:v0.15.0rcfrom
Conversation
- STACK.md - Technologies and dependencies - ARCHITECTURE.md - System design and patterns - STRUCTURE.md - Directory layout - CONVENTIONS.md - Code style and patterns - TESTING.md - Test structure - INTEGRATIONS.md - External services - CONCERNS.md - Technical debt and issues
Refactoring auto-mode-service.ts (5k+ lines) into smaller, focused services with clear boundaries.
User preference: keep .planning/ local-only
- Test lease counting basics (acquire/release semantics) - Test running count queries (project and worktree level) - Test feature state queries (isRunning, getRunningFeature, getAllRunning) - Test edge cases (multiple features, multiple worktrees) - 36 test cases documenting expected behavior Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Lease-based reference counting for nested execution support - acquire() creates entry with leaseCount: 1 or increments existing - release() decrements leaseCount, deletes at 0 or with force:true - Project and worktree-level running counts - RunningFeature interface exported for type sharing Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- AutoModeService now delegates to ConcurrencyManager for all running feature tracking - Constructor accepts optional ConcurrencyManager for dependency injection - Remove local RunningFeature interface (imported from ConcurrencyManager) - Migrate all this.runningFeatures usages to concurrencyManager methods - Update tests to use concurrencyManager.acquire() instead of direct Map access - ConcurrencyManager accepts getCurrentBranch function for testability BREAKING: AutoModeService no longer exposes runningFeatures Map directly. Tests must use concurrencyManager.acquire() to add running features. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add TypedEventBus as wrapper around EventEmitter - Implement emitAutoModeEvent method for auto-mode event format - Add emit, subscribe, getUnderlyingEmitter methods - Create comprehensive test suite (20 tests) - Verify exact event format for frontend compatibility
- Create WorktreeResolver class for git worktree discovery - Extract getCurrentBranch, findWorktreeForBranch, listWorktrees methods - Add WorktreeInfo interface for worktree metadata - Always resolve paths to absolute for cross-platform compatibility - Add 20 unit tests covering all worktree operations
- Import TypedEventBus into AutoModeService - Add eventBus property initialized via constructor injection - Remove private emitAutoModeEvent method (now in TypedEventBus) - Update all 66 emitAutoModeEvent calls to use this.eventBus - Constructor accepts optional TypedEventBus for testing
- Create FeatureStateManager class for feature status updates - Extract updateFeatureStatus, markFeatureInterrupted, resetStuckFeatures - Extract updateFeaturePlanSpec, saveFeatureSummary, updateTaskStatus - Persist BEFORE emit pattern for data integrity (Pitfall 2) - Handle corrupted JSON with readJsonWithRecovery backup support - Preserve pipeline_* statuses in markFeatureInterrupted - Fix bug: version increment now checks old content before applying updates - Add 33 unit tests covering all state management operations
…utoModeService - Add WorktreeResolver and FeatureStateManager as constructor parameters - Remove top-level getCurrentBranch function (now in WorktreeResolver) - Delegate loadFeature, updateFeatureStatus to FeatureStateManager - Delegate markFeatureInterrupted, resetStuckFeatures to FeatureStateManager - Delegate updateFeaturePlanSpec, saveFeatureSummary, updateTaskStatus - Replace findExistingWorktreeForBranch calls with worktreeResolver - Update tests to mock featureStateManager instead of internal methods - All 89 tests passing across 3 service files
- Extract plan approval workflow from AutoModeService - Timeout-wrapped Promise creation via waitForApproval() - Resolution handling (approve/reject) with needsRecovery flag - Cancellation support for stopped features - Per-project configurable timeout (default 30 minutes) - Event emission through TypedEventBus for plan_rejected
- 24 tests covering approval, rejection, timeout, cancellation, recovery - Tests use Vitest fake timers for timeout testing - Covers needsRecovery flag for server restart recovery - Covers plan_rejected event emission - Covers configurable timeout from project settings
- Add PlanApprovalService import and constructor parameter - Delegate waitForPlanApproval, cancelPlanApproval, hasPendingApproval - resolvePlanApproval checks needsRecovery flag and calls executeFeature - Remove pendingApprovals Map (now in PlanApprovalService) - Remove PendingApproval interface (moved to plan-approval-service.ts)
- Extract parseTasksFromSpec for parsing tasks from spec content - Extract marker detection functions (task start/complete, phase complete) - Extract detectSpecFallback for non-Claude model support - Extract extractSummary with multi-format support and last-match behavior - Add 65 unit tests covering all functions and edge cases
- Add import for all spec parsing functions from spec-parser.ts - Remove 209 lines of function definitions (now imported) - Functions extracted: parseTasksFromSpec, parseTaskLine, detectTaskStartMarker, detectTaskCompleteMarker, detectPhaseCompleteMarker, detectSpecFallback, extractSummary - All server tests pass (1608 tests)
- Create AgentExecutor class with constructor injection for TypedEventBus, FeatureStateManager, PlanApprovalService, and SettingsService - Extract streaming pipeline from AutoModeService.runAgent() - Implement execute() with stream processing, marker detection, file output - Support recovery path with executePersistedTasks() - Handle spec generation and approval workflow - Multi-agent task execution with progress events - Single-agent continuation fallback - Debounced file writes (500ms) - Heartbeat logging for silent model calls - Abort signal handling throughout execution Key interfaces: - AgentExecutionOptions: All execution parameters - AgentExecutionResult: responseText, specDetected, tasksCompleted, aborted - Callbacks: waitForApproval, saveFeatureSummary, updateFeatureSummary, buildTaskPrompt
- Test constructor injection with all dependencies - Test interface exports (AgentExecutionOptions, AgentExecutionResult) - Test callback type signatures (WaitForApprovalFn, SaveFeatureSummaryFn, etc.) - Test dependency injection patterns with custom implementations - Verify execute method signature Note: Full integration tests for streaming/marker detection require complex mocking of @automaker/utils module which has hoisting issues. Integration testing covered in E2E and auto-mode-service tests.
- Add AgentExecutor import to auto-mode-service.ts - Add agentExecutor as constructor parameter (optional, with default) - Initialize AgentExecutor with TypedEventBus, FeatureStateManager, PlanApprovalService, and SettingsService dependencies This enables constructor injection for testing and prepares for incremental delegation of runAgent() logic to AgentExecutor. The AgentExecutor contains the full execution pipeline; runAgent() delegation will be done incrementally to ensure stability.
- Replace stream processing loop with AgentExecutor.execute() delegation - Build AgentExecutionOptions object from runAgent() parameters - Create callbacks for waitForApproval, saveFeatureSummary, etc. - Remove ~930 lines of duplicated stream processing code - Progress events now flow through AgentExecutor File: auto-mode-service.ts reduced from 5086 to 4157 lines
- Add 11 new test cases for execute() behavior - Test callback invocation (progress events, tool events) - Test error handling (API errors, auth failures) - Test result structure and response accumulation - Test abort signal propagation - Test branchName propagation in event payloads Test file: 388 -> 935 lines (+547 lines)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…-merge - Extract pipeline orchestration logic from AutoModeService - executePipeline: Sequential step execution with context continuity - buildPipelineStepPrompt: Builds prompts with feature context and previous output - detectPipelineStatus: Identifies pipeline status for resumption - resumePipeline/resumeFromStep: Handle excluded steps and missing context - executeTestStep: 5-attempt agent fix loop (REQ-F07) - attemptMerge: Auto-merge with conflict detection (REQ-F05) - buildTestFailureSummary: Concise test failure summary for agent Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Tests for executePipeline: step sequence, events, status updates - Tests for buildPipelineStepPrompt: context inclusion, previous work - Tests for detectPipelineStatus: pipeline status detection and parsing - Tests for resumePipeline/resumeFromStep: excluded steps, slot management - Tests for executeTestStep: 5-attempt fix loop, failure events - Tests for attemptMerge: merge endpoint, conflict detection - Tests for buildTestFailureSummary: output parsing 37 tests covering all core functionality Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add PipelineOrchestrator constructor parameter and property - Initialize PipelineOrchestrator with all required dependencies and callbacks - Delegate executePipelineSteps to pipelineOrchestrator.executePipeline() - Delegate detectPipelineStatus to pipelineOrchestrator.detectPipelineStatus() - Delegate resumePipelineFeature to pipelineOrchestrator.resumePipeline()
- Add AutoModeService integration tests for delegation verification - Test executePipeline delegation with context fields - Test detectPipelineStatus delegation for pipeline/non-pipeline status - Test resumePipeline delegation with autoLoadClaudeMd and useWorktrees - Add edge case tests for abort signals, missing context, deleted steps
- Delete executePipelineSteps method (~115 lines) - Delete buildPipelineStepPrompt method (~38 lines) - Delete resumePipelineFeature method (~88 lines) - Delete resumeFromPipelineStep method (~195 lines) - Delete detectPipelineStatus method (~104 lines) - Remove unused PipelineStatusInfo interface (~18 lines) - Update comments to reference PipelineOrchestrator Total reduction: ~546 lines (4150 -> 3604 lines)
- Extract loop lifecycle from AutoModeService - Export AutoModeConfig, ProjectAutoLoopState, getWorktreeAutoLoopKey - Export callback types for AutoModeService integration - Methods: start/stop/isRunning/getConfig for project/worktree - Failure tracking with threshold and quota error detection - Sleep helper interruptible by abort signal
- 41 tests covering loop lifecycle and failure tracking - Tests for getWorktreeAutoLoopKey key generation - Tests for start/stop/isRunning/getConfig methods - Tests for runAutoLoopForProject loop behavior - Tests for failure tracking threshold and quota errors - Tests for multiple concurrent projects/worktrees - Tests for edge cases (null settings, reset errors)
- Extract executeFeature, stopFeature, buildFeaturePrompt from AutoModeService - Export callback types for test mocking and integration - Implement persist-before-emit pattern for status updates - Support approved plan continuation and context resumption - Track failures and signal pause when threshold reached Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- status.ts: Add facadeFactory parameter for per-project status - context-exists.ts: Add facadeFactory parameter for context checks - running-agents/index.ts: Add facade parameter for getRunningAgents All routes maintain backward compatibility by accepting both autoModeService (legacy) and facade/facadeFactory (new).
- stop-feature.ts: Add facade parameter for feature stopping - stop.ts: Add facadeFactory parameter for auto loop control - verify-feature.ts: Add facadeFactory parameter for verification - commit-feature.ts: Add facadeFactory parameter for committing All routes maintain backward compatibility by accepting both autoModeService (legacy) and facade/facadeFactory (new).
…attern - start.ts: Add facadeFactory parameter, use facade.isAutoLoopRunning/startAutoLoop - resume-feature.ts: Add facadeFactory parameter, use facade.resumeFeature - resume-interrupted.ts: Add facadeFactory parameter, use facade.resumeInterruptedFeatures - All routes maintain backward compatibility with autoModeService fallback
- run-feature.ts: Add facadeFactory parameter, use facade.checkWorktreeCapacity/executeFeature - follow-up-feature.ts: Add facadeFactory parameter, use facade.followUpFeature - approve-plan.ts: Add facadeFactory parameter, use facade.resolvePlanApproval - analyze-project.ts: Add facadeFactory parameter, use facade.analyzeProject - All routes maintain backward compatibility with autoModeService fallback
- features/routes/list.ts: Add facadeFactory parameter, use facade.detectOrphanedFeatures - projects/routes/overview.ts: Add facadeFactory parameter, use facade.getRunningAgents/getStatusForProject - features/index.ts: Pass facadeFactory to list handler - projects/index.ts: Pass facadeFactory to overview handler - auto-mode/index.ts: Accept facadeFactory parameter and wire to all route handlers - All routes maintain backward compatibility with autoModeService fallback
- Delete the 2705-line auto-mode-service.ts monolith - Create AutoModeServiceCompat as compatibility layer for routes - Create GlobalAutoModeService for cross-project operations - Update all routes to use AutoModeServiceCompat type - Add SharedServices interface for state sharing across facades - Add getActiveProjects/getActiveWorktrees to AutoLoopCoordinator - Delete obsolete monolith test files Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- agent-executor.ts: 1317 -> 283 lines (merged duplicate task loops) - execution-service.ts: 675 -> 314 lines (extracted callback types) - pipeline-orchestrator.ts: 662 -> 471 lines (condensed methods) - auto-loop-coordinator.ts: 590 -> 277 lines (condensed type definitions) - recovery-service.ts: 558 -> 163 lines (simplified state methods) Created execution-types.ts for callback type definitions. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…rchestrator - Create agent-executor-types.ts with execution option/result/callback types - Create pipeline-types.ts with context/status/result types - Condense agent-executor.ts stream processing and add buildExecOpts helper - Condense pipeline-orchestrator.ts methods and simplify event emissions Further line reduction limited by Prettier reformatting condensed code. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…y URL - Updated lint-staged dependency to use caret versioning (^16.2.7) in package.json and package-lock.json. - Changed the resolved URL for node-gyp in package-lock.json from HTTPS to SSH.
The facade had stubs for runAgentFn that threw errors, causing feature execution to fail with "runAgentFn not implemented in facade". This fix wires both ExecutionService and PipelineOrchestrator runAgentFn callbacks to properly call AgentExecutor.execute() with: - Provider from ProviderFactory.getProviderForModel() - Bare model from stripProviderPrefix() - Proper AgentExecutorCallbacks for waitForApproval, saveFeatureSummary, etc. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The wrench emoji (🔧) was accidentally removed in commit 6ec9a25 during the service condensing refactor. This broke: 1. Log parser - uses startsWith('🔧') to detect tool calls, causing them to be categorized as "info" instead of "tool_call" 2. Agent context parser - uses '🔧 Tool: TodoWrite' marker to find tasks, causing task list to not appear on kanban cards This fix restores the emoji to fix both issues. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The PipelineOrchestrator passes previousContent to preserve the agent output history when running pipeline steps. This was being lost because the facade's runAgentFn callback wasn't forwarding it to AgentExecutor. Without this fix, pipeline steps would overwrite the agent-output.md file instead of appending to it with a "Follow-up Session" separator. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- agent-executor: move executeQuery into try block for proper heartbeat cleanup, re-parse tasks when edited plan is approved - auto-loop-coordinator: handle feature execution failures with proper logging and failure tracking, support backward-compatible method signatures - facade: delegate getActiveAutoLoopProjects/Worktrees to coordinator, always create own AutoLoopCoordinator (not shared), pass projectPath to approval methods and branchName to failure tracking - global-service: document shared autoLoopCoordinator is for monitoring only - execution-types: fix ExecuteFeatureFn type to match implementation - feature-state-manager: use readJsonWithRecovery for loadFeature - pipeline-orchestrator: add defensive null check and try/catch for merge response parsing - plan-approval-service: use project-scoped keys to prevent cross-project collisions, maintain backward compatibility for featureId-only lookups Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…ss-platform tests - Extract merge logic from pipeline-orchestrator to merge-service.ts to avoid HTTP self-call - Make agent-executor error handling provider-agnostic using shared isAuthenticationError utility - Fix cross-platform path handling in tests using path.normalize/path.resolve helpers - Add catch handlers in plan-approval-service tests to prevent unhandled promise rejection warnings Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Added caching for facades in AutoModeServiceCompat to persist auto loop state across API calls. - Improved error handling in BoardView for starting and stopping auto mode, with user-friendly toast notifications. - Updated WorktreePanel to manage auto mode state and concurrency limits more effectively. - Enhanced useAutoMode hook to prevent state overwrites during transitions and synchronize UI with backend status. This update optimizes performance and user experience in the auto mode feature.
… feature retrieval - Updated getStatusForProject method in AutoModeServiceCompat and its facade to be asynchronous, allowing for better handling of feature status retrieval. - Modified related status handlers in the server routes to await the updated method. - Introduced a new method, getRunningFeaturesForWorktree, in ConcurrencyManager to improve feature ID retrieval based on branch normalization. - Adjusted BoardView component to ensure consistent handling of running auto tasks across worktrees. These changes improve the responsiveness and accuracy of the auto mode feature in the application.
…obal service - Replaced synchronous feature retrieval with asynchronous logic in both AutoModeServiceFacade and GlobalAutoModeService. - Updated filtering logic to resolve the primary branch name for main worktrees, improving accuracy in feature status checks. - This change enhances the responsiveness and correctness of feature handling in auto mode operations.
…mode-service-gsxdsm
- Added error handling for feature creation in BoardView component to log errors and display user-friendly messages. - Updated persistFeatureCreate function to throw errors on failure, allowing for better state management. - Introduced removal of features from state if server creation fails, improving user experience during conflicts. Also added @playwright/test to devDependencies in package-lock.json for improved testing capabilities.
- Enhanced the Kanban card component to support additional feature statuses ('interrupted' and 'ready') in the backlog display logic.
- Updated relevant components to reflect these changes, ensuring consistent behavior across the UI.
|
Caution Review failedFailed to post review comments 📝 WalkthroughWalkthroughComprehensive refactor restructuring the auto-mode service architecture from a monolithic design to a modular, facade-based system with centralized global management and per-project facades. Introduces supporting services for concurrency, execution, pipeline orchestration, plan approval, and recovery. Upgrades Claude to Opus 4.6 with adaptive thinking support. Adds extensive planning documentation, Playwright E2E testing infrastructure, and comprehensive unit tests. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello @gsxdsm, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request delivers a significant architectural overhaul by decomposing the core Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This is an excellent and extensive refactoring of the monolithic AutoModeService. Breaking it down into smaller, focused services like ConcurrencyManager, ExecutionService, and RecoveryService is a huge step forward for maintainability and testability. The use of a compatibility layer to ensure a smooth transition is a great approach.
I'm also impressed with the number of bug fixes and UX improvements included, such as the correct handling of custom provider model IDs, more robust UI state syncing, and the ability to stop a running feature by dragging it to the backlog. The new planning and architecture documents are a fantastic addition.
I've found one very minor issue in the .gitignore file, but overall this is a high-quality pull request that significantly improves the codebase's architecture.
See: #733
Bug fixes and improvements from @Shironex awesome refactor of AutoModeService
Summary by CodeRabbit
Release Notes
New Features
Improvements