feat: add cron workflow trigger and workflow runs table#385
Conversation
- Add CronWorkflowTrigger type with schedule, timezone, overlap_policy, timeout - Add WorkflowRun type for execution history tracking - Add workflow_runs DB table with indexes - Validate cron triggers in workflow validation (exactly one trigger source) - Support overlap policies: skip, queue, parallel
|
Reviews (1): Last reviewed commit: "feat: add cron workflow trigger and work..." | Re-trigger Greptile |
- Fix workflow_normalize.go syntax error (extra closing brace) - Fix cron_scheduler.go to use pointer iteration over ws.Workflows - Fix cron_scheduler.go to use cs.cron.Schedule() correctly (returns EntryID only) - Remove unused context import from cron_scheduler.go - Remove unused types import from cron_api.go - Wire cron scheduler start/stop into server lifecycle
- ws.Workflows is []*WorkflowConfig, so iteration by value gives *WorkflowConfig - Remove incorrect &ws.Workflows[i] which created **WorkflowConfig - Same fix for both reloadWorkflows() and manualTrigger()
|
|
Reviews (3): Last reviewed commit: "fix: update cron test to expect timezone..." | Re-trigger Greptile |
- go mod tidy promoted robfig/cron from indirect to direct - Removed stale testcontainers dependencies no longer used in codebase
|
Reviews (4): Last reviewed commit: "fix: run go mod tidy to make robfig/cron..." | Re-trigger Greptile |
- Fix RunContext scan: scan into string then json.Unmarshal into map[string]interface{}
- Add finishRunByClawID to mark runs completed/failed/canceled by claw ID
- Wire finishRunByClawID into all claw terminal status paths:
* idle (handleClawDoneSignal) -> completed
* manual kill (server.go) -> canceled
* error (stopAgentWithReason) -> failed
* issue left trigger (github_issues.go, linear.go) -> canceled
* PR merged (pr_watcher.go) -> completed
* pipeline terminal (pipeline_runner.go) -> completed
* factory trigger failures (github_issues, linear, shortcut, external) -> failed
* factory trigger reclaimed (factory_triggers.go) -> canceled
|
Reviews (5): Last reviewed commit: "fix: address Greptile review comments on..." | Re-trigger Greptile |
- recordRun now accepts runID as first parameter instead of generating a new one - Fixes updateRun always matching zero rows because runID was never in DB - Fixes error path leaving 'running' row stuck forever while inserting new 'failed' row - Skipped runs still generate their own runID (no updateRun needed for them)
|
- Add cronTriggerNotFoundError type for 'not found' / 'not cron-triggered' cases - manualTrigger returns typed error for 404 cases, plain error for DB failures - API handler returns 404 for not-found, 500 for infrastructure errors
|
Reviews (7): Last reviewed commit: "fix: distinguish 404 vs 500 errors in ma..." | Re-trigger Greptile |
- Change running map from bool to int (counter) - Increment counter when run starts, decrement when it finishes - Check > 0 instead of true for active runs - Prevents parallel run defer from corrupting tracker when another run is still active
|
Reviews (8): Last reviewed commit: "fix: use reference counter for running m..." | Re-trigger Greptile |
Addresses Greptile review comment: the error path was calling recordRun again with the same runID, which caused a primary key conflict and left the run stuck in 'running' status forever. Now uses failRun() which UPDATEs the existing row with status='failed', result message, and finished_at timestamp.
|
Reviews (9): Last reviewed commit: "fix: use failRun instead of recordRun on..." | Re-trigger Greptile |
The running counter was decremented immediately after claw creation, making skip/queue overlap policies ineffective since the claw was still running when the next cron firing occurred. Now the counter stays elevated until finishRunByClawID is called when the claw reaches a terminal status (idle, deleted, error). A clawWorkflow map tracks clawID -> workflow key for this purpose. Addresses Greptile review comment about overlap enforcement being a no-op.
|
Reviews (10): Last reviewed commit: "merge: resolve conflicts with main" | Re-trigger Greptile |
…olicy runWorkflow now returns a bool indicating whether a run was actually started. When overlap policy causes a skip, manualTrigger returns a cronTriggerSkippedError which the API handler translates to HTTP 409 Conflict instead of 200 OK. Addresses Greptile review comment about manualTrigger silently returning success when the run is skipped.
|
Reviews (11): Last reviewed commit: "fix: manualTrigger returns error when ru..." | Re-trigger Greptile |
|
|
Reviews (13): Last reviewed commit: "Mark failed pipeline terminals in workfl..." | Re-trigger Greptile |
Adds cron-based workflow triggers and execution history tracking.
Changes:
CronWorkflowTriggertype with schedule, timezone, overlap_policy, timeoutWorkflowRuntype for tracking workflow executionsworkflow_runsSQLite table with indexes for efficient queryingskip,queue,parallel(default: skip)Schema additions:
workflow_runstable with status tracking (pending, running, completed, failed, skipped, timed_out, canceled)