Skip to content

feat(scheduler): retry mechanism for failed scheduled executions #271

Closed

Description

@vybe

Summary

Add a configurable retry mechanism for scheduled executions that fail. When a scheduled task fails (timeout, agent error, rate limit), automatically retry it after a configurable delay.

Default: 1 retry, ON by default — most failures are transient (agent not ready, 429 rate limits, brief network issues). Users who set up schedules expect resilience without needing to discover a retry toggle.

Schema Changes

agent_schedules — 2 new columns

max_retries INTEGER DEFAULT 1,          -- 0 = no retry, 1-5 range
retry_delay_seconds INTEGER DEFAULT 60   -- seconds between retries (30-600)

schedule_executions — 2 new columns

attempt_number INTEGER DEFAULT 1,        -- which attempt this is (1 = first try)
retry_of_execution_id TEXT,              -- links retry to original execution

Execution Flow

Cron fires → Execute → Failed?
  ├─ No  → Done (status=success)
  └─ Yes → attempt_number < max_retries + 1?
       ├─ No  → Done (status=failed, final)
       └─ Yes → Schedule delayed retry (retry_delay_seconds)
                → New execution record with:
                    attempt_number = previous + 1
                    retry_of_execution_id = original execution id
                    triggered_by = "retry"

Design Decisions

Decision Choice Rationale
Default retries 1 (ON) Most failures are transient; autonomous agents should be resilient by default
Retry = new execution record Yes Full observability — each attempt has own logs, cost, duration
Link retries retry_of_execution_id → first attempt UI can group attempts together
Delay mechanism APScheduler date trigger Survives scheduler restart (vs asyncio.sleep)
Which failures retry All except skipped and cancelled Skipped = capacity issue. Cancelled = intentional.
Rate limit (429) Retry with 2x delay Already detected in task_execution_service
Max retries cap Hard cap at 5 Prevents misconfiguration
Delay range 30–600 seconds Too short = same issue. Too long = defeats purpose.

Implementation Scope

Backend

  • Migration: 4 new columns across 2 tables
  • db/schedules.py: new fields in create/update/query operations
  • models.py: new fields in schedule and execution request/response models
  • Scheduler service: retry scheduling logic after execution failure (~50 lines)
  • New triggered_by value: "retry"

MCP Server

  • schedules.ts: max_retries and retry_delay_seconds params on create/update tools

Frontend

  • Schedule form: "Retries" section — max_retries (0-5 dropdown), delay (seconds input)
  • Execution history: attempt number badge (e.g., "Attempt 2/2"), link to related attempts
  • Execution detail: "Retry of: [link to original]" when applicable

Acceptance Criteria

  • Failed scheduled executions auto-retry up to max_retries times with retry_delay_seconds delay
  • Each retry is a separate execution record linked to the original via retry_of_execution_id
  • Default for new schedules: 1 retry, 60s delay
  • Existing schedules get default values via migration (1 retry, 60s delay)
  • skipped and cancelled executions are NOT retried
  • Rate-limited (429) retries use 2x the configured delay
  • UI shows attempt number and links between retry attempts
  • MCP tools support retry configuration
  • Retry survives scheduler restart (uses APScheduler date trigger, not asyncio.sleep)

Activity

  1. added
    enhancement
    priority-p2
    status-in-progress
    on Apr 6, 2026
  2. removed
    status-in-progress
    on Apr 17, 2026
  3. added
    complexity-medium
    on Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity-mediumenhancementpriority-p2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions