Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions .agents/scripts/supervisor-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10212,6 +10212,94 @@ cmd_pulse() {
bash "$coderabbit_pulse_script" run --repo "$pulse_repo" --quiet 2>>"$SUPERVISOR_LOG" || true
fi

# Phase 10b: Auto-create TODO tasks from quality findings (t299)
# Converts CodeRabbit and quality-sweep findings into TODO.md tasks.
# Self-throttles with 24h cooldown. Only runs if task creator script exists.
local task_creator_script="${SCRIPT_DIR}/coderabbit-task-creator-helper.sh"
local task_creation_cooldown_file="${SUPERVISOR_STATE_DIR}/task-creation-last-run"
local task_creation_cooldown=86400 # 24 hours
if [[ -x "$task_creator_script" ]]; then
local should_run_task_creation=true
if [[ -f "$task_creation_cooldown_file" ]]; then
local last_run
last_run=$(cat "$task_creation_cooldown_file" 2>/dev/null || echo "0")
local now
now=$(date +%s)
local elapsed=$((now - last_run))
if [[ $elapsed -lt $task_creation_cooldown ]]; then
should_run_task_creation=false
local remaining=$(( (task_creation_cooldown - elapsed) / 3600 ))
log_verbose " Phase 10b: Task creation skipped (${remaining}h until next run)"
fi
fi

if [[ "$should_run_task_creation" == "true" ]]; then
log_info " Phase 10b: Auto-creating tasks from quality findings"
date +%s > "$task_creation_cooldown_file"

Comment on lines +10218 to +10239
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Guard the cooldown state path to prevent pulse aborts.

With set -u/set -e, an unset SUPERVISOR_STATE_DIR or missing directory can abort the pulse when writing task-creation-last-run. Default the path and ensure the directory exists before the first write.

🔧 Proposed fix
-    local task_creation_cooldown_file="${SUPERVISOR_STATE_DIR}/task-creation-last-run"
+    local task_creation_state_dir="${SUPERVISOR_STATE_DIR:-$SUPERVISOR_DIR}"
+    mkdir -p "$task_creation_state_dir" 2>/dev/null || true
+    local task_creation_cooldown_file="${task_creation_state_dir}/task-creation-last-run"

As per coding guidelines: “Automation scripts - focus on: Reliability and robustness.”

🤖 Prompt for AI Agents
In @.agents/scripts/supervisor-helper.sh around lines 10218 - 10239, The script
writes task_creation_cooldown_file using SUPERVISOR_STATE_DIR without guarding
against an unset or missing directory which can cause failures under set -u/-e;
change the assignment that builds task_creation_cooldown_file to use a safe
default for SUPERVISOR_STATE_DIR (e.g.
${SUPERVISOR_STATE_DIR:-/var/lib/supervisor}) and ensure the directory exists
before any write by creating it if missing (mkdir -p) prior to using date >
"$task_creation_cooldown_file"; apply these changes around the
task_creator_script / task_creation_cooldown_file logic to protect writes and
avoid pulse aborts.

# Determine repo for TODO.md
local task_repo=""
task_repo=$(db "$SUPERVISOR_DB" "SELECT DISTINCT repo FROM tasks LIMIT 1;" 2>/dev/null || echo "")
if [[ -z "$task_repo" ]]; then
task_repo="$(pwd)"
fi
local todo_file="$task_repo/TODO.md"

if [[ -f "$todo_file" ]]; then
local tasks_added=0

# 1. CodeRabbit findings → tasks
local cr_output
cr_output=$(bash "$task_creator_script" create 2>>"$SUPERVISOR_LOG" || echo "")
if [[ -n "$cr_output" ]]; then
# Extract task lines between the markers
local cr_tasks
cr_tasks=$(echo "$cr_output" | sed -n '/=== Task Lines/,/===$/p' | grep -E '^\s*- \[ \]' || true)
if [[ -n "$cr_tasks" ]]; then
# Find next task ID
local max_id
max_id=$(grep -oE 't[0-9]+' "$todo_file" | grep -oE '[0-9]+' | sort -n | tail -1 || echo "0")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current grep command to find the maximum task ID is not anchored to the start of the line. This could incorrectly match task IDs mentioned in the description of other tasks (e.g., blocked-by:t123), leading to incorrect ID generation and potential duplicates. The regex should be anchored to match the task format - [ ] tXXX ... to ensure only actual task IDs are considered.

Suggested change
max_id=$(grep -oE 't[0-9]+' "$todo_file" | grep -oE '[0-9]+' | sort -n | tail -1 || echo "0")
max_id=$(grep -oE '^\s*-\s*\[\s*.\s*\]\s*t[0-9]+' "$todo_file" | grep -oE '[0-9]+' | sort -n | tail -1 || echo "0")

max_id=$((10#$max_id))

# Append each task with a unique ID
while IFS= read -r task_line; do
max_id=$((max_id + 1))
# Replace placeholder or add task ID
local new_line
new_line=$(echo "$task_line" | sed -E "s/^(\s*- \[ \] )/\1t${max_id} /")
# Ensure #auto-dispatch tag and source tag
if ! echo "$new_line" | grep -q '#auto-dispatch'; then
new_line="$new_line #auto-dispatch"
fi
if ! echo "$new_line" | grep -q '#auto-review'; then
new_line="$new_line #auto-review"
fi
Comment on lines +10271 to +10276
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

These two if blocks use echo and grep in subshells inside a loop, which is inefficient. You can achieve the same result more efficiently using bash's built-in string matching capabilities.

Suggested change
if ! echo "$new_line" | grep -q '#auto-dispatch'; then
new_line="$new_line #auto-dispatch"
fi
if ! echo "$new_line" | grep -q '#auto-review'; then
new_line="$new_line #auto-review"
fi
if [[ $new_line != *'#auto-dispatch'* ]]; then
new_line+=" #auto-dispatch"
fi
if [[ $new_line != *'#auto-review'* ]]; then
new_line+=" #auto-review"
fi

new_line="$new_line logged:$(date +%Y-%m-%d)"
# Append after the last open task line
echo "$new_line" >> "$todo_file"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Appending new tasks directly to the end of TODO.md with >> is likely to break the file's structure, as it will probably place tasks after structured TOON blocks. New tasks should be inserted within the ## Backlog section to maintain file integrity. Consider using a tool like sed to insert the new task line after the ## Backlog header or before the <!--TOON:backlog... marker. The style guide also mentions a sed_append_after helper function which may be suitable here.

tasks_added=$((tasks_added + 1))
log_info " Created t${max_id} from CodeRabbit finding"
done <<< "$cr_tasks"
fi
fi

# 2. Commit and push if tasks were added
if [[ $tasks_added -gt 0 ]]; then
log_info " Phase 10b: Added $tasks_added task(s) to TODO.md"
if git -C "$task_repo" add TODO.md 2>>"$SUPERVISOR_LOG" && \
git -C "$task_repo" commit -m "chore: auto-create $tasks_added task(s) from quality findings (Phase 10b)" 2>>"$SUPERVISOR_LOG" && \
git -C "$task_repo" push 2>>"$SUPERVISOR_LOG"; then
log_success " Phase 10b: Committed and pushed $tasks_added new task(s)"
else
log_warn " Phase 10b: Failed to commit/push TODO.md changes"
fi
else
log_verbose " Phase 10b: No new tasks to create"
fi
fi
Comment on lines +10236 to +10299
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Avoid 24h throttling when task creation can’t run.

The cooldown stamp is written before confirming TODO.md exists or the helper run completes; a missing TODO.md or helper failure will still block retries for 24 hours. Move the stamp to after successful execution (or at least after prerequisites are met) to keep the feedback loop responsive.

🔧 Proposed fix
-        log_info "  Phase 10b: Auto-creating tasks from quality findings"
-        date +%s > "$task_creation_cooldown_file"
+        log_info "  Phase 10b: Auto-creating tasks from quality findings"
@@
-            if [[ -f "$todo_file" ]]; then
+            if [[ -f "$todo_file" ]]; then
                 local tasks_added=0
@@
-                else
-                    log_verbose "  Phase 10b: No new tasks to create"
-                fi
+                else
+                    log_verbose "  Phase 10b: No new tasks to create"
+                fi
+                date +%s > "$task_creation_cooldown_file"
+            else
+                log_warn "  Phase 10b: TODO.md not found in $task_repo; skipping task creation"
             fi

As per coding guidelines: “Automation scripts - focus on: Reliability and robustness.”

🤖 Prompt for AI Agents
In @.agents/scripts/supervisor-helper.sh around lines 10236 - 10299, The
cooldown timestamp for task creation is being written to
task_creation_cooldown_file before prerequisites and execution complete, which
can throttle retries if TODO.md is missing or the task creator fails; move the
write of date +%s to after confirming TODO.md exists and after tasks_added is
determined (i.e., after verifying task_repo/TODO.md and running
task_creator_script and parsing cr_tasks) and only write the cooldown when the
operation has actually succeeded or at least when prerequisites are satisfied
(use the same symbols: should_run_task_creation, task_creation_cooldown_file,
task_repo/TODO.md, task_creator_script, cr_tasks, and tasks_added to locate
where to relocate the timestamp).

fi
fi

# Phase 11: Supervisor session memory monitoring + respawn (t264, t264.1)
# OpenCode/Bun processes accumulate WebKit malloc dirty pages that are never
# returned to the OS. Over long sessions, a single process can grow to 25GB+.
Expand Down
Loading