Repository navigation
fix(goals): rebuild a pruned goal worktree on recovery instead of failing forever - #3366
Conversation
…ling forever A live goal whose saved checkout disappeared (for example pruned by the host cleanup timer after its container exited) could never recover: the worker job threw "Saved goal worktree is missing" out of preparation, which left the attempt claimed with a dead heartbeat, and the recovery sweep re-enqueued it ~every 2.5 minutes indefinitely. The task kept reporting "Resuming native goal session" so the goal looked alive in the UI. The rebuild logic already existed for operator-continued terminal goals but was gated behind continue_requested. Extract it into restoreMissingGoalWorktree and call it from ensureGoalWorktree, so a missing checkout is rebuilt from the published branch (same directory name, so the saved provider session resumes against the same mount path). The resumed session is told its checkout was rebuilt and that uncommitted work is gone. When the branch itself no longer exists on the remote there is nothing to resume from, so preparation now finalizes the goal as failed (via the same path continued-goal preparation failures use) instead of throwing, which is what recovery would otherwise relaunch forever. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
/review |
|
✅ AI Code Review Complete requested by @integry Posted 1 review: |
🔍 AI Code Review — claude:claude-opus-5-5Overall EvaluationThis PR fixes an infinite recovery loop. When a live goal's checkout was pruned, The fix has three parts:
I traced the restore path against the claim fences, the recovery producer ( ✅ Faithful reuse of hardened logic — ✅ Fenced path persistence — When the rebuild lands at a different path, the new ✅ Terminal handling for the lost-branch case — Merge blockersNo merge blockers. SuggestionsThese are optional follow-ups and are not sent to S1: 🟢 Other permanent restore failures still loop
That conflicts with the PR's stated principle that "no prepare failure should leave an attempt claimed with a dead heartbeat." This is not a regression, because these cases already threw before the PR. Classifying such errors as terminal (excluding claim-loss and transient errors) or landing the recovery attempt cap from the follow-up list would close the remaining loop shapes. S2: 🟢
|
|
/review astra |
|
✅ AI Code Review Complete requested by @integry Posted 1 review: |
🔍 AI Code Review — astraOverall EvaluationThe PR adds a useful restoration path, but needs changes before merge: restoration errors can still reproduce the recovery loop, and some resumed sessions never receive the checkout-loss notice. ✅ Preserved checkout identity — Restoration reuses the saved directory name and branch; a changed path is persisted under the attempt claim. ✅ Confirmed branch loss — The restoration dependency checks repository access before treating a missing remote ref as lost work. ✅ Fenced retries — Transient failures recheck attempt ownership before retrying, with a test covering takeover during failure. The supplied checks show no failures and four pending test shards. This review uses static analysis of the supplied code; no commands were run. Merge blockersEvery finding below was introduced by this PR and must be resolved before merging. F1: 🔴 Other restoration failures retain the recovery loop
F2: 🔴 Restoration notices can disappear before delivery
SuggestionsThese are optional follow-ups and are not sent to S6: 🟢 Bound automatic recovery attemptsThe proposed recovery cap remains a useful separate follow-up. Recovery currently rotates generations without a bound, so unrelated future worker failures could produce the same operational symptom. This is broader hardening beyond correcting the restoration paths in this PR. ScoreThe restoration mechanism and claim-aware retry handling are sound improvements, but incomplete failure settlement and notice delivery leave two correctness gaps. Passing checks do not cover these sequences; four test shards remain pending. Score: 6/10 🤖 Review Details
Copy and edit to choose records from this review: 🤖 Review by ProPR |
|
/fix |
|
✅ Applied the requested follow-up changes in commit d3f7eb0
Summary of ChangesImplemented F1 and F2 only.
🤖 Implementation Details
Undo Changes • View Task Execution 💡 ProPR Slash Commands
🤖 Generated by ProPR |
Implemented F1 and F2 only. - Restoration failures now settle through fenced preparation failure handling while preserving saved recovery identities. - Durable restoration notices survive preparation exits and reach providers without conflating native user-input acknowledgements. - All 50 focused tests pass. TypeScript, ESLint, and diff checks pass. PR: #3366 Comment by: @integry (ID: 6483413357) Model: GPT-6.1 Sol
|
/review astra |
|
✅ AI Code Review Complete requested by @integry Posted 1 review: |
🔍 AI Code Review — astraOverall EvaluationThe PR addresses missing-checkout recovery with shared restoration logic and durable agent notices, but two failure paths still need correction before merge. ✅ Fenced persistence — Worktree updates and restoration notices share a transaction guarded by task, generation, claim, and nonterminal state. ✅ Preparation failures settle — Checkout errors now reach goal finalization, with tests covering permanent failures, exhausted transient retries, and takeover. Review verification was static only, as requested. Current checks show no failures and five pending. Merge blockersEvery finding below was introduced by this PR and must be resolved before merging. F3: 🔴 Pending notices cause unlimited failed attempts
F4: 🔴 Rebuild completion can lose its notice
SuggestionsThese are optional follow-ups and are not sent to No suggestions. ScoreThe implementation has useful fencing and focused coverage, but unsuccessful execution can loop indefinitely and worker interruption can silently lose the restoration warning. Both require localized corrections. Score: 5/10 🤖 Review Details
Copy and edit to choose records from this review: 🤖 Review by ProPR |
|
/ultrafix |
|
🔄 Ultrafix loop started (goal: 8/10, max cycles: 10) First action:
|
|
✅ Applied the requested follow-up changes in commit fc0c16e
Summary of ChangesImplemented F3 and F4 only.
Validation: all 62 focused tests pass; TypeScript, source ESLint, and diff checks pass. No visual preview needed. 🤖 Implementation Details
Undo Changes • View Task Execution 💡 ProPR Slash Commands
🤖 Generated by ProPR |
Implemented F3 and F4 only. - Pending restoration notices no longer trigger retries after permanent execution failures. - Both rebuild paths persist fenced notice obligations before filesystem changes and retain them through worker recovery until delivery. - Added regressions for interruptions, claim takeovers, delivery, and failure scheduling. Validation: all 62 focused tests pass; TypeScript, source ESLint, and diff checks pass. No visual preview needed. PR: #3366 Comment by: @integry (ID: 6483786934) Model: GPT-6.1 Sol
|
✅ AI Code Review Complete requested by @propr-ultrafix Posted 1 review: |
🔍 AI Code Review — claude:claude-opus-5-5Overall EvaluationThe PR fixes the endless relaunch loop for a live goal whose saved checkout was pruned. There are three parts to the fix:
The fencing work is careful. The obligation is committed under a One defect remains. The durable notice outlives the cases where its text is true. When the goal moves to a fresh branch, the agent is told its checkout holds the last published checkpoint when it actually holds only the base branch. This needs a small fix before merge. ✅ Obligation-before-mutation ordering — ✅ Prepare failures can no longer leave a claimed zombie — ✅ Independent acknowledgement identities — for native providers, Merge blockersEvery finding below was introduced by this PR and must be resolved before merging. F5: 🔴 Restoration notice survives a move to a fresh branch and misinforms the agent
SuggestionsThese are optional follow-ups and are not sent to S7: 🟢 Transient rebuild failures now fail the goal terminally
S8: 🟢 Pending notice can re-trigger "continuing" on native successFor native providers, a successful run that never steered the notice re-enqueues the goal, because S9: 🟢 Skipped control acknowledgement on failed restoration-only turnsWhen S10: 🟢 Unused
|
|
✅ Applied the requested follow-up changes in commit 5aefc43
Summary of ChangesAddressed F5 only. Both fresh-branch paths now supersede pending restoration notices atomically with the branch reset. Regressions cover deleted branches, merged PRs, notices retained after failures, and claim loss during awaited operations. Both test files pass; source ESLint passes. No visual preview needed for this backend change. 🤖 Implementation Details
💡 ProPR Slash Commands
🤖 Generated by ProPR |
…nding restoration notices atomically with the branch reset. Addressed F5 only. Both fresh-branch paths now supersede pending restoration notices atomically with the branch reset. Regressions cover deleted branches, merged PRs, notices retained after failures, and claim loss during awaited operations. Both test files pass; source ESLint passes. No visual preview needed for this backend change. PR: #3366 Comment by: @propr-ultrafix (ID: 0) Model: GPT-6.1 Sol
|
✅ AI Code Review Complete requested by @propr-ultrafix Posted 1 review: |
🔍 AI Code Review — claude:claude-opus-5-5Overall EvaluationThe PR fixes a recovery loop. A live goal whose saved checkout was pruned no longer throws out of
I traced the claim/fence paths, the four restore failure modes, the pause, takeover and interruption interleavings, and the provider delivery paths. All of them hold up, and CI is fully green. I found no merge blockers. The PR is ready to merge, with a few optional follow-ups below. ✅ Obligation committed before external mutation —
✅ No prepare failure leaves a claimed, stale attempt —
✅ Failure-safe acknowledgement and scheduling —
Merge blockersNo merge blockers. SuggestionsThese are optional follow-ups and are not sent to S11: 🟢 Transient rebuild outage now terminal for live goals
S12: 🟢 Rejected-checkpoint feedback suppressed by a pending notice
S13: 🟢 Fresh whole-session start pauses on a pending noticeFor a whole-session provider with no S14: 🟢 Check other goal_inputs consumers for the new kind
S15: 🟢 Restoration runs before the cancelled/paused boundary check
ScoreThe PR closes the reported recovery loop with properly fenced, durable restoration, and its tests are thorough across the takeover, interruption and provider paths. CI is green, and no verified blockers remain. Score: 8/10 🤖 Review Details
Copy and edit to choose records from this review: 🤖 Review by ProPR |
…) into the branch and added both fixes to the 0.9.0 release notes. One catch: this is not a real merge commit, because `git merge` can't run in this workspace. Git's metadata folder is read-only here, so it failed trying to write `ORIG_HEAD`. Instead I made the working tree match what the merge would produce: I brought `main` (`2727fe3ad`, which includes #3364 and #3366) into the branch and added both fixes to the 0.9.0 release notes. One catch: this is not a real merge commit, because `git merge` can't run in this workspace. Git's metadata folder is read-only here, so it failed trying to write `ORIG_HEAD`. Instead I made the working tree match what the merge would produce: - **Files only `main` changed** (8 of them, from the two PRs) were copied over from `origin/main` unchanged. - **`src/jobs/processGoalJob.ts`** was changed on both sides, so I combined it with a three-way merge. There were no conflicts, and the only difference from `main` is this branch's earlier agent-failure-reason change. When ProPR commits this, the commit will have one parent rather than two, so GitHub may still show the branch as behind `main`. The contents will merge cleanly either way. If you need a true merge commit, use ProPR's merge-from-main flow. **Release notes:** - **`CHANGELOG.md`**: no existing bullet covered goal recovery, and **Worker restarts** under 0.9.0 **Fixed** already covers worker recovery and storage claims. So I added both fixes to that bullet rather than starting new ones. - **`docs/release-0.9.0-audit.md`**: I added a "Later merges" note to the end of the 2026-10-29 section. It lists #3364 and #3366 and says the release scope now runs through `2727fe3ad`. Nothing else changed. There's nothing visual here, so I made no previews. **Checks:** - `EXPECTED_VERSION=0.9.0 RELEASE_TAG=v0.9.0 RELEASE_CANDIDATE=true npm run release:verify`: passed ("Release metadata is consistent for v0.9.0"). - `node --test test/releaseValidation.test.mjs`: all 15 tests passed. - `git diff --check` is clean, and eslint with zero warnings allowed passes on the merged `processGoalJob.ts`. - `test/processGoalJob.test.ts` (18), `test/goalContinuation.test.ts` (46) and `test/workerTaskStateRecovery.test.ts` (11) all pass when run one file at a time. Running all three in a single `tsx --test` command gave 46 failures. I put that down to the files clashing with each other rather than the merge, since every file passes alone, but I didn't confirm it. I didn't merge, tag, publish or deploy anything. PR: #3368 Comment by: @integry (ID: 6484905795) Model: Claude Opus 5.5
Problem
Goal
5db30345ran for 4+ hours showing "running" in the UI while nothing was executing. Its worktree under/tmp/git-processor/worktrees/...had been pruned by the host cleanup timer after the agent container exited. From then on:goalRecovery.tssaw a running, claimed goal with a dead heartbeat, no live container, and a saved session + worktree path, so it rotated the generation and enqueued a new job.ensureGoalWorktreethrewSaved goal worktree is missing; exact-session recovery cannot continue.processGoalJobuncaught. The BullMQ job failed (attempts: 1) with the attempt still claimed, which is exactly the shape step 1 recovers.Result: 121 generations, a failed job every ~2.5 minutes, and a task history full of "Resuming native goal session" that made the goal look alive.
Fix
prepareContinuedGoal, but only ran for operator-continued terminal goals (continue_requested). It is extracted intorestoreMissingGoalWorktreeandensureGoalWorktreenow calls it when the saved directory is gone. The worktree is recreated under the same directory name, so the saved provider session resumes against the same mount path. The branch carries every published checkpoint; only uncommitted work is lost.restoreMissingGoalWorktreethrowsGoalWorktreeLostErrorand preparation finalizes the goal as failed through the same path continued-goal preparation failures use. No prepare failure should leave an attempt claimed with a dead heartbeat, because recovery relaunches that forever.failContinuedGoalis generalized tofailGoalPreparation; the transient-retry and claim-guard helpers are shared between the continue and restore paths.Tests
test/goalContinuation.test.ts: live goal rebuilt in place, rebuilt at a new path is saved under the claim, existing checkout untouched, lost branch throwsGoalWorktreeLostError, takeover during a transient rebuild error prevents retry.test/processGoalJob.test.ts:ensureGoalWorktreeuses the restore path for a missing checkout, skips it for an existing one, and surfacesGoalWorktreeLostError.Both files pass (39 tests). ESLint is clean on the changed sources;
tsc --noEmitreports no errors in the touched files (the remaining errors are pre-existing inpackages/api/mcp,hooklessGit.ts, andscripts/generate-openapi.ts).Follow-ups not in this PR
recoverClaimedAttemptwould bound any future unrecoverable prepare error.🤖 Generated with Claude Code