Skip to content

fix(bin): bound wake drain presentation lock waits - #3475

Merged
kunchenguid merged 6 commits into
mainfrom
fm/fm-startup-fix-b-presentation-lock-deadline-r1
Sep 2, 2026
Merged

kunchenguid merged 6 commits into
mainfrom
fm/fm-startup-fix-b-presentation-lock-deadline-r1

Conversation

@kunchenguid

@kunchenguid kunchenguid commented Sep 1, 2026 •

Copy link
Copy Markdown
Owner

Intent

Startup fix B: bounded acquire for presentation-path locks (drain, status-presentation) that skips a pass with an advisory line on a live holder, mutation-critical locks keep blocking semantics, ack unchanged

What Changed

  • Add bounded lock acquisition with safe ownership handoff for presentation-only wake drain paths.
  • Skip contended queue or status presentation passes with live-holder PID advisories while keeping acknowledgement locks blocking and atomic.
  • Document the deadline behavior and add regression coverage for bounded, retriable contention and malformed locks.

Risk Assessment

✅ Low: The change is bounded to presentation-path acquisition, preserves blocking acknowledgement paths, and handles live, stale, and malformed lock states consistently.

Testing

Targeted executable tests and a manual end-to-end CLI run confirmed both presentation locks time out cleanly with holder-specific advisories, skipped wakes remain retriable, malformed locks fail safely, and acknowledgement locking remains blocking and lossless.

Evidence: Bounded presentation-lock end-to-end CLI transcript

Source: Bounded presentation-lock end-to-end CLI transcript

FirstMate wake drain: bounded presentation-lock end-to-end transcript

$ FM_STATUS_PRESENTATION_LOCK_TIMEOUT=1 bin/fm-wake-drain.sh  # queue lock held by pid 37800
WAKE DRAIN SKIPPED: queue lock remains held by live pid 37800 after 1s; retry on the next drain.
Durable queue rows after skipped pass: 1

$ FM_STATUS_PRESENTATION_LOCK_TIMEOUT=1 bin/fm-wake-drain.sh  # status lock held by pid 41895
1788301350	1	signal	task.status	signal: ~/.no-mistakes/worktrees/52b07e9083e7/01M1FGAHY8FABW1NYTQAAXWY5X/.manual-presentation-lock.dCLmeZ/state/task.status
STATUS PRESENTATION SKIPPED: lock remains held by live pid 41895 after 1s; retry on the next drain.
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 37666.1788301350.kyFfzj
Durable queue rows after skipped status presentation: 1

$ FM_STATUS_PRESENTATION_LOCK_TIMEOUT=1 bin/fm-wake-drain.sh  # holder released; next pass
1788301350	1	signal	task.status	signal: ~/.no-mistakes/worktrees/52b07e9083e7/01M1FGAHY8FABW1NYTQAAXWY5X/.manual-presentation-lock.dCLmeZ/state/task.status
wake annotation: latest wake-EVENT observed at drain, not current state: task.status: needs-decision [key=fixture]: retried presentation is visible
OPEN DECISIONS (still open, folded from the durable status logs - not just the latest line):
task [key=fixture] needs-decision: retried presentation is visible
OPEN DECISIONS: close one by answering it: bin/fm-send.sh <task> --resolve-key <key> '<answer>'
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 37666.1788301350.kyFfzj

$ bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 37666.1788301350.kyFfzj
Durable queue rows after acknowledgement: 0

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 2 issues found → auto-fixed (2) ✅
  • 🚨 bin/fm-wake-drain.sh:412 - Intent requires bounded acquisition for both presentation paths: “(drain, status-presentation)”. The initial drain still unconditionally calls fm_lock_acquire_wait before distinguishing acknowledgement mode. If a live process holds .wake-queue.lock, a normal no-ack startup drain blocks forever and emits no advisory. Use bounded acquisition for the no-ack presentation path while retaining blocking acquisition when ACK_THROUGH is set.
  • ⚠️ bin/fm-wake-lib.sh:977 - A timeout is always returned as live-holder contention, even when the lock is malformed or otherwise unrecoverable. For example, a regular file at .status-presentation-lock makes every acquire fail without a holder; after the deadline this returns 124 and the caller reports a fictitious live PID, while status presentation remains skipped indefinitely. Return 124 only after validating a numeric, currently live holder; report other acquisition failures as lock errors.

🔧 Fix: Distinguish malformed presentation locks from live contention
1 error still open:

  • 🚨 bin/fm-wake-drain.sh:414 - Intent requires “bounded acquire for presentation-path locks (drain, status-presentation)” while keeping mutation-critical and acknowledgement locking blocking. A normal no-ack drain still enters unconditional fm_lock_acquire_wait &#34;$FM_WAKE_QUEUE_LOCK&#34;; with a live holder it blocks forever before reaching the bounded status-presentation acquire, so no pass is skipped and no advisory is emitted. At this initial boundary, use bounded acquisition for no-ack presentation drains while retaining blocking acquisition when ACK_THROUGH is set.

🔧 Fix: Bound no-ack drain queue lock acquisition
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • Focused execution of test_live_presentation_holder_is_deadlined_without_weakening_ack from tests/fm-wake-queue.test.sh
  • Focused execution of test_malformed_presentation_lock_reports_acquire_failure from tests/fm-wake-queue.test.sh
  • Manual CLI verification with live queue and status lock holders: confirmed bounded skip advisories, intact durable queue, next-pass presentation, and successful acknowledgement
✅ **Document** - passed

✅ No issues found.

🔧 **Lint** - 1 issue found → auto-fixed ✅
  • ⚠️ linter found issues (exit code 1)

🔧 Fix: Annotate bounded lock output global
✅ Re-checked - no issues remain.

✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (2): Last reviewed commit: "no-mistakes(ci): Added deterministic reg..." | Re-trigger Greptile

Comment thread tests/fm-wake-queue.test.sh Resolved
…ul bounded-lock acquisition after live contention, verifying helper-to-caller PID ownership handoff and caller release. Verified with bash syntax checks, git diff checks, and the full fm-wake-queue test suite
@kunchenguid
kunchenguid merged commit f42a629 into main Sep 2, 2026
25 of 27 checks passed
@kunchenguid
kunchenguid deleted the fm/fm-startup-fix-b-presentation-lock-deadline-r1 branch September 2, 2026 00:09
Marcos-Leyva added a commit to Marcos-Leyva/firstmate that referenced this pull request Sep 3, 2026