Files
multica/server/migrations/043_fix_orphaned_autopilot_runs.down.sql
Jiayuan Zhang f94b0100cd refactor(autopilot): remove broken concurrency policies and fix multiple bugs (#1048)
Remove the concurrency_policy system (skip/queue/replace) — skip had an
orphan bug that permanently blocked triggers, queue didn't actually queue,
and replace didn't cancel running tasks. Every trigger now simply executes.

Bug fixes:
- Listener now handles in_review status (was silently ignored)
- Issue deletion fails linked autopilot runs before DELETE (prevents orphans)
- ComputeNextRun rejects invalid timezones instead of silent UTC fallback
- dispatchCreateIssue post-commit failures now properly fail the run

Reliability:
- Scheduler recovers lost triggers on startup (crash recovery)
- New index on autopilot_run(issue_id) for deletion lookups
- Migration 043 cleans up historical orphaned/skipped/pending runs
2026-04-15 13:48:21 +08:00

17 lines
839 B
SQL

-- Drop the issue_id index added in the up migration.
DROP INDEX IF EXISTS idx_autopilot_run_issue;
-- Restore the original partial status index.
DROP INDEX IF EXISTS idx_autopilot_run_status;
CREATE INDEX IF NOT EXISTS idx_autopilot_run_status ON autopilot_run(autopilot_id, status)
WHERE status IN ('pending', 'issue_created', 'running');
-- Restore concurrency_policy column.
ALTER TABLE autopilot ADD COLUMN IF NOT EXISTS concurrency_policy TEXT NOT NULL DEFAULT 'skip'
CHECK (concurrency_policy IN ('skip', 'queue', 'replace'));
-- Restore the original status CHECK constraint.
ALTER TABLE autopilot_run DROP CONSTRAINT IF EXISTS autopilot_run_status_check;
ALTER TABLE autopilot_run ADD CONSTRAINT autopilot_run_status_check
CHECK (status IN ('pending', 'issue_created', 'running', 'skipped', 'completed', 'failed'));