Commit 9699138
feat: add backup agent failover for review jobs (#283)
## Human summary
I found myself hitting codex limits really quickly and then dumping back
to copilot in this case. I wanted a way to automate this so I didnt have
to keep switching the config.toml. This PR adds a `*backup_agent`
setting as a fallback in case the review fails.
Coincidentally while making this PR I ran out of codex and the fallback
worked perfectly!
## Summary
- Add per-workflow and default backup agent configuration
(`default_backup_agent`, `review_backup_agent`, etc.) with the same
repo-overrides-global priority as primary agents
- Implement failover in the worker pool: when an agent error exhausts
retries, the worker resolves the backup agent from config and requeues
the job with the new agent
- Distinguish agent errors (eligible for failover) from non-agent errors
(prompt build failures) in the worker's retry logic
- No schema migration — backup agent is resolved from config at failover
time, not stored per-job
## Changes
- `internal/config/config.go` — backup agent fields on
`Config`/`RepoConfig`, `ResolveBackupAgentForWorkflow` resolution
- `internal/storage/jobs.go` — `FailoverJob(jobID, workerID,
backupAgent)` atomically swaps agent and requeues
- `internal/daemon/worker.go` — `resolveBackupAgent` reads config at
failover time, canonicalizes (verify installed, skip if same as
primary), `failOrRetryAgent` path with failover split from `failOrRetry`
- Tests for config resolution, storage failover, worker-level backup
agent resolution, and edge cases
## Test plan
- [x] `go test ./...` passes
- [ ] Verify failover works end-to-end: configure `backup_agent`,
trigger a review with a failing primary agent, confirm job retries with
the backup
- [ ] Verify no failover when `backup_agent` is unset (existing behavior
unchanged)
- [ ] Verify second failover with same backup is a no-op (agent already
swapped)
---------
Co-authored-by: Wes McKinney <wesmckinn+git@gmail.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent 7d4040c commit 9699138
File tree
11 files changed
+773
-68
lines changed- internal
- config
- daemon
- storage
11 files changed
+773
-68
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| |||
92 | 93 | | |
93 | 94 | | |
94 | 95 | | |
95 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
96 | 105 | | |
97 | 106 | | |
98 | 107 | | |
| |||
348 | 357 | | |
349 | 358 | | |
350 | 359 | | |
| 360 | + | |
351 | 361 | | |
352 | 362 | | |
353 | 363 | | |
| |||
402 | 412 | | |
403 | 413 | | |
404 | 414 | | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
405 | 422 | | |
406 | 423 | | |
407 | 424 | | |
| |||
729 | 746 | | |
730 | 747 | | |
731 | 748 | | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
732 | 798 | | |
733 | 799 | | |
734 | 800 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
1227 | 1228 | | |
1228 | 1229 | | |
1229 | 1230 | | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
1230 | 1326 | | |
1231 | 1327 | | |
1232 | 1328 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
427 | 427 | | |
428 | 428 | | |
429 | 429 | | |
430 | | - | |
| 430 | + | |
431 | 431 | | |
432 | 432 | | |
433 | 433 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1278 | 1278 | | |
1279 | 1279 | | |
1280 | 1280 | | |
1281 | | - | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
1282 | 1284 | | |
1283 | 1285 | | |
1284 | 1286 | | |
| |||
1291 | 1293 | | |
1292 | 1294 | | |
1293 | 1295 | | |
1294 | | - | |
1295 | | - | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
1296 | 1300 | | |
1297 | 1301 | | |
1298 | 1302 | | |
| |||
1313 | 1317 | | |
1314 | 1318 | | |
1315 | 1319 | | |
1316 | | - | |
1317 | | - | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
1318 | 1324 | | |
1319 | 1325 | | |
1320 | 1326 | | |
| |||
1332 | 1338 | | |
1333 | 1339 | | |
1334 | 1340 | | |
1335 | | - | |
1336 | | - | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
1337 | 1345 | | |
1338 | 1346 | | |
1339 | 1347 | | |
1340 | 1348 | | |
1341 | | - | |
1342 | | - | |
1343 | | - | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
1344 | 1354 | | |
1345 | 1355 | | |
1346 | 1356 | | |
| |||
1388 | 1398 | | |
1389 | 1399 | | |
1390 | 1400 | | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
1391 | 1404 | | |
1392 | 1405 | | |
1393 | 1406 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1591 | 1591 | | |
1592 | 1592 | | |
1593 | 1593 | | |
1594 | | - | |
| 1594 | + | |
1595 | 1595 | | |
1596 | 1596 | | |
1597 | 1597 | | |
| |||
0 commit comments