Repository navigation
fix(storage): reclaim the lifecycle gate of a dead holder and stop recovery steps piling up - #3364
Conversation
…covery steps piling up The storage lifecycle gate (a directory shared by every service container) had no owner record or expiry, and every job, indexing scan and release waited for it forever without logging. When the worker died of a heap OOM while holding it, the restarted worker picked up 10 jobs that never logged a line, indexing froze, and goal recovery piled up one copy per minute for hours until the gate was removed by hand. The holder now records itself (container, pid, start time) inside the gate. A waiter probes the holder every 5 s and removes a gate whose holder is gone; a gate with no record is abandoned after 10 minutes. Release only removes the gate this call took, so a holder wrongly judged dead cannot remove its successor's gate. Waits are reported every minute with the holder, unless the caller supplies its own warning. The worker's recovery pass abandons a step that exceeds its budget but cannot cancel it; starting the step again every minute piled up dozens of copies (93 goal-recovery runs in a heap snapshot) and is the likely cause of the OOM. A step is now skipped, with a warning, while its previous run is still pending. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
/review fable astra |
|
✅ AI Code Review Complete requested by @integry Posted 2 reviews: |
🔍 AI Code Review — fableOverall EvaluationThe PR addresses a real production freeze with two targeted changes: the storage lifecycle gate now carries an owner record so a waiter can reclaim a gate whose holder is provably gone (reusing the existing Two correctness problems in the changed code block merge. The reclaim path acts on stale evidence across an awaited ✅ Token-scoped release — ✅ Proof-based reclaim, not TTL — Reclaiming an owned gate goes through the existing ✅ In-flight guard is settle-safe — Merge blockersEvery finding below was introduced by this PR and must be resolved before merging. F1: 🔴 Reclaim can remove a live successor's gate, breaking mutual exclusion
F2: 🔴
|
🔍 AI Code Review — astraOverall EvaluationThe PR addresses abandoned storage gates and accumulating recovery promises, but needs changes before merge: concurrent reclamation can break mutual exclusion, and recovery steps now start before their deadline is checked. ✅ Pending-step tracking — Unfinished recovery promises remain tracked after timeout, and both fulfillment and rejection remove them from the map. ✅ Operational visibility — Default admission/release waits now report the holder periodically while preserving caller-supplied warnings. ✅ Focused coverage — Tests cover dead and live holders, ownerless grace periods, and pending-step suppression. All reported current-head checks passed or were skipped. Merge blockersEvery finding below was introduced by this PR and must be resolved before merging. F3: 🔴 Concurrent reclaimers can delete a successor’s gate
F4: 🔴 Recovery starts work after its budget expires
SuggestionsThese are optional follow-ups and are not sent to S7: 🟢 Cover rejected pending stepsThe new recovery test exercises fulfillment after timeout. A companion test where that pending promise rejects would confirm that rejection is handled and the step becomes eligible again. The implementation already attaches both settlement handlers, so this is optional coverage. ScoreThe change is focused and has passing checks, but the reclamation race compromises the storage barrier, and the recovery wrapper regresses deadline enforcement. Both require correction before merge. Score: 5/10 🤖 Review Details
Copy and edit to choose records from this review: 🤖 Review by ProPR |
|
/fix all |
|
✅ Applied the requested follow-up changes in commit 08c4b30
Summary of ChangesAll selected records are applied and verified. No visual previews: nothing here is user-visible UI. F1 / F3, gate reclaim atomicity (
F2 / F4, step start after budget (
Suggestions
Verification
Independent observations, not acted on: the ownerless-grace 🤖 Implementation Details
Undo Changes • View Task Execution 💡 ProPR Slash Commands
🤖 Generated by ProPR |
…eviews: nothing here is user-visible UI. All selected records are applied and verified. No visual previews: nothing here is user-visible UI. **F1 / F3, gate reclaim atomicity** (`packages/core/src/storage/lifecycle.ts`) - The holder's record is now named by its own token, `owner-<token>`, instead of a fixed `owner` file. A reclaim unlinks the record under the name it probed, so the kernel's unlink is the compare-and-remove: a successor's record has a different name and survives. The waiter whose unlink fails with `ENOENT` lost the race and keeps waiting. - Only the winner removes the then-recordless directory. Nothing else can act on it in that window: `mkdir` sees it, its fresh mtime is far from the ownerless grace, and there is no record left to unlink. - Release uses the same conditional unlink. A holder wrongly judged dead finds its own record gone and leaves the successor's gate alone. - I did not use the rename-to-tombstone approach F1 proposed. A rename moves whatever is at the gate path, so a reread followed by a rename still has the window F3 points out. Unlink by token-specific name has no such window. - Acquisition retries if its record write hits `ENOENT`, which closes the only remaining microsecond hazard where an ownerless-grace sweep removes a freshly created empty gate. The ownerless path also removes stale leftover entries only by the names it saw. - Regression: two `StorageLifecycle` instances wait on a dead holder's gate, one with a probe that answers only after the other has reclaimed and entered its callback. The late waiter does not enter, the holder's record survives, and exactly one reclaim is logged. The test fails on an unguarded-unlink variant with the mutual-exclusion break and passes on the fix. **F2 / F4, step start after budget** (`src/workerTaskStateRecovery.ts`) - `runStep` now starts and registers the step inside the thunk handed to `runWithinDeadline`, so the deadline and abort checks run before the step is invoked. Regression: reconciliation consumes the whole budget and neither `resumePending` nor `recoverGoals` is invoked, the lease is released, and the next pass runs both. This fails on the branch's previous `runStep`. **Suggestions** - S1: the first holder probe waits a full interval. A new `orphanCheckMs` option lets tests shorten it. A test asserts no probe is spawned during a wait shorter than the interval. - S2, S3, S6: `maintenance.md` now scopes automatic reclaim to Docker-hosted services with the manual unblock for native installs, describes precisely when the gate is held, and documents the ownerless grace as a bounded TTL during mixed-version upgrades, with a matching note in the upgrade steps. The class comment states the same exception. - S4: step results are logged unless the step was skipped (`!== null`), restoring the previous logging contract for any return type. - S5: the pending-step test awaits the "Failed to reconcile" log call instead of a fixed sleep. - S7: a companion test rejects the pending step late and asserts the step becomes eligible again with no unhandled rejection. **Verification** - Gate suite 8 passed, recovery suite 11 passed, related storage suites 123 passed. - Core `tsc --noEmit` and root `tsc` clean; eslint zero warnings on the changed source files. **Independent observations, not acted on:** the ownerless-grace `rmdir` can in a microsecond window remove a just-created empty gate whose holder has not yet written its record. The holder now retries, so mutual exclusion holds, but this is inherent to directory-as-lock without a holder record. No code depends on the old fixed `owner` file name elsewhere in the repo. PR: #3364 Comment by: @integry (ID: 6480394746) Model: Claude Fable 5.1
|
/review astra |
|
✅ AI Code Review Complete requested by @integry Posted 1 review: |
🔍 AI Code Review — astraOverall EvaluationThe PR addresses abandoned storage gates and duplicate recovery work with focused changes and useful regression coverage. It needs changes before merge: concurrent ownerless-gate reclamation can allow two callers into the exclusive section. ✅ Recovery deduplication — Pending steps remain tracked after a timeout, and both fulfillment and rejection restore eligibility. ✅ Token-specific reclamation — A delayed probe cannot unlink a successor’s differently named owner record; the added test covers this case. ✅ Operational visibility — Default wait warnings identify the holder, and deployment documentation explains mixed-version behavior. The supplied current-head checks report 21 passed, none failed, and none pending. This review used static analysis only, as requested. Merge blockersEvery finding below was introduced by this PR and must be resolved before merging. F5: 🔴 Ownerless reclamation can break exclusivity
SuggestionsThese are optional follow-ups and are not sent to S8: 🟢 Bound test log pollingThe new ScoreThe recovery guard, documentation, and passing checks are strong, but the remaining takeover race violates the central storage-exclusion guarantee and requires correction before merge. 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 f6ac268
Summary of ChangesF5 is applied. Nothing here is user-visible UI, so no preview files were created. The defect. Holder publication was a plain write into whatever directory sat at the gate path, and an ownerless reclaim removed that path after an age check that could be stale. Two reclaimers plus one acquirer paused between creating the directory and writing its record could therefore end with two records in one gate and two callbacks running at once. The correction in
Sibling check. The other Regressions in
Both fail on the previous implementation with the release ENOTEMPTY the finding predicts, and pass ten of ten runs on the new one. The full storage suite set passes (133 tests), as do core typecheck and lint. Docs. The maintenance page now describes the prepare-and-rename protocol and the leftover Independent observation, not changed. The admission test in 🤖 Implementation Details
Undo Changes • View Task Execution 💡 ProPR Slash Commands
🤖 Generated by ProPR |
…ew files were created. F5 is applied. Nothing here is user-visible UI, so no preview files were created. **The defect.** Holder publication was a plain write into whatever directory sat at the gate path, and an ownerless reclaim removed that path after an age check that could be stale. Two reclaimers plus one acquirer paused between creating the directory and writing its record could therefore end with two records in one gate and two callbacks running at once. **The correction** in `packages/core/src/storage/lifecycle.ts`: - A holder now prepares its gate under a token-unique name with its record already inside, then renames that directory onto the gate path. The record can only ever land in the directory its writer prepared, so the "created but not yet published" moment no longer exists at the gate path. - The rename is the only way in. It fails while any directory exists at the path and, per rename(2), atomically replaces only an empty one. Outside a reclaim the acquirer still creates the gate plainly first, so an empty gate from an older version or a release in progress is waited on rather than replaced before the grace period, as before. - Reclamation no longer removes the directory by pathname. It empties the gate (record unlinked under its token name, or ownerless leftovers after the grace period) and then renames the reclaimer's own prepared gate onto it. A stale, age-authorized takeover can only succeed against a directory that is still empty, never against a holder that has published a record. A replacement during acquisition yields ENOTEMPTY, which forces a retry without entering the callback. - Release treats ENOTEMPTY as a successor having taken the briefly empty directory. The prepared directory is removed if acquisition fails. **Sibling check.** The other `rmdir` and `wx` sites in `packages/core/src/storage` (database export lease, registry, generated payloads, cache removal) each act on token-unique names or on paths only their own call creates, so none share the pathname-replacement assumption. The claim-owner tests that create and remove the gate by hand still pass. **Regressions** in `packages/core/test/storageLifecycleGate.test.ts`, both driven by holding the lifecycle's own stat and mkdir calls rather than by timing: - Two reclaimers of an ownerless gate, one stalled after its age check, the other paused between creating the gate directory and publishing. Critical sections must not overlap and each holder must release its own gate. - A stale reclaim against a fresh acquirer paused between creation and publication. Both fail on the previous implementation with the release ENOTEMPTY the finding predicts, and pass ten of ten runs on the new one. The full storage suite set passes (133 tests), as do core typecheck and lint. **Docs.** The maintenance page now describes the prepare-and-rename protocol and the leftover `gate-<token>` directory a crash can leave. **Independent observation, not changed.** The admission test in `storageClaimOwner.test.ts` measures free disk space twice and expects it not to grow in between. It failed once while lint ran concurrently and passed five of five alone, so it is environmental. PR: #3364 Comment by: @integry (ID: 6482695676) Model: Claude Fable 5.1
|
/review |
|
✅ AI Code Review Complete requested by @integry Posted 1 review: |
🔍 AI Code Review — claude:claude-opus-5-5Overall EvaluationThis PR fixes the two failure modes behind the five-hour worker freeze.
I traced the gate protocol across these interleavings:
The design closes each of these windows:
Release is fenced by token, and a successor's rename onto a briefly empty gate is tolerated ( The PR is ready to merge. I found no verified blockers. ✅ Publish-by-rename removes the record/directory window — ✅ Token-named compare-and-remove — ✅ Recovery steps cannot pile up and are not launched out of budget — Merge blockersNo merge blockers. SuggestionsThese are optional follow-ups and are not sent to S9: 🟢 Sweep leftover
|
…) 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
Summary
Today the worker was frozen for five hours: 10 jobs sat in
activewithout a single log line, indexing stopped, and goal recovery piled up 93 copies. Cause: the storage lifecycle gate (/tmp/git-processor/.clones-storage-lifecycle/gate, a directory shared by every service container) had been created by the worker 8 minutes before it died of a JS heap OOM. The gate had no owner record or expiry, anduse()waits for it forever without logging, so nothing recovered until the directory was removed by hand.Changes
The gate records its holder and is reclaimed when the holder is gone (
packages/core/src/storage/lifecycle.ts)owner(container id, pid, process start time, a token) inside the gate right aftermkdir.claimOwnerGonecheck (container restarted or pid gone) and removes an abandoned gate; a gate with no record is abandoned after 10 minutes.Still waiting for the storage lifecycle gate after Ns (held by <host> pid <pid>)) unless the caller supplies its own warning, as worktree removal does.Recovery steps no longer pile up (
src/workerTaskStateRecovery.ts)runWithinDeadlineabandons a step that exceeds its budget but cannot cancel it. The pass then started the same step again every minute; the heap snapshot of the frozen worker held 93 pendingrecoverNonterminalGoalsruns, and the crashed worker had logged 94 abandoned passes in the two hours before its OOM. A step is now skipped, with a warning, while its previous run is still pending.Docs:
maintenance.mddescribes the gate, its logs, and the manual unblock for older versions.Tests
packages/core/test/storageLifecycleGate.test.ts(new, real filesystem): holder record and cleanup; a dead holder's gate is reclaimed; a live holder's gate is respected; an ownerless gate is reclaimed only after the grace period; a reclaimed-and-retaken gate is left alone by the original holder; the wait warning names the holder.test/workerTaskStateRecovery.test.ts: a step whose previous run is still pending is skipped and runs again once it finishes.storageClaimOwner,instanceStorage,generatedPayloadStorage,fleetDataPlane) pass.🤖 Generated with Claude Code