Skip to content

fix(remote-job): stop leaked Linux workers with single-flight ownership and idle timeout - #60

Merged
alandomio merged 5 commits into
mainfrom
fm/remote-job-worker-accumulo
Oct 14, 2026
Merged

alandomio merged 5 commits into
mainfrom
fm/remote-job-worker-accumulo

Conversation

@alandomio

@alandomio alandomio commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fix remote Linux second-mate job workers accumulating after SSH clients disappear or ownership becomes ambiguous.

The root cause was split-brain ownership: stale heartbeat handling could start a replacement when the recorded owner could not be disproved, while an existing --serve worker did not continuously fence itself against lock replacement and had no idle retirement path.

Changes

  • Make worker ownership single-flight with live, stale, and ambiguous identity states.
  • Record a locale- and timezone-stable Linux process-start identity, with a fail-safe portable fallback.
  • Reclaim only ownership records proven stale; malformed or unpublished records must also be aged and lack a fresh heartbeat.
  • Never signal a PID unless its recorded identity is proven.
  • Revalidate ownership during jobs and between jobs so displaced workers stop and cannot claim more work.
  • Add a bounded Linux idle timeout, defaulting to 600 seconds.
  • Recover the staging-versus-idle-exit race by restarting a missing worker while a queued job is waiting.
  • Add fake-SSH and worker regressions for duplicate prevention, dead-client retirement, stable identity, stale-lock recovery, and fencing.
  • Document the lifecycle and the one-time upgrade case: workers leaked by older code without a trusted owner record require manual cleanup by individually verified PID.

No broad process matching or pkill -f is used. No command was run against wks-domio.

Validation

  • tests/fm-remote-job.test.sh
  • tests/fm-on.test.sh
  • ShellCheck and workflow lint
  • Full GitHub CI: 14 checks passed
  • Regression tests verified against the prior implementation for stale-heartbeat duplicate launch and dead-client idle retirement

tests/fm-remote-job-orphan-reap.test.sh still hits its existing host-specific fixture precondition locally because this environment reparents the fixture outside PID 1; the same precondition fails on the base revision, and CI covers the repository behavior suite.

Validated head: 006cb01c21428642920e8f401c297738bdc07ee3.

Pipeline

Updates from git push no-mistakes

Alan Domio added 5 commits October 7, 2026 16:28
…omio/firstmate PR #60 (run 37640667274), in tests/fm-remote-job.test.sh: "not ok - a worker whose state root vanished exited cleanly instead of failing for its supervisor to restart". Caused by this PR's code. Root cause (inferred from the code and the CI log; I did not reproduce the failure locally, it is timing-dependent): the new worker_ownership_intact in bin/fm-remote-job-worker.sh checked that the state root and worker.lock exist first, then read the owner record. If the state root was deleted between that check and the reads, the failed pid read returned 2 ("ownership moved to another process"), so the worker exited 0 instead of 1. A supervisor would then not restart it. Fix (bin/fm-remote-job-worker.sh only, uncommitted in the worktree): the owner-record comparison moved into worker_owner_record_matches, and worker_ownership_intact now inspects the state tree only after the record fails to match. A vanished root or lock always reports 1 (exit 1); only a mismatch with the tree still present reports 2 (displaced, exit 0). The owner identity proof, heartbeat fencing and idle timeout are otherwise unchanged. No test changes; the existing tripwire test is the regression. Verification: tests/fm-remote-job.test.sh passed 3 of 3 local runs (35 ok each, including the deleted-state-root tripwire); tests/fm-on.test.sh passed; shellcheck -x on the worker is clean. The full serial shard 2 lane was not re-run locally
@alandomio
alandomio merged commit d0b2ad6 into main Oct 14, 2026
16 checks passed
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