Skip to content

fix(bin): exclude omp daemon workers from session lock anchoring - #6870

Closed
avivl wants to merge 4 commits into
kunchenguid:mainfrom
avivl:avivl/omp-daemon-worker-lock
Closed

avivl wants to merge 4 commits into
kunchenguid:mainfrom
avivl:avivl/omp-daemon-worker-lock

Conversation

@avivl

@avivl avivl commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Upstream pull request #6870 (fork branch avivl/omp-daemon-worker-lock on [email protected]:avivl/firstmate.git, current head e4226052196b6238c07b64f26e13459b63a96034) "fix(bin): exclude omp daemon workers from session lock anchoring" is approved by the upstream owner's reviewer and auto-merges once its checks are green, but it now conflicts with main. Main took #7415 ("re-anchor a Claude session's lock so /clear keeps ownership") on 2026-10-17, which edits the same test file, and a trial merge shows one conflict: tests/fm-session-lock-ancestry.test.sh. The branch is 3 commits ahead (one fix commit 79aaf0c4 plus two "Merge branch 'main'" commits) and 56 behind origin/main. The captain approved this one upstream push with the words: fix it, for pr://6870. The task is to resolve the conflict, keep every behavior and test of the PR and of main, and re-raise the PR through the no-mistakes pipeline once on the final head.

What Changed

  • bin/fm-session-lock-lib.sh: added fm_omp_daemon_worker, which recognizes omp daemon worker processes (omp __omp_worker_* as the first argument). fm_harness_process_matches now never treats one as a harness, and the ancestry walk in fm_harness_ancestry_pids stops at one without a verdict. A new fm_harness_ancestry_under_omp_worker helper reports whether the walk hit such a worker first. This keeps a named omp bash call from recording the shared daemon broker as the session in state/.lock.
  • bin/fm-lock.sh: when no harness can be found and the ancestry runs through an omp daemon worker, the error now says the command is running under a named bash call and should be rerun without name. Other failures keep the original message.
  • tests/fm-session-lock-ancestry.test.sh and the omp docs (docs/supervision-protocols/omp.md, .agents/skills/harness-adapters/references/harness/omp.md): added ancestry tests for the daemon-worker cases and documented that session-lock commands must run as ordinary bash calls. The branch also resolves the conflict with fix(bin): re-anchor a Claude session's lock so /clear keeps ownership #7415 (re-anchoring a Claude session's lock so /clear keeps ownership) in the test file, keeping the tests from both sides.

Risk Assessment

✅ Low: The conflict resolution now has one definition and one call of each test from both main and the PR, and the lock-library change is narrowly scoped to excluding omp __omp_worker_* processes from anchoring.

Testing

I ran the merged session-lock ancestry suite, which drives real fm-lock.sh processes. All 20 tests passed, including main's re-anchor lease and auto-arm tests and the PR's omp daemon worker unit and e2e tests. There are no duplicate definitions or calls. I did not drive a live omp primary in a lab, because the existing e2e test already covers the omp daemon worker scenario.

  • Live validation: ✅ go - 2 of 2 scenarios driven live against the product
Scenario Result Live Evidence
Run the merged suite end to end: main's re-anchor and auto-arm tests and the PR's omp daemon worker tests all pass once, with no duplicates ✅ pass live session-lock-run.txt
fm-lock.sh refuses under an omp daemon worker, and the session reclaims a worker-pinned lock (e2e) ✅ pass live session-lock-run.txt: 'ok - session-lock e2e: fm-lock.sh refuses under an omp daemon worker...'
Evidence: session-lock suite run

Source: session-lock suite run

ok - session-lock: a version-named Claude Code session is identified from its install path and argv[0]
ok - session-lock: a harness that is pid 1 of its own namespace is examined, not skipped
ok - session-lock: ordinary script paths under a harness directory are not harness processes
ok - session-lock: ownership stops at the first non-harness gap above the contiguous run
ok - session-lock: a live version-named session holding the lock is not mistaken for a stale owner
ok - session-lock: a trusted same-session id keeps owning a recycled background chain, and nothing weaker does
ok - session-lock: a trusted id anchors the lock on the model-loop process, anything else on the outermost pid
ok - session-lock e2e: a version-named session claims the home and arms supervision
ok - session-lock e2e: a session parented by a harness-named daemon claims the home and arms supervision
ok - session-lock e2e: a version-named session under a harness-named daemon keeps its own lock
ok - session-lock e2e: a background session keeps its lock and its supervision across a recycled helper chain and a same-process session-id change
ok - session-lock: a same-session confirmation waits for the claim lock and refreshes a re-keyed id
ok - session-lock: a waiting confirmation does not steal another session's lock
ok - session-lock: a failed lock write restores the previous sidecar
ok - session-lock: a failed lock write removes a newly created sidecar
ok - session-lock: a verified reclaim keeps the new sidecar beside the new pid
ok - session-lock: a re-anchor keeps both supervision actors' task leases live
ok - session-lock: a re-anchor during a rewake turn keeps the mid-turn auto-arm proof healthy
ok - session-lock: an omp daemon worker is never the session, and a lock pinned to one is stale
ok - session-lock e2e: fm-lock.sh refuses under an omp daemon worker and the session reclaims a worker-pinned lock

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

🔧 **Rebase** - 1 issue found → auto-fixed ✅
  • ⚠️ tests/fm-session-lock-ancestry.test.sh - merge conflict rebasing onto refs/remotes/no-mistakes-push/avivl/omp-daemon-worker-lock

🔧 Fix applied.
✅ Re-checked - no issues remain.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • 🚨 tests/fm-session-lock-ancestry.test.sh:1330 - The conflict resolution in tests/fm-session-lock-ancestry.test.sh duplicated content. Main's test_reanchor_keeps_task_leases_live, autoarm_midturn_healthy and test_reanchor_keeps_autoarm_midturn_healthy (defined at lines 1115-1215) are defined a second time at lines 1330-1438. The PR's test_omp_daemon_worker_is_never_the_session and test_e2e_fm_lock_under_omp_daemon_worker are defined twice (1225/1289 and 1440/1504). The invocation list at the end (1559-1566) calls each of the four tests twice. The re-anchor tests use fixed dirs ($TMP_ROOT/reanchor-leases, reanchor-autoarm) and leave a state/stop file behind. On the second run the stub loops exit immediately and the stale front-pid is dead, so the kill -0 "$front_pid" check fails with 'the front-end exited'. The suite should fail on the second invocation. Remove the second copy of the definitions (lines 1330-1566 region duplicates) and the four duplicate calls, keeping one definition and one call of each test.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 2 of 2 scenarios driven live against the product
Scenario Result Live Evidence
Run the merged suite end to end: main's re-anchor and auto-arm tests and the PR's omp daemon worker tests all pass once, with no duplicates ✅ pass live session-lock-run.txt
fm-lock.sh refuses under an omp daemon worker, and the session reclaims a worker-pinned lock (e2e) ✅ pass live session-lock-run.txt: 'ok - session-lock e2e: fm-lock.sh refuses under an omp daemon worker...'
  • bash tests/fm-session-lock-ancestry.test.sh (run twice, exit 0, 20 ok, 0 not ok)
  • Counted test definitions (20) against invocations (20) to confirm the duplicate blocks are gone
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@avivl
avivl marked this pull request as ready for review October 8, 2026 15:51
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @avivl. That's a clear write-up of a nasty one. A shared broker pinning state/.lock for days is exactly the kind of silent supervision loss we want gone.

I compared head b5178356 against main 19fcbbde.

What I checked: fm_omp_daemon_worker looks only at the first argument after the executable, so a session whose prompt mentions __omp_worker_ still counts as a session. fm_harness_process_matches rejects a worker, so a lock pinned to the broker reads stale and can be reclaimed. The ancestry walk stops at a worker instead of climbing into whichever omp started it, and fm-lock.sh names the cause and the fix ("rerun without name"). Other harnesses' matching is unchanged, and the tests use fake ps and fake-omp processes only.

CI: this is a fork contribution whose runs were waiting on approval. I reviewed the diff first (bin/, docs/, tests/, and one skill reference, with no workflow, network, or secret surface), then approved CI 37847030662 and Require no-mistakes 37847030661.

Waiting on you, the author:

  1. Re-raise for this head. The body's attestation is bound to 79aaf0c4, but the head is now your merge-from-main commit b5178356, so "PR must be raised via no-mistakes" will report a mismatch. Please push the current branch through git push no-mistakes so the attestation binds the head.
  2. Live check with a real omp. Live validation counts 1 of 3, and that one used fake-omp processes. You noted a real omp 18.8.x broker wasn't exercised. Could you run a real omp primary, make a named bash call to bin/fm-session-start.sh, and post evidence that fm-lock.sh refuses with the new hint? A plain call should still take the lock, and a lock left pinned to the broker should be reclaimed. The re-raise can capture this too. Thank you, and no rush.

Contract-class: restore. The omp primary's session lock is an existing, specified default path. It's meant to record the session's own omp process, and the shared broker broke that. This makes it record only real sessions, and it changes nothing for other harnesses.

VISION.md, rule by rule

  • One captain, one interface: aligns. It removes a days-long silent supervision outage, and the new refusal speaks to the agent, not the captain.
  • Authority is explicit and never inferred: aligns. The lock refuses rather than guesses when the ancestry runs through a shared worker.
  • Scripts own the mechanics, agents own the judgment: aligns. The process classification is exact and scripted.
  • A restart is a non-event: aligns. A lock pinned to a dead-end worker now reads stale and can be reclaimed, instead of surviving every session.
  • Delegation with a spine: aligns, pending the live omp evidence above.
  • The fleet outlives any vendor: aligns. It's bound to omp's observable process shape and documented in the omp adapter reference with the verified version range (18.8.0 to 18.8.4).
  • Scope: aligns. Session-lock library only.

Next step: waiting on you for the re-raise and the live omp evidence. Once the attested head is fully green, this is an auto-merge candidate. Nothing here is waiting on Kun.

@avivl

avivl commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

I re-ran the lock behavior against a real omp primary using omp/18.8.6, JSON-RPC mode, and fresh isolated FM_HOME directories.

Base was 19fcbbde12c4e916e0d5faa60c399d2fd2845740 (origin/main).
Fixed head was b517835671890a314717db4098c375d02a7bb56d.
The capture wrapper only added ps ancestry, exit-code, and lock-content output around the commands shown below; paths are relative to each temporary lab project.

Scenario Exact omp bash call Trimmed live output Result
Before fix: named service call bash({name: "pr6870-base-named", command: "bin/fm-lock.sh"}) 80601 79704 .../omp __omp_worker_daemon_broker
79704 79703 omp omp --mode rpc ...
lock acquired: harness pid 80601
rc=0
lock=80601
PASS: reproduced the bug. The live broker was recorded as the session lock holder.
Fixed head: named service call bash({name: "pr6870-fix-named", command: "bin/fm-lock.sh"}) 82328 81566 .../omp __omp_worker_daemon_broker
81566 81565 omp omp --mode rpc ...
error: cannot locate harness process in ancestry: this command runs under an omp daemon worker (a bash call with \name`), whose ancestry belongs to whichever omp started that shared worker; rerun it as an ordinary bash call without `name`<br>rc=1<br>lock=absent`
PASS: refused with the new hint, and the process tree proves the broker was the ancestor.
Fixed head: ordinary call bash({command: "bin/fm-lock.sh"}) 81566 81565 omp omp --mode rpc ...
lock acquired: harness pid 81566
rc=0
lock=81566
PASS: the lock names the real omp session pid, not broker pid 82328.
Fixed head: reclaim broker-pinned lock bash({command: "printf '%s\\n' 82328 > \"$FM_HOME/state/.lock\"; bin/fm-lock.sh"}) before_lock=82328
82328 81566 omp .../omp __omp_worker_daemon_broker
lock acquired: harness pid 81566
rc=0
after_lock=81566
PASS: the live broker holder was classified stale and replaced with the real session pid.

This verifies the same behavior on 18.8.6, in addition to the previously documented 18.8.0 through 18.8.4 versions. This run did not test 18.8.5.
Suggested follow-up, not committed here: document 18.8.6 as an additionally verified version in .agents/skills/harness-adapters/references/harness/omp.md.

The temporary homes and omp processes used for this run were removed after capture.

The branch was re-raised through no-mistakes at head b517835671890a314717db4098c375d02a7bb56d. The new attestation workflow is awaiting upstream approval: https://github.com/kunchenguid/firstmate/actions/runs/37929941629

The cancelled Behavior portable serial 2 job also needs a rerun: https://github.com/kunchenguid/firstmate/actions/runs/37847030662/job/113779297467

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @avivl, and thank you for the real omp 18.8.6 run. All four rows (bug reproduced on main, named call refused with the new hint, plain call locks the real session pid, broker-pinned lock reclaimed) are exactly what I asked for. The live ask is cleared.

What changed since my last stamp (b5178356): head is now e4226052, a second merge from main. I diffed the PR against main at both heads; the change set is byte-identical (same 5 files, +175/-2). Contract-class stays restore and my VISION verdict from the earlier comment stands (all rules align; delegation now evidenced live).

CI: I approved CI 37986414079 and Require no-mistakes 37986414174 for this head.

Waiting on you, the author (one small thing): the body's attestation is bound to b5178356, so "PR must be raised via no-mistakes" will report a mismatch on e4226052. Could you push the current branch through git push no-mistakes once more so it binds this head? Merging main isn't needed unless GitHub shows a conflict, and each merge re-opens this. Once CI and no-mistakes are green, this auto-merges. Thanks again.

@avivl avivl changed the title fix(bin): never record an omp daemon worker as the session lock holder fix(bin): exclude omp daemon workers from session lock anchoring Oct 10, 2026
@avivl

avivl commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

Friendly ping: this branch is ready for review, and the fork workflow runs still need approval from a maintainer before CI can run. Thanks.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @avivl, and thanks for re-raising.

The body's attestation is now bound to head e4226052, so the mismatch I asked about on 2026-10-09 is cleared. The head hasn't moved since my last review, so the change set is the same 5 files, and main has not touched bin/fm-session-lock-lib.sh, bin/fm-lock.sh, or the ancestry tests since your merge base. CI on this head was already green. I just approved the two re-raise runs of Require no-mistakes (38009943504, 38009965453), which had been waiting on maintainer approval. They're queued behind a busy runner pool.

Contract-class: restore (unchanged), and my VISION verdict from 2026-10-09 still stands. Once the no-mistakes check reports green on this head, this auto-merges. Nothing else is needed from you right now.

avivl and others added 4 commits October 19, 2026 09:33
omp's daemon broker (omp __omp_worker_daemon_broker) runs every bash call made with name, carries the bare process name omp, and is shared by every omp in one project directory, so it outlives sessions and its parent is whichever omp started it. A named bin/fm-session-start.sh call recorded the broker in state/.lock, which then pinned the home's lock: every later session saw another live firstmate session holding it and supervision never started (omp 18.8.0-18.8.4).

The lock library now rejects omp __omp_worker_* processes as harnesses and stops its ancestry walk at one, so a worker-pinned lock reads stale and the session reclaims it, and a lock-taking script run under a worker refuses with a message naming the cause instead of recording the wrong pid. The omp protocol and harness reference say to run lock-taking scripts as ordinary bash calls.
…kunchenguid#7415)

* fix(bin): re-anchor a Claude session's lock so /clear keeps ownership

A same-session confirmation over a live lock line 1 outside the current
harness ancestry now rewrites line 1 to the session's CLAUDE_PID anchor
under the claim lock, so a later /clear re-key in the same process is
still proven by ancestry instead of being refused as a foreign owner.

Fixes kunchenguid#6820

* fix(bin): move task leases with a session-lock re-anchor

A same-session re-anchor rewrote lock line 1 off a live pid while task
leases still named that pid, so a lease held by main or the supervision
branch read as stale and the other actor could claim the task. The
re-anchor now takes the lease-command lock after the claim lock and,
in the same critical section as the line-1 write, rewrites leases
recorded against the old pid to the new anchor (fm_lease_rekey_holder).
If the lease-command lock stays busy past a short bound, the
confirmation keeps line 1 as before and a later acquisition re-anchors.

The foreign-owner reproduction now asserts the re-anchor contract: the
same trusted id from a live process outside the owner's ancestry moves
line 1 onto that process's CLAUDE_PID, and a different id is refused
against it afterwards. The ancestry membership loop is shared through
one session-lock lib helper.

The earlier commit dropped the ancestry suite's dead-front-end reclaim
phase; that coverage lives in the existing reclaim tests
(test_verified_reclaim_keeps_new_sidecar and the Stop auto-arm's
test_reclaims_stale_session_lock_before_arming).

* fix(bin): record the lock holder for a lease pinned before a re-anchor

The supervision host pins FM_LEASE_HOLDER_PID to lock line 1 at the
start of each engine turn. A same-session re-anchor inside that turn
moved line 1 to a new pid while the pinned holder stayed alive, so a
later claim or same-actor refresh in the turn recorded the old pid and
the lease read stale, letting main claim the branch's task.

A claim now records the live line 1 when the pinned holder is alive but
is no longer line 1. Another session takes the lock only from a dead
owner, so that state comes from a re-anchor; a dead pin is still
recorded as before and its lease stays stale.

* no-mistakes(review): Move auto-arm rewake session pid with lock re-anchor

* no-mistakes(review): Align startup-network downgrade test and lock-rewrite comment

* no-mistakes(review): Correct lock takeover and re-anchor signal-window comments

* no-mistakes(review): Record re-anchor rewake and pinned-claim verification evidence

* no-mistakes(document): Update network-checks diagnostic for re-anchored lock holder
omp's daemon broker (omp __omp_worker_daemon_broker) runs every bash call made with name, carries the bare process name omp, and is shared by every omp in one project directory, so it outlives sessions and its parent is whichever omp started it. A named bin/fm-session-start.sh call recorded the broker in state/.lock, which then pinned the home's lock: every later session saw another live firstmate session holding it and supervision never started (omp 18.8.0-18.8.4).

The lock library now rejects omp __omp_worker_* processes as harnesses and stops its ancestry walk at one, so a worker-pinned lock reads stale and the session reclaims it, and a lock-taking script run under a worker refuses with a message naming the cause instead of recording the wrong pid. The omp protocol and harness reference say to run lock-taking scripts as ordinary bash calls.
@avivl
avivl force-pushed the avivl/omp-daemon-worker-lock branch from e422605 to 4cac953 Compare October 19, 2026 13:39
@avivl

avivl commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Friendly ping: the conflict with main is fixed on head 4cac953 (same 5 files, 0 behind main). The fork workflow runs on this head still need maintainer approval before CI can run, and the attestation needs a refresh. Thanks.

@avivl

avivl commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

Heads up: main took #6300 today and now conflicts with this branch in bin/fm-lock.sh and bin/fm-session-lock-lib.sh. I will rebase as soon as someone looks at it, so the rebase lands on the final state of main. The fork workflow runs on head 4cac953 are still waiting for maintainer approval. Thanks.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @avivl — really appreciate you taking the time on this. The fix landed via #8731 (dbb3f19). I'm closing this PR in favor of that port. Please reopen if anything was missed.

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.

3 participants