-
Notifications
You must be signed in to change notification settings - Fork 55
t1273: Add supervisor sanity-check for self-healing queue stalls #2015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8ea0c8f
feat: add supervisor sanity-check for self-healing queue stalls (t1273)
marcusquinn 8fd10d8
refactor: extract sanity-check helper function and improve sed robust…
marcusquinn ef42b00
fix: address CodeRabbit review — stdout leakage, COALESCE, regex esca…
marcusquinn bee152b
fix: escape task_id dots in grep, eliminate IFS mutation, fix fallbac…
marcusquinn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -612,6 +612,31 @@ get_task_timeout() { | |
| return 0 | ||
| } | ||
|
|
||
| ####################################### | ||
| # Phase 0.9 helper: run sanity check for a single repo | ||
| # Extracted to avoid duplicating the open-task check + sanity-check + auto-pickup | ||
| # sequence for the multi-repo and single-repo code paths in cmd_pulse. | ||
| ####################################### | ||
| _run_sanity_check_for_repo() { | ||
| local repo_path="$1" | ||
| local todo_file="$repo_path/TODO.md" | ||
|
|
||
| if [[ ! -f "$todo_file" ]]; then | ||
| return | ||
| fi | ||
|
|
||
| local open_count | ||
| open_count=$(grep -cE '^\s*- \[ \] t[0-9]+' "$todo_file" 2>/dev/null || echo 0) | ||
| if [[ "$open_count" -gt 0 ]]; then | ||
| local sanity_fixed | ||
| sanity_fixed=$(run_sanity_check "$repo_path" 2>>"$SUPERVISOR_LOG") | ||
| if [[ "${sanity_fixed:-0}" -gt 0 ]]; then | ||
| log_info "Phase 0.9: Sanity check fixed $sanity_fixed issue(s) in $repo_path — re-running auto-pickup" | ||
| cmd_auto_pickup --repo "$repo_path" 2>>"$SUPERVISOR_LOG" || true | ||
| fi | ||
| fi | ||
| } | ||
|
|
||
| ####################################### | ||
| # Supervisor pulse - stateless check and dispatch cycle | ||
| # Designed to run via cron every 5 minutes | ||
|
|
@@ -1938,6 +1963,25 @@ cmd_pulse() { | |
| fi | ||
| fi | ||
|
|
||
| # Phase 0.9: Sanity check — question assumptions when queue appears empty | ||
| # Runs after all recovery phases (0.5–0.8, 1–1d) and before dispatch (Phase 2). | ||
| # When the queue has zero dispatchable tasks but open tasks exist in TODO.md, | ||
| # cross-references DB state, TODO.md state, and system state to find | ||
| # contradictions that cause silent stalls. Fixes: stale claims on DB-failed | ||
| # tasks, failed blocker cascades, missing #auto-dispatch tags, DB orphans. | ||
| local queued_before_sanity | ||
| queued_before_sanity=$(db "$SUPERVISOR_DB" "SELECT COUNT(*) FROM tasks WHERE status = 'queued';" 2>/dev/null || echo 0) | ||
| if [[ "$queued_before_sanity" -eq 0 ]]; then | ||
| # No queued tasks — check if there are open tasks in TODO.md that should be | ||
| if [[ -n "$all_repos" ]]; then | ||
| while IFS= read -r repo_path; do | ||
| _run_sanity_check_for_repo "$repo_path" | ||
| done <<<"$all_repos" | ||
| else | ||
| _run_sanity_check_for_repo "$(pwd)" | ||
| fi | ||
| fi | ||
|
Comment on lines
+1974
to
+1983
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic inside the _run_sanity_check_for_repo() {
local repo_path="$1"
local todo_file="$repo_path/TODO.md"
if [[ ! -f "$todo_file" ]]; then
return
fi
local open_count
open_count=$(grep -cE '^\s*- \[ \] t[0-9]+' "$todo_file" || echo 0)
if [[ "$open_count" -gt 0 ]]; then
local sanity_fixed
sanity_fixed=$(run_sanity_check "$repo_path" 2>>"$SUPERVISOR_LOG")
if [[ "${sanity_fixed:-0}" -gt 0 ]]; then
log_info "Phase 0.9: Sanity check fixed $sanity_fixed issue(s) in $repo_path — re-running auto-pickup"
cmd_auto_pickup --repo "$repo_path" 2>>"$SUPERVISOR_LOG" || true
fi
fi
}
if [[ "$queued_before_sanity" -eq 0 ]]; then
# No queued tasks — check if there are open tasks in TODO.md that should be
if [[ -n "$all_repos" ]]; then
while IFS= read -r repo_path; do
_run_sanity_check_for_repo "$repo_path"
done <<<"$all_repos"
else
_run_sanity_check_for_repo "$(pwd)"
fi
fiReferences
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| # Phase 2: Dispatch queued tasks up to concurrency limit | ||
|
|
||
| if [[ -n "$batch_id" ]]; then | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suppressing
stderrwith2>/dev/nullcan hide important underlying errors fromdb(like SQL syntax errors or connection issues) and violates general repository rules. ForSELECToperations,2>/dev/nullshould generally be avoided to ensure diagnostic information is visible for debugging. The|| echo 0guard is sufficient to handle cases where no rows are returned or the command fails gracefully. Please remove2>/dev/nullto allow genuine errors to be visible for debugging. This applies to other similar calls in this file (lines 1955, 1971).References