Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
4d4143f
fix(dev-lead): intent-based model dispatch and fix copilot write fall…
May 16, 2026
8d4e2cc
fix(dev-lead): engine-agnostic model dispatch and copilot write guard
May 16, 2026
6c63d8e
Merge branch 'main' into fix/issue-195-intent-dispatch-and-copilot
don-petry May 16, 2026
6789814
Merge branch 'main' into fix/issue-195-intent-dispatch-and-copilot
don-petry May 16, 2026
28374b4
fix(dev-lead): treat engine-not-installed (exit 127) as unavailable i…
May 17, 2026
40434c3
Merge branch 'main' into fix/issue-195-intent-dispatch-and-copilot
don-petry May 17, 2026
2612f50
Merge branch 'main' into fix/issue-195-intent-dispatch-and-copilot
don-petry May 17, 2026
43b7095
Merge branch 'main' into fix/issue-195-intent-dispatch-and-copilot
don-petry May 17, 2026
d43f88f
Merge branch 'main' into fix/issue-195-intent-dispatch-and-copilot
don-petry May 17, 2026
dc6c258
Merge branch 'main' into fix/issue-195-intent-dispatch-and-copilot
don-petry May 17, 2026
3b54da1
Merge branch 'main' into fix/issue-195-intent-dispatch-and-copilot
don-petry May 17, 2026
ec023ba
Merge branch 'main' into fix/issue-195-intent-dispatch-and-copilot
don-petry May 17, 2026
03e225f
Merge branch 'main' into fix/issue-195-intent-dispatch-and-copilot
don-petry May 17, 2026
e00479b
Merge branch 'main' into fix/issue-195-intent-dispatch-and-copilot
don-petry May 17, 2026
2b29c86
Merge branch 'main' into fix/issue-195-intent-dispatch-and-copilot
don-petry May 17, 2026
b16caed
Merge branch 'main' into fix/issue-195-intent-dispatch-and-copilot
don-petry May 17, 2026
1a99ba7
Merge branch 'main' into fix/issue-195-intent-dispatch-and-copilot
don-petry May 17, 2026
922fadf
Merge branch 'main' into fix/issue-195-intent-dispatch-and-copilot
May 18, 2026
0987378
Merge branch 'main' into fix/issue-195-intent-dispatch-and-copilot
don-petry May 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion scripts/dev-lead-fix-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set -euo pipefail

source "$(dirname "$0")/engine.sh"

INTENT_TYPE="fix-ci"
PR_NUMBER="${PR_NUMBER:-}"
HEAD_SHA="${HEAD_SHA:-}"
CHECKS_JSON="${CHECKS_JSON:-[]}"
Expand Down Expand Up @@ -202,7 +203,7 @@ main() {
echo " [fix-ci] cycle $cycle/$MAX_CI_CYCLES"

local engine_rc=0
run_writer_with_fallback "$prompt_file" || engine_rc=$?
run_writer_with_fallback "$prompt_file" "$(model_for_intent "$INTENT_TYPE")" || engine_rc=$?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in commit 8d4e2cc. model_for_intent now returns a tier key ("triage"/"action"/"deep") instead of a concrete model string. run_writer_with_fallback calls _setup_engine_vars($engine) before each invocation so ENGINE_*_MODEL vars are correct for each provider in the fallback chain. run_writer resolves the tier against those vars, so Gemini and Copilot always receive their own compatible model IDs.


if [ "$engine_rc" -ne 0 ]; then
if [ "$engine_rc" -eq 2 ]; then
Expand Down
3 changes: 2 additions & 1 deletion scripts/dev-lead-fix-issue.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set -euo pipefail

source "$(dirname "$0")/engine.sh"

INTENT_TYPE="fix-issue"
ISSUE_NUMBER="${ISSUE_NUMBER:-}"
REPO="${REPO:-${GITHUB_REPOSITORY:-}}"
DEV_LEAD_DRY_RUN="${DEV_LEAD_DRY_RUN:-false}"
Expand Down Expand Up @@ -51,7 +52,7 @@ main() {
local branch="dev-lead/issue-${ISSUE_NUMBER}-$(date +%Y%m%d-%H%M)"
git checkout -b "$branch"

if ! run_writer_with_fallback "$prompt_file"; then
if ! run_writer_with_fallback "$prompt_file" "$(model_for_intent "$INTENT_TYPE")"; then

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in commit 8d4e2cc. model_for_intent now returns a tier key ("triage"/"action"/"deep") instead of a concrete model string. run_writer_with_fallback calls _setup_engine_vars($engine) before each invocation so ENGINE_*_MODEL vars are correct for each provider in the fallback chain. run_writer resolves the tier against those vars, so Gemini and Copilot always receive their own compatible model IDs.

echo "::error::Engine failed to implement issue #${ISSUE_NUMBER}"
rm -f "$prompt_file"
exit 1
Expand Down
13 changes: 7 additions & 6 deletions scripts/dev-lead-fix-reviews.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ fi

build_and_run() {
local template_name="$1"
local model="${2:-$ENGINE_ACTION_MODEL}"
local prompt_file="/tmp/dev-lead-${template_name}-prompt-$$.md"
# Export required vars then envsubst
envsubst < "${PROMPTS_DIR}/${template_name}.md" > "$prompt_file"
Expand All @@ -39,7 +40,7 @@ build_and_run() {
fi

local rc=0
run_writer_with_fallback "$prompt_file" || rc=$?
run_writer_with_fallback "$prompt_file" "$model" || rc=$?
rm -f "$prompt_file"
return "$rc"
Comment on lines 46 to 50

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in commit 8d4e2cc. model_for_intent now returns a tier key ("triage"/"action"/"deep") instead of a concrete model string. run_writer_with_fallback calls _setup_engine_vars($engine) before each invocation so ENGINE_*_MODEL vars are correct for each provider in the fallback chain. run_writer resolves the tier against those vars, so Gemini and Copilot always receive their own compatible model IDs.

}
Expand Down Expand Up @@ -199,7 +200,7 @@ case "$INTENT_TYPE" in
--jq '.data.repository.pullRequest.reviewThreads.nodes | map(select(.isResolved == false))' 2>/dev/null || echo "[]")
export OPEN_THREADS_JSON
rc=0
build_and_run "fix-reviews" || rc=$?
build_and_run "fix-reviews" "$(model_for_intent "fix-reviews")" || rc=$?
[ "$rc" -eq 2 ] && handle_rate_limit "fix-reviews"
[ "$rc" -eq 0 ] && post_reviews_terminal "fix-reviews" "applied"
exit "$rc"
Expand All @@ -208,15 +209,15 @@ case "$INTENT_TYPE" in
export PR_NUMBER PR_URL="https://github.com/${REPO}/pull/${PR_NUMBER}"
export REPO ACTOR="${ACTOR:-}" COMMENT_BODY="${COMMENT_BODY:-}" HEAD_SHA
rc=0
build_and_run "fix-bot-comment" || rc=$?
build_and_run "fix-bot-comment" "$(model_for_intent "fix-bot-comment")" || rc=$?
[ "$rc" -eq 2 ] && handle_rate_limit "fix-bot-comment"
exit "$rc"
;;
human)
export PR_NUMBER PR_URL="https://github.com/${REPO}/pull/${PR_NUMBER}"
export REPO ACTOR="${ACTOR:-}" USER_INSTRUCTION="${USER_INSTRUCTION:-}" PR_DESCRIPTION="${PR_DESCRIPTION:-}"
rc=0
build_and_run "human" || rc=$?
build_and_run "human" "$(model_for_intent "human")" || rc=$?
[ "$rc" -eq 2 ] && handle_rate_limit "human"
exit "$rc"
;;
Expand All @@ -237,7 +238,7 @@ case "$INTENT_TYPE" in
--jq '.data.repository.pullRequest.reviewThreads.nodes | map(select(.isResolved == false))' 2>/dev/null || echo "[]")
export OPEN_THREADS_JSON BASE_REF="${BASE_REF:-main}"
rc=0
build_and_run "human-pr" || rc=$?
build_and_run "human-pr" "$(model_for_intent "human-pr")" || rc=$?
[ "$rc" -eq 2 ] && handle_rate_limit "human-pr"
[ "$rc" -eq 0 ] && post_reviews_terminal "human-pr" "applied"
exit "$rc"
Expand All @@ -258,7 +259,7 @@ case "$INTENT_TYPE" in
CONFLICTING_FILES=$(git merge-tree "$(git merge-base HEAD "origin/${BASE_REF}")" HEAD "origin/${BASE_REF}" 2>/dev/null | grep "^changed in both" | awk '{print $NF}' || true)
export CONFLICTING_FILES
rc=0
build_and_run "rebase" || rc=$?
build_and_run "rebase" "$(model_for_intent "rebase")" || rc=$?
[ "$rc" -eq 2 ] && handle_rate_limit "rebase"
[ "$rc" -eq 0 ] && post_reviews_terminal "rebase" "applied"
exit "$rc"
Expand Down
38 changes: 26 additions & 12 deletions scripts/engine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ set -euo pipefail
# Supports: claude, gemini, copilot
#
# Sourced by review-one-pr.sh — provides:
# run_triage <prompt_file> — no-tool tier (stdout capture)
# run_agentic <prompt_file> <model> — full-tool tier (stdout)
# run_duck <prompt_file> <model> — cross-engine adversarial (stdout)
# run_triage <prompt_file> — no-tool tier (review-one-pr.sh only)
# run_agentic <prompt_file> <model> — full-tool tier (review-one-pr.sh only)
# run_duck <prompt_file> <model> — adversarial cross-engine (review-one-pr.sh only)
# ENGINE_* env vars for model names and labels
# DUCK_ENGINE / DUCK_MODEL for rubber-duck cross-engine review
#
# Sourced by dev-lead scripts — provides:
# model_for_intent <intent> — select model tier by intent complexity
# run_writer <prompt_file> [model] — write-capable agent run
# run_writer_with_fallback <prompt_file> [model] — run with engine fallback

REVIEW_ENGINE="${REVIEW_ENGINE:-claude}"
export REVIEW_ENGINE
Expand Down Expand Up @@ -445,6 +450,20 @@ parse_reset_time() {
printf '%s' "${iso:-}" > /tmp/dev-lead-rate-limit-reset
}

# model_for_intent <intent>
# Returns the ENGINE_* model variable appropriate for the intent's complexity.
# haiku — human-pr, fix-bot-comment: lightweight checks, short-circuit if nothing to do
# sonnet — fix-reviews, fix-ci, rebase: write operations on known-scope diffs
# sonnet — fix-issue, human: full agentic feature work (deep = action = sonnet for now)
model_for_intent() {
case "${1:-}" in
human-pr|fix-bot-comment) echo "$ENGINE_TRIAGE_MODEL" ;;
fix-reviews|fix-ci|rebase) echo "$ENGINE_ACTION_MODEL" ;;
fix-issue|human) echo "$ENGINE_DEEP_MODEL" ;;
*) echo "$ENGINE_ACTION_MODEL" ;;
esac
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

# run_writer <prompt_file> [model]
# Full write-access mode for applying code fixes.
# When DEV_LEAD_DRY_RUN=true: builds prompt but does NOT call engine; exits 0.
Expand Down Expand Up @@ -483,15 +502,10 @@ run_writer() {
< "$prompt_file" | tee "$_tmp" || rc=${PIPESTATUS[0]}
;;
copilot)
# Copilot (gh copilot suggest) is text-only — falls back to Claude for write ops
echo "::warning::Copilot engine is text-only; falling back to Claude for write operations" >&2
local saved="$REVIEW_ENGINE"
REVIEW_ENGINE="claude" timeout "$ACTION_TIMEOUT_SEC" claude --print \
--model "$model" \
--permission-mode acceptEdits \
--allowed-tools "Bash,Read,Write,Edit,Grep,Glob" \
< "$prompt_file" | tee "$_tmp" || rc=${PIPESTATUS[0]}
REVIEW_ENGINE="$saved"
# GitHub Models REST API — text-only, no Write/Edit tool access.
# The rate-limit text (HTTP 429) is echoed to stdout by copilot_chat so
# is_rate_limited() will fire and return exit 2 for engine fallback.
copilot_chat "$prompt_file" "$ACTION_TIMEOUT_SEC" | tee "$_tmp" || rc=${PIPESTATUS[0]}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep text-only Copilot from satisfying write jobs

When REVIEW_ENGINE=copilot or fallback reaches Copilot after Claude/Gemini rate-limit, this call can return 0 with only a text response from GitHub Models; the comment above says it has no Write/Edit tool access, and nothing applies the returned patch. Because run_writer_with_fallback treats that 0 as success, write intents such as fix-reviews can post applied and fix-ci can stop with no changes instead of returning the rate-limited/fallback status for a retry.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in commit 8d4e2cc. The copilot case in run_writer now returns exit 2 immediately (text-only, no Write/Edit tool access) instead of calling copilot_chat and returning 0. This ensures write intents never post a false status=applied or status=no-changes when copilot is reached — instead the retry cron re-triggers when a write-capable engine is available.

;;
Comment on lines 524 to 532

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The copilot engine implementation in run_writer is a functional regression. The previous code correctly identified that Copilot (via the GitHub Models API) is text-only and lacks tool-use capabilities (like Write or Edit), so it fell back to Claude to perform the actual file modifications. By removing this fallback and calling copilot_chat directly, the run_writer function will now "succeed" (exit 0) without actually applying any code changes. This will lead to confusing "no changes made by engine" messages in the calling scripts even when the model provides a valid fix in its text response.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in commit 8d4e2cc. The copilot case in run_writer now returns exit 2 immediately (with a ::notice:: message) rather than calling copilot_chat and returning 0. Exit 2 exhausts the fallback chain and causes run_writer_with_fallback to emit ::error::All engines rate-limited or unavailable — the calling scripts then post a status=rate-limited marker and the retry cron re-triggers when a write-capable engine (claude, gemini) is available again. No false 'no changes made' or 'applied' markers.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is not a good solution. Waiting for Claude to become available is not an acceptable solution. If we can't use Copilot with this architecture then we should disable it until we can design a valid approach.

Should we be using GitHub Agentic Workflows? https://github.github.com/gh-aw/

esac

Expand Down
13 changes: 5 additions & 8 deletions tests/dev-lead/unit/test_engine_fallback.bats
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,14 @@ STUBEOF
}

@test "fallback: all rate-limited → returns 2" {
# All engines exit 2
# All engines exit 2 (rate-limited). copilot calls copilot_chat directly
# (no claude fallback), so all three engines are independent paths.
_make_stub "claude" 2
_make_stub "gemini" 2
# copilot falls back to claude internally, so we only need claude and gemini
# Create a copilot stub that also fails with 2
cat > "$STUB_BIN_DIR/copilot" <<'STUBEOF'
#!/usr/bin/env bash
exit 2
STUBEOF
chmod +x "$STUB_BIN_DIR/copilot"
_source_engine "claude"
# Override copilot_chat to simulate copilot being rate-limited (exit 2 from run_writer)
copilot_chat() { echo "rate limit exceeded"; return 1; }
export -f copilot_chat

run run_writer_with_fallback "$TEST_PROMPT"

Expand Down
76 changes: 69 additions & 7 deletions tests/dev-lead/unit/test_engine_writer.bats
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,20 @@ _source_engine() {
[ "$status" -eq 0 ]
}

@test "writer: copilot falls back to claude in run_writer (internal)" {
# When REVIEW_ENGINE=copilot, run_writer internally falls back to claude
@test "writer: copilot uses copilot_chat directly (no claude fallback)" {
# When REVIEW_ENGINE=copilot, run_writer calls copilot_chat — NOT claude.
# Removing claude from PATH verifies the old fallback-to-claude bug is gone.
export COPILOT_API_MODEL="openai/o4-mini"
export COPILOT_GITHUB_TOKEN="stub-token"
_source_engine "copilot"
export STUB_ENGINE_EXIT=0
export DEV_LEAD_DRY_RUN=false
rm -f "$STUB_BIN_DIR/claude"
# Override copilot_chat after sourcing so no real curl call is made
copilot_chat() { echo "mock copilot text response"; return 0; }
export -f copilot_chat

run run_writer "$TEST_PROMPT"

# Should succeed because the internal claude stub is present
[ "$status" -eq 0 ]
}

Expand Down Expand Up @@ -178,7 +183,7 @@ STUB
@test "writer: run_writer_with_fallback retries all engines and returns 2 when all rate-limited" {
_source_engine "claude"
export DEV_LEAD_DRY_RUN=false
# All engines output rate-limit text and exit 1 → run_writer returns 2 for each
# claude and gemini stubs output rate-limit text and exit 1 → run_writer returns 2
for engine in claude gemini; do
cat > "$STUB_BIN_DIR/$engine" << 'STUB'
#!/usr/bin/env bash
Expand All @@ -187,8 +192,9 @@ exit 1
STUB
chmod +x "$STUB_BIN_DIR/$engine"
done
# Add copilot stub (falls back to claude internally)
cp "$STUB_BIN_DIR/claude" "$STUB_BIN_DIR/copilot"
# copilot calls copilot_chat (a function, not a binary); mock it to rate-limit
copilot_chat() { echo "rate limit exceeded"; return 1; }
export -f copilot_chat

run run_writer_with_fallback "$TEST_PROMPT"

Expand Down Expand Up @@ -240,3 +246,59 @@ STUB
result=$(cat /tmp/dev-lead-rate-limit-reset)
[ -z "$result" ]
}

# ── model_for_intent tests ─────────────────────────────────────────────────────

@test "model_for_intent: human-pr → ENGINE_TRIAGE_MODEL (haiku)" {
_source_engine "claude"
result=$(model_for_intent "human-pr")
[ "$result" = "$ENGINE_TRIAGE_MODEL" ]
}

@test "model_for_intent: fix-bot-comment → ENGINE_TRIAGE_MODEL (haiku)" {
_source_engine "claude"
result=$(model_for_intent "fix-bot-comment")
[ "$result" = "$ENGINE_TRIAGE_MODEL" ]
}

@test "model_for_intent: fix-reviews → ENGINE_ACTION_MODEL (sonnet)" {
_source_engine "claude"
result=$(model_for_intent "fix-reviews")
[ "$result" = "$ENGINE_ACTION_MODEL" ]
}

@test "model_for_intent: fix-ci → ENGINE_ACTION_MODEL (sonnet)" {
_source_engine "claude"
result=$(model_for_intent "fix-ci")
[ "$result" = "$ENGINE_ACTION_MODEL" ]
}

@test "model_for_intent: rebase → ENGINE_ACTION_MODEL (sonnet)" {
_source_engine "claude"
result=$(model_for_intent "rebase")
[ "$result" = "$ENGINE_ACTION_MODEL" ]
}

@test "model_for_intent: fix-issue → ENGINE_DEEP_MODEL (sonnet)" {
_source_engine "claude"
result=$(model_for_intent "fix-issue")
[ "$result" = "$ENGINE_DEEP_MODEL" ]
}

@test "model_for_intent: human → ENGINE_DEEP_MODEL (sonnet)" {
_source_engine "claude"
result=$(model_for_intent "human")
[ "$result" = "$ENGINE_DEEP_MODEL" ]
}

@test "model_for_intent: unknown intent → ENGINE_ACTION_MODEL (default)" {
_source_engine "claude"
result=$(model_for_intent "unknown-intent")
[ "$result" = "$ENGINE_ACTION_MODEL" ]
}

@test "model_for_intent: empty intent → ENGINE_ACTION_MODEL (default)" {
_source_engine "claude"
result=$(model_for_intent "")
[ "$result" = "$ENGINE_ACTION_MODEL" ]
}
19 changes: 19 additions & 0 deletions tests/dev-lead/unit/test_fix_ci.bats
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ setup() {
export PATH="$STUB_BIN_DIR:$PATH"
export STUB_BIN_DIR

# Stub curl so copilot_chat returns a 429 rate-limit response for GitHub Models API.
# This makes the copilot fallback behave as rate-limited without a real API call.
cat > "$STUB_BIN_DIR/curl" << 'CURLEOF'
#!/usr/bin/env bash
# Detect GitHub Models API calls and return a synthetic 429 response.
for arg in "$@"; do
if [[ "$arg" == *"models.github.ai"* ]]; then
echo '{"error":{"message":"rate limit exceeded","type":"rate_limit"}}'
echo "429"
exit 0
fi
done
# Non-API curl calls: pass through to system curl
exec /usr/bin/curl "$@"
CURLEOF
chmod +x "$STUB_BIN_DIR/curl"

# Default environment for fix-ci
export PR_NUMBER="42"
export HEAD_SHA="abc123def456"
Expand All @@ -27,6 +44,8 @@ setup() {
export REVIEW_ENGINE="claude"
export DEV_LEAD_DRY_RUN="true"
export GH_STUB_COMMENT_BODY=""
export COPILOT_GITHUB_TOKEN="stub-token"
export COPILOT_API_MODEL="openai/o4-mini"
# Point to project root for prompts
cd "$SCRIPT_DIR"
}
Expand Down
17 changes: 17 additions & 0 deletions tests/dev-lead/unit/test_fix_reviews.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ setup() {
export PATH="$STUB_BIN_DIR:$PATH"
export STUB_BIN_DIR

# Stub curl so copilot_chat returns a 429 rate-limit response for GitHub Models API.
# This makes the copilot fallback behave as rate-limited without a real API call.
cat > "$STUB_BIN_DIR/curl" << 'CURLEOF'
#!/usr/bin/env bash
for arg in "$@"; do
if [[ "$arg" == *"models.github.ai"* ]]; then
echo '{"error":{"message":"rate limit exceeded","type":"rate_limit"}}'
echo "429"
exit 0
fi
done
exec /usr/bin/curl "$@"
CURLEOF
chmod +x "$STUB_BIN_DIR/curl"

# Default env
export PR_NUMBER="54"
export HEAD_SHA="ddd444eee555"
Expand All @@ -27,6 +42,8 @@ setup() {
export GITHUB_REPOSITORY="petry-projects/.github-private"
export BASE_REF="main"
export ACTOR="donpetry"
export COPILOT_GITHUB_TOKEN="stub-token"
export COPILOT_API_MODEL="openai/o4-mini"

# Install a graphql-aware gh stub
cat > "$STUB_BIN_DIR/gh" <<'GHEOF'
Expand Down
Loading