Skip to content

Conversation

@marcusquinn
Copy link
Owner

@marcusquinn marcusquinn commented Feb 6, 2026

Summary

  • Workers exit after PR creation (context limit). The supervisor now handles the remaining lifecycle stages directly in the pulse cycle: CI wait, merge (squash), postflight, deploy, and worktree cleanup.
  • Adds 6 new states (pr_review, merging, merged, deploying, deployed) and 3 new commands (pr-lifecycle, pr-check, pr-merge) to supervisor-helper.sh.
  • Pulse cycle Phase 3 automatically processes all tasks in complete state with PR URLs through the full post-PR lifecycle.

Changes

New State Machine Extension

complete -> pr_review -> merging -> merged -> deploying -> deployed

New Commands

  • pr-check <task_id> - Check PR CI/review status via gh CLI
  • pr-merge <task_id> [--dry-run] - Squash merge a task's PR
  • pr-lifecycle <task_id> [--dry-run] - Full post-PR lifecycle (CI wait, merge, postflight, deploy, cleanup)

Pulse Cycle Enhancement

  • Phase 3: Automatically processes tasks with PRs through merge/deploy
  • Phase 4: Process hygiene (orphaned PID cleanup)
  • Phase 5: Enhanced summary with post-PR counts

Schema Migration

  • Existing databases auto-migrate on first access (SQLite table recreation)
  • New CHECK constraint includes all 14 states

Quality

  • Zero ShellCheck violations
  • Full state transition tests pass (queued -> deployed lifecycle verified)
  • Schema migration tested with old-format databases
  • Backward compatible: existing complete state still works, post-PR lifecycle is additive

Task

Closes t128.8 (Supervisor post-PR lifecycle - merge, postflight, deploy)

Summary by CodeRabbit

  • New Features
    • Post-PR lifecycle automation for review → merge → deploy, with new visible states (pr_review, merging, merged, deploying, deployed)
    • New commands: pr-check (view PR status and URL), pr-merge (merge when ready), pr-lifecycle (orchestrate full workflow); all support dry-run
    • GitHub PR status integration to validate readiness before merge
    • UI/status updates and pulse summaries to reflect new PR lifecycle states and metrics

Workers exit after PR creation due to context limits. The supervisor now
detects complete tasks with PR URLs and handles remaining stages directly
in the pulse cycle: wait for CI, merge (squash), postflight, deploy,
and worktree cleanup.

New states: pr_review, merging, merged, deploying, deployed
New commands: pr-lifecycle, pr-check, pr-merge
Pulse Phase 3: automatic post-PR processing for all eligible tasks
Schema migration: existing databases auto-upgraded on first access

Zero ShellCheck violations. Full state transition tests pass.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 6, 2026

Caution

Review failed

The pull request is closed.

Walkthrough

Adds a post-PR lifecycle to the supervisor script: new public commands (pr-lifecycle, pr-check, pr-merge), expanded state machine and DB migration for post-PR states, GitHub PR checks and merge logic, postflight/deploy/cleanup orchestration, and pulse-loop integration.

Changes

Cohort / File(s) Summary
Supervisor script (new commands & helpers)
.agent/scripts/supervisor-helper.sh
Adds public commands cmd_pr_lifecycle, cmd_pr_check, cmd_pr_merge and helpers (check_pr_status, merge_task_pr, run_postflight_for_task, run_deploy_for_task, cleanup_after_merge, process_post_pr_lifecycle) implementing PR checks, merge, postflight, deploy and cleanup flows.
State machine & public API
.agent/scripts/supervisor-helper.sh
Extends VALID_STATES and VALID_TRANSITIONS with pr_review, merging, merged, deploying, deployed; updates main() routing to expose pr-lifecycle/pr-check/pr-merge and augments help/usage text.
Pulse integration & orchestration
.agent/scripts/supervisor-helper.sh
Integrates post-PR processing into cmd_pulse phases (Phase 3 triggers process_post_pr_lifecycle; Phase 4 hygiene updated); introduces batch/global lifecycle processing and memory/log hooks.
DB migration & status reporting
.agent/scripts/supervisor-helper.sh
Adds DB migration path and constraints/indices for new post-PR states; updates status/color mappings, pulse summaries, task/batch views, and notification/update functions to include new states and outcomes.
Usage/options & dry-run behavior
.agent/scripts/supervisor-helper.sh
Adds --dry-run option handling for pr-lifecycle and pr-merge; surfaces new commands and post-PR state descriptions in help/manifest text.

Sequence Diagram

sequenceDiagram
    actor Supervisor
    participant Processor as Post-PR Processor
    participant GitHub as GitHub API
    participant DB as State DB
    participant Deployer as Deployment System
    participant Cleanup as Cleanup Handler

    Supervisor->>Processor: process_post_pr_lifecycle()
    loop per eligible task
      Processor->>GitHub: check_pr_status(task)
      GitHub-->>Processor: PR status (ready/ci/draft/changes)
      Processor->>DB: transition -> pr_review
      alt ready_to_merge
        Processor->>GitHub: merge_task_pr (gh pr merge --squash)
        GitHub-->>Processor: merged
        Processor->>DB: transition pr_review -> merging -> merged
        Processor->>Deployer: run_postflight_for_task (verify main)
        Deployer-->>Processor: postflight result
        Processor->>Deployer: run_deploy_for_task
        Deployer-->>Processor: deployed
        Processor->>DB: transition merged -> deploying -> deployed
        Processor->>Cleanup: cleanup_after_merge
        Cleanup-->>Processor: cleanup done
      else not_ready
        Processor->>DB: record PR state (ci_pending / changes_requested / draft)
      end
    end
    Processor-->>Supervisor: lifecycle pass complete
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

A branch becomes a story, checked and merged with care,
States march through review, deploy, and tidy up the air,
GitHub nods, CI hums, postflight sings its song,
Cleanup sweeps the stage and moves the world along,
Automated hands applaud — the pipeline flows along. 🚀

🚥 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 'feat: Supervisor post-PR lifecycle (t128.8)' clearly and concisely summarizes the main change: adding post-PR lifecycle automation to the supervisor, with a reference to the feature ticket.
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 feature/t128-8-supervisor-post-pr-lifecycle

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.

@gemini-code-assist
Copy link

Summary of Changes

Hello @marcusquinn, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the supervisor's capabilities by introducing an automated post-Pull Request lifecycle. Previously, workers would exit after PR creation, leaving subsequent steps like CI monitoring, merging, deployment, and cleanup to manual intervention or separate processes. The supervisor now takes over these stages, managing tasks through new states such as pr_review, merging, merged, deploying, and deployed. This automation streamlines the development workflow, ensures consistent handling of merged code, and provides new commands for granular control and visibility into the post-PR process.

Highlights

  • Automated Post-PR Lifecycle: The supervisor now fully manages tasks after PR creation, including CI wait, merging, postflight, deployment, and worktree cleanup, reducing reliance on worker processes for these stages.
  • Extended State Machine: Introduced new task states (pr_review, merging, merged, deploying, deployed) and their transitions to accurately track the post-PR process.
  • New CLI Commands: Added pr-lifecycle, pr-check, and pr-merge commands to supervisor-helper.sh for manual control and inspection of the post-PR stages.
  • Pulse Cycle Integration: Phase 3 of the supervisor's pulse cycle now automatically identifies and processes tasks through the new post-PR lifecycle.
  • Database Schema Migration: The task database schema is automatically migrated to support the new states, ensuring backward compatibility.
Changelog
  • .agent/scripts/supervisor-helper.sh
    • Added pr-lifecycle, pr-check, and pr-merge commands to the script's usage documentation.
    • Extended VALID_STATES constant to include pr_review, merging, merged, deploying, deployed.
    • Defined new VALID_TRANSITIONS for the post-PR lifecycle, such as complete:pr_review, pr_review:merging, merging:merged, merged:deploying, and deploying:deployed.
    • Implemented an automatic database schema migration to update the tasks table's status CHECK constraint to include the new states.
    • Modified ensure_db to handle the schema migration for the tasks table.
    • Updated cmd_transition to recognize deployed as a terminal state for setting completed_at.
    • Adjusted check_batch_completion to consider deployed and merged as completion states.
    • Updated cmd_status and cmd_list to assign appropriate colors (yellow for in-progress, green for deployed, cyan for merged) to the new states in status output.
    • Modified cmd_cancel to correctly identify deployed and merged as terminal states.
    • Introduced check_pr_status function to determine PR readiness (CI status, review decisions, draft status).
    • Added merge_task_pr function to perform squash merges using gh pr merge.
    • Implemented run_postflight_for_task to verify merges and run_deploy_for_task to execute setup.sh for aidevops repositories.
    • Created cleanup_after_merge to remove worktrees and delete remote branches post-merge.
    • Added cmd_pr_check, cmd_pr_merge, and cmd_pr_lifecycle functions to expose the new PR management capabilities.
    • Implemented process_post_pr_lifecycle to automatically manage tasks through the new states during the pulse cycle.
    • Reordered and renumbered phases in cmd_pulse, introducing "Phase 3: Post-PR lifecycle" and shifting subsequent phases.
    • Updated the pulse summary in cmd_pulse to include counts for "Post-PR" tasks.
    • Modified cmd_cleanup to include deployed and merged states when identifying worktrees for cleanup.
    • Updated cmd_update_todo to handle deployed and merged states.
    • Expanded the help output to document the new commands and the post-PR lifecycle state machine.
    • Integrated the new pr-lifecycle, pr-check, and pr-merge commands into the main function's command dispatch.
Activity
  • The pull request introduces significant new functionality and includes a detailed summary in its description, outlining the changes, new state machine extensions, new commands, pulse cycle enhancements, schema migration, and quality assurances. No specific review comments or interactions are provided in the context.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link

github-actions bot commented Feb 6, 2026

🔍 Code Quality Report

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

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

�[0;34m[INFO]�[0m Recent monitoring activity:
Fri Feb 6 15:17:01 UTC 2026: Code review monitoring started
Fri Feb 6 15:17:02 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 20
Fri Feb 6 15:17:02 UTC 2026: Qlty - 0 issues found, auto-formatting applied
Fri Feb 6 15:17:04 UTC 2026: Codacy analysis completed with auto-fixes

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 20
  • VULNERABILITIES: 0

Generated on: Fri Feb 6 15:17:07 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant and well-designed feature for handling the post-PR lifecycle of tasks directly within the supervisor. The new state machine, commands, and pulse cycle enhancements are comprehensive. The database migration logic is robust. My review focuses on improving the script's debuggability and maintainability by addressing the widespread suppression of error messages, which could make troubleshooting difficult in a production environment.

…ssing

Address code review feedback:
- merge_task_pr: capture gh merge stderr for debugging
- run_deploy_for_task: capture setup.sh output on failure
- pr-lifecycle: log warnings for non-critical failures instead of
  suppressing all stderr with 2>/dev/null
@github-actions
Copy link

github-actions bot commented Feb 6, 2026

🔍 Code Quality Report

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

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

�[0;34m[INFO]�[0m Recent monitoring activity:
Fri Feb 6 15:21:16 UTC 2026: Code review monitoring started
Fri Feb 6 15:21:16 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 20
Fri Feb 6 15:21:16 UTC 2026: Qlty - 0 issues found, auto-formatting applied
Fri Feb 6 15:21:18 UTC 2026: Codacy analysis completed with auto-fixes

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 20
  • VULNERABILITIES: 0

Generated on: Fri Feb 6 15:21:21 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 6, 2026

@marcusquinn marcusquinn merged commit d6ce9f4 into main Feb 6, 2026
10 checks passed
@marcusquinn marcusquinn deleted the feature/t128-8-supervisor-post-pr-lifecycle branch February 6, 2026 15:22
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: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.agent/scripts/supervisor-helper.sh (1)

648-659: ⚠️ Potential issue | 🟡 Minor

ORDER BY CASE doesn't include the new post-PR states.

The cmd_status query (and the analogous one in cmd_list at lines 858-868) doesn't include pr_review, merging, merged, deploying, or deployed in the sort CASE. These states get a NULL sort key, so they appear in an undefined position.

🔧 Proposed fix — add new states to sort order
             CASE status
                 WHEN 'running' THEN 1
                 WHEN 'dispatched' THEN 2
                 WHEN 'evaluating' THEN 3
                 WHEN 'retrying' THEN 4
                 WHEN 'queued' THEN 5
-                WHEN 'blocked' THEN 6
-                WHEN 'failed' THEN 7
-                WHEN 'complete' THEN 8
-                WHEN 'cancelled' THEN 9
+                WHEN 'pr_review' THEN 6
+                WHEN 'merging' THEN 7
+                WHEN 'deploying' THEN 8
+                WHEN 'blocked' THEN 9
+                WHEN 'failed' THEN 10
+                WHEN 'complete' THEN 11
+                WHEN 'merged' THEN 12
+                WHEN 'deployed' THEN 13
+                WHEN 'cancelled' THEN 14
             END;

Apply the same change to the cmd_list CASE at lines 858-868.

🤖 Fix all issues with AI agents
In @.agent/scripts/supervisor-helper.sh:
- Around line 95-108: The PR lifecycle list in supervisor-helper.sh is missing
the "pr_review:deployed" transition which causes cmd_pr_lifecycle (called from
cmd_pr_lifecycle and using check_pr_status) to attempt a pr_review → deployed
transition that cmd_transition cannot perform; add the string
"pr_review:deployed" into the Post-PR lifecycle transitions block (the same list
containing "complete:pr_review", "merged:deploying", etc.) so cmd_transition can
succeed and tasks won't get stuck in pr_review.
- Around line 2022-2033: The fallback PR lookup calls gh pr view from the wrong
directory and may pass an empty $repo_slug; change the logic around the gh
invocation (referencing variables pr_number, repo_slug, tworktree,
SUPERVISOR_DB, escaped_id) so gh runs inside the task's worktree (e.g., run gh
in a subshell or use pushd/popd to cd into "$tworktree") and only pass --repo
"$repo_slug" if $repo_slug is non-empty (otherwise rely on the repo inferred
from the worktree); ensure you restore/avoid changing the outer shell's cwd
after the lookup.
- Around line 2497-2523: The block that runs cmd_transition "$task_id"
"deploying" then calls run_postflight_for_task, run_deploy_for_task and
cleanup_after_merge currently swallows all errors with "|| true" and always
transitions to "deployed"; remove the unconditional suppression and instead
check each command's exit status (or use set -e semantics) so failures are
detected, call cmd_transition "$task_id" "deploying:failed" (or the existing
"deploying:failed" transition) and send a failure notification if any step
fails, only calling cmd_transition "$task_id" "deployed", send_task_notification
and store_success_pattern when all steps succeed; also add handling at the top
to resume tasks already in "deploying" state by re-running the same guarded
sequence (or verifying current state before transitioning) so interrupted
deployments exercise the "deploying:failed" path correctly.
🧹 Nitpick comments (3)
.agent/scripts/supervisor-helper.sh (3)

2194-2203: gh pr merge stderr suppressed — merge failure details lost.

Redirecting 2>/dev/null on the merge command discards the error reason (e.g., "merge requirements not met", "branch protection", "network error"). This makes it difficult to diagnose why a merge failed — the task simply transitions to blocked with a generic "Merge failed" message.

🔧 Proposed fix — capture and log stderr
-    if gh pr merge "$pr_number" --repo "$repo_slug" --squash 2>/dev/null; then
+    local merge_stderr
+    if merge_stderr=$(gh pr merge "$pr_number" --repo "$repo_slug" --squash 2>&1); then
         log_success "PR #$pr_number merged successfully"
         return 0
     else
-        log_error "Failed to merge PR #$pr_number"
+        log_error "Failed to merge PR #$pr_number: $merge_stderr"
         return 1
     fi

2296-2303: Deploy stderr suppressed and no execution timeout.

2>/dev/null on ./setup.sh hides deploy errors. A hung setup.sh would block the entire pulse cycle indefinitely since there's no timeout.

🔧 Proposed fix — log errors and add timeout
     log_info "Running setup.sh for $task_id..."
-    if (cd "$repo" && ./setup.sh) 2>/dev/null; then
+    local deploy_log="$SUPERVISOR_DIR/logs/${task_id}-deploy-$(date +%Y%m%d%H%M%S).log"
+    if (cd "$repo" && timeout 300 ./setup.sh) > "$deploy_log" 2>&1; then
         log_success "Deploy complete for $task_id"
         return 0
     else
-        log_warn "Deploy (setup.sh) returned non-zero for $task_id"
+        log_warn "Deploy (setup.sh) returned non-zero for $task_id (see $deploy_log)"
         return 1
     fi

2569-2580: Lifecycle output entirely suppressed — consider logging instead.

cmd_pr_lifecycle "$tid" 2>/dev/null discards all logging and error output from the lifecycle processing. Combined with the 2>/dev/null || true patterns inside cmd_pr_lifecycle, this creates a debugging black hole during pulse runs. When a task silently fails to advance, there's no trail to investigate.

Consider redirecting to the task's log file or the supervisor cron log instead:

-        if cmd_pr_lifecycle "$tid" 2>/dev/null; then
+        if cmd_pr_lifecycle "$tid" >> "$SUPERVISOR_DIR/post-pr.log" 2>&1; then

marcusquinn added a commit that referenced this pull request Feb 6, 2026
marcusquinn added a commit that referenced this pull request Feb 7, 2026
…y errors (t147.2)

- Add post-PR states to ORDER BY CASE in cmd_status and cmd_list
- Add 300s timeout to deploy setup.sh with portable fallback
- Deploy failures now transition to 'failed' instead of silently marking 'deployed'
- Redirect cmd_pr_lifecycle output to post-pr.log instead of /dev/null
- Fix missing $SUPERVISOR_DB arg in db() calls for no_pr retry counter
- Remove unused no_pr_key variable

Dismissed 3 of 6 review threads as already fixed or invalid:
- gh pr merge stderr: already uses 2>&1
- Fallback PR lookup: already uses git -C and gh pr list --repo
- Missing pr_review:deployed transition: not needed, complete:deployed handles it
marcusquinn added a commit that referenced this pull request Feb 7, 2026
…y errors (t147.2) (#451)

* chore: mark t142 complete in TODO.md (#449)

* chore: mark t135.9 complete in TODO.md (#448)

* fix(supervisor): triage PR #392 review feedback - stderr, sort, deploy errors (t147.2)

- Add post-PR states to ORDER BY CASE in cmd_status and cmd_list
- Add 300s timeout to deploy setup.sh with portable fallback
- Deploy failures now transition to 'failed' instead of silently marking 'deployed'
- Redirect cmd_pr_lifecycle output to post-pr.log instead of /dev/null
- Fix missing $SUPERVISOR_DB arg in db() calls for no_pr retry counter
- Remove unused no_pr_key variable

Dismissed 3 of 6 review threads as already fixed or invalid:
- gh pr merge stderr: already uses 2>&1
- Fallback PR lookup: already uses git -C and gh pr list --repo
- Missing pr_review:deployed transition: not needed, complete:deployed handles it
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