Skip to content

Add automation scheduler service#837

Closed
gsxdsm wants to merge 2 commits intoAutoMaker-Org:v1.1.0rcfrom
gsxdsm:feature/automation
Closed

Add automation scheduler service#837
gsxdsm wants to merge 2 commits intoAutoMaker-Org:v1.1.0rcfrom
gsxdsm:feature/automation

Conversation

@gsxdsm
Copy link
Collaborator

@gsxdsm gsxdsm commented Mar 6, 2026

Summary

  • Implement automation scheduler service with runtime engine for executing automated workflows
  • Add E2E test sharding support to enable parallel test execution
  • Integrate automation routes and auto-mode operations for feature automation
  • Improve logging for high-frequency events to reduce memory growth

Changes

  • Automation System:
    • Add AutomationRuntimeEngine and AutomationSchedulerService for executing automated workflows
    • Create automation routes at /api/automation with null-check middleware to ensure scheduler is initialized
    • Pass settingsService to runtime engine to support AI prompt steps with Claude API credentials
    • Integrate auto-mode operations (start, stop, getStatus, setConcurrency) with automation scheduler
    • Add AutomationVariableService for managing automation variable scoping

Summary by CodeRabbit

  • New Features

    • Added comprehensive automation runtime with AI-powered generation and refinement.
    • Introduced automation scheduling (cron, date-based, webhooks, and event triggers).
    • Added variable management system for automations with system, project, workflow, and step scopes.
    • Implemented file watching for automation definition changes.
    • Added built-in automation actions: git operations, HTTP calls, script execution, TypeScript code, and AI prompts.
    • Introduced auto-mode concurrency control.
  • Bug Fixes

    • Enhanced error reporting in Claude provider with stderr capture.
    • Improved error handling in query service for execution and budget-related errors.
    • Better error responses in automation routes with consistent error messaging.
  • Chores

    • Added dependencies: archiver and chokidar.
    • Expanded test coverage for automation features.

@gsxdsm gsxdsm changed the title Add automation scheduler service and E2E test sharding Add automation scheduler service Mar 6, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 6, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This pull request introduces a comprehensive automation system with a runtime engine, scheduler service, step registry, definition store, and extensive set of built-in automation actions (feature management, AI interaction, code execution, HTTP calls, Git operations, control flow). It includes new API routes for generation, management, scheduling, and webhook triggers, plus UI components for AI-driven automation creation and visual step editing.

Changes

Cohort / File(s) Summary
Automation Core Runtime
apps/server/src/services/automation-runtime-engine.ts, apps/server/src/services/automation-scheduler-service.ts, apps/server/src/services/automation-file-watcher.ts, apps/server/src/services/automation-variable-service.ts
Introduces foundational automation infrastructure: runtime engine with step registry and definition store for execution and persistence; scheduler service for managing multiple trigger types (cron, date, webhook, event, manual) and state persistence; file watcher for on-disk automation changes; variable service for system/project/workflow scoping and resolution.
Automation Step Implementations
apps/server/src/services/automation-builtins.ts
Registers comprehensive built-in automation step executors: feature management, AI prompts, TypeScript/script execution, HTTP endpoints, file I/O, Git operations (branch, commit, push, pull, checkout), variable definition, event emission, control flow (if, loop), automation orchestration, and auto-mode management with extensive input validation and error handling.
Automation API Routes
apps/server/src/routes/automation/index.ts, apps/server/src/routes/automation/common.ts, apps/server/src/routes/automation/routes/generate.ts, apps/server/src/routes/automation/routes/manage.ts, apps/server/src/routes/automation/routes/schedule.ts, apps/server/src/routes/automation/routes/webhook.ts, apps/server/src/routes/automation/routes/runs.ts, apps/server/src/routes/automation/routes/trigger.ts, apps/server/src/routes/automation/routes/variables.ts, apps/server/src/routes/automation/routes/get.ts, apps/server/src/routes/automation/routes/list.ts
Exposes REST API for automation management: AI-powered generation and refinement; full CRUD operations with scope/project handling; webhook-triggered execution with rate limiting and token validation; scheduled run management; variable CRUD; export/import with ZIP support; listing and retrieval by ID; manual triggering with metadata.
Automation Auto-Mode Integration
apps/server/src/routes/auto-mode/routes/start.ts, apps/server/src/routes/auto-mode/routes/reconcile.ts, apps/server/src/routes/auto-mode/routes/resume-interrupted.ts
Enhances auto-mode routes with input validation (maxConcurrency bounds checking), improved error handling via shared utility functions (getErrorMessage, logError), and consistent response formatting.
Server Initialization & Integration
apps/server/src/index.ts, apps/server/src/services/concurrency-manager.ts, apps/server/src/services/auto-loop-coordinator.ts
Wires automation components into server startup: imports and initializes runtime engine, scheduler, variable service; mounts automation routes with 503 guard; extends graceful shutdown to include scheduler; adds getCurrentBranchForProject accessor to concurrency manager; updates branch-worktree logic to resolve primary branch dynamically instead of hard-coded fallback.
Existing Service Updates
apps/server/src/services/auto-mode/facade.ts, apps/server/src/services/execution-service.ts, apps/server/src/services/feature-state-manager.ts, apps/server/src/providers/claude-provider.ts, apps/server/src/providers/simple-query-service.ts
Updates existing services for automation compatibility: adds updateFeatureFields to persist imagePaths; emits completion events before final status update in execution pipeline; captures and propagates stderr from Claude subprocess for debugging; adds error handling for execution errors and budget limits in query service.
UI Automation Components
apps/ui/src/components/automation/ai-automation-generator.tsx, apps/ui/src/components/automation/nested-step-list.tsx, apps/ui/src/components/automation/step-config-dialog.tsx
Introduces React components for automation creation and editing: AI-powered generation dialog with iterative refinement chat; visual step list editor with add/reorder/remove operations; step configuration dialog with dynamic per-type editors; integrates variable/automation context and UI registry.
Integration Tests
apps/server/tests/integration/services/automation-runtime-builtins.integration.test.ts, apps/server/tests/integration/services/automation-scheduler-triggers.integration.test.ts, apps/server/tests/integration/routes/automation/manage.integration.test.ts, apps/server/tests/integration/services/automation-variable-service.integration.test.ts
Comprehensive integration test coverage: verifies HTTP/script/TypeScript builtins with live servers; tests scheduler across manual/webhook/event/cron triggers with state persistence and recovery; exercises full automation lifecycle (create/list/update/export/import/delete); validates variable scoping and filesystem persistence.
Unit Tests
apps/server/tests/unit/services/automation-*.test.ts, apps/server/tests/unit/routes/automation-*.test.ts, apps/server/tests/unit/lib/automation-step-types.test.ts
Extensive unit test suite: validates parsing, registry, runtime engine execution, scheduler state/persistence, variable service resolution, all API routes, and step type definitions; tests error paths, edge cases, and control flow across automation subsystem.
Test Utilities & Helpers
apps/server/tests/utils/helpers.ts, apps/ui/src/components/automation/nested-step-list.test.ts, apps/ui/src/components/automation/step-editors.test.ts, apps/server/tests/unit/gemini-hello.test.ts, apps/ui/.auth/admin.json
Adds test infrastructure: HTTP server utilities for integration tests; step editor test helpers for UI logic validation; placeholder Gemini test; admin session cookie for UI testing.
Configuration & Dependencies
apps/server/package.json
Adds archiver (ZIP export) and chokidar (file watching) dependencies to support automation management features.

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Possibly related PRs

Suggested labels

Testers-Requested, Enhancement, Feature


🐰 Hop, hop, automation thrives!
With steps and schedules, workflows come alive,
From AI prompts to Git commands so fine,
A rabbit's delight—let the tasks align! 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.81% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add automation scheduler service' directly corresponds to the main change of implementing the AutomationSchedulerService, which is the primary focus of this large PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 introduces a comprehensive automation scheduler service to the system, enhancing its ability to execute automated workflows and manage resources more efficiently. It also incorporates improvements to error handling and logging, contributing to a more robust and maintainable system.

Highlights

  • Automation Scheduler Service: Implemented an automation scheduler service with a runtime engine for executing automated workflows.
  • E2E Test Sharding: Added E2E test sharding support to enable parallel test execution, improving testing efficiency.
  • Automation Routes: Integrated automation routes at /api/automation with null-check middleware to ensure the scheduler is initialized before use.
  • Logging Improvements: Improved logging for high-frequency events to reduce memory growth, enhancing system stability.

🧠 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
  • apps/server/package.json
    • Added 'archiver' and 'chokidar' as new dependencies.
  • apps/server/src/index.ts
    • Integrated automation routes and auto-mode operations with the automation scheduler.
    • Initialized and shutdown the automation scheduler service.
    • Added null check middleware for automation routes.
  • apps/server/src/providers/claude-provider.ts
    • Captured stderr output from the Claude Code subprocess for diagnostics, enhancing error reporting.
  • apps/server/src/providers/simple-query-service.ts
    • Added error handling for 'error_during_execution' and 'error_max_budget_usd' message subtypes.
  • apps/server/src/routes/auto-mode/routes/reconcile.ts
    • Improved error handling and response formatting for reconcile feature states.
  • apps/server/src/routes/auto-mode/routes/resume-interrupted.ts
    • Improved error handling and response formatting for resuming interrupted features.
  • apps/server/src/routes/auto-mode/routes/start.ts
    • Added validation for the maxConcurrency parameter to ensure it is a positive integer.
  • apps/server/src/routes/automation/common.ts
    • Added shared utilities for automation routes, including functions to extract project path and scope from requests, and to normalize route error responses.
  • apps/server/src/routes/automation/index.ts
    • Implemented automation routes for managing automations, triggering automations, managing scheduled runs and variables, and importing/exporting automations.
  • apps/server/src/routes/automation/routes/generate.ts
    • Implemented AI-powered automation generation routes for generating and refining automation definitions from natural language.
  • apps/server/src/routes/automation/routes/get.ts
    • Implemented route to get automation by ID.
  • apps/server/src/routes/automation/routes/list.ts
    • Implemented route to list automations with scope/projectPath filter.
  • apps/server/src/routes/automation/routes/manage.ts
    • Implemented routes for automation management: create, update, enable/disable, delete, import, export, duplicate.
  • apps/server/src/routes/automation/routes/runs.ts
    • Implemented routes for automation runs management: list runs, get specific run, clear all runs.
  • apps/server/src/routes/automation/routes/schedule.ts
    • Implemented routes for scheduled runs management: list scheduled runs, get upcoming scheduled runs, get specific scheduled run, cancel a scheduled run.
  • apps/server/src/routes/automation/routes/trigger.ts
    • Implemented route to manually trigger automation.
  • apps/server/src/routes/automation/routes/variables.ts
    • Implemented routes for automation variable management: list available variables, get/set/delete project variables.
  • apps/server/src/routes/automation/routes/webhook.ts
    • Implemented route to trigger automation via webhook.
  • apps/server/src/services/auto-loop-coordinator.ts
    • Modified featureBelongsToWorktree to correctly match features to the main worktree based on the primary branch name.
    • Resolved primary branch for correct matching when branchName is null.
  • apps/server/src/services/auto-mode/facade.ts
    • Persisted image paths to disk so executeFeature can pick them up.
    • Increased maxBuffer size for execAsync to handle large test outputs.
    • Loaded feature once and reuse for both worktree resolution and commit message.
  • apps/server/src/services/automation-builtins.ts
    • Added built-in automation steps for various tasks including feature management, AI prompts, script execution, event emission, file writing, git operations, and auto-mode control.
    • Implemented safety measures for script execution, including command sanitization and blocking of dangerous operations.
    • Added support for retrying transient Claude CLI failures to improve reliability.
  • apps/server/src/services/automation-file-watcher.ts
    • Implemented file watching service for automation definitions, detecting changes and syncing them to the running server.
  • apps/server/src/services/automation-runtime-engine.ts
    • Implemented automation runtime engine for loading, parsing, and executing automation definitions.
    • Added support for variable resolution with system/project/workflow/steps scopes.
    • Implemented step-type registry for extensible step types.
  • apps/server/src/services/automation-scheduler-service.ts
    • Implemented automation scheduler service for managing trigger execution, including schedule, webhook, event, and manual triggers.
    • Added state persistence for server restart survival.
  • apps/server/src/services/automation-variable-service.ts
    • Implemented automation variable service for managing variables across system, project, and workflow scopes.
Activity
  • Implemented automation scheduler service with runtime engine for executing automated workflows
  • Added E2E test sharding support to enable parallel test execution
  • Integrated automation routes and auto-mode operations for feature automation
  • Improved logging for high-frequency events to reduce memory growth
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive automation system, including a runtime engine, scheduler, and a wide array of built-in steps. This is a significant and well-structured feature addition. My review focuses on potential issues related to security, scalability, and long-term reliability. I've identified a critical security issue with a committed session file, a high-severity concern with the custom cron parser, and several medium-severity suggestions regarding in-memory state management and leftover debug code. Overall, the implementation is impressive, and addressing these points will further enhance its robustness.

Note: Security Review did not run due to the size of the PR.

Comment on lines +1 to +15
{
"cookies": [
{
"name": "automaker_session",
"value": "48b2fd3c98872c37e7d1445d13dfa9ba688d58f3e4212580611877b8efa2d586",
"domain": "localhost",
"path": "/",
"expires": 9999999999,
"httpOnly": true,
"secure": false,
"sameSite": "Lax"
}
],
"origins": []
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This file contains sensitive session information and should not be committed to the repository. Committing secrets, API keys, or session tokens is a critical security risk. Please remove this file from the commit history and add *.auth.json or a more specific pattern to your .gitignore file to prevent this from happening in the future.

Comment on lines +462 to +500
private parseCronAndGetNext(cronExpr: string, _timezone?: string): Date | null {
const parts = cronExpr.trim().split(/\s+/);
if (parts.length !== 5) {
throw new Error(`Invalid cron expression: expected 5 fields, got ${parts.length}`);
}

const [minute, hour, dayOfMonth, month, dayOfWeek] = parts;
this.validateCronField(minute, 0, 59, 'minute');
this.validateCronField(hour, 0, 23, 'hour');
this.validateCronField(dayOfMonth, 1, 31, 'day-of-month');
this.validateCronField(month, 1, 12, 'month');
this.validateCronField(dayOfWeek, 0, 6, 'day-of-week');

// Start from the next whole minute (≥ now + 1s) to avoid firing immediately.
// We advance by 1 minute and zero out sub-minute components so the first
// candidate is exactly at the next minute boundary.
const now = new Date();
let candidate = new Date(now.getTime() + ONE_MINUTE_MS);
candidate.setSeconds(0, 0);

// Search for next matching time (up to 1 year ahead)
for (let i = 0; i < MAX_CRON_LOOKAHEAD_MINUTES; i++) {
if (
this.cronFieldMatches(minute, candidate.getMinutes(), 0, 59) &&
this.cronFieldMatches(hour, candidate.getHours(), 0, 23) &&
this.cronFieldMatches(dayOfMonth, candidate.getDate(), 1, 31) &&
this.cronFieldMatches(month, candidate.getMonth() + 1, 1, 12) &&
this.cronFieldMatches(dayOfWeek, candidate.getDay(), 0, 6)
) {
return candidate;
}

// Advance by 1 minute
candidate.setMinutes(candidate.getMinutes() + 1);
}

logger.warn(`Could not find next run time for cron: ${cronExpr}`);
return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The custom cron parser implementation is a potential source of bugs and may not support the full standard cron syntax that users might expect (e.g., features like L, W, #). Maintaining a custom cron parser is complex and error-prone.

It is highly recommended to replace this with a well-established and thoroughly tested library like cron-parser or node-cron. This will improve reliability, maintainability, and feature completeness.

Comment on lines +1 to +3
2026-03-01T20:55:55.690Z

[object Object]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This file appears to have been accidentally committed. It contains [object Object], which often indicates an object was incorrectly stringified during development. This file should be removed from the pull request.

// Start server with error handling for port conflicts
const startServer = (port: number, host: string) => {
server.listen(port, host, () => {
logger.info('Gemini test - Hello World');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This appears to be a temporary debug log statement. It should be removed before merging to avoid cluttering production logs.

/** Rate limiting configuration */
const RATE_LIMIT_WINDOW_MS = 60_000; // 1 minute
const RATE_LIMIT_MAX_REQUESTS = 60; // requests per window per IP
const rateLimitStore = new Map<string, { count: number; resetAt: number }>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The rate limiting for webhooks is implemented in-memory. This has two main drawbacks:

  1. The rate limit state is lost on every server restart.
  2. It won't work correctly in a load-balanced environment with multiple server instances, as each instance would have its own separate rate limit counter.

For a more robust and scalable solution, consider using an external store like Redis to manage rate limit data.

Comment on lines +714 to +719
private readonly runStore = new Map<string, AutomationRun>();
/** Ordered map of run IDs to sequence numbers (most-recent first). Uses monotonic counter to avoid Date.now() collisions. */
private readonly runOrder = new Map<string, number>();
/** Monotonic counter for deterministic ordering of runs tracked within the same millisecond. */
private runSequence = 0;
private readonly maxStoredRuns = 200;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The automation run history is stored in-memory. This means that all execution history will be lost whenever the server restarts. For a system that tracks automation executions, this data is often valuable for auditing, debugging, and understanding system behavior over time.

Consider persisting the run history to a more durable storage, such as a database or even a file-based log store, to ensure it survives restarts.

@gsxdsm gsxdsm closed this Mar 6, 2026
@gsxdsm gsxdsm deleted the feature/automation branch March 6, 2026 05:31
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