Skip to content

fix(bin): return 124 on retriable bounded lock contention - #8119

Merged
kunchenguid merged 2 commits into
kunchenguid:mainfrom
Azd325:fm/fm-8105-lock-timeout
Nov 3, 2026
Merged

kunchenguid merged 2 commits into
kunchenguid:mainfrom
Azd325:fm/fm-8105-lock-timeout

Conversation

@Azd325

@Azd325 Azd325 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What Changed

  • fm_lock_acquire_wait_bounded in bin/fm-wake-lib.sh now returns 124 for any retriable contention at the deadline: a live holder, an unpublished holder pid, an exited holder, or a lock released during the wait. Before, only a live holder gave 124 and the other cases returned 1. FM_LOCK_HELD_PID is set only when a live holder is known. A malformed pid or a non-directory lock path still returns 1.
  • Updated the function comment to describe the new 124 contract.
  • Added tests in tests/fm-watcher-lock.test.sh for the deadline cases: unpublished holder, exited holder, released lock, live holder, and malformed lock.

Risk Assessment

✅ Low: The change is confined to the deadline branch of one helper: unpublished, exited and released holders now return 124, and malformed pid data, non-directory locks and a removed parent still fail hard. Each test mode reaches the branch it names, because the live steal mutex in the fixture blocks the final acquire.

Testing

The watcher-lock test file ran with no failures, including the five bounded-deadline cases. An unstubbed probe against the real function returned 124 for both a live holder (pid advertised) and an unpublished-pid lock (no pid). Before the change, the unpublished case returned 1.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Unpublished-pid holder at the deadline returns 124 (real function probe) ✅ pass live real-probe.log: unpublished-holder rc=124
Live holder at the deadline still returns 124 and sets FM_LOCK_HELD_PID (real function probe) ✅ pass live real-probe.log: live holder rc=124 held=<pid>
Exited holder, released/absent lock, malformed pid and non-directory lock outcomes ✅ pass live watcher-lock.log bounded deadline cases ok
Evidence: watcher lock test log

Source: watcher lock test log

ok - disposable watcher refuses inherited state outside its marked lab
ok - tombstone cleanup respects a live reaper and recovers a recycled reaper pid
ok - wait deadline diagnoses and reaps a stopped test child without hanging
ok - simultaneous watcher starts leave exactly one live process
ok - fm_pid_identity real ps fallback is locale-invariant
ok - fm_pid_identity is locale-invariant across LC_ALL/LC_TIME
ok - fm_pid_identity ps fallback is terminal-width-invariant
ok - /proc process identity ignores simulated btime changes
ok - /proc process identity detects pid reuse
ok - MSYS /proc process identity regression skipped on non-Windows host
ok - killed watcher stale lock is reclaimed
ok - dead watcher reclaim fails promptly when downtime marker cannot be published
tests/fm-watcher-lock.test.sh: line 2365: 89020 Killed: 9                  FM_STATE_OVERRIDE="$state" bash -c '
    . "$1"
    fm_lock_remove_path() {
      if [ "$1" = "$STATE/.watch.lock" ]; then
        kill -KILL "${BASHPID:-$$}"
      fi
      return 1
    }
    fm_lock_try_acquire "$2"
  ' _ "$LIB" "$lockdir" > /dev/null 2>&1
ok - stale watcher reclaim publishes durable recovery evidence before clear
ok - live watcher lock with stale heartbeat is actionable
ok - live watcher lock with a beacon past the hard bound is replaced, under it is still refused
ok - a fresh watcher replaces a live holder whose pre-UTC-pin identity no longer recomputes, and the old holder stands down unsignalled
ok - a replaced holder stands down cleanly even when its successor has already exited and released the lock
ok - guard banner leads when down with pending wakes (repair-after-drain) and stays silent when live and fresh
ok - concurrent fm_lock_try_acquire yields exactly one winner
ok - dead-pid stale lock is reclaimed by a single acquirer
ok - concurrent stale-lock steal yields exactly one winner
ok - dead steal owner is reclaimed once without a nested steal marker
ok - dead nested steal chain from an interrupted reclaim is recovered
ok - a competing reaper cannot remove the successor's steal mutex
ok - a steal mutex abandoned by this process does not block its own reclaim
ok - a steal reap interrupted in this process is resumed from its own tombstone
ok - live steal mutex is not reclaimed
ok - live-held lock is not stolen
ok - lock whose recorded holder pid was reused by a live process is reclaimed
ok - live holder matching its recorded start time keeps its lock
ok - lock whose recorded identity no longer recomputes is reclaimed without signalling its pid; a matching or unrecorded identity stays held
ok - live supervise-daemon lock with a stale local-time identity and no start time is not reclaimed
ok - empty mid-acquire lock keeps a minimum grace
ok - late original claimant cannot claim a recreated lock
ok - bounded wait earns one grace window for an unpublished-pid lock, still bounds a live holder
ok - bounded deadline with an unpublished holder is retriable
ok - bounded deadline with an exited holder is retriable
ok - bounded deadline with a released lock is retriable
ok - bounded deadline preserves the live holder advisory
ok - bounded deadline rejects malformed pid data and non-directory locks
ok - paused mid-acquire claimant backs off to active stealer
ok - watch restart preserves recovery without signaling a reused pid
ok - watch restart attaches to a verified healthy peer and later surfaces a successor gap
ok - watcher self-evicts when the lock pid no longer names it
ok - watcher exits 1 with its reason when its state directory is torn down and recreated during startup
ok - arm turns clean self-eviction without a successor into a typed failure
ok - arm attaches to a live fresh watcher and fails loudly when that cycle has no successor
ok - attached arm signals record a classified lifecycle entry
ok - arm starts cleanly and resurfaces recovery after a dead-pid lock
ok - arm cleans child watcher and temp output on HUP
ok - arm defers TERM until startup watcher can run its lock cleanup
ok - arm TERM waits out a stalled singleton claim past the deadline and leaves no lock evidence
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 16307.1793709359.au4PjE
WARNING: queued wakes pending - drain them with bin/fm-wake-drain.sh before anything else.
ok - arm propagates an immediate watcher wake before confirmation
ok - arm attaches to a peer watcher after child stands down and surfaces a missing successor
watcher: lock held by live pid 21723 but heartbeat is stale for 847028173s (>300s); inspect or stop that watcher before re-arming.
ok - arm reports FAILED and exits non-zero when no fresh watcher can be confirmed
ok - cycle-exit ledger links a verified successor and remains size-capped
ok - arm confirms a watcher whose post-claim startup exceeds the legacy budget
watcher: FAILED - startup lock /private/var/folders/m7/v02n8pqn167dn42b0vdb3l4h0000gn/T/fm-watcher-lock-tests.zl6foq/arm-startup-lock-held/state/.wake-queue.lock held by live pid 38011
ok - arm relays a live-holder startup-lock refusal and keeps the downtime drainable
ok - staged-owner cleanup removes only unpublished empty or self-owned staging
ok - startup cleanup waits for in-flight staging and publication, preserving foreign owners
ok - a stop forced before the safe point waits for it and leaves no lock evidence
ok - a watcher that cannot publish its identity exits through its cleanup
ok - SIGSTOP distinguishes live PID from stale beacon and termination records the exit class
Evidence: real function probe

Source: real function probe

live holder rc=124 held=51455
unpublished-holder rc=124 held=

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Unpublished-pid holder at the deadline returns 124 (real function probe) ✅ pass live real-probe.log: unpublished-holder rc=124
Live holder at the deadline still returns 124 and sets FM_LOCK_HELD_PID (real function probe) ✅ pass live real-probe.log: live holder rc=124 held=<pid>
Exited holder, released/absent lock, malformed pid and non-directory lock outcomes ✅ pass live watcher-lock.log bounded deadline cases ok
  • bash tests/fm-watcher-lock.test.sh (bounded-deadline cases: unpublished, exited, released, live, malformed/file)
  • Unstubbed probe of the real function with a live sleeping holder and with an unpublished-pid lock dir
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Issues

Closes #8105

@greptile-apps

greptile-apps Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; retriable timeouts still refuse acquisition and leave protected work untouched.

Reviews (2) · Last reviewed commit: "no-mistakes(review): Return 124 when bou..." · Reviewed by Greptile

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @Azd325 for picking up #8105 so quickly. The fix is the right shape. After the deadline, an empty pid, an exited holder, or a lock that is already gone now returns 124 (retry later). Malformed pid data, a non-directory lock and a missing parent still return 1, so a genuinely broken lock is still reported as broken. FM_LOCK_HELD_PID is cleared first and named only for a live holder, which is what the callers expect. The new cases in tests/fm-watcher-lock.test.sh are deterministic, fail on the base library, and don't touch any timeout or wait budget, which matches the issue's constraints.

Contract-class (my own read): restore. The function's documented contract is "124 means retry later", and fm-wake-drain.sh already promises the WAKE DRAIN SKIPPED ... retry path for contention. This makes the default path keep that promise.

VISION.md: aligns throughout. It removes a false hard failure (honest interface, fewer pointless wakes), the classification stays in the script, malformed locks still refuse, and nothing touches vendors, scope or authority.

Waiting on you for one thing: the no-mistakes attestation on d2ce106f records the rebase step as skipped. Our gate needs every step completed on the head that lands, with no exceptions for skips. Please re-raise once through git push no-mistakes so every step runs. No code change is needed. Quick checks pass, Greptile is 5/5 with no threads, and the branch merges cleanly into main 5b91acfb.

After that, we run the full suite. The Full suite check fails until we add our label, and that isn't your code.

Preserve retry-later status after an unpublished or exited lock holder at the deadline. Keep malformed lock records as hard failures and cover each classification with deterministic lock fixtures.

Closes kunchenguid#8105
@Azd325
Azd325 force-pushed the fm/fm-8105-lock-timeout branch from d2ce106 to e9e9a08 Compare November 3, 2026 12:39
@Azd325 Azd325 changed the title fix: return 124 for retriable bounded lock contention fix(bin): return 124 on retriable bounded lock contention Nov 3, 2026
@kunchenguid kunchenguid added the full-ci Maintainer go-ahead: run the full CI suite on this outside pull request label Nov 3, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @Azd325 for the quick re-raise. On head e9e9a082 the no-mistakes attestation records every step as completed, including rebase, so the one thing we asked for is done. The branch contains main, and the change is the same as the head we read before: fm_lock_acquire_wait_bounded returns 124 at the deadline for an empty pid, an exited holder or a released lock, and it still returns 1 for malformed pid data, a non-directory lock or a missing parent. Repo invariants, the coverage guard and the no-mistakes check all pass, live validation is go 3 of 3, and Greptile is 5/5 with no threads.

I've added the full-ci label so the Full suite runs on this head. Contract-class: restore, because "124 means retry later" is the helper's documented contract. If Full comes back green, this auto-merges and closes #8105, with nothing more needed from you.

@kunchenguid
kunchenguid merged commit 89cdf4b into kunchenguid:main Nov 3, 2026
35 of 36 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @Azd325 for the fix and for the quick clean re-raise. Bounded lock waits now return 124 when the lock is just busy at the deadline, so callers can retry later instead of reading it as a hard failure. Really appreciate you taking the time on this.

kayis-rahman pushed a commit to kayis-rahman/firstmate that referenced this pull request Nov 8, 2026
…d#8119)

* Fix retriable bounded lock deadline races

Preserve retry-later status after an unpublished or exited lock holder at the deadline. Keep malformed lock records as hard failures and cover each classification with deterministic lock fixtures.

Closes kunchenguid#8105

* no-mistakes(review): Return 124 when bounded lock is released
joergoss pushed a commit to joergoss/firstmate that referenced this pull request Nov 23, 2026
…d#8119)

* Fix retriable bounded lock deadline races

Preserve retry-later status after an unpublished or exited lock holder at the deadline. Keep malformed lock records as hard failures and cover each classification with deterministic lock fixtures.

Closes kunchenguid#8105

* no-mistakes(review): Return 124 when bounded lock is released
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Maintainer go-ahead: run the full CI suite on this outside pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fm_lock_acquire_wait_bounded turns a retriable lock-wait timeout into a hard failure (flaky fm-wake-queue concurrent append/drain)

2 participants