[Phase 6.7] Scheduler #76

Closed
opened 2026-04-02 20:54:42 +00:00 by Mark · 1 comment
Owner

Overview

Cron-like scheduling for recurring intents and delayed execution.

Problem Statement

Current mesh only processes intents when submitted. Cannot:

  • Schedule recurring tasks (daily reports, weekly summaries)
  • Delay execution (process overnight, off-peak)
  • Set reminders and follow-ups
  • Automate periodic maintenance

Proposed Solution

6.7.1: Schedule Table

CREATE TABLE scheduled_intents (
    schedule_id TEXT PRIMARY KEY,
    intent_type TEXT,
    payload JSON,
    schedule TEXT,  -- Cron expression or interval
    next_run TIMESTAMP,
    last_run TIMESTAMP,
    enabled BOOLEAN,
    project TEXT,
    created_at TIMESTAMP
);

6.7.2: Scheduler Service

class IntentScheduler:
    """Schedule and execute recurring intents."""
    
    def schedule(self, intent: dict, schedule: str) -> ScheduleID:
        """Schedule intent with cron expression"""
        
    def schedule_delayed(self, intent: dict, delay_seconds: int) -> ScheduleID:
        """Execute intent after delay"""
        
    def cancel(self, schedule_id: str):
        """Cancel scheduled intent"""
        
    def get_next_run(self, schedule_id: str) -> datetime:
        """Get next execution time"""
        
    def tick(self):
        """Check for due intents, execute them"""

6.7.3: Cron Expressions

# Examples
schedules:
  daily_report: "0 9 * * *"  # Every day at 9am
  weekly_summary: "0 10 * * 1"  # Every Monday at 10am
  hourly_check: "0 * * * *"  # Every hour
  custom: "*/15 * * * *"  # Every 15 minutes
  
# Or simple intervals:
intervals:
  every_5_min: "interval:300"  # Every 5 minutes
  every_hour: "interval:3600"

6.7.4: API Endpoints

endpoints:
  POST /v1/schedules:
    body: {intent_type, payload, schedule}
    returns: {schedule_id, next_run}
    
  GET /v1/schedules:
    returns: List of scheduled intents
    
  GET /v1/schedules/<id>:
    returns: Schedule details
    
  DELETE /v1/schedules/<id>:
    returns: {cancelled: true}
    
  POST /v1/schedules/<id>/pause:
    returns: {paused: true}
    
  POST /v1/schedules/<id>/resume:
    returns: {resumed: true, next_run}

Deliverables

  • scheduled_intents table in ledger
  • runtime/scheduler.py - Scheduler service
  • Cron expression parsing
  • Background tick loop (or external cron trigger)
  • API endpoints: /v1/schedules/*
  • Unit tests
  • Integration tests

Dependencies

  • None (standalone)

Estimated Duration

1 week

Success Criteria

  • Intents scheduled with cron expressions
  • Scheduled intents execute on time
  • Can pause/resume schedules
  • Can list and cancel schedules
  • Parent: #69 (Phase 6 Meta)
## Overview Cron-like scheduling for recurring intents and delayed execution. ## Problem Statement Current mesh only processes intents when submitted. Cannot: - Schedule recurring tasks (daily reports, weekly summaries) - Delay execution (process overnight, off-peak) - Set reminders and follow-ups - Automate periodic maintenance ## Proposed Solution ### 6.7.1: Schedule Table ```sql CREATE TABLE scheduled_intents ( schedule_id TEXT PRIMARY KEY, intent_type TEXT, payload JSON, schedule TEXT, -- Cron expression or interval next_run TIMESTAMP, last_run TIMESTAMP, enabled BOOLEAN, project TEXT, created_at TIMESTAMP ); ``` ### 6.7.2: Scheduler Service ```python class IntentScheduler: """Schedule and execute recurring intents.""" def schedule(self, intent: dict, schedule: str) -> ScheduleID: """Schedule intent with cron expression""" def schedule_delayed(self, intent: dict, delay_seconds: int) -> ScheduleID: """Execute intent after delay""" def cancel(self, schedule_id: str): """Cancel scheduled intent""" def get_next_run(self, schedule_id: str) -> datetime: """Get next execution time""" def tick(self): """Check for due intents, execute them""" ``` ### 6.7.3: Cron Expressions ```yaml # Examples schedules: daily_report: "0 9 * * *" # Every day at 9am weekly_summary: "0 10 * * 1" # Every Monday at 10am hourly_check: "0 * * * *" # Every hour custom: "*/15 * * * *" # Every 15 minutes # Or simple intervals: intervals: every_5_min: "interval:300" # Every 5 minutes every_hour: "interval:3600" ``` ### 6.7.4: API Endpoints ```yaml endpoints: POST /v1/schedules: body: {intent_type, payload, schedule} returns: {schedule_id, next_run} GET /v1/schedules: returns: List of scheduled intents GET /v1/schedules/<id>: returns: Schedule details DELETE /v1/schedules/<id>: returns: {cancelled: true} POST /v1/schedules/<id>/pause: returns: {paused: true} POST /v1/schedules/<id>/resume: returns: {resumed: true, next_run} ``` ## Deliverables - [ ] `scheduled_intents` table in ledger - [ ] `runtime/scheduler.py` - Scheduler service - [ ] Cron expression parsing - [ ] Background tick loop (or external cron trigger) - [ ] API endpoints: `/v1/schedules/*` - [ ] Unit tests - [ ] Integration tests ## Dependencies - None (standalone) ## Estimated Duration 1 week ## Success Criteria - [ ] Intents scheduled with cron expressions - [ ] Scheduled intents execute on time - [ ] Can pause/resume schedules - [ ] Can list and cancel schedules ## Related - Parent: #69 (Phase 6 Meta)
Author
Owner

Implemented and committed on main at f867983.

Deliverables:

  • scheduled_intents table in ledger (schema.py + core.py + models.py)
  • runtime/scheduler.py — IntentScheduler with schedule/schedule_delayed/cancel/tick/pause/resume/list
  • Cron expression parsing with compute_next_run (named aliases, step/range/list fields, interval: support)
  • Background tick loop via start() daemon thread
  • API endpoints: POST/GET /v1/schedules, GET/DELETE /v1/schedules/, POST */pause and */resume
  • Unit tests: tests/unit/test_cron_parser.py (186 lines)

Closing as completed.

Implemented and committed on `main` at f867983. Deliverables: - `scheduled_intents` table in ledger (schema.py + core.py + models.py) - `runtime/scheduler.py` — IntentScheduler with schedule/schedule_delayed/cancel/tick/pause/resume/list - Cron expression parsing with compute_next_run (named aliases, step/range/list fields, interval: support) - Background tick loop via start() daemon thread - API endpoints: POST/GET /v1/schedules, GET/DELETE /v1/schedules/<id>, POST */pause and */resume - Unit tests: tests/unit/test_cron_parser.py (186 lines) Closing as completed.
Mark closed this issue 2026-07-16 14:27:59 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Mark/mesh-seed#76
No description provided.