Repository navigation
fix: prevent stale lock recovery races and recursive steal chains - #91
Merged
Merged
Conversation
Ivory2024
force-pushed
the
fm/firstmate-stale-steal-lock-recovery-20261005
branch
from
October 5, 2026 04:12
2f45c7c to
d8e62e8
Compare
- Replace unconditional check-then-remove with a persistent advisory lock (.reclaim-guard sidecar, a doc'd state artifact) covering the whole remove+create critical section of fm_lock_try_acquire. The guard is acquired by spawning perl flock on an inherited FD whose OFD persists until the shell closes it, so kernel releases it on process death and it can never itself go stale. Two slots bound nesting to primary (slot 9) and steal (slot 8) so no recursive self-deadlock. - allow_steal=no steal-mutex cleans one bounded stale level, inside the same guard, and never recurses, so the previous allow_steal=yes -> no chain in fm_lock_try_acquire cannot again grow .steal suffixes into ENAMETOOLONG. - Post-create re-verifies the new link actually points to the fresh owner before rc=0. - Regressions: stale .steal simlock chain smoke test, compare-and-remove stub probe (dead-vs-live) and a two-process concurrent-recovery test asserting exactly one winner and no suffix growth.
The public-surface hermeticity suite asserts the shared test library leaves every public-surface credential genuinely unset. Exporting them as empty strings satisfied fm_discord_load_config's 'defined' check but reported an empty value rather than unset, and left the credential scrub looking effective when it was not. Pin FM_HOME to the synthetic credential-free home again so the .env fallback stays blocked without defining the tokens.
…urrent recovery test owners
Ivory2024
force-pushed
the
fm/firstmate-stale-steal-lock-recovery-20261005
branch
from
October 6, 2026 01:24
b60a141 to
47b13ff
Compare
…pter regressions. Reproduced both failures, then bound all sibling Grok fixture paths to their isolated case homes. Passed: `bin/fm-lint.sh tests/fm-cursor-primary.test.sh tests/fm-turnend-guard.test.sh`, `bash tests/fm-cursor-primary.test.sh`, `bash tests/fm-turnend-guard.test.sh`, and `git diff --check`
Ivory2024
added a commit
that referenced
this pull request
Oct 7, 2026
* Serialise stale lock reclaim with a kernel-flock guard file - Replace unconditional check-then-remove with a persistent advisory lock (.reclaim-guard sidecar, a doc'd state artifact) covering the whole remove+create critical section of fm_lock_try_acquire. The guard is acquired by spawning perl flock on an inherited FD whose OFD persists until the shell closes it, so kernel releases it on process death and it can never itself go stale. Two slots bound nesting to primary (slot 9) and steal (slot 8) so no recursive self-deadlock. - allow_steal=no steal-mutex cleans one bounded stale level, inside the same guard, and never recurses, so the previous allow_steal=yes -> no chain in fm_lock_try_acquire cannot again grow .steal suffixes into ENAMETOOLONG. - Post-create re-verifies the new link actually points to the fresh owner before rc=0. - Regressions: stale .steal simlock chain smoke test, compare-and-remove stub probe (dead-vs-live) and a two-process concurrent-recovery test asserting exactly one winner and no suffix growth. * fix(wake): wrap exec fd close in compound command to prevent stderr silencing * no-mistakes(test): Reuse prior wake acknowledgement token after replay * no-mistakes(test): Stabilize wake acknowledgement and isolate guard fixtures * no-mistakes(document): Document bounded lock recovery and PID safety * no-mistakes(lint): Fix ShellCheck findings in wake queue tests * no-mistakes(test): Wait for drain PID ownership before interrupting replay test * no-mistakes(test): Wait for recovery handling state before interrupting drain * no-mistakes(lint): Resolve ShellCheck SC2015 with explicit control flow * fix(test): populate test default home dirs and satisfy lint * fix(test): neutralize credentials without exporting ambient FM_HOME * fix(test): keep FMX tokens unset rather than exporting empty strings * fix(test): unset Discord tokens instead of exporting empty strings The public-surface hermeticity suite asserts the shared test library leaves every public-surface credential genuinely unset. Exporting them as empty strings satisfied fm_discord_load_config's 'defined' check but reported an empty value rather than unset, and left the credential scrub looking effective when it was not. Pin FM_HOME to the synthetic credential-free home again so the .env fallback stays blocked without defining the tokens. * fix(test): scrub inherited Discord token alias * no-mistakes(review): Preserve caller descriptors and synchronize concurrent recovery test owners * no-mistakes(document): Clarify lock recovery and credential isolation documentation * no-mistakes(lint): Fix ShellCheck empty assignment and intentional subprocess quoting * no-mistakes(ci): Fixed fixture FM_HOME binding in Cursor and Grok adapter regressions. Reproduced both failures, then bound all sibling Grok fixture paths to their isolated case homes. Passed: `bin/fm-lint.sh tests/fm-cursor-primary.test.sh tests/fm-turnend-guard.test.sh`, `bash tests/fm-cursor-primary.test.sh`, `bash tests/fm-turnend-guard.test.sh`, and `git diff --check` * fix: drain harness list before returning * fix: drain harness list before support verdict
Ivory2024
added a commit
that referenced
this pull request
Oct 7, 2026
* Serialise stale lock reclaim with a kernel-flock guard file - Replace unconditional check-then-remove with a persistent advisory lock (.reclaim-guard sidecar, a doc'd state artifact) covering the whole remove+create critical section of fm_lock_try_acquire. The guard is acquired by spawning perl flock on an inherited FD whose OFD persists until the shell closes it, so kernel releases it on process death and it can never itself go stale. Two slots bound nesting to primary (slot 9) and steal (slot 8) so no recursive self-deadlock. - allow_steal=no steal-mutex cleans one bounded stale level, inside the same guard, and never recurses, so the previous allow_steal=yes -> no chain in fm_lock_try_acquire cannot again grow .steal suffixes into ENAMETOOLONG. - Post-create re-verifies the new link actually points to the fresh owner before rc=0. - Regressions: stale .steal simlock chain smoke test, compare-and-remove stub probe (dead-vs-live) and a two-process concurrent-recovery test asserting exactly one winner and no suffix growth. * fix(wake): wrap exec fd close in compound command to prevent stderr silencing * no-mistakes(test): Reuse prior wake acknowledgement token after replay * no-mistakes(test): Stabilize wake acknowledgement and isolate guard fixtures * no-mistakes(document): Document bounded lock recovery and PID safety * no-mistakes(lint): Fix ShellCheck findings in wake queue tests * no-mistakes(test): Wait for drain PID ownership before interrupting replay test * no-mistakes(test): Wait for recovery handling state before interrupting drain * no-mistakes(lint): Resolve ShellCheck SC2015 with explicit control flow * fix(test): populate test default home dirs and satisfy lint * fix(test): neutralize credentials without exporting ambient FM_HOME * fix(test): keep FMX tokens unset rather than exporting empty strings * fix(test): unset Discord tokens instead of exporting empty strings The public-surface hermeticity suite asserts the shared test library leaves every public-surface credential genuinely unset. Exporting them as empty strings satisfied fm_discord_load_config's 'defined' check but reported an empty value rather than unset, and left the credential scrub looking effective when it was not. Pin FM_HOME to the synthetic credential-free home again so the .env fallback stays blocked without defining the tokens. * fix(test): scrub inherited Discord token alias * no-mistakes(review): Preserve caller descriptors and synchronize concurrent recovery test owners * no-mistakes(document): Clarify lock recovery and credential isolation documentation * no-mistakes(lint): Fix ShellCheck empty assignment and intentional subprocess quoting * no-mistakes(ci): Fixed fixture FM_HOME binding in Cursor and Grok adapter regressions. Reproduced both failures, then bound all sibling Grok fixture paths to their isolated case homes. Passed: `bin/fm-lint.sh tests/fm-cursor-primary.test.sh tests/fm-turnend-guard.test.sh`, `bash tests/fm-cursor-primary.test.sh`, `bash tests/fm-turnend-guard.test.sh`, and `git diff --check` * fix: drain harness list before returning * fix: drain harness list before support verdict
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.
91 고쳐 그리고 병렬로. 이것도 처리해 코드는 오픈코드 이용하고 네가 컨펌하고. 오픈코드에서 말고 정 안되는건 여기서 네가 코드작업해 하위 에이전트에 위임하고. 꼭 필요한 테스트만 해. 진행해. 하던거 이어서 해. 91 맞아 마저 고쳐.
What Changed
.stealcleanup without further recursion or signaling live or uncertain PIDs.Risk Assessment
✅ Low: Bounded recovery preserves caller descriptors, serializes stale replacement, and retains PID signaling safeguards; no concrete introduced defect was found.
Testing
Completed only the requested missing scenario. Actual production CLI used an intercepted transport: positive control posted once; isolated decision and report paths made zero requests. Retained driver and transcript, removed disposable fixtures, and did not repeat earlier lock/PID/FD checks or suites.
Evidence: Live credential isolation CLI transcript
Source: Live credential isolation CLI transcript
Evidence: Reproducible isolated CLI driver
Source: Reproducible isolated CLI driver
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
🔧 **Rebase** - 1 issue found → auto-fixed ✅
bin/fm-wake-lib.sh- merge conflict rebasing onto origin/main🔧 Fix applied.
✅ Re-checked - no issues remain.
🔧 **Review** - 2 issues found → auto-fixed ✅
bin/fm-wake-lib.sh:615- Fixed guard descriptors overwrite caller-owned descriptors. Concrete path: an extension runner retains its inbox on FD 8 (bin/fm-procevent.sh:841), releases its source lock, then publish_result reacquires that lock (bin/fm-procevent.sh:596). If another holder dies leaving a stale primary and stale .steal lock, recovery replaces and closes FD 8. The subsequent result.silent/result.terminal handoff requires that inbox descriptor (bin/fm-procevent.sh:312), so classification fails and a silent or terminal result is incorrectly announced or left registered. Preserve existing descriptors at the shared guard boundary. Related changed sites: bin/fm-wake-lib.sh:616 overwrites FD 9; :626–627 close descriptors on contention; :634–635 close descriptors on release.tests/fm-wake-queue.test.sh:1802- The concurrent recovery test permits its winner to exit immediately after printing rc=0. If A finishes before B checks owner liveness, B correctly reclaims A's now-stale lock and also returns 0, failing the exactly-one-success assertion despite correct serialization. Both worker launches at tests/fm-wake-queue.test.sh:1802–1803 have this problem; :1805 asserts the invalid lifetime assumption. Keep the successful owner alive until both acquisition attempts finish, then release it.🔧 Fix applied.
✅ Re-checked - no issues remain.
🔧 **Test** - 1 issue found → no changes applied ✅
bash .local-test-phase/live.sh: real registration, stale-chain list recovery, descriptor retention, and live-PID protectionSelected executable wake regressions:test_stale_steal_chain_recovers_without_unbounded_suffixes,test_stale_recovery_preserves_caller_descriptors,test_concurrent_stale_lock_recovery_yields_one_owner,test_self_held_lock_reclaims_instead_of_deadlockingSelected watcher regression:test_watch_restart_rejects_reused_pidSelected isolation regressions:test_library_scrubs_public_credentials,test_library_replaces_hostile_ambient_homeRemoved generated drivers and disposable state;git status --shortclean🔧 No changes applied.
✅ Re-checked - no issues remain.
bash ~/.no-mistakes/evidence/01M47C4YWN7HJDEM8XGK78FSPA/credential-cli.shActual notification CLI positive control: one intercepted POST using dummy home credentials.Actual decision and report CLI after sourcing tests/lib.sh: tokens unset, credential-free home selected, zero transport requests.git status --shortconfirmed disposable workspace cleanup.✅ **Document** - passed
✅ No issues found.
🔧 **Lint** - 1 issue found → auto-fixed ✅
🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Push** - passed
✅ No issues found.