Repository navigation
2026-90: fix(wake): bound stale .steal mutex recovery to stop unbounded lock recursion - #90
Merged
Conversation
fm_lock_try_acquire reacquired its own ".steal" mutex through a recursive call, so a stale steal lock (e.g. left by an interrupted recovery) made every recovery attempt nest one more ".steal" level until path names exceeded ENAMETOOLONG. Acquire the steal mutex without nesting its own steal recovery and reclaim at most one verified-dead, non-fresh steal level directly, preserving the PID-identity safety contract. Adds a focused regression covering a stale primary lock with a stale two-level .steal chain.
Ivory2024
added a commit
that referenced
this pull request
Oct 7, 2026
) fm_lock_try_acquire reacquired its own ".steal" mutex through a recursive call, so a stale steal lock (e.g. left by an interrupted recovery) made every recovery attempt nest one more ".steal" level until path names exceeded ENAMETOOLONG. Acquire the steal mutex without nesting its own steal recovery and reclaim at most one verified-dead, non-fresh steal level directly, preserving the PID-identity safety contract. Adds a focused regression covering a stale primary lock with a stale two-level .steal chain.
Ivory2024
added a commit
that referenced
this pull request
Oct 7, 2026
) fm_lock_try_acquire reacquired its own ".steal" mutex through a recursive call, so a stale steal lock (e.g. left by an interrupted recovery) made every recovery attempt nest one more ".steal" level until path names exceeded ENAMETOOLONG. Acquire the steal mutex without nesting its own steal recovery and reclaim at most one verified-dead, non-fresh steal level directly, preserving the PID-identity safety contract. Adds a focused regression covering a stale primary lock with a stale two-level .steal chain.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
PID identity 문제 먼저 해결할 수 있어? Investigate and fix the recurring Firstmate lock-recovery failure observed during bin/fm-procevent.sh list: lock recovery emitted recursively growing .steal suffixes for ~/.local/state/firstmate/procevent-claims/bot-manager-issues.lock until File name too long. Current code evidence: fm_lock_try_acquire() in bin/fm-wake-lib.sh recursively calls itself for "$lockdir.steal"; a stale steal lock may cause unbounded recursion. Preserve the PID identity safety contract: never signal an unverified, reused, or uncertain PID.
What Changed
fm_lock_try_acquire()inbin/fm-wake-lib.shnow takes anallow_stealparameter (defaultyes); recovery of the.stealserialization mutex calls itself withallow_steal=no, so steal-mutex acquisition never recurses into its own.steal.steal...chain.allow_steal=no, a stale.stealmutex (dead owner PID, not mid-acquire-fresh) is reclaimed directly viafm_lock_remove_pathinstead of recursing, preserving the existing dead/reused-PID safety checks.steal_owner-dependent release/ownership-check calls are now guarded so they no-op when no steal lock was acquired (i.e. during the boundedallow_steal=nopath).test_stale_steal_chain_recovers_without_unbounded_suffixestotests/fm-wake-queue.test.sh, which builds a stale primary lock plus a stale.stealand.steal.stealchain and asserts recovery succeeds without growing a.steal.steal.stealsuffix.🤖 Generated with Claude Code
Risk Assessment
✅ Low: Fix bounds steal-mutex recursion to one level via a new allow_steal flag; the unguarded recovery of the steal lock itself remains safe because fm_lock_claim/fm_lock_points_to_owner re-validates ownership before any primary-lock claim and fm_lock_release only removes a lock whose recorded pid matches the current process, so a concurrent recovery race fails closed rather than double-claiming or mis-signaling; no PID-signaling code was touched, preserving the PID identity contract; the added test exercises real fm_lock_try_acquire behavior against a pre-built stale .steal.steal chain and asserts observable lock state.</risk_rationale>
["bin/fm-wake-lib.sh", "tests/fm-wake-queue.test.sh"]
Testing
Drove the real fm_lock_try_acquire function (not source inspection) against a fixture reproducing the reported stale-.steal-chain shape, confirming the fix's one-bounded-level reclaim path runs instead of unbounded self-recursion, and ran the author's own added regression test plus the PID-identity and watcher-lock suites; only a pre-existing, unrelated watcher-lock test failure appears, identical on base and target commits.
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
bash tests/fm-wake-queue.test.sh (test_stale_steal_chain_recovers_without_unbounded_suffixes) — pass with fixManual fm_lock_try_acquire call against a built 30-level stale .steal chain (base and fixed lib) — both unwind/release cleanly for a single uncontended call; confirms the fix's bounded-recursion path (allow_steal=no direct reclaim) activates without recursing into nested .steal.stealbash tests/fm-session-lock-ancestry.test.sh — all pass, PID-identity/trust contract unaffectedbash tests/fm-watcher-lock.test.sh — same pre-existing unrelated failure on base and fixed commit; no new failures introduced✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.