Skip to content

fix: preserve wake grants when queue-lock acquisition fails - #7912

Merged
kunchenguid merged 2 commits into
kunchenguid:mainfrom
WTF-Am-ID:fm/up-fm-3602
Oct 29, 2026
Merged

kunchenguid merged 2 commits into
kunchenguid:mainfrom
WTF-Am-ID:fm/up-fm-3602

Conversation

@WTF-Am-ID

@WTF-Am-ID WTF-Am-ID commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #3602

Authoring and no-mistakes review were single-family (Codex) by the owner's temporary choice.

Intent

1 p1-p7 codex only no cross model review

Context: this task is upstream scan 3 pick P3: upstream issue #3602 in kunchenguid/firstmate. The owner approved fixing scan picks P1-P7 upstream through PRs, written and reviewed by Codex only, with no cross-model review. Scan notes for this pick:

Issue: #3602

Wake-grant release and deactivate can mutate eligibility state after lock acquisition fails.
Size S.
Contract class: restore.
Recorded triage.

Current-source evidence: bin/fm-wake-grant.sh:44,60,89,98 calls fm_lock_acquire_wait unchecked under set -u, then marks the lock held. Release and deactivate proceed to removal.

Competing-work check: No exact issue target in the complete index. #5798 changes lock failure detection in wake/procevent libraries, not this script. The inspected #5172 diff still leaves the acquire calls bare while adding owner-record durability. It does not close the failed-acquire path.

Closure test: Run the real grant command in a disposable copied fixture with an injected lock-acquire failure and preexisting owner/row records. release and deactivate must exit nonzero, retain both records and not release another owner's lock. Include activate/publish controls and successful acquisition controls. A narrow fixture or the existing wake-queue suite can own it. No real full disk, live grant, or home mutation is needed.

What Changed

  • Make fm-wake-grant.sh exit nonzero when queue-lock acquisition fails during activate, publish, release, or deactivate, preserving grant records and another owner's lock.
  • Add disposable-fixture regression coverage for failed and successful acquisition across all four actions, and document the failure behavior.

Risk Assessment

✅ Low: All four grant commands now stop on failed acquisition before mutating eligibility records or marking the lock held, with behavioral regression coverage and no unrelated changes.

Testing

The focused wake-queue suite passed after correcting fixture placement. Real CLI failures, successful acquisitions, contention, injected-failure controls, and baseline reproduction matched expectations. State evidence was retained and scratch removed.

  • Live validation: ✅ go - 9 of 9 scenarios driven live against the product
Scenario Result Live Evidence
Release exits nonzero and preserves grant records when acquisition fails ✅ pass live grant-cli-state.json: real-acquire-failure/release
Deactivate exits nonzero and preserves both grant records when acquisition fails ✅ pass live grant-cli-state.json: real-acquire-failure/deactivate
Activate exits nonzero without replacing ownership when acquisition fails ✅ pass live grant-cli-state.json: real-acquire-failure/activate
Publish exits nonzero and preserves eligibility when acquisition fails ✅ pass live grant-cli-state.json: real-acquire-failure/publish
Release acquires the lock, removes rows, and retains ownership ✅ pass live grant-cli-state.json: real-success/release
Deactivate acquires the lock and removes both grant records ✅ pass live grant-cli-state.json: real-success/deactivate
Activate acquires the lock, replaces ownership, and clears old rows ✅ pass live grant-cli-state.json: real-success/activate
Publish acquires the lock and installs rows without changing ownership ✅ pass live grant-cli-state.json: real-success/publish
Release preserves a foreign lock while waiting, then completes after handoff ✅ pass live grant-contention.log
Evidence: Grant CLI exits and before/after state, including baseline reproduction

Source: Grant CLI exits and before/after state, including baseline reproduction

[
  {
    "mode": "injected-failure",
    "action": "release",
    "revision": "8dce46f1707bb950cacfbc03d145442ac03a9dd4",
    "command": [
      "bash",
      "~/.no-mistakes-upstream-codex/worktrees/d3c5a4c1e8a9/01M619AKHZZ4PM0HFR59XMA839/.test-3602/injected/bin/fm-wake-grant.sh",
      "release",
      "existing"
    ],
    "exit": 1,
    "stdout": "",
    "stderr": "injected acquire failure\n",
    "before": {
      ".branch-eligible-owner": "fm-branch-eligible-owner-v1\n23424\nWed Oct 28 12:59:25 2026     /opt/homebrew/Cellar/[email protected]/3.15.1/Frameworks/Python.framework/Versions/3.15/Resources/Python.app/Contents/MacOS/Python .test-3602/grant_probe.py\nexisting\n",
      ".branch-eligible-rows": "1\n",
      ".wake-queue": "1\t1\tsignal\ttask.status\tsignal: task\n",
      "lock_exists": true,
      "lock_pid": "23424\n",
      "temporary_records": []
    },
    "after": {
      ".branch-eligible-owner": "fm-branch-eligible-owner-v1\n23424\nWed Oct 28 12:59:25 2026     /opt/homebrew/Cellar/[email protected]/3.15.1/Frameworks/Python.framework/Versions/3.15/Resources/Python.app/Contents/MacOS/Python .test-3602/grant_probe.py\nexisting\n",
      ".branch-eligible-rows": "1\n",
      ".wake-queue": "1\t1\tsignal\ttask.status\tsignal: task\n",
      "lock_exists": true,
      "lock_pid": "23424\n",
      "temporary_records": []
    },
    "expected_observed": true
  },
  {
    "mode": "injected-failure",
    "action": "deactivate",
    "revision": "8dce46f1707bb950cacfbc03d145442ac03a9dd4",
    "command": [
      "bash",
      "~/.no-mistakes-upstream-codex/worktrees/d3c5a4c1e8a9/01M619AKHZZ4PM0HFR59XMA839/.test-3602/injected/bin/fm-wake-grant.sh",
      "deactivate",
      "23424",
      "existing"
    ],
    "exit": 1,
    "stdout": "",
    "stderr": "injected acquire failure\n",
    "before": {
      ".branch-eligible-owner": "fm-branch-eligible-owner-v1\n23424\nWed Oct 28 12:59:25 2026     /opt/homebrew/Cellar/[email protected]/3.15.1/Frameworks/Python.framework/Versions/3.15/Resources/Python.app/Contents/MacOS/Python .test-3602/grant_probe.py\nexisting\n",
      ".branch-eligible-rows": "1\n",
      ".wake-queue": "1\t1\tsignal\ttask.status\tsignal: task\n",
      "lock_exists": true,
      "lock_pid": "23424\n",
      "temporary_records": []
    },
    "after": {
      ".branch-eligible-owner": "fm-branch-eligible-owner-v1\n23424\nWed Oct 28 12:59:25 2026     /opt/homebrew/Cellar/[email protected]/3.15.1/Frameworks/Python.framework/Versions/3.15/Resources/Python.app/Contents/MacOS/Python .test-3602/grant_probe.py\nexisting\n",
      ".branch-eligible-rows": "1\n",
      ".wake-queue": "1\t1\tsignal\ttask.status\tsignal: task\n",
      "lock_exists": true,
      "lock_pid": "23424\n",
      "temporary_records": []
    },
    "expected_observed": true
  },
  {
    "mode": "injected-failure",
    "action": "activate",
    "revision": "8dce46f1707bb950cacfbc03d145442ac03a9dd4",
    "command": [
      "bash",
      "~/.no-mistakes-upstream-codex/worktrees/d3c5a4c1e8a9/01M619AKHZZ4PM0HFR59XMA839/.test-3602/injected/bin/fm-wake-grant.sh",
      "activate",
      "23424",
      "replacement"
    ],
    "exit": 1,
    "stdout": "",
    "stderr": "injected acquire failure\n",
    "before": {
      ".branch-eligible-owner": "fm-branch-eligible-owner-v1\n23424\nWed Oct 28 12:59:25 2026     /opt/homebrew/Cellar/[email protected]/3.15.1/Frameworks/Python.framework/Versions/3.15/Resources/Python.app/Contents/MacOS/Python .test-3602/grant_probe.py\nexisting\n",
      ".branch-eligible-rows": "1\n",
      ".wake-queue": "1\t1\tsignal\ttask.status\tsignal: task\n",
      "lock_exists": true,
      "lock_pid": "23424\n",
      "temporary_records": []
    },
    "after": {
      ".branch-eligible-owner": "fm-branch-eligible-owner-v1\n23424\nWed Oct 28 12:59:25 2026     /opt/homebrew/Cellar/[email protected]/3.15.1/Frameworks/Python.framework/Versions/3.15/Resources/Python.app/Contents/MacOS/Python .test-3602/grant_probe.py\nexisting\n",
      ".branch-eligible-rows": "1\n",
      ".wake-queue": "1\t1\tsignal\ttask.status\tsignal: task\n",
      "lock_exists": true,
      "lock_pid": "23424\n",
      "temporary_records": []
    },
    "expected_observed": true
  },
  {
    "mode": "injected-failure",
    "action": "publish",
    "revision": "8dce46f1707bb950cacfbc03d145442ac03a9dd4",
    "command": [
      "bash",
      "~/.no-mistakes-upstream-codex/worktrees/d3c5a4c1e8a9/01M619AKHZZ4PM0HFR59XMA839/.test-3602/injected/bin/fm-wake-grant.sh",
      "publish",
      "existing",
      "1"
    ],
    "exit": 1,
    "stdout": "",
    "stderr": "injected acquire failure\n",
    "before": {
      ".branch-eligible-owner": "fm-branch-eligible-owner-v1\n23424\nWed Oct 28 12:59:25 2026     /opt/homebrew/Cellar/[email protected]/3.15.1/Frameworks/Python.framework/Versions/3.15/Resources/Python.app/Contents/MacOS/Python .test-3602/grant_probe.py\nexisting\n",
      ".branch-eligible-rows": "1\n",
      ".wake-queue": "1\t1\tsignal\ttask.status\tsignal: task\n",
      "lock_exists": true,
      "lock_pid": "23424\n",
      "temporary_records": []
    },
    "after": {
      ".branch-eligible-owner": "fm-branch-eligible-owner-v1\n23424\nWed Oct 28 12:59:25 2026     /opt/homebrew/Cellar/[email protected]/3.15.1/Frameworks/Python.framework/Versions/3.15/Resources/Python.app/Contents/MacOS/Python .test-3602/grant_probe.py\nexisting\n",
      ".branch-eligible-rows": "1\n",
      ".wake-queue": "1\t1\tsignal\ttask.status\tsignal: task\n",
      "lock_exists": true,
      "lock_pid": "23424\n",
      "temporary_records": []
    },
    "expected_observed": true
  },
  {
    "mode": "real-acquire-failure",
    "action": "release",
    "revision": "8dce46f1707bb950cacfbc03d145442ac03a9dd4",
    "command": [
      "bash",
      "~/.no-mistakes-upstream-codex/worktrees/d3c5a4c1e8a9/01M619AKHZZ4PM0HFR59XMA839/bin/fm-wake-grant.sh",
      "release",
      "existing"
    ],
    "exit": 1,
    "stdout": "",
    "stderr": "",
    "before": {
      ".branch-eligible-owner": "fm-branch-eligible-owner-v1\n23424\nWed Oct 28 12:59:25 2026     /opt/homebrew/Cellar/[email protected]/3.15.1/Frameworks/Python.framework/Versions/3.15/Resources/Python.app/Contents/MacOS/Python .test-3602/grant_probe.py\nexisting\n",
      ".branch-eligible-rows": "1\n",
      ".wake-queue": "1\t1\tsignal\ttask.status\tsignal: task\n",
      "lock_exists": true,
      "lock_pid": "23424\n",
      "temporary_records": []
    },
    "after": {
      ".branch-eligible-owner": "fm-branch-eligible-owner-v1\n23424\nWed Oct 28 12:59:25 2026     /opt/homebrew/Cellar/[email protected]/3.15.1/Frameworks/Python.framework/Versions/3.15/Resources/Python.app/Contents/MacOS/Python .test-3602/grant_probe.py\nexisting\n",
      ".branch-eligible-rows": "1\n",
      ".wake-queue": "1\t1\tsignal\ttask.status\tsignal: task\n",
      "lock_exists": true,
      "lock_pid": "23424\n",
      "temporary_records": []
    },
    "expected_observed": true
  },
  {
    "mode": "real-acquire-failure",
    "action": "deactivate",
    "revision": "8dce46f1707bb950cacfbc03d145442ac03a9dd4",
    "command": [
      "bash",
      "~/.no-mistakes-upstream-codex/worktrees/d3c5a4c1e8a9/01M619AKHZZ4PM0HFR59XMA839/bin/fm-wake-grant.sh",
      "deactivate",
      "23424",
      "existing"
    ],
    "exit": 1,
    "stdout": "",
    "stderr": "",
    "before": {
      ".branch-eligible-owner": "fm-branch-eligible-owner-v1\n23424\nWed Oct 28 12:59:25 2026     /opt/homebrew/Cellar/[email protected]/3.15.1/Frameworks/Python.framework/Versions/3.15/Resources/Python.app/Contents/MacOS/Python .test-3602/grant_probe.py\nexisting\n",
      ".branch-eligible-rows": "1\n",
      ".wake-queue": "1\t1\tsignal\ttask.status\tsignal: task\n",
      "lock_exists": true,
      "lock_pid": "23424\n",
      "temporary_records": []
    },
    "after": {
      ".branch-eligible-owner": "fm-branch-eligible-owner-v1\n23424\nWed Oct 28 12:59:25 2026     /opt/homebrew/Cellar/[email protected]/3.15.1/Frameworks/Python.framework/Versions/3.15/Resources/Python.app/Contents/MacOS/Python .test-3602/grant_probe.py\nexisting\n",
      ".branch-eligible-rows": "1\n",
      ".wake-

... [5364 bytes truncated] ...

expected_observed": true
  },
  {
    "mode": "real-success",
    "action": "activate",
    "revision": "8dce46f1707bb950cacfbc03d145442ac03a9dd4",
    "command": [
      "bash",
      "~/.no-mistakes-upstream-codex/worktrees/d3c5a4c1e8a9/01M619AKHZZ4PM0HFR59XMA839/bin/fm-wake-grant.sh",
      "activate",
      "23424",
      "replacement"
    ],
    "exit": 0,
    "stdout": "",
    "stderr": "",
    "before": {
      ".branch-eligible-owner": "fm-branch-eligible-owner-v1\n23424\nWed Oct 28 12:59:25 2026     /opt/homebrew/Cellar/[email protected]/3.15.1/Frameworks/Python.framework/Versions/3.15/Resources/Python.app/Contents/MacOS/Python .test-3602/grant_probe.py\nexisting\n",
      ".branch-eligible-rows": "1\n",
      ".wake-queue": "1\t1\tsignal\ttask.status\tsignal: task\n",
      "lock_exists": false,
      "lock_pid": null,
      "temporary_records": []
    },
    "after": {
      ".branch-eligible-owner": "fm-branch-eligible-owner-v1\n23424\nWed Oct 28 12:59:25 2026     /opt/homebrew/Cellar/[email protected]/3.15.1/Frameworks/Python.framework/Versions/3.15/Resources/Python.app/Contents/MacOS/Python .test-3602/grant_probe.py\nreplacement\n",
      ".branch-eligible-rows": null,
      ".wake-queue": "1\t1\tsignal\ttask.status\tsignal: task\n",
      "lock_exists": false,
      "lock_pid": null,
      "temporary_records": []
    },
    "expected_observed": true
  },
  {
    "mode": "real-success",
    "action": "publish",
    "revision": "8dce46f1707bb950cacfbc03d145442ac03a9dd4",
    "command": [
      "bash",
      "~/.no-mistakes-upstream-codex/worktrees/d3c5a4c1e8a9/01M619AKHZZ4PM0HFR59XMA839/bin/fm-wake-grant.sh",
      "publish",
      "existing",
      "1"
    ],
    "exit": 0,
    "stdout": "",
    "stderr": "",
    "before": {
      ".branch-eligible-owner": "fm-branch-eligible-owner-v1\n23424\nWed Oct 28 12:59:25 2026     /opt/homebrew/Cellar/[email protected]/3.15.1/Frameworks/Python.framework/Versions/3.15/Resources/Python.app/Contents/MacOS/Python .test-3602/grant_probe.py\nexisting\n",
      ".branch-eligible-rows": null,
      ".wake-queue": "1\t1\tsignal\ttask.status\tsignal: task\n",
      "lock_exists": false,
      "lock_pid": null,
      "temporary_records": []
    },
    "after": {
      ".branch-eligible-owner": "fm-branch-eligible-owner-v1\n23424\nWed Oct 28 12:59:25 2026     /opt/homebrew/Cellar/[email protected]/3.15.1/Frameworks/Python.framework/Versions/3.15/Resources/Python.app/Contents/MacOS/Python .test-3602/grant_probe.py\nexisting\n",
      ".branch-eligible-rows": "1\n",
      ".wake-queue": "1\t1\tsignal\ttask.status\tsignal: task\n",
      "lock_exists": false,
      "lock_pid": null,
      "temporary_records": []
    },
    "expected_observed": true
  },
  {
    "mode": "baseline-injected-failure",
    "action": "release",
    "revision": "417cec2feb4e2976c0acdb2527b87b3ccc71535f",
    "command": [
      "bash",
      "~/.no-mistakes-upstream-codex/worktrees/d3c5a4c1e8a9/01M619AKHZZ4PM0HFR59XMA839/.test-3602/baseline/bin/fm-wake-grant.sh",
      "release",
      "existing"
    ],
    "exit": 0,
    "stdout": "",
    "stderr": "injected acquire failure\n",
    "before": {
      ".branch-eligible-owner": "fm-branch-eligible-owner-v1\n23424\nWed Oct 28 12:59:25 2026     /opt/homebrew/Cellar/[email protected]/3.15.1/Frameworks/Python.framework/Versions/3.15/Resources/Python.app/Contents/MacOS/Python .test-3602/grant_probe.py\nexisting\n",
      ".branch-eligible-rows": "1\n",
      ".wake-queue": "1\t1\tsignal\ttask.status\tsignal: task\n",
      "lock_exists": true,
      "lock_pid": "23424\n",
      "temporary_records": []
    },
    "after": {
      ".branch-eligible-owner": "fm-branch-eligible-owner-v1\n23424\nWed Oct 28 12:59:25 2026     /opt/homebrew/Cellar/[email protected]/3.15.1/Frameworks/Python.framework/Versions/3.15/Resources/Python.app/Contents/MacOS/Python .test-3602/grant_probe.py\nexisting\n",
      ".branch-eligible-rows": null,
      ".wake-queue": "1\t1\tsignal\ttask.status\tsignal: task\n",
      "lock_exists": true,
      "lock_pid": "23424\n",
      "temporary_records": []
    },
    "expected_observed": true
  },
  {
    "mode": "baseline-injected-failure",
    "action": "deactivate",
    "revision": "417cec2feb4e2976c0acdb2527b87b3ccc71535f",
    "command": [
      "bash",
      "~/.no-mistakes-upstream-codex/worktrees/d3c5a4c1e8a9/01M619AKHZZ4PM0HFR59XMA839/.test-3602/baseline/bin/fm-wake-grant.sh",
      "deactivate",
      "23424",
      "existing"
    ],
    "exit": 0,
    "stdout": "",
    "stderr": "injected acquire failure\n",
    "before": {
      ".branch-eligible-owner": "fm-branch-eligible-owner-v1\n23424\nWed Oct 28 12:59:25 2026     /opt/homebrew/Cellar/[email protected]/3.15.1/Frameworks/Python.framework/Versions/3.15/Resources/Python.app/Contents/MacOS/Python .test-3602/grant_probe.py\nexisting\n",
      ".branch-eligible-rows": "1\n",
      ".wake-queue": "1\t1\tsignal\ttask.status\tsignal: task\n",
      "lock_exists": true,
      "lock_pid": "23424\n",
      "temporary_records": []
    },
    "after": {
      ".branch-eligible-owner": null,
      ".branch-eligible-rows": null,
      ".wake-queue": "1\t1\tsignal\ttask.status\tsignal: task\n",
      "lock_exists": true,
      "lock_pid": "23424\n",
      "temporary_records": []
    },
    "expected_observed": true
  },
  {
    "mode": "baseline-injected-failure",
    "action": "activate",
    "revision": "417cec2feb4e2976c0acdb2527b87b3ccc71535f",
    "command": [
      "bash",
      "~/.no-mistakes-upstream-codex/worktrees/d3c5a4c1e8a9/01M619AKHZZ4PM0HFR59XMA839/.test-3602/baseline/bin/fm-wake-grant.sh",
      "activate",
      "23424",
      "replacement"
    ],
    "exit": 0,
    "stdout": "",
    "stderr": "injected acquire failure\n",
    "before": {
      ".branch-eligible-owner": "fm-branch-eligible-owner-v1\n23424\nWed Oct 28 12:59:25 2026     /opt/homebrew/Cellar/[email protected]/3.15.1/Frameworks/Python.framework/Versions/3.15/Resources/Python.app/Contents/MacOS/Python .test-3602/grant_probe.py\nexisting\n",
      ".branch-eligible-rows": "1\n",
      ".wake-queue": "1\t1\tsignal\ttask.status\tsignal: task\n",
      "lock_exists": true,
      "lock_pid": "23424\n",
      "temporary_records": []
    },
    "after": {
      ".branch-eligible-owner": "fm-branch-eligible-owner-v1\n23424\nWed Oct 28 12:59:25 2026     /opt/homebrew/Cellar/[email protected]/3.15.1/Frameworks/Python.framework/Versions/3.15/Resources/Python.app/Contents/MacOS/Python .test-3602/grant_probe.py\nreplacement\n",
      ".branch-eligible-rows": null,
      ".wake-queue": "1\t1\tsignal\ttask.status\tsignal: task\n",
      "lock_exists": true,
      "lock_pid": "23424\n",
      "temporary_records": []
    },
    "expected_observed": true
  },
  {
    "mode": "baseline-injected-failure",
    "action": "publish",
    "revision": "417cec2feb4e2976c0acdb2527b87b3ccc71535f",
    "command": [
      "bash",
      "~/.no-mistakes-upstream-codex/worktrees/d3c5a4c1e8a9/01M619AKHZZ4PM0HFR59XMA839/.test-3602/baseline/bin/fm-wake-grant.sh",
      "publish",
      "existing",
      "1"
    ],
    "exit": 0,
    "stdout": "",
    "stderr": "injected acquire failure\n",
    "before": {
      ".branch-eligible-owner": "fm-branch-eligible-owner-v1\n23424\nWed Oct 28 12:59:25 2026     /opt/homebrew/Cellar/[email protected]/3.15.1/Frameworks/Python.framework/Versions/3.15/Resources/Python.app/Contents/MacOS/Python .test-3602/grant_probe.py\nexisting\n",
      ".branch-eligible-rows": "1\n",
      ".wake-queue": "1\t1\tsignal\ttask.status\tsignal: task\n",
      "lock_exists": true,
      "lock_pid": "23424\n",
      "temporary_records": []
    },
    "after": {
      ".branch-eligible-owner": "fm-branch-eligible-owner-v1\n23424\nWed Oct 28 12:59:25 2026     /opt/homebrew/Cellar/[email protected]/3.15.1/Frameworks/Python.framework/Versions/3.15/Resources/Python.app/Contents/MacOS/Python .test-3602/grant_probe.py\nexisting\n",
      ".branch-eligible-rows": "1\n",
      ".wake-queue": "1\t1\tsignal\ttask.status\tsignal: task\n",
      "lock_exists": true,
      "lock_pid": "23424\n",
      "temporary_records": []
    },
    "expected_observed": true
  }
]
Evidence: Live foreign-lock contention and successful handoff

Source: Live foreign-lock contention and successful handoff

{"command": ["bash", "~/.no-mistakes-upstream-codex/worktrees/d3c5a4c1e8a9/01M619AKHZZ4PM0HFR59XMA839/bin/fm-wake-grant.sh", "release", "existing"], "while_foreign_lock_held": {"process_waiting": true, "owner_record_retained": true, "rows": "1\n", "lock_pid": "87473\n"}}
{"after_foreign_owner_releases_lock": {"exit": 0, "stdout": "", "stderr": "", "rows_removed": true, "owner_record_retained": true, "acquired_lock_released": true}}

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 validat