Skip to content

fix: use gh pr update-branch CLI instead of raw API with empty sha#2113

Merged
marcusquinn merged 3 commits intomainfrom
bugfix/phase4b2-skip-ai-lifecycle
Feb 21, 2026
Merged

fix: use gh pr update-branch CLI instead of raw API with empty sha#2113
marcusquinn merged 3 commits intomainfrom
bugfix/phase4b2-skip-ai-lifecycle

Conversation

@marcusquinn
Copy link
Owner

@marcusquinn marcusquinn commented Feb 21, 2026

The raw API call gh api repos/.../update-branch -f expected_head_sha="" was passing an empty sha, causing 422 errors. Switch to gh pr update-branch which handles sha correctly.

Summary by CodeRabbit

  • Chores
    • Enhanced logging and instrumentation in internal supervisor automation scripts for improved debugging and monitoring of automated processes
    • Improved branch update handling with updated error reporting in continuous integration automation
    • Added conditional logic to support AI-driven lifecycle management as an alternative to legacy task recovery processes

@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 addresses a critical issue where GitHub PR branch updates were failing due to an incorrect API call. By switching to the more robust gh pr update-branch CLI command, it ensures reliable branch synchronization. Additionally, the changes improve the observability of the AI lifecycle process through enhanced logging and prevent potential conflicts between legacy and AI-driven task management by introducing a conditional execution guard.

Highlights

  • GitHub PR Branch Update: The method for updating GitHub PR branches has been changed from a raw GitHub API call (which was failing due to an empty SHA) to using the gh pr update-branch CLI command, which correctly handles the SHA.
  • AI Lifecycle Logging Improvements: Enhanced logging within the AI lifecycle script to include the total number of eligible tasks, detailed task status transitions, and warnings for failed task processing.
  • Stale PR Review Recovery Guard: Implemented a conditional guard in the pulse.sh script to prevent the legacy stale PR review recovery mechanism from interfering with tasks managed by the AI lifecycle.
Changelog
  • .agents/scripts/supervisor/ai-lifecycle.sh
    • Switched from raw GitHub API call to gh pr update-branch CLI command for updating PR branches.
    • Updated log message for branch update success/failure.
    • Introduced logging for the count of eligible tasks.
    • Added informational logging for task status updates.
    • Added a warning log when process_task_lifecycle fails.
  • .agents/scripts/supervisor/pulse.sh
    • Enclosed the stale PR review recovery logic within a conditional block, ensuring it only executes when AI lifecycle is not active.
    • Added comments explaining the purpose of the new conditional guard.
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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 21, 2026

Caution

Review failed

The pull request is closed.

Walkthrough

This PR enhances supervisor script instrumentation and control flow. It migrates GitHub API calls to CLI commands in ai-lifecycle.sh, adds diagnostic logging for state transitions, and introduces conditional gating in pulse.sh to respect AI-driven lifecycle handling when enabled.

Changes

Cohort / File(s) Summary
AI Lifecycle Instrumentation
.agents/scripts/supervisor/ai-lifecycle.sh
Replaces GitHub API PUT with gh pr update-branch CLI command; adds pre-loop computation of total eligible tasks; introduces per-task status trace logs and process failure warnings for enhanced debugging of lifecycle state transitions.
Pulse Phase 4b2 Gating
.agents/scripts/supervisor/pulse.sh
Introduces SUPERVISOR_AI_LIFECYCLE conditional guard around legacy pr_review stale recovery logic; when AI lifecycle is enabled, skips Phase 4b2 legacy recovery; when disabled, preserves legacy behavior with improved stale PR detection logging.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

✨ AI lifecycle takes the helm,
Gates the legacy at phase's realm,
Traces log each state transition true,
CLI commands fresh, old API adieu! 🚀

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix/phase4b2-skip-ai-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.

@github-actions
Copy link

🔍 Code Quality Report

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

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

�[0;34m[INFO]�[0m Recent monitoring activity:
Sat Feb 21 16:57:17 UTC 2026: Code review monitoring started
Sat Feb 21 16:57:17 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 38

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 38
  • VULNERABILITIES: 0

Generated on: Sat Feb 21 16:57:20 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@sonarqubecloud
Copy link

@marcusquinn marcusquinn merged commit 17ab2a2 into main Feb 21, 2026
10 of 11 checks passed
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 correctly replaces the raw GitHub API call for updating a branch with the more robust gh pr update-branch CLI command, resolving the 422 errors. The added logging in ai-lifecycle.sh and the guard for the legacy stale PR recovery logic in pulse.sh are also good improvements for observability and correctness.

I've found one minor bug in the new line-counting logic for logging eligible tasks and have left a suggestion to fix it, which also aligns with repository rules regarding set -e and || true.

local repos_with_changes=""

local total_eligible=0
total_eligible=$(printf '%s\n' "$eligible_tasks" | grep -c '.' || echo "0")

Choose a reason for hiding this comment

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

medium

This line-counting logic is buggy when $eligible_tasks is empty. The combination of grep -c's output on no match and the || echo "0" guard results in $total_eligible being assigned a multi-line value (0\n0), which will cause problems in logs or arithmetic operations.

A more robust way to count lines in a variable is to use a here-string with grep and guard with || true, which correctly handles the empty case by returning 0.

Suggested change
total_eligible=$(printf '%s\n' "$eligible_tasks" | grep -c '.' || echo "0")
total_eligible=$(grep -c . <<< "$eligible_tasks" || true)
References
  1. The style guide (line 13) requires using || true to guard commands that may fail under set -e, such as grep. The current implementation uses || echo "0", which causes incorrect behavior when grep finds no matches. (link)
  2. In shell scripts with 'set -e' enabled, use '|| true' to prevent the script from exiting when a command like 'grep' fails (e.g., no matches found). This ensures script continuity without suppressing error output.

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