t1085.2: AI Supervisor reasoning engine#1609
Conversation
Create supervisor/ai-reason.sh that spawns an opus-tier AI session with project context and has it reason about: - Issue solvability (can open issues be broken into tasks?) - Verification (have closed issues been properly verified?) - Linkage (do closed issues have linked PRs?) - Communication (should any issues get a comment?) - Priority (what should be worked on next?) Features: - Structured JSON action plan output (7 action types) - Dry-run mode for testing without AI calls - Interval-based scheduling (default: every 30min) - Full audit trail in dedicated log directory - Robust JSON extraction from AI responses (4 parsing strategies) - Adds ai-reason, ai-status CLI commands to supervisor
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Summary of ChangesHello @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 intelligence by integrating an autonomous AI reasoning engine. This engine will proactively analyze the project's current state, identify areas needing attention, and propose actionable steps in a structured format. This advancement aims to streamline project management, automate routine decision-making, and improve overall project flow by leveraging AI to maintain oversight and suggest interventions. Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
🔍 Code Quality Report�[0;35m[MONITOR]�[0m Code Review Monitoring Report �[0;34m[INFO]�[0m Latest Quality Status: �[0;34m[INFO]�[0m Recent monitoring activity: 📈 Current Quality Metrics
Generated on: Wed Feb 18 01:16:10 UTC 2026 Generated by AI DevOps Framework Code Review Monitoring |
|
There was a problem hiding this comment.
Code Review
This pull request introduces a significant new feature: an AI reasoning engine for the supervisor. The new script ai-reason.sh is well-structured and the integration into supervisor-helper.sh is clean. My review focuses on improving the robustness of the new code. I've suggested changes to make an arithmetic calculation safer, to improve the error handling of the JSON parsing logic by using exit codes, and to fix a bug in the argument parsing for the standalone script mode. These improvements will make the new functionality more reliable and easier to maintain.
| echo " Enabled: ${SUPERVISOR_AI_ENABLED:-true}" | ||
| echo " Interval: ${SUPERVISOR_AI_INTERVAL:-15} pulses (~$((${SUPERVISOR_AI_INTERVAL:-15} * 2))min)" | ||
| echo " Log dir: ${AI_REASON_LOG_DIR:-$HOME/.aidevops/logs/ai-supervisor}" |
There was a problem hiding this comment.
The arithmetic expression ((${SUPERVISOR_AI_INTERVAL:-15} * 2)) on line 701 is not safe under set -e. If SUPERVISOR_AI_INTERVAL is set to a non-numeric value, this command will fail and cause the script to exit. According to the repository style guide (line 13), arithmetic that might fail should be guarded.
To make this more robust, pre-calculate the value with a fallback.
| echo " Enabled: ${SUPERVISOR_AI_ENABLED:-true}" | |
| echo " Interval: ${SUPERVISOR_AI_INTERVAL:-15} pulses (~$((${SUPERVISOR_AI_INTERVAL:-15} * 2))min)" | |
| echo " Log dir: ${AI_REASON_LOG_DIR:-$HOME/.aidevops/logs/ai-supervisor}" | |
| echo " Enabled: ${SUPERVISOR_AI_ENABLED:-true}" | |
| local interval_minutes | |
| interval_minutes=$(( ${SUPERVISOR_AI_INTERVAL:-15} * 2 )) 2>/dev/null || interval_minutes="?" | |
| echo " Interval: ${SUPERVISOR_AI_INTERVAL:-15} pulses (~${interval_minutes}min)" | |
| echo " Log dir: ${AI_REASON_LOG_DIR:-$HOME/.aidevops/logs/ai-supervisor}" |
References
- The style guide requires that arithmetic operations that might fail (e.g., with non-numeric input) must be guarded to prevent script termination under
set -e. (link)
| local action_plan | ||
| action_plan=$(extract_action_plan "$ai_result") | ||
|
|
||
| if [[ -z "$action_plan" || "$action_plan" == "null" ]]; then | ||
| log_warn "AI Reasoning: no parseable action plan in response" | ||
| { | ||
| echo "## Parsing Result" | ||
| echo "" | ||
| echo "Status: FAILED - no parseable JSON action plan" | ||
| } >>"$reason_log" | ||
| echo '{"error":"no_action_plan","actions":[]}' | ||
| return 1 | ||
| fi |
There was a problem hiding this comment.
To properly handle the error-signaling exit code from extract_action_plan (as suggested in other comments), the call site should be updated to check the exit code directly. This is a more robust way to handle errors in shell scripts, especially with set -e enabled.
| local action_plan | |
| action_plan=$(extract_action_plan "$ai_result") | |
| if [[ -z "$action_plan" || "$action_plan" == "null" ]]; then | |
| log_warn "AI Reasoning: no parseable action plan in response" | |
| { | |
| echo "## Parsing Result" | |
| echo "" | |
| echo "Status: FAILED - no parseable JSON action plan" | |
| } >>"$reason_log" | |
| echo '{"error":"no_action_plan","actions":[]}' | |
| return 1 | |
| fi | |
| local action_plan | |
| if ! action_plan=$(extract_action_plan "$ai_result"); then | |
| log_warn "AI Reasoning: no parseable action plan in response" | |
| { | |
| echo "## Parsing Result" | |
| echo "" | |
| echo "Status: FAILED - no parseable JSON action plan" | |
| } >>"$reason_log" | |
| echo '{"error":"no_action_plan","actions":[]}' | |
| return 1 | |
| fi |
References
- Functions that wrap a command should propagate its exit code to the caller. Callers should check the exit code to handle errors robustly, aligning with the principle of not masking errors with
return 0.
| if [[ -z "$response" ]]; then | ||
| echo "" | ||
| return 0 | ||
| fi |
There was a problem hiding this comment.
This function should signal a failure to parse using a non-zero exit code instead of returning an empty string with a success code. This makes error handling at the call site more robust and idiomatic for shell scripts. This change aligns with the general rule of not masking errors with return 0.
This change should be paired with another change at the end of the function and at the call site in run_ai_reasoning.
| if [[ -z "$response" ]]; then | |
| echo "" | |
| return 0 | |
| fi | |
| if [[ -z "$response" ]]; then | |
| return 1 | |
| fi |
References
- Functions should not mask potential errors with a hardcoded
return 0. Instead, they should propagate failure by returning a non-zero exit code, allowing callers to handle errors robustly.
| # Failed to parse | ||
| echo "" | ||
| return 0 | ||
| } |
There was a problem hiding this comment.
On failure to parse, the function should return a non-zero exit code to signal an error, rather than returning an empty string with exit code 0. This aligns with the general rule of not masking errors and allows the caller to reliably detect and handle parsing failures.
| # Failed to parse | |
| echo "" | |
| return 0 | |
| } | |
| # Failed to parse | |
| return 1 | |
| } |
References
- Functions should not mask potential errors with a hardcoded
return 0. Instead, they should propagate failure by returning a non-zero exit code, allowing callers to handle errors robustly.
| while [[ $# -gt 0 ]]; do | ||
| case "$1" in | ||
| --mode) | ||
| mode="$2" | ||
| shift 2 | ||
| ;; | ||
| --repo) | ||
| repo_path="$2" | ||
| shift 2 | ||
| ;; | ||
| --help | -h) | ||
| echo "Usage: ai-reason.sh [--mode full|dry-run|read-only] [--repo /path]" | ||
| echo "" | ||
| echo "Run AI supervisor reasoning cycle." | ||
| echo "" | ||
| echo "Options:" | ||
| echo " --mode full|dry-run Reasoning mode (default: full)" | ||
| echo " --repo /path Repository path (default: git root)" | ||
| echo " --help Show this help" | ||
| exit 0 | ||
| ;; | ||
| *) | ||
| echo "Unknown option: $1" >&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| done |
There was a problem hiding this comment.
The argument parsing logic is not robust. If --mode or --repo is the last argument on the command line, $2 will be empty and shift 2 will cause the script to exit with an error because of set -e. You should validate that an argument is provided for these options.
while [[ $# -gt 0 ]]; do
case "$1" in
--mode)
if [[ -z "$2" ]]; then
echo "Error: --mode requires an argument." >&2
exit 1
fi
mode="$2"
shift 2
;;
--repo)
if [[ -z "$2" ]]; then
echo "Error: --repo requires an argument." >&2
exit 1
fi
repo_path="$2"
shift 2
;;
--help | -h)
echo "Usage: ai-reason.sh [--mode full|dry-run|read-only] [--repo /path]"
echo ""
echo "Run AI supervisor reasoning cycle."
echo ""
echo "Options:"
echo " --mode full|dry-run Reasoning mode (default: full)"
echo " --repo /path Repository path (default: git root)"
echo " --help Show this help"
exit 0
;;
*)
echo "Unknown option: $1" >&2
exit 1
;;
esac
done


Summary
supervisor/ai-reason.sh— opus-tier AI reasoning engine for the supervisorbuild_ai_context)~/.aidevops/logs/ai-supervisor/ai-reason,ai-statusCLI commandsAction Types
The AI can propose:
comment_on_issue— Post comments on GitHub issuescreate_task— Add tasks to TODO.mdcreate_subtasks— Break down existing tasksflag_for_review— Flag issues for human reviewadjust_priority— Suggest task reorderingclose_verified— Close verified issues (with evidence check)request_info— Ask for clarification on issuesTesting
TODO Reference