Skip to content

Conversation

@marcusquinn
Copy link
Owner

@marcusquinn marcusquinn commented Feb 8, 2026

Summary

  • Adds Phase 4c to the supervisor pulse cycle that detects and cancels stale diagnostic subtasks
  • Diagnostic tasks (diagnostic_of IS NOT NULL) become stale when their parent task reaches a terminal state (deployed/cancelled/failed/complete/merged) before the diagnostic is dispatched
  • Cancels them automatically during pulse, freeing queue slots

Problem

t175-diag-1 was lingering in the queue as queued even though its parent t175 had already been deployed. This wastes a concurrency slot and clutters the batch dashboard.

Changes

  • supervisor-helper.sh: New Phase 4c block between Phase 4b (orphan cleanup) and Phase 5 (summary)
  • Queries for diagnostic tasks in queued/retrying state whose parent is in a terminal state
  • Transitions them to cancelled with a descriptive error message
  • Follows existing patterns: local variables, IFS='|' parsing, error logging to $SUPERVISOR_LOG

Testing

  • ShellCheck clean
  • All 78 supervisor tests pass (77 passed, 1 skipped)

Summary by CodeRabbit

  • Chores
    • Enhanced automatic cleanup of diagnostic subtasks by cancelling those that become obsolete when their parent tasks reach a terminal state (deployed, cancelled, failed, complete, or merged).

Diagnostic tasks (diagnostic_of IS NOT NULL) become stale when their
parent task reaches a terminal state (deployed/cancelled/failed) before
the diagnostic is dispatched. Phase 4c now detects these and cancels
them automatically during pulse, freeing queue slots.

Fixes: t175-diag-1 lingering in queue after t175 was deployed.
@gemini-code-assist
Copy link

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 8, 2026

Walkthrough

Adds Phase 4c to the pulse cycle cleanup routine that identifies and cancels stale diagnostic subtasks whose parent tasks have reached terminal states (deployed, cancelled, failed, complete, or merged). This targeted garbage collection prevents orphaned diagnostic work from lingering in queued or retrying states.

Changes

Cohort / File(s) Summary
Diagnostic Subtask Cleanup
.agents/scripts/supervisor-helper.sh
Introduces Phase 4c query logic that identifies diagnostic subtasks still in queued/retrying states when their parent task has achieved a terminal state, then transitions each to cancelled with explicit reasoning.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

Diagnostic ghosts no more shall linger,
When parents reach their final state,
Phase 4c's cleanup-wielding finger
Cancels the orphans, seals their fate. ✨
Zero debt, maintained with care.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: cancel stale diagnostic subtasks in pulse Phase 4c' accurately and clearly summarizes the primary change in the changeset, which adds Phase 4c to cancel stale diagnostic subtasks.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix/stale-diagnostic-cleanup

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

github-actions bot commented Feb 8, 2026

🔍 Code Quality Report

�[0;35m[MONITOR]�[0m Code Review Monitoring Report

�[0;34m[INFO]�[0m Latest Quality Status:
SonarCloud: 0 bugs, 0 vulnerabilities, 41 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Sun Feb 8 22:31:57 UTC 2026: Code review monitoring started
Sun Feb 8 22:31:57 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 41

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 41
  • VULNERABILITIES: 0

Generated on: Sun Feb 8 22:32:00 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 8, 2026

@marcusquinn marcusquinn merged commit aad724c into main Feb 8, 2026
10 of 11 checks passed
@marcusquinn marcusquinn deleted the bugfix/stale-diagnostic-cleanup branch February 8, 2026 22:35
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In @.agents/scripts/supervisor-helper.sh:
- Around line 5484-5496: The SQL that builds stale_diags currently treats parent
tasks with p.status IN ('deployed','cancelled','failed','complete','merged') as
terminal and cancels their diagnostic subtasks; remove 'failed' from that IN
list (or replace it with a stronger explicit condition) so diagnostics for
failed parents are not cancelled by the stale_diags logic in the
supervisor-helper.sh script when evaluating the SUPERVISOR_DB query, preserving
self‑heal behavior for failed tasks.
- Around line 5489-5499: The DB output parsing is brittle because sqlite3's
output separator can be changed by ~/.sqliterc; modify the db invocation that
produces stale_diags so it sets the output separator explicitly (to the '|' used
by the parser) and disable headers/null-related formatting so the while IFS='|'
read -r diag_id parent_id parent_status loop reliably splits fields; update the
call that populates stale_diags (the db "$SUPERVISOR_DB" ... invocation) to pass
the sqlite3 options that force a deterministic '|' separator and consistent row
formatting.

Comment on lines +5484 to +5496
# Phase 4c: Cancel stale diagnostic subtasks whose parent is already resolved
# Diagnostic tasks (diagnostic_of != NULL) become stale when the parent task
# reaches a terminal state (deployed, cancelled, failed) before the diagnostic
# is dispatched. Cancel them to free queue slots.
local stale_diags
stale_diags=$(db "$SUPERVISOR_DB" "
SELECT d.id, d.diagnostic_of, p.status AS parent_status
FROM tasks d
JOIN tasks p ON d.diagnostic_of = p.id
WHERE d.diagnostic_of IS NOT NULL
AND d.status IN ('queued', 'retrying')
AND p.status IN ('deployed', 'cancelled', 'failed', 'complete', 'merged');
" 2>/dev/null || echo "")
Copy link
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 cancelling diagnostics for failed parents — it breaks self‑heal.

When a task fails, a diagnostic subtask is created to recover it. On Line 5495, including failed in the parent terminal list will cancel queued diagnostics whenever concurrency is tight, effectively disabling self‑heal for failed tasks. Consider excluding failed (or gating on a stronger condition) so diagnostics can still run for failed parents.

🔧 Suggested fix
-          AND p.status IN ('deployed', 'cancelled', 'failed', 'complete', 'merged');
+          AND p.status IN ('deployed', 'cancelled', 'complete', 'merged');

As per coding guidelines, "Automation scripts - focus on: Reliability and robustness".

🤖 Prompt for AI Agents
In @.agents/scripts/supervisor-helper.sh around lines 5484 - 5496, The SQL that
builds stale_diags currently treats parent tasks with p.status IN
('deployed','cancelled','failed','complete','merged') as terminal and cancels
their diagnostic subtasks; remove 'failed' from that IN list (or replace it with
a stronger explicit condition) so diagnostics for failed parents are not
cancelled by the stale_diags logic in the supervisor-helper.sh script when
evaluating the SUPERVISOR_DB query, preserving self‑heal behavior for failed
tasks.

Comment on lines +5489 to +5499
stale_diags=$(db "$SUPERVISOR_DB" "
SELECT d.id, d.diagnostic_of, p.status AS parent_status
FROM tasks d
JOIN tasks p ON d.diagnostic_of = p.id
WHERE d.diagnostic_of IS NOT NULL
AND d.status IN ('queued', 'retrying')
AND p.status IN ('deployed', 'cancelled', 'failed', 'complete', 'merged');
" 2>/dev/null || echo "")

if [[ -n "$stale_diags" ]]; then
while IFS='|' read -r diag_id parent_id parent_status; do
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Harden DB output parsing with an explicit separator.

The loop assumes | separators, but sqlite3 output can be influenced by user .sqliterc settings. Line 5489 should explicitly set the separator to keep parsing deterministic.

🔧 Suggested fix
-    stale_diags=$(db "$SUPERVISOR_DB" "
+    stale_diags=$(db -separator '|' "$SUPERVISOR_DB" "
         SELECT d.id, d.diagnostic_of, p.status AS parent_status
         FROM tasks d
         JOIN tasks p ON d.diagnostic_of = p.id
         WHERE d.diagnostic_of IS NOT NULL
           AND d.status IN ('queued', 'retrying')
           AND p.status IN ('deployed', 'cancelled', 'failed', 'complete', 'merged');
     " 2>/dev/null || echo "")

As per coding guidelines, "Automation scripts - focus on: Reliability and robustness".

🤖 Prompt for AI Agents
In @.agents/scripts/supervisor-helper.sh around lines 5489 - 5499, The DB output
parsing is brittle because sqlite3's output separator can be changed by
~/.sqliterc; modify the db invocation that produces stale_diags so it sets the
output separator explicitly (to the '|' used by the parser) and disable
headers/null-related formatting so the while IFS='|' read -r diag_id parent_id
parent_status loop reliably splits fields; update the call that populates
stale_diags (the db "$SUPERVISOR_DB" ... invocation) to pass the sqlite3 options
that force a deterministic '|' separator and consistent row formatting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant