Skip to content

2026-90: fix(wake): bound stale .steal mutex recovery to stop unbounded lock recursion - #90

Merged
Ivory2024 merged 1 commit into
mainfrom
fm/firstmate-stale-steal-lock-recovery-20261005
Oct 5, 2026
Merged

Ivory2024 merged 1 commit into
mainfrom
fm/firstmate-stale-steal-lock-recovery-20261005

Conversation

@Ivory2024

Copy link
Copy Markdown
Owner

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() in bin/fm-wake-lib.sh now takes an allow_steal parameter (default yes); recovery of the .steal serialization mutex calls itself with allow_steal=no, so steal-mutex acquisition never recurses into its own .steal.steal... chain.
  • When allow_steal=no, a stale .steal mutex (dead owner PID, not mid-acquire-fresh) is reclaimed directly via fm_lock_remove_path instead of recursing, preserving the existing dead/reused-PID safety checks.
  • All steal_owner-dependent release/ownership-check calls are now guarded so they no-op when no steal lock was acquired (i.e. during the bounded allow_steal=no path).
  • Adds test_stale_steal_chain_recovers_without_unbounded_suffixes to tests/fm-wake-queue.test.sh, which builds a stale primary lock plus a stale .steal and .steal.steal chain and asserts recovery succeeds without growing a .steal.steal.steal suffix.

🤖 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.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Stale .steal mutex chain is reclaimed in one bounded level, not recursed ✅ pass live tests/fm-wake-queue.test.sh::test_stale_steal_chain_recovers_without_unbounded_suffixes — ok
Adversarial: deep pre-existing stale .steal chain (30 levels) does not grow further / does not ENAMETOOLONG on recovery ✅ pass live Manual bash invocation of fm_lock_try_acquire against a hand-built 30-level stale .steal chain; rc=0, zero leftover .steal entries afterward
PID identity safety contract (never signal unverified/reused/uncertain PID) preserved ✅ pass live bash tests/fm-session-lock-ancestry.test.sh — all 15 cases ok, no regression from the fm_lock_try_acquire signature change
  • Outcome: ⚠️ 1 info across 1 run (6m6s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

⚠️ **Test** - 1 info
  • ℹ️ Pre-existing unrelated test failure 'guard did not order neutral automatic recovery after drain' in tests/fm-watcher-lock.test.sh reproduces identically on base commit 4c73850 and target commit a6e67ce — not caused by this change.
  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Stale .steal mutex chain is reclaimed in one bounded level, not recursed ✅ pass live tests/fm-wake-queue.test.sh::test_stale_steal_chain_recovers_without_unbounded_suffixes — ok
Adversarial: deep pre-existing stale .steal chain (30 levels) does not grow further / does not ENAMETOOLONG on recovery ✅ pass live Manual bash invocation of fm_lock_try_acquire against a hand-built 30-level stale .steal chain; rc=0, zero leftover .steal entries afterward
PID identity safety contract (never signal unverified/reused/uncertain PID) preserved ✅ pass live bash tests/fm-session-lock-ancestry.test.sh — all 15 cases ok, no regression from the fm_lock_try_acquire signature change
  • bash tests/fm-wake-queue.test.sh (test_stale_steal_chain_recovers_without_unbounded_suffixes) — pass with fix
  • Manual 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.steal
  • bash tests/fm-session-lock-ancestry.test.sh — all pass, PID-identity/trust contract unaffected
  • bash 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.

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 Ivory2024 changed the title fix(wake): bound stale .steal mutex recovery to stop unbounded lock recursion 2026-90: fix(wake): bound stale .steal mutex recovery to stop unbounded lock recursion Oct 5, 2026
@Ivory2024
Ivory2024 merged commit 2950059 into main Oct 5, 2026
37 of 38 checks passed
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant