Repository navigation
fix(bin): retire a task's process-event sources during teardown - #48
Merged
Merged
Conversation
Reviewer's GuideTeardown now retires a task's process-event registrations through owner-checked retirement before cleanup, refusing safely when retirement is uncertain; task-ID ownership validation, regression tests, test mappings, and documentation accompany the change. Sequence diagram for safe task teardown and process-event retirementsequenceDiagram
actor Operator
participant Teardown as fm-teardown.sh
participant Retirement as fm-teardown-procevent-lib.sh
participant Procevent as fm-procevent.sh
participant Registry as ProcessEventRegistry
Operator->>Teardown: teardown(task-id, --force)
Teardown->>Retirement: teardown_retire_process_events(state, task-id, script-dir)
Retirement->>Registry: enumerate task-owned sources
loop each matching source
Retirement->>Procevent: retire(source-id, --if-owner, task-id)
Procevent->>Registry: validate canonical kind and owner_task
alt ownership and retirement are valid
Procevent-->>Retirement: success
else pending round, uncertain state, or mismatch
Procevent-->>Retirement: refusal with reason
Retirement-->>Teardown: failure, retain task record
Teardown-->>Operator: teardown refused
end
end
Retirement-->>Teardown: all sources retired
Teardown->>Teardown: destructive cleanup
Teardown-->>Operator: teardown complete
Sequence diagram for owner-checked process-event retirementsequenceDiagram
participant Caller
participant Procevent as fm-procevent.sh
participant Registry as ProcessEventRegistry
Caller->>Procevent: retire(source-id, --if-owner, task-id)
Procevent->>Procevent: fm_pr_task_id_valid(task-id)
Procevent->>Registry: load canonical adapter, kind, owner_task header
alt kind=task-owned and owner_task matches task-id
Procevent->>Registry: retire source and stop runner
Procevent-->>Caller: success
else different owner or malformed registration
Procevent-->>Caller: refuse source registration mismatch
Registry-->>Caller: source remains registered
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="bin/fm-teardown-procevent-lib.sh" line_range="14" />
<code_context>
+ echo "error: cannot enumerate process-event sources for task $task: unsafe registry $reg" >&2
+ return 1
+ fi
+ for rec in "$reg"/*.source; do
+ [ -e "$rec" ] || [ -L "$rec" ] || continue
+ id=${rec##*/}; id=${id%.source}
</code_context>
<issue_to_address>
**Listeners outlive removed tasks**
When a task-owned source is published after teardown expands the registry glob and before it removes the task record, `teardown_retire_process_events` never visits the new source, and teardown removes the task record while the registration remains; reconciliation can then relaunch its listener for a dead task.
Serialize task-owned registration with teardown’s task-record lock, and ensure teardown retires all task-owned registrations before removing the task record.
</issue_to_address>
### Comment 2
<location path="bin/fm-teardown.sh" line_range="3792" />
<code_context>
fi
fi
+teardown_retire_process_events "$STATE" "$ID" "$SCRIPT_DIR" || exit 1
+
# A Herdr close may reposition shared workspace order, so the whole
</code_context>
<issue_to_address>
**Refused teardown loses listeners**
When a later preflight refuses, or a later source retirement is refused after an earlier source was retired, `teardown_retire_process_events` removes listeners before teardown completes, then teardown retains the task record after refusing; the still-live task loses process-event monitoring, and a retry cannot restore the retired sources.
Make source retirement transactional: run refusal checks first and restore already-retired sources if any retirement fails.
Also at `bin/fm-teardown-procevent-lib.sh:24-27`.
</issue_to_address>… PR. Teardown now requires and sources bin/fm-teardown-procevent-lib.sh at startup. tests/fm-gotmp.test.sh builds a selective fake bin/ for real teardown and did not link that new library, so teardown refused at startup and the test failed with "teardown exited non-zero with a valid tasktmp". Invariant: every fake bin/ fixture that runs the real fm-teardown.sh must provide each library teardown requires at startup. Only tests/fm-gotmp.test.sh builds such a selective fixture, and it does so twice. Fix: link fm-teardown-procevent-lib.sh in both fixtures. Verified locally: tests/fm-gotmp.test.sh passes all 3 cases, tests/fm-teardown-procevent.test.sh passes and shellcheck is clean. ci-1 (Behavior portable serial 1) was not caused by this PR. The failing case was test_report_without_acknowledgement_hands_the_wake_to_main in tests/fm-supervision-host.test.sh. The CI log shows the host did the right thing: it recorded the turn as failed with unacked=1 and handed the wake to main. It just finished about 30s after starting, which is past the test's wait, inside a suite that ran 25 minutes on CI. bin/fm-supervision-host.sh and that test never use teardown or procevent code, and the test file is untouched by this PR. Run alone locally on this branch, that test passes. No code change for ci-1
Owner
Author
|
Review disposition for head 1c9bfb4
Merging under the standing firstmate-PR authority. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Reported by the research second mate on 2026-10-06: bin/fm-teardown.sh does not retire a torn-down worker's crew-hosted Lavish process-event source, so the source stays registered under a dead task owner and reconcile keeps relaunching it (seen with a GTM board source in the research home, and consistent with the platform mate's board note). Fix: teardown retires the task's registered process-event sources through bin/fm-procevent.sh retire with the owner-matched guard, refusing when retirement is uncertain, with a colocated test.
What Changed
bin/fm-teardown.shnow retires every process-event source registered astask-ownedby the task being torn down. It does this throughfm-procevent.sh retire <id> --if-owner <task-id>, using the newbin/fm-teardown-procevent-lib.sh. Teardown runs this retirement twice: once after the landed-work check and before any destructive cleanup, and again after the endpoint closes, just before the task record is removed, so it catches sources registered during cleanup. If a retirement is refused (for example, an unacknowledged pending round, an unsafe registry, or a source whose ownership can't be read), teardown exits and keeps the task record.--forcedoes not skip this step.fm-procevent.sh retire --if-ownernow accepts a task id as well as an extension registration token. A task id matches only a registration whose canonical header iskind=task-ownedwithowner_task=<task-id>(newfm_procevent_task_registration_owned_lockedinbin/fm-procevent-lib.sh). Any other owner is still refused.tests/fm-procevent-retire-task.test.shandtests/fm-teardown-procevent.test.share added to the changed-path families inbin/fm-test-run.sh. The fakebin/fixtures intests/fm-gotmp.test.shnow link the new teardown library.docs/configuration.mddocuments that teardown retires a task's sources.🤖 Generated with Claude Code
Risk Assessment
✅ Low: Teardown now retires the task's sources through
fm-procevent.sh retire --if-owner <task-id>. Retirement runs once before destructive cleanup and again just before the task record is removed. Ownership is checked against the registration header (adapter, kind and owner_task lines) while the source lock is held. When retirement is blocked or uncertain, teardown refuses and keeps the task record, which fails safe. Extension-token retirement behaves as before, and I found no reachable path that retires another owner's source or leaves a source registered under a dead owner.Testing
I ran the two new colocated test scripts (all 7 cases pass, including both late-source cases). I then drove the real
fm-procevent.shandfm-teardown.shend to end in disposable lab homes with a private tmux server. With the fix, teardown retired worker-a's registered and listening board and killed its listener. Reconcile then relaunched nothing. worker-b's board was untouched. With an unacknowledged round open, teardown refused by name, kept worker-b's record and kept the source. After the owner acknowledged the round, a retry succeeded. The same flow on the base commit left gtm-board registered astask:worker-a/listeningwith its listener still running after a successful teardown, which reproduces the report. Live wrong-owner and invalid-owner retire calls were refused and left the source intact. The late-registration race during endpoint close was covered only by colocated tests, not live, so it is marked untested. I removed every lab home and killed the leftover processes from the base run. The worktree is clean.fm-procevent.sh listno longer shows it, its listener process is gone, and reconcile relaunches nothingfm-teardown.sh worker-a --forcethe list shows only other-board, reconcile reports started=0, and the gtm-board sleep child is gonetask:worker-a/listeningafter teardown and after reconcile, and both listener children are alivetask:worker-b/listeningand its listener stays alive after worker-a teardownhandled other-board 1, then teardown worker-b complete, then 'no sources registered'retire --if-ownerwith a different task id or an invalid id refuses and keeps the source; the matching owner retires itEvidence: Live driver script (lab home + private tmux + real register-task/reconcile/teardown)
Source: Live driver script (lab home + private tmux + real register-task/reconcile/teardown)
Evidence: Fixed: teardown retires own board, spares other task, refuses on open round, succeeds after ack
Source: Fixed: teardown retires own board, spares other task, refuses on open round, succeeds after ack
Evidence: Base commit: bug reproduced (gtm-board still task:worker-a/listening after teardown)
Source: Base commit: bug reproduced (gtm-board still task:worker-a/listening after teardown)
$ fm-teardown.sh worker-a --force -> teardown worker-a complete [rc=0] $ fm-procevent.sh list gtm-board lavish task:worker-a/listening 0 other-board lavish task:worker-b/listening 0 (listener /bin/sleep 6017 for gtm-board still running)Evidence: Live retire --if-owner guard: wrong owner and invalid id refused, matching owner retires
Source: Live retire --if-owner guard: wrong owner and invalid id refused, matching owner retires
Evidence: Colocated focused tests
Source: Colocated focused tests
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.
fm-procevent.sh listno longer shows it, its listener process is gone, and reconcile relaunches nothingfm-teardown.sh worker-a --forcethe list shows only other-board, reconcile reports started=0, and the gtm-board sleep child is gonetask:worker-a/listeningafter teardown and after reconcile, and both listener children are alivetask:worker-b/listeningand its listener stays alive after worker-a teardownhandled other-board 1, then teardown worker-b complete, then 'no sources registered'retire --if-ownerwith a different task id or an invalid id refuses and keeps the source; the matching owner retires itbash bin/fm-test-run.sh tests/fm-teardown-procevent.test.sh tests/fm-procevent-retire-task.test.sh(all 7 cases ok)live-teardown-procevent.sh <worktree>/bin fixed: disposablebin/fm-lab-home.shlab home with a private tmux server and real worker windows. It runs realfm-procevent.sh register-task lavishfor gtm-board (worker-a) and other-board (worker-b), thenreconcile(starts 2 real runners), thenfm-teardown.sh worker-a --force, thenlist,reconcileand a ps check of the listener childrenSame driver, adversarial section: worker-b's board is re-registered as a listener that completes, giving a real captured round (round-open 1). Thenfm-teardown.sh worker-b --forceis checked for refusal, thenfm-procevent.sh handled other-board 1, then teardown is retriedlive-teardown-procevent.sh <base-archive>/bin base: the same lab flow ongit archive 40429373reproduces the bugLivefm-procevent.sh retire gtm-board --if-owner worker-b/--if-owner 'bad id!'/--if-owner worker-ain a lab home✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
Summary by Sourcery
Retire task-owned process-event sources during teardown so dead workers cannot leave listeners that reconciliation relaunches.
Bug Fixes:
Enhancements:
Documentation:
Tests: