Skip to content

fix: safely reclaim stale extension runner records - #6286

Open
AnPod wants to merge 5 commits into
kunchenguid:mainfrom
AnPod:fix/stale-extension-runner-record-6173
Open

AnPod wants to merge 5 commits into
kunchenguid:mainfrom
AnPod:fix/stale-extension-runner-record-6173

Conversation

@AnPod

@AnPod AnPod commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Fix issue #6173: extension process-event capture creates state/procevent/.runner with O_CREAT|O_EXCL; if a run dies before removing it every later start fails with 'cannot create .runner'. Add a reclaim path that replaces dead or empty residue only after claim/lock safeguards show the previous owner is gone, opens existing paths with O_NONBLOCK so a FIFO named like a runner cannot hang while holding the source lock, and still refuses live owners, malformed records and unsafe paths. Includes added empty/FIFO refusal coverage in tests/fm-extension-binding.test.sh.

What Changed

  • Reclaim dead or empty extension runner records under claim and source-lock safeguards, while refusing live owners, malformed records, and unsafe paths; open existing records nonblocking to prevent FIFO hangs.
  • Record the capture helper as the runner, preserve its claim while capture continues after the supervising shell exits, and remove runner records only when their inode still matches. Check active ownership before waiting on the registration lifecycle lock and use directory descriptors for launch files.
  • Document the recovery rules and expand regression coverage for stale and empty records, unsafe-record refusal, shell termination, and replacement-record preservation.

Risk Assessment

✅ Low: The bounded reclaim logic preserves claim and lock safeguards, refuses unsafe or live records, and protects in-flight capture from replacement.

Testing

Both targeted executable-interface segments passed against the real product after correcting fixture placement; logs capture reclaim, refusal, ownership, directory-swap and cleanup checks. No full suite or static analysis ran, and all disposable fixtures were removed.

  • Live validation: ✅ go - 7 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Start with dead or empty runner residue and capture a result successfully ✅ pass live lifecycle-runner.log: dead and empty residue restart assertions
Empty an active capture's runner record; restart and registration replacement still refuse to displace it ✅ pass live lifecycle-runner.log: active-owner and registration replacement assertions
Kill the launching shell; preserve the live capture claim until capture stops, then allow restart ✅ pass live lifecycle-runner.log: shell-only TERM and KILL assertions
Start with live, malformed, symlink or FIFO runner records; refuse promptly without invoking the adapter or altering the record ✅ pass live lifecycle-runner.log: live, malformed, symlink and FIFO refusal assertions, including bounded FIFO timing
Replace registry or inbox paths during capture; retain pinned directories and prevent redirected evidence ✅ pass live lifecycle-state.log: descriptor-bound registry swap and substitution assertions
Replace a runner record during capture; completion preserves the replacement on every cleanup path ✅ pass live lifecycle-state.log: replacement runner preservation across captured, no-result and failure outcomes
Exercise ownership and state safeguards; reject forged authority and recover only the recorded state root ✅ pass live lifecycle-state.log: authority, reservation, overridden-state crash recovery and owner-token assertions
Evidence: Runner lifecycle executable-interface evidence

Source: Runner lifecycle executable-interface evidence

ok - all registration owner transitions wait for the prior extension runner
ok - shell-only TERM and KILL retain the live capture claim until polling stops
ok - a dead extension runner record allows restart and capture
ok - an empty extension runner residue allows restart and capture
ok - live, malformed, symlink, and FIFO extension runner records remain refused

all extension-binding tests passed
Evidence: State boundaries and replacement cleanup evidence

Source: State boundaries and replacement cleanup evidence

ok - owner-matched retirement refuses a stale generation and accepts the current one
ok - caller environment, descriptors, and lifecycle entry cannot forge capture authority
ok - extension capture reservations are bounded to their runner lifecycle
error: process-event state root is not a private directory
ok - control-byte state roots cannot serialize claims or reservations
ok - crash recovery revalidates and cleans only the recorded state root
ok - post-registration inbox symlink substitution cannot redirect extension evidence
ok - post-registration registry symlink substitution cannot redirect external evidence
ok - external staging remains descriptor-bound across a registry directory swap
ok - external staging leaves remain no-follow descriptor-bound through capture
ok - external publication remains descriptor-bound after capture
ok - signal-terminated extension capture cannot publish an empty success
ok - capture helper retains the inherited inbox descriptor before publication
ok - capture cleanup preserves replacement runner records on every completion path
not-autohandled: legacy-link-source (left for the handler; still unacknowledged)
ok - absent-registry built-in capture retains its legacy state-path behavior
error[retirement-failed]: error[binding-in-use]: error: binding still owns process-event registration: inbox-swap-source
ok - overridden state confines extension work and captured-result operations
ok - bounded home sweep retires an extension source through its exact owner token
ok - legacy built-in registrations retain behavior and gain exact conditional retirement

all extension-binding tests passed
- Outcome: 🔧 4 issues found → auto-fixed (2) ✅ across 3 runs (21m27s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

🔧 **Test** - 4 issues found → auto-fixed (2) ✅
  • 🚨 tests/fm-extension-binding.test.sh:1373 - The lifecycle-runner check blocked indefinitely at registration replacement while capture remained active; it required explicit termination. The targeted segment cannot complete as written.
  • 🚨 tests/fm-extension-binding.test.sh:1850 - The new replacement-cleanup test creates its readiness marker with touch, but wait_for_file requires a nonempty file. It therefore always reports that polling did not start and cannot verify replacement preservation.
  • 🚨 tests/fm-extension-binding.test.sh:1637 - The lifecycle-state segment fails because it expects 'cannot acquire source ownership' while the command reports 'cannot claim source'. A temporary diagnostic adjustment exposed a further failure: the overridden-state crash fixture did not create both expected reservations.
  • 🚨 live validation verdict: no-go (6 of 6 scenarios were driven live against the product); failed: An empty record cannot displace an active claim, and registration replacement promptly refuses the active capture, Capture completion preserves a replacement runner record on captured, no-result and failure paths
  • Live validation: ❌ no-go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Restart with a dead runner record captures a result and removes residue ✅ pass live runner-recovery.log
Restart with an empty runner record captures a result and removes residue ✅ pass live runner-recovery.log
Live PID, malformed, symlink and FIFO records refuse capture without changing the record; FIFO refusal returns before timeout ✅ pass live runner-recovery.log
TERM and KILL of the launcher retain capture ownership until completion and permit a subsequent fresh start ✅ pass live runner-recovery.log
An empty record cannot displace an active claim, and registration replacement promptly refuses the active capture ❌ fail live Original lifecycle-runner segment blocked at registration replacement and was terminated
Capture completion preserves a replacement runner record on captured, no-result and failure paths ❌ fail live replacement-cleanup.log
  • FM_EXTENSION_BINDING_SEGMENT=lifecycle-runner bash tests/fm-extension-binding.test.sh with isolated TMPDIR; stopped blocked registration check
  • FM_EXTENSION_BINDING_SEGMENT=lifecycle-state bash tests/fm-extension-binding.test.sh with isolated TMPDIR
  • Temporary focused executable-interface driver: remaining lifecycle-runner scenarios under timeout 90
  • Temporary lifecycle-state driver with diagnostic adjustment under timeout 90
  • Isolated replacement-cleanup block under timeout 30
  • Removed temporary driver and fixture directory; verified clean working tree

🔧 Fix applied.
2 errors still open:

  • 🚨 tests/fm-extension-binding.test.sh:1721 - The lifecycle-state segment reproducibly fails when the registry directory is replaced during active capture. The real start command reports 'cannot establish the source launch boundary: registry-race-source', contradicting the test's expected successful descriptor-bound completion. Three runs failed at this boundary.
  • 🚨 live validation verdict: no-go (7 of 7 scenarios were driven live against the product); failed: Swap the registry directory during active capture and complete through pinned directories
  • Live validation: ❌ no-go - 7 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Start with a dead PID runner record and capture a fresh result ✅ pass live lifecycle-runner.log
Start with empty runner residue and capture a fresh result ✅ pass live lifecycle-runner.log
Empty an active runner record; restart preserves its claim and registration replacement promptly refuses ✅ pass live lifecycle-runner.log
Start with live, malformed, symlink or FIFO runner records; refuse without invoking the adapter or hanging ✅ pass live lifecycle-runner.log
Terminate the launcher with TERM or KILL; active capture retains ownership until completion and subsequently permits restart ✅ pass live lifecycle-runner.log
Replace a runner record during capture; captured, no-result and failure cleanup preserve the replacement ✅ pass live replacement-cleanup.log
Swap the registry directory during active capture and complete through pinned directories ❌ fail live state-race-diagnostic.log
  • FM_EXTENSION_BINDING_SEGMENT=lifecycle-runner timeout 240 bash tests/fm-extension-binding.test.sh with isolated evidence-directory TMPDIR
  • FM_EXTENSION_BINDING_SEGMENT=lifecycle-state timeout 240 bash tests/fm-extension-binding.test.sh twice with isolated evidence-directory TMPDIR
  • Executed the existing three replacement-cleanup cases independently against the real Perl capture helper
  • Repeated lifecycle-state with a temporary diagnostic driver printing the failing start command's output
  • Removed temporary drivers and fixture directories; verified clean git status

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

  • Live validation: ✅ go - 7 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Start with dead or empty runner residue and capture a result successfully ✅ pass live lifecycle-runner.log: dead and empty residue restart assertions
Empty an active capture's runner record; restart and registration replacement still refuse to displace it ✅ pass live lifecycle-runner.log: active-owner and registration replacement assertions
Kill the launching shell; preserve the live capture claim until capture stops, then allow restart ✅ pass live lifecycle-runner.log: shell-only TERM and KILL assertions
Start with live, malformed, symlink or FIFO runner records; refuse promptly without invoking the adapter or altering the record ✅ pass live lifecycle-runner.log: live, malformed, symlink and FIFO refusal assertions, including bounded FIFO timing
Replace registry or inbox paths during capture; retain pinned directories and prevent redirected evidence ✅ pass live lifecycle-state.log: descriptor-bound registry swap and substitution assertions
Replace a runner record during capture; completion preserves the replacement on every cleanup path ✅ pass live lifecycle-state.log: replacement runner preservation across captured, no-result and failure outcomes
Exercise ownership and state safeguards; reject forged authority and recover only the recorded state root ✅ pass live lifecycle-state.log: authority, reservation, overridden-state crash recovery and owner-token assertions
  • FM_TEST_SKIP_ORPHAN_REAP=1 FM_EXTENSION_BINDING_SEGMENT=lifecycle-runner timeout 240 bash tests/fm-extension-binding.test.sh
  • FM_TEST_SKIP_ORPHAN_REAP=1 FM_EXTENSION_BINDING_SEGMENT=lifecycle-state timeout 240 bash tests/fm-extension-binding.test.sh
  • Initially ran both segments with workspace-local TMPDIR; package binding correctly refused fixtures inside Git. Reran successfully with TMPDIR under the permitted evidence directory.
  • Inspected both evidence logs, verified fixture cleanup, and ran git status --short.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[High risk] Changes process event runner record handling and lock ordering.

The PR appears safe to merge based on the reviewed changes.

Reviews (3) · Last reviewed commit: "no-mistakes(document): Document safe ext..."

Comment thread bin/fm-procevent-extension-capture.pl Resolved
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: first stamp vs tip 549e07f37fd73aa01d74cd126b1111c99175abed (#6255). Closes ready-for-pr #6173: yes (dead/empty extension .runner residues block restart; tip still uses bare O_EXCL open_new for the runner record).

HEAD 9bee4e040e06f967ae5f0d00d47928c7c270bfb9. MERGEABLE/UNSTABLE. Attestation: MISSING (body notes git push no-mistakes still required). NM FAILURE. Behavior portable + Herdr + Lint green. Greptile FAILURE (confidence 4/5) with open P1: if the runner shell exits while its capture helper is still polling, reclaim can treat the shell PID as dead and start a second capture (evidence loss / runner-record races). Author AnPod not blocked.

contract-class: restore — extension sources already had a restart path; reclaim restores that path when a crashed run left a stale .runner (built-in adapter already overwrites). Tip has no reclaim.

VISION (per-rule)

  • One captain / Authority: aligns — no new autonomy; reclaim stays behind existing claim/lock refusals for live owners.
  • Scripts own mechanics: aligns — exact PID/ESRCH/FIFO/symlink refusals in the capture helper.
  • Restart is a non-event: aligns — dead residue no longer permanently bricks a source.
  • Delegation / Scope: aligns — procevent extension adapter only.
  • Fleet outlives vendor: aligns — harness-agnostic process-event path.

Waiting on you: (1) git push no-mistakes so the body attests this head; (2) address or refute the Greptile P1 (live shell gone, capture helper still polling). Not otherwise-ready → no Firstmate flag.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: re-triage vs tip 241d4617d6c160471d7da8ffe637b59f8f4a7af9 (#6355). Closes ready-for-pr #6173: yes (dead/empty extension .runner residues block restart; tip still uses bare O_EXCL open_new without reclaim).

HEAD 1504e92ae59c36179c9215305dcae4c02674b96b. MERGEABLE/UNSTABLE. Attestation: MISSING (body still requires git push no-mistakes). NM FAILURE (run 36970098375). Behavior CI SUCCESS (36970098270). Greptile SUCCESS (confidence 5/5 on this head): prior P1 (live capture displaced when shell exits) addressed by writing the capture helper PID into the runner record and CAPTURE_IN_FLIGHT so claim release waits until capture stops; regression covers shell-only TERM/KILL. Author AnPod not blocked.

contract-class: restore — extension sources already had a restart path; reclaim restores that path when a crashed run left a stale .runner (built-in adapter already overwrites). Tip has no reclaim. Not a new default-on surface.

VISION.md (per-rule)

  • One captain / Authority: aligns — no new consent; restores an already-started extension source.
  • Scripts / judgment: aligns — deterministic reclaim with ESRCH-only death proof, FIFO nonblock, inode match.
  • Restart non-event / Delegation / Fleet / Scope: aligns — durable restart without vendor coupling or workshop growth.

Blocker: push a matching no-mistakes attestation on this head so NM goes green. CI already green; Greptile clean. Firstmate flag: no (author/NM blocker).

AnPod and others added 5 commits October 4, 2026 09:46
Fixes kunchenguid#6173. Extension capture used O_CREAT|O_EXCL for <id>.runner;
a crash left a residue that blocked every later start. Reclaim dead or
empty residue under claim/lock safeguards, open existing paths with
O_NONBLOCK so FIFO names cannot hang, and refuse live owners.
Do not treat a runner record as dead while its capture helper is still
polling after the shell exits, so a new start cannot displace in-flight
evidence collection.
@AnPod
AnPod force-pushed the fix/stale-extension-runner-record-6173 branch from 1504e92 to d1317ba Compare October 4, 2026 08:09
@AnPod AnPod changed the title fix(bin): reclaim dead extension procevent runner records fix: safely reclaim stale extension runner records Oct 4, 2026
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.

2 participants