This diagram shows the complete automated workflow for handling GitHub issues and PRs, including our intelligent retry strategies and worktree-based CI fixing.
flowchart TD
A[GitHub Agent Scan] --> B{Found Items?}
B -->|Yes| C[Categorize Items]
B -->|No| Z[Sleep & Retry]
Z --> A
C --> D[Issues with help wanted/bot]
C --> E[PRs with Conflicts]
C --> F[PRs with CI Failures]
%% Issue Handling
D --> D1{Issue in Progress?}
D1 -->|Yes| D2[Check Staleness]
D1 -->|No| D3{Concurrency Limit?}
D2 -->|Stale >15min| D4[Restart Worker]
D2 -->|Fresh| D5[Continue]
D3 -->|Under Limit| D6[Spawn Issue Worker]
D3 -->|At Limit| D7[Queue Issue]
D6 --> D8[Create Worktree]
D8 --> D9[Apply in-progress Label]
D9 --> D10[Claude Code Worker]
D10 --> D11{Success?}
D11 -->|Yes| D12[Create PR]
D11 -->|Crash| D13[Restart Counter]
D12 --> D14[Apply cerebruh Label]
D13 --> D15{Max Restarts?}
D15 -->|No| D4
D15 -->|Yes| D16[Mark Stalled]
%% PR Conflict Handling
E --> E1{Conflict Backoff?}
E1 -->|Yes| E2[Skip - In Backoff]
E1 -->|No| E3[Auto-rebase Attempt]
E3 --> E4{Rebase Success?}
E4 -->|Yes| E5[Push Updated Branch]
E4 -->|No| E6[Spawn Conflict Worker]
E6 --> E7[Create Conflict Worktree]
E7 --> E8[Manual Resolution]
E8 --> E9{Resolution Success?}
E9 -->|Yes| E5
E9 -->|No| E10[Increment Attempts]
%% PR CI Failure Handling
F --> F1[Analyze Failure Type]
F1 --> F2{Infrastructure Failure?}
F2 -->|Yes| F3{In Backoff?}
F2 -->|No| F4[Real CI Failure]
F3 -->|Yes| F5[Skip - Backoff Active]
F3 -->|No| F6[Apply Infrastructure Backoff]
F4 --> F7[Spawn Worker IMMEDIATELY]
F7 --> F8[Create CI Fix Worktree]
F8 --> F9[npm ci --silent]
F9 --> F10[Analyze Logs]
F10 --> F11[Apply Fixes]
F11 --> F12[Test Locally]
F12 --> F13{Tests Pass?}
F13 -->|Yes| F14[Push Fix]
F13 -->|No| F15[Debug & Retry]
F14 --> F16[Monitor CI]
%% Auto-merge Flow
F16 --> G{CI Passes?}
E5 --> G
D14 --> G
G -->|Yes| H{Has cerebruh Label?}
G -->|No| I[Wait for Fixes]
H -->|Yes| J{Age > 2min?}
H -->|No| K[Manual Review Needed]
J -->|Yes| L[AUTO-MERGE]
J -->|No| M[Wait for Age]
L --> N[Close Issue if Linked]
%% Failure Types
F2 -.->|timeout, cancelled, action_required| F3
F2 -.->|test failures, lint errors, build errors| F7
%% Backoff Strategy
F6 -.-> O[Backoff: 5, 15, 15, 15, 15, 15 min]
E10 -.-> P[Conflict Backoff: 5, 15, 15, 15, 15, 15 min]
%% Labels Applied
D9 -.-> Q[in-progress]
D14 -.-> R[cerebruh]
D16 -.-> S[stalled]
%% Cleanup
F14 --> T[Cleanup Worktree]
E8 --> T
D12 --> T
T --> A
classDef worktree fill:#e1f5fe
classDef immediate fill:#c8e6c9
classDef backoff fill:#ffcdd2
classDef label fill:#fff3e0
class D8,F8,E7 worktree
class F7,F4 immediate
class F5,E2,O,P backoff
class Q,R,S label
- Real CI Failures: Test failures, lint errors, build errors β Immediate worker spawn
- Infrastructure Failures: Timeouts, cancelled jobs, action_required β Backoff applied
- Each worker gets dedicated
/tmp/worktrees/directory - Clean dependency installation with
npm ci --silent - No cross-contamination between parallel work
- No artificial delays for actionable failures
- Real test failures get worker attention within seconds
- Backoffs only for temporary/infrastructure issues
in-progress: Issue has active workercerebruh: Ready for auto-mergestalled: Hit restart limits- No more broken CI state labels
- CI Fixes: Max 6 attempts with 5,15,15,15,15,15 min backoff (infrastructure only)
- Conflicts: Max 6 attempts with same backoff schedule
- Issues: Max 3 restarts per day with staleness detection
- Has
cerebruhlabel - All CI checks pass
- PR age > 2 minutes (safety buffer)
- Automatic issue closure if linked
- Issues: Max 2 concurrent workers
- PRs: Unlimited (each in isolated worktree)
- Total System: Balanced for machine performance
- β Fast response to real failures (no artificial delays)
- β Isolated workspaces prevent conflicts
- β Intelligent categorization of failure types
- β Self-healing automation with proper restart limits
- β Clean labeling for visibility
- β Efficient resource usage with worktrees