Repository navigation
fix(bin): anchor supervision markers and wake grants on the lock holder - #5172
ardydedase wants to merge 8 commits into
Conversation
|
Speaking as Kun's firstmate: stamped waiting-ci. HEAD contract-class: restore — tip restores two specified broken paths: (1) extension loaded markers record the lock-holder pid from the ownership walk instead of a descendant VISION: One captain/interface aligns (durable supervision evidence); Authority aligns (activation refuses live foreign owner); Scripts/judgment aligns; Restart aligns (markers + owner record survive churn); Delegation aligns (wake drain spine); Fleet/vendor aligns (Pi + omp ports); Scope aligns. Align: strengthens refusal/continuity under process churn. Security skim: no workflow changes; no secret handling. Fork CI approved this pass: runs 35638392306 (CI), 35638392488 (Require no-mistakes) — now queued. Overlaps with open #5174 on Pi/omp watch extensions, Firstmate-flag: no. |
fcdc7b3 to
816d9a7
Compare
816d9a7 to
182c290
Compare
|
Speaking as Kun's firstmate: stamped waiting-ci. HEAD contract-class: restore — tip restores two already-specified broken paths: (1) extension loaded markers record the lock-holder pid from the ownership walk instead of a descendant VISION: One captain/interface aligns (durable supervision evidence); Authority aligns (activation refuses live foreign owner); Scripts/judgment aligns; Restart aligns (markers + owner record survive churn); Delegation aligns (wake drain spine); Fleet/vendor aligns (Pi + omp ports); Scope aligns. Overlap with merged #5174: #5174 (retain Pi watcher predecessor / handoff phase) landed and is a different fix. Main tip still writes Fork workflows approved this pass: CI Firstmate-flag: no. Security FYI: none. closes-claim: n/a (no Fixes). |
…lder Pi and omp primary extensions recorded their loaded markers with process.pid, so a transient descendant pi process (a compaction child) that loaded the extensions rewrote the markers with its own pid; the live lock-holder session then read healthy extensions as foreign and the lazy branch marker audit depended on who happened to load first. All five markers now anchor on the lock-holder pid the ownership walk resolves to, keeping process.pid only on the cold-start path where no lock exists yet. The 2026-09-17 branch recovery also lost the eligible-rows snapshots to descendant-process churn, wedging the drain and acknowledgement until the snapshots were hand-regenerated. The branch owner grant record now carries the published seq list (v2 record), activation refuses a live different-pid owner, release clears the list, and the branch drain and acknowledgement rebuild a lost or corrupt snapshot from that record under the queue lock before presenting, acknowledging, or reclaiming. docs/watcher-continuity.md records the new durable contract.
The review round caught two real hazards the new code introduced. The ack section calls restore_branch_eligible_rows_locked with its own live ack temp, but the restore reassigned the shared DRAIN_TMP and cleared it on success, so an ack-window rebuild that actually fired would redirect the following awk to an empty filename and fail the acknowledgement it was added to protect, while orphaning the ack temp. The restore now uses a dedicated local temp it cleans on every failure path, leaving the caller's variable untouched. In fm-wake-grant.sh, publish's idempotent republish path kept the rows temp in the shared TMP when owner_record_seqs_rewritten reassigned it for the owner record, leaking the rows temp on every same-content republish and orphaning it whenever the owner-record mktemp failed. The rows temp is now removed on the replace=0 path and the owner-record rewrite uses its own trap-free dedicated temp with explicit cleanup, so no path can leak either temp. A colocated test asserts an idempotent republish leaves no temp files and keeps the recorded sequence list.
…e in drain comment
…er record before rows snapshot
…ck atomic Stock macOS Bash 3.2 reparses quotes inside a heredoc nested in command substitution, so the three new JavaScript comments in the descendant-marker test each drop their apostrophe to keep the body quote-balanced while the heredoc stays nested, preserving the subshell holder that keeps the test robust when the test shell itself is pid 1. The contributions fake forge advanced its clock with a truncate write, so a concurrent reader could observe an empty clock that bash arithmetic treats as 0 and reset the budget window; advances now rename a unique temp into place atomically.
182c290 to
3e0f76b
Compare
Intent
The developer tasked an autonomous worker with fixing two supervision-durability bugs in the firstmate repo: (1) pi primary extension "loaded" markers in .pi/extensions/fm-primary-pi-watch.ts, fm-primary-turnend-guard.ts, and fm-branch-supervision.ts were being overwritten by transient descendant pi processes recording their own process.pid instead of the live lock-holder pid, and (2) lost .branch-eligible-rows/.main-eligible-rows snapshots were wedging wake-queue drain/acknowledgement. The fix direction was to record the lock pid resolved by the ownership walk while keeping the cold-start missing-lock path writable, and to make lost snapshots regenerate durably inside the documented contract in docs/watcher-continuity.md (studying bin/fm-wake-grant.sh first) rather than inventing a parallel recovery path. Explicit constraints included reading and following the firstmate-coding-guidelines skill before editing, colocated tests for testable extension logic and snapshot regeneration, shellcheck-clean changed bin/ scripts, no changes to supervision semantics beyond these fixes, reporting a needs-decision line if the root cause proved different, and never stopping/restarting the shared no-mistakes daemon.
What Changed
fm-wake-drain.shrebuilds a lost or corruptstate/.branch-eligible-rowssnapshot from that record under the queue lock before presenting, acknowledging, claiming, or reclaiming, andfm-wake-grant.shrefuses activation while a live different-pid owner holds the grant (same pid may still reactivate, dead owners stay replaceable).tests/fm-wake-queue.test.shplus extension, turn-end guard, and omp harness suites for descendant-clobbered markers, lost-snapshot rebuilds, and refused takeovers.Risk Assessment
✅ Low: Both durability fixes are well-bounded, anchor their invariants at shared boundaries (the lock-holder pid and the queue-locked v2 owner record), carry executed behavioral regression tests for every claimed failure shape, and update the documented contract; the only residual note is a minor multi-reader maintenance hazard on the new record format.
Testing
Exercised the descendant-marker fix with a side-by-side regression driver that reproduces the bug on the base commit (marker names the transient descendant pid 20100 instead of holder 20097) and shows the fixed commit anchoring on the holder through both the init and session_start markLoaded paths, then ran the six targeted suites (turnend-guard, pi-watch, pi-branch, omp-harness, wake-queue, contributions) covering the marker anchoring across all four extensions and the lost-eligible-snapshot regeneration in drain and ack for both branch and main actors - all 286 tests pass with Node 22.24.2; three initial failures were environment artifacts (default node v18 cannot import .ts plugins, the ancestry-based omp-harness tests see the pi agent running this validation as a structural ancestor, and fm-pi-branch-extension.test.sh must run from the repo root), each reproduced and confirmed green once the environment was corrected, so no product defects were found.
Evidence: Base-vs-fixed descendant marker regression driver transcript
Source: Base-vs-fixed descendant marker regression driver transcript
=== base extension === lock holder pid: 20097 transient descendant (node): 20100 marker pid after init: 20100 marker pid after session_start: 20100 VERDICT: marker anchored on the TRANSIENT DESCENDANT (bug reproduced) === fixed extension === lock holder pid: 20097 transient descendant (node): 20159 marker pid after init: 20097 marker pid after session_start: 20097 VERDICT: marker anchored on the LOCK HOLDER (correct)Evidence: Targeted suite transcripts (turnend-guard, pi-watch, pi-branch, omp-harness, wake-queue, contributions)
Source: Targeted suite transcripts (turnend-guard, pi-watch, pi-branch, omp-harness, wake-queue, contributions)
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-wake-lib.sh:2072- The v2 owner-record five-line shape is now parsed independently in fm_wake_branch_owner_matches (fm-wake-lib.sh:2014), fm_wake_branch_owner_seqs (fm-wake-lib.sh:2072), owner_record_seqs_rewritten's three sed reads (bin/fm-wake-grant.sh:40), and the activate refusal's sed -n '2p' (bin/fm-wake-grant.sh:66). No reachable bug exists today - each reader validates before use and all writers hold the queue lock - but a future format change must keep four readers in lockstep; a single record reader in fm-wake-lib.sh would be the natural consolidation point. Purely a maintenance note on code introduced by this change.✅ **Test** - passed
✅ No issues found.
Manual regression driver: real node descendant writes state/.lock naming its parent as holder, imports fm-primary-turnend-guard.ts from both da9607d (marker records the transient descendant pid - bug reproduced) and 077a914 (marker records the lock holder pid) across both init and session_start markLoaded pathsbash tests/fm-turnend-guard.test.sh (Node 22) - 90 ok, includes '.pi primary extension: the loaded marker anchors on the lock holder from a descendant process'bash tests/fm-pi-watch-extension.test.sh (Node 22, from repo root) - 51 ok, includes 'Pi watch extension marker anchors on the lock holder from a descendant process'bash tests/fm-pi-branch-extension.test.sh (Node 22, from repo root) - 46 okbash tests/fm-omp-harness.test.sh (Node 22, via systemd transient service so no pi process is in the ancestry) - 13 ok, includes descendant-marker tests for both .omp extensionsbash tests/fm-wake-queue.test.sh (Node 22) - 48 ok, includes 'a lost branch-eligible row snapshot is rebuilt from the live owner record for both drain and ack', 'a main drain rebuilds a lost eligible snapshot and stays fenced out of the branch rows', and the runtime log 'wake drain: restored a lost branch-eligible row snapshot from the live owner record'bash tests/fm-contributions.test.sh (Node 22) - 38 ok✅ **Document** - passed
✅ No issues found.
⏭️ **Lint** - skipped
✅ **Push** - passed
✅ No issues found.