Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
36 changes: 29 additions & 7 deletions .github/workflows/dev-lead.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ jobs:
CHECKS_JSON: ${{ env.INTENT_CHECKS }}
REPO: ${{ github.repository }}
REVIEW_ENGINE: ${{ env.DEV_LEAD_ENGINE }}
run: bash scripts/dev-lead-fix-ci.sh
run: |
rc=0
bash scripts/dev-lead-fix-ci.sh || rc=$?
# exit 2 = rate-limited; script already posted a marker — not a workflow failure
[ "$rc" -eq 2 ] && exit 0 || exit "$rc"

# ── fix-reviews ───────────────────────────────────────────────────────
- name: Run fix-reviews
Expand All @@ -179,7 +183,10 @@ jobs:
HEAD_SHA: ${{ env.INTENT_HEAD_SHA }}
REPO: ${{ github.repository }}
REVIEW_ENGINE: ${{ env.DEV_LEAD_ENGINE }}
run: bash scripts/dev-lead-fix-reviews.sh
run: |
rc=0
bash scripts/dev-lead-fix-reviews.sh || rc=$?
[ "$rc" -eq 2 ] && exit 0 || exit "$rc"

# ── fix-bot-comment ───────────────────────────────────────────────────
- name: Run fix-bot-comment
Expand All @@ -191,7 +198,10 @@ jobs:
COMMENT_BODY: ${{ env.INTENT_COMMENT_BODY }}
REPO: ${{ github.repository }}
REVIEW_ENGINE: ${{ env.DEV_LEAD_ENGINE }}
run: bash scripts/dev-lead-fix-reviews.sh
run: |
rc=0
bash scripts/dev-lead-fix-reviews.sh || rc=$?
[ "$rc" -eq 2 ] && exit 0 || exit "$rc"

# ── human ─────────────────────────────────────────────────────────────
- name: Run human
Expand All @@ -203,7 +213,10 @@ jobs:
USER_INSTRUCTION: ${{ env.INTENT_COMMENT_BODY }}
REPO: ${{ github.repository }}
REVIEW_ENGINE: ${{ env.DEV_LEAD_ENGINE }}
run: bash scripts/dev-lead-fix-reviews.sh
run: |
rc=0
bash scripts/dev-lead-fix-reviews.sh || rc=$?
[ "$rc" -eq 2 ] && exit 0 || exit "$rc"

# ── human-pr ──────────────────────────────────────────────────────────
- name: Run human-pr
Expand All @@ -213,7 +226,10 @@ jobs:
HEAD_SHA: ${{ env.INTENT_HEAD_SHA }}
REPO: ${{ github.repository }}
REVIEW_ENGINE: ${{ env.DEV_LEAD_ENGINE }}
run: bash scripts/dev-lead-fix-reviews.sh
run: |
rc=0
bash scripts/dev-lead-fix-reviews.sh || rc=$?
[ "$rc" -eq 2 ] && exit 0 || exit "$rc"

# ── issue ─────────────────────────────────────────────────────────────
- name: Run issue
Expand All @@ -222,7 +238,10 @@ jobs:
ISSUE_NUMBER: ${{ env.INTENT_ISSUE_NUMBER }}
REPO: ${{ github.repository }}
REVIEW_ENGINE: ${{ env.DEV_LEAD_ENGINE }}
run: bash scripts/dev-lead-fix-issue.sh
run: |
rc=0
bash scripts/dev-lead-fix-issue.sh || rc=$?
[ "$rc" -eq 2 ] && exit 0 || exit "$rc"

# ── rebase ────────────────────────────────────────────────────────────
- name: Run rebase
Expand All @@ -231,7 +250,10 @@ jobs:
PR_NUMBER: ${{ env.INTENT_PR_NUMBER }}
REPO: ${{ github.repository }}
REVIEW_ENGINE: ${{ env.DEV_LEAD_ENGINE }}
run: bash scripts/dev-lead-fix-reviews.sh
run: |
rc=0
bash scripts/dev-lead-fix-reviews.sh || rc=$?
[ "$rc" -eq 2 ] && exit 0 || exit "$rc"

# ── enable-auto-merge ─────────────────────────────────────────────────
# Triggered when a trusted bot approves a PR. Skips engine install and
Expand Down
15 changes: 14 additions & 1 deletion scripts/dev-lead-fix-issue.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,20 @@ main() {
local pre_engine_sha
pre_engine_sha=$(git rev-parse HEAD)

if ! run_writer_with_fallback "$prompt_file"; then
local engine_rc=0
run_writer_with_fallback "$prompt_file" || engine_rc=$?
if [ "$engine_rc" -eq 2 ]; then
echo "::warning::All engines rate-limited — cannot implement issue #${ISSUE_NUMBER}; re-apply the label to retry"
local reset_msg=""
if [ -f /tmp/dev-lead-rate-limit-reset ]; then
local reset_time
reset_time=$(cat /tmp/dev-lead-rate-limit-reset)
[ -n "$reset_time" ] && reset_msg=" The limit is expected to reset at ${reset_time}."
fi
gh issue comment "$ISSUE_NUMBER" --repo "$REPO" --body "<!-- dev-lead-rate-limited -->All engines are currently rate-limited.${reset_msg} Please re-apply the \`dev-lead\` label when the rate limit clears to retry." 2>/dev/null || true
rm -f "$prompt_file"
exit 2
elif [ "$engine_rc" -ne 0 ]; then
echo "::error::Engine failed to implement issue #${ISSUE_NUMBER}"
rm -f "$prompt_file"
exit 1
Expand Down
99 changes: 99 additions & 0 deletions tests/dev-lead/unit/test_fix_issue.bats
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,102 @@ GHEOF
# Dry-run message contains reference to the issue
[[ "$output" == *"issue #${ISSUE_NUMBER}"* ]]
}

# ── rate-limit handling tests ─────────────────────────────────────────────────

@test "fix-issue: rate-limited: all engines rate-limited → exits 2, not 1" {
# Override engine stubs to emit a rate-limit message and exit 1
for engine in claude gemini; do
cat > "$STUB_BIN_DIR/$engine" <<'STUB'
#!/usr/bin/env bash
echo "You've hit your limit · resets 11:20pm (UTC)"
exit 1
STUB
chmod +x "$STUB_BIN_DIR/$engine"
done
export COPILOT_GITHUB_TOKEN="stub-token"

# Stub git to avoid real branch creation in the workspace
cat > "$STUB_BIN_DIR/git" <<'GITEOF'
#!/usr/bin/env bash
case "$*" in
"config"*) exit 0 ;;
"checkout"*) exit 0 ;;
"rev-parse HEAD") echo "abc123deadbeef" ;;
*) exit 0 ;;
esac
GITEOF
chmod +x "$STUB_BIN_DIR/git"

# gh stub: no existing PRs, issue API, comment posts ok, copilot rate-limited
cat > "$STUB_BIN_DIR/gh" <<'GHEOF'
#!/usr/bin/env bash
case "$*" in
*"pulls?state=open"*) echo "0" ;;
*"api"*"repos/"*"issues/"*) echo '{"title":"Test Issue","body":"Test body"}' ;;
*"api"*"users/"*) echo '{"id":12345}' ;;
*"issue comment"*) exit 0 ;;
*"copilot"*) echo "rate limit exceeded"; exit 1 ;;
*) echo "{}" ;;
esac
GHEOF
chmod +x "$STUB_BIN_DIR/gh"

export DEV_LEAD_DRY_RUN="false"

run bash "$FIX_ISSUE_SCRIPT"

# Must exit 2 (rate-limited), not 1 (engine error)
[ "$status" -eq 2 ]
[[ "$output" == *"rate-limited"* ]] || [[ "$output" == *"rate limited"* ]]
[[ "$output" != *"Engine failed"* ]]
}

@test "fix-issue: rate-limited: posts comment on issue before exiting" {
for engine in claude gemini; do
cat > "$STUB_BIN_DIR/$engine" <<'STUB'
#!/usr/bin/env bash
echo "rate limit exceeded"
exit 1
STUB
chmod +x "$STUB_BIN_DIR/$engine"
done
export COPILOT_GITHUB_TOKEN="stub-token"

local comment_posted_sentinel
comment_posted_sentinel="$(mktemp)"
rm "$comment_posted_sentinel" # deleted; presence after run = was posted

cat > "$STUB_BIN_DIR/git" <<'GITEOF'
#!/usr/bin/env bash
case "$*" in
"config"*) exit 0 ;;
"checkout"*) exit 0 ;;
"rev-parse HEAD") echo "abc123deadbeef" ;;
*) exit 0 ;;
esac
GITEOF
chmod +x "$STUB_BIN_DIR/git"

cat > "$STUB_BIN_DIR/gh" <<GHEOF
#!/usr/bin/env bash
case "\$*" in
*"pulls?state=open"*) echo "0" ;;
*"api"*"repos/"*"issues/"*) echo '{"title":"Test","body":"body"}' ;;
*"api"*"users/"*) echo '{"id":12345}' ;;
*"issue comment"*) touch "${comment_posted_sentinel}"; exit 0 ;;
*"copilot"*) echo "rate limit exceeded"; exit 1 ;;
*) echo "{}" ;;
esac
GHEOF
chmod +x "$STUB_BIN_DIR/gh"

export DEV_LEAD_DRY_RUN="false"

run bash "$FIX_ISSUE_SCRIPT"

[ "$status" -eq 2 ]
[ -f "$comment_posted_sentinel" ]

rm -f "$comment_posted_sentinel" 2>/dev/null || true
}
Loading