Repository navigation
fix(bin): keep remote launch failures diagnosable and their cleanup honest - #12
Conversation
…onest A first remote Rex secondmate launch on ds9 refused to publish its task record because the existing parent-route state directory transiently could not be canonicalized, then reported that failed-dispatch cleanup had not removed both records although nothing had been published. The same remote spawn also relayed bash's job-control setpgid race message from an earlier remote job. - fm_backlog_canonical_existing now reports the component lstat refused and its errno (or perl's exit status), and every "cannot be resolved" refusal carries that reason. - The failed-dispatch rollback treats a provisional record that lstat proves absent as removed, so a dispatch that never published its record no longer reports incomplete cleanup; a record a refused lookup could still hide is still reported. - The remote job worker keeps supervising a command that is not in its own process group (the state a failed setpgid leaves), signaling the command process instead of returning at once with its timeout, cancellation, and preemption unenforced, and keeps bash's fork-time setpgid race message out of the job's stderr.
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7c40b3e64a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| worker_signal_job() { # <signal> <command-pid> | ||
| if worker_process_or_group_alive group "$2"; then | ||
| worker_signal_process_or_group group "$1" "$2" | ||
| else | ||
| worker_signal_process_or_group process "$1" "$2" | ||
| fi |
There was a problem hiding this comment.
Apply process fallback during recorded-job shutdown
When a command moves itself out of the recorded process group, worker_signal_job correctly falls back to signaling the command PID, but worker shutdown and replacement cleanup still call worker_signal_recorded_execution with the stale group record. In that scenario the group signal is a no-op, worker_recorded_execution_alive then reports the group gone, and the worker exits while the command continues running (and can still mutate state). Use the same process-vs-group fallback in the recorded cleanup path so cancellation and worker replacement terminate commands that changed process groups.
Useful? React with 👍 / 👎.
Intent
Find and fix why launching a remote second mate on ds9 with the Rex backend fails, so
bin/fm-spawn.sh ds9-rex --secondmate --backend rexsucceeds.Context: the captain asked for new remote second mates
ds9-rexandproxima-rexon the Rex backend. ds9-rex was seeded fine (bin/fm-remote-home-seed.sh --backend rex ds9-rex ds9 ~/code/firstmate-rex-code ~/code/fmh-home/ds9-rex dalp=https://github.com/settlemint/dalp.git, doctor all ok, route registered in data/secondmates.md, remote home provisioned). The launch then failed with, in order:~/code/firstmate-rex-code/bin/fm-remote-job-worker.sh: child setpgid (75309 to 75309): Operation not permitted;error: task record for ds9-rex could not be published (task record staged record authorized directory cannot be resolved at ~/code/fmh-home/ds9-rex/state/parent-route);error: failed-dispatch cleanup did not remove both task and busy records for ds9-rex;error: remote host-local secondmate launch failed. ds9 is macOS Darwin 27.0.0 (proxima, the other host, is 27.2.0). The code that fails is the merged fork main (the fork PR that unified the upstream and fork Rex integrations; the remote job worker in bin/fm-remote-job-worker.sh and the remote secondmate launch path in bin/fm-remote-secondmate-control.sh and bin/fm-spawn.sh come from there and from the earlier remote-secondmate work).Later decision (option 1): ship the three provable script defects - the failed-dispatch cleanup reporting failure for a task record that was never published, the path-resolution error that hides the failing path component and errno, and the remote job worker leaving a job outside its own process group (unsupervised by its timeout, cancellation, and preemption) after the bash job-control setpgid race - and note in the PR that the host cause of the transient path-resolution failure is unproven.
What Changed
bin/fm-backlog-transition-lib.sh): rollback now uses a newfm_backlog_path_absentcheck (lstat reports ENOENT/ENOTDIR). A provisional task record that was never published counts as removed, even when its authorized directory can't be resolved. Records that may exist still go through the authorized removal. This stops the misleading "did not remove both task and busy records" error.bin/fm-backlog-transition-lib.sh):fm_backlog_canonical_existingnow prints the failing path component and its errno, or the perl exit status, when it can't resolve a path. The "cannot be resolved at …" messages fromfm_backlog_record_parent_authorizedappend that reason.bin/fm-remote-job-worker.sh): macOS bash 3.2 job control can intermittently failsetpgidwith EPERM, which leaves the job outside its own process group. Supervision now falls back to the command process in that case (worker_job_running,worker_signal_job), so timeout, cancellation and preemption are still enforced. A zombie command no longer counts as running, and the lane's own group is never signaled. The forked subshell's stderr is redirected so bash'schild setpgid … Operation not permittedmessage isn't relayed as job output.tests/fm-backlog-record-resolution.test.shand extendstests/fm-remote-job.test.sh.Not proven: the host cause of the transient path-resolution failure on ds9 is unproven. This change fixes the three script defects and makes the failing path and errno visible if it recurs.
Follow-up
The worker's recorded-execution teardown paths -
worker_recorded_execution_alive,worker_signal_recorded_execution, andworker_group_identity_statusinbin/fm-remote-job-worker.sh- still treat a job as group-only, so a worker shutdown, exit-trap teardown, or orphan cleanup could leave a command that the setpgid race put in the lane's group running.Extending the same process fallback to those sites is the follow-up.
fm-startup-network.sh runprocess alive after its home was deleted.Host-side evidence
ds9-rex, anddocs/verification/runtime-backends.mdrecords the samestate/parent-routerefusal clearing on retry on another host on 2026-10-22.fm-remote-secondmate-control.sh launch <lab-id> claude - - rexthrough the job queue exited 0 and published its record; the lab mate was then retired and removed. Both changed test suites also pass on ds9 (Darwin 27.0).bin/fm-spawn.sh ds9-rex --secondmate --backend rexis the command for any future relaunch; ds9-rex is already live from the 12:51 retry.Risk Assessment
✅ Low: The three fixes match the stated intent (rollback of never-published records, path-failure diagnostics, process fallback for supervision) and are bounded and covered by tests; the only gap is that worker shutdown and orphan teardown still assume a process group.
Testing
I ran the two test files the change touches. Both exercise the real scripts: the backlog record-resolution and rollback code, and the remote job worker, including a job that joins the lane's process group. All tests passed. I did not run a live ds9 Rex launch, because that needs the remote host. The host cause of the transient path-resolution failure remains unproven, as the PR note says.
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-remote-job-worker.sh:437- The process-group fallback is applied only inside worker_run_with_timeout's own loop (timeout, cancel, preempt). The recorded-execution teardown paths still treat the job as a group only. If the setpgid race leaves the command in the lane's group,kill -0 -- -pidfails there, so the job reads as dead and is never signaled. Same invariant, other sites: worker_recorded_execution_alive (bin/fm-remote-job-worker.sh:~437-457), worker_signal_recorded_execution (~469), and worker_group_identity_status (~419, which concludes 'dead' when the leader's start identity is readable but no group exists). A worker shutdown or exit-trap teardown, or orphan cleanup using .claim/group, would leave such a command running. The user intent lists timeout, cancellation and preemption, so this goes beyond the stated scope. Extending the fallback to those sites is a small, optional follow-up.✅ **Test** - passed
✅ No issues found.
bash tests/fm-backlog-record-resolution.test.shbash tests/fm-remote-job.test.sh✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.