Skip to content

fix(bin): keep remote launch failures diagnosable and their cleanup honest - #12

Merged
roderik merged 1 commit into
mainfrom
fm/fm-remote-launch-fix
Oct 23, 2026
Merged

roderik merged 1 commit into
mainfrom
fm/fm-remote-launch-fix

Conversation

@roderik

@roderik roderik commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

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 rex succeeds.

Context: the captain asked for new remote second mates ds9-rex and proxima-rex on 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

  • Failed-dispatch cleanup (bin/fm-backlog-transition-lib.sh): rollback now uses a new fm_backlog_path_absent check (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.
  • Path-resolution errors (bin/fm-backlog-transition-lib.sh): fm_backlog_canonical_existing now 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 from fm_backlog_record_parent_authorized append that reason.
  • Remote job worker (bin/fm-remote-job-worker.sh): macOS bash 3.2 job control can intermittently fail setpgid with 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's child setpgid … Operation not permitted message isn't relayed as job output.
  • Adds tests/fm-backlog-record-resolution.test.sh and extends tests/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

  • Review finding review-1 was deliberately not fixed in this PR (decision: beyond the accepted timeout/cancellation/preemption scope).
    The worker's recorded-execution teardown paths - worker_recorded_execution_alive, worker_signal_recorded_execution, and worker_group_identity_status in bin/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.
  • Separate finding from the investigation: retiring a remote second mate left that mate's detached fm-startup-network.sh run process alive after its home was deleted.

Host-side evidence

  • The 12:46 ds9 failure was intermittent: the unchanged retry at 12:51 launched ds9-rex, and docs/verification/runtime-backends.md records the same state/parent-route refusal clearing on retry on another host on 2026-10-22.
  • The setpgid message came from an earlier remote job of the same spawn (pid 75309 started at 12:46:19), not from the launch job that failed at 12:46:55.
  • The ds9 kernel log shows perl ran at the publish and rollback checks and realpath returned nothing on an existing directory; perl 5.34's realpath is a per-component lstat walk, so an intermediate component was transiently missing or refused. Which one is unproven - this PR makes the next occurrence name it.
  • With the fixed scripts on ds9 (fresh clone of this branch, private isolated job worker, fresh lab home), fm-remote-secondmate-control.sh launch <lab-id> claude - - rex through 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).
  • After merge, bin/fm-spawn.sh ds9-rex --secondmate --backend rex is 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.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Failed-dispatch cleanup treats a never-published task record as removed, and still refuses when a record may exist behind a refused lookup ✅ pass live tests/fm-backlog-record-resolution.test.sh: 'rollback treats a provably absent provisional record as removed' and 'rollback still refuses when a record may exist behind a refused lookup' both ok
An unresolvable authorized directory reports the failing path component and errno ✅ pass live tests/fm-backlog-record-resolution.test.sh: 'an unresolvable authorized directory names the failing component and errno' ok
The worker still times out a job that is outside its own process group, within about 4s on a 1s timeout, and the job can then be reaped ✅ pass live tests/fm-remote-job.test.sh: 'the worker still times out a job that is not in its own process group' ok; whole file ended ALL TESTS PASSED

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 warning
  • ⚠️ 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 -- -pid fails 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.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Failed-dispatch cleanup treats a never-published task record as removed, and still refuses when a record may exist behind a refused lookup ✅ pass live tests/fm-backlog-record-resolution.test.sh: 'rollback treats a provably absent provisional record as removed' and 'rollback still refuses when a record may exist behind a refused lookup' both ok
An unresolvable authorized directory reports the failing path component and errno ✅ pass live tests/fm-backlog-record-resolution.test.sh: 'an unresolvable authorized directory names the failing component and errno' ok
The worker still times out a job that is outside its own process group, within about 4s on a 1s timeout, and the job can then be reaped ✅ pass live tests/fm-remote-job.test.sh: 'the worker still times out a job that is not in its own process group' ok; whole file ended ALL TESTS PASSED
  • bash tests/fm-backlog-record-resolution.test.sh
  • bash tests/fm-remote-job.test.sh
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T12:13:12.596946Z 7c40b3e PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +389 to +394
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@roderik
roderik merged commit 52b2dc6 into main Oct 23, 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.

1 participant