summaryrefslogtreecommitdiff
path: root/scripts/reset-failed-tasks
diff options
context:
space:
mode:
authorPeter Stone <thepeterstone@gmail.com>2026-03-26 08:02:09 +0000
committerPeter Stone <thepeterstone@gmail.com>2026-03-26 08:02:09 +0000
commit5f3e9900358649f1356d0a242e643790e29e3701 (patch)
treedd75fd4707e1dc4e5cef5822372997a47cea2830 /scripts/reset-failed-tasks
parent34b4f397b1f46cb5027ba910983021a68f3e7333 (diff)
feat: cascade retry deps when running a task with failed dependencies
When /run is called on a CANCELLED/FAILED task that has deps in a terminal failure state, automatically reset and resubmit those deps so the task isn't immediately re-cancelled by the pool's dep check. Also update reset-failed-tasks script to handle CANCELLED tasks and clean up preserved sandbox workspaces. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'scripts/reset-failed-tasks')
-rwxr-xr-xscripts/reset-failed-tasks48
1 files changed, 46 insertions, 2 deletions
diff --git a/scripts/reset-failed-tasks b/scripts/reset-failed-tasks
index eddfff0..1f3b6d5 100755
--- a/scripts/reset-failed-tasks
+++ b/scripts/reset-failed-tasks
@@ -1,5 +1,49 @@
#!/bin/bash
+# Reset FAILED and CANCELLED tasks to PENDING and delete their preserved workspaces.
+# Usage: reset-failed-tasks [--dry-run]
-DB_PATH="/site/doot.terst.org/data/claudomator.db"
+set -euo pipefail
-sqlite3 "$DB_PATH" "UPDATE tasks SET state = 'PENDING' WHERE state = 'FAILED';"
+DB_PATH="${CLAUDOMATOR_DB:-/site/doot.terst.org/data/claudomator.db}"
+DRY_RUN=false
+[[ "${1:-}" == "--dry-run" ]] && DRY_RUN=true
+
+# Collect preserved sandbox dirs before resetting so we can clean them up.
+SANDBOX_DIRS=$(sqlite3 "$DB_PATH" "
+ SELECT DISTINCT e.sandbox_dir
+ FROM executions e
+ JOIN tasks t ON t.id = e.task_id
+ WHERE t.state IN ('FAILED','CANCELLED')
+ AND e.sandbox_dir IS NOT NULL
+ AND e.sandbox_dir != '';
+")
+
+TASK_COUNT=$(sqlite3 "$DB_PATH" "SELECT COUNT(*) FROM tasks WHERE state IN ('FAILED','CANCELLED');")
+
+echo "Tasks to reset: $TASK_COUNT"
+
+if [[ "$DRY_RUN" == "true" ]]; then
+ echo "[dry-run] Would reset $TASK_COUNT task(s) to PENDING."
+ if [[ -n "$SANDBOX_DIRS" ]]; then
+ echo "[dry-run] Workspaces to delete:"
+ echo "$SANDBOX_DIRS"
+ else
+ echo "[dry-run] No preserved workspaces to delete."
+ fi
+ exit 0
+fi
+
+sqlite3 "$DB_PATH" "UPDATE tasks SET state = 'PENDING' WHERE state IN ('FAILED','CANCELLED');"
+echo "Reset $TASK_COUNT task(s) to PENDING."
+
+DELETED=0
+while IFS= read -r dir; do
+ [[ -z "$dir" ]] && continue
+ if [[ -d "$dir" ]]; then
+ rm -rf "$dir"
+ echo "Deleted workspace: $dir"
+ DELETED=$((DELETED + 1))
+ fi
+done <<< "$SANDBOX_DIRS"
+
+echo "Deleted $DELETED workspace(s)."