fix: fail fast on structural worktree-setup failures instead of retry-looping - #486
Conversation
execute_work's "claim succeeded but no worktree was created" and "failed to chdir into <worktree>" paths were structural git-state failures (e.g. a stale prunable worktree registration, confirmed live for items #465/#466) that retry identically every time, but went through the normal max_retries backoff budget before the terminal- failure recovery hook could swap the item off `dispatched`. Add a `fatal` flag to JobFailure/WorkOutcome that Queue::fail uses to skip straight to terminal `state=failed` regardless of retries remaining, and set it on those two setup-failure branches. Agent-run failures are unaffected and keep the existing retry/cooldown behavior. dispatch_item's ready-for-work/dispatched label-flip timing is untouched. Agentflare-Agent: claude-code Agentflare-Branch: task/467-fail-fast-on-structural-worktree-setup-f Agentflare-Item: 467
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThe change adds fatal status to job failures, maps structural worktree failures to fatal outcomes, propagates failure status through workers, and prevents fatal jobs from entering retry handling. ChangesFatal failure handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The change makes structural worktree-setup failures terminal instead of retrying them, while preserving retries for agent-run failures. No actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Commit landed cleanly with trailers auto-added by the repo's hook. Work is committed and verified.
Summary
Item #465/#466's incident:
execute_work's structural setup-failure paths (no worktree created, or a claimed worktree that can't be chdir'd into — both caused by broken git state, like a stale prunable worktree registration) were retried through the normalmax_retriesbackoff budget even though the underlying cause can't change between attempts. This delayed reaching terminalstate=failed, where the existinghandle_terminal_job_failurehook would swap the item offdispatchedback to discoverable.Change: added a
fatal: boolflag threaded throughJobFailure(agentflare-jobs) →WorkOutcome(cli/work.rs) →Queue::fail, which now skips the retry budget entirely and marks the job terminal immediately whenfatalis set, regardless of retries remaining.crates/agentflare-jobs/src/executor.rs:JobFailuregainsfatal.crates/agentflare-jobs/src/queue.rs:Queue::failtakes afatalparam;retried = !fatal && retries < max_retries. Added testfail_fatal_marks_failed_immediately_even_with_retries_remaining.crates/agentflare-jobs/src/worker.rs: threadsfatalthroughrecord_fail/queue.failcall sites.src/cli/work.rs:WorkOutcomegainsfatal; the "no worktree created" and "failed to chdir into worktree" branches now setfatal: true; the agent-run failure branch staysfatal: false(unaffected, keeps existing retry/cooldown behavior). Extracted theWorkOutcome → JobFailuremapping intojob_failure_forso it's unit-testable without a real claim/worktree cycle; added two tests covering both the fatal and non-fatal mapping.Did not touch
src/supervisor.rs—dispatch_item'sready-for-work→dispatchedlabel-flip timing is unchanged, andorphan_reconcile.rs's terminal-failure-hook tests pass unmodified.Verified:
cargo fmt --check,cargo clippy --workspace --all-features [--tests] -A unsafe_code -A clippy::pedantic -D warnings,cargo test -p agentflare-jobs(31 passed), and thecli::work/dashboard::orphan_reconciletest modules in the main binary (51 passed) — all green.Summary by CodeRabbit
Bug Fixes
Tests