Skip to content

fix: preserve remote job quarantine during repeated shutdown - #53

Merged
levelupself merged 4 commits into
mainfrom
fm/remote-job-worker-replacement-race-orpha-5a
Aug 14, 2026
Merged

levelupself merged 4 commits into
mainfrom
fm/remote-job-worker-replacement-race-orpha-5a

Conversation

@levelupself

Copy link
Copy Markdown
Owner

Intent

Make the remote-job worker quarantine publication survive a second TERM during worker replacement. Preserve the diagnosed race as a deterministic behavioral regression in tests/fm-remote-job.test.sh that fails before the fix and passes after it on the same machine: the second TERM must land after mktemp creates worker.lock/.quarantine.* and before rename to worker.lock/quarantine, without changing test timing, adding retries, or inserting sleeps. Fix only bin/fm-remote-job-lib.sh, bin/fm-remote-job-worker.sh, and the existing remote-job behavior test; do not touch task 212 spawn-recovery implementation because it is disconfirmed as causal, and do not conflate watcher-extension work. Choose direction A so quarantine publication survives any repeat shutdown signal instead of merely removing the supervisors redundant TERM source, and safely recover a pre-existing regular bounded orphaned .quarantine.* from an already damaged lock by promoting it to fail-closed canonical quarantine before ownership cleanup. Verify tests/fm-remote-job.test.sh serially and under concurrent load, run repository lint, and provide full-suite evidence. Pipeline-authored risk rationales, fix summaries, and PR bodies must use role-neutral prose with no second person and no captain, user, firstmate, or crewmate role nouns; this constraint does not apply to product code, prompts, or user-facing copy.

What Changed

  • Ignore repeated shutdown signals while atomically publishing worker quarantine state.
  • Promote bounded orphaned .quarantine.* files to canonical fail-closed quarantine before stale lock cleanup.
  • Add deterministic coverage for a second TERM during quarantine publication and interrupted-publication recovery.

Risk Assessment

✅ Low: The change is narrowly scoped and preserves fail-closed worker ownership across repeated shutdown signals and interrupted quarantine publication without exposing a substantiated unsafe sibling path.

Testing

The targeted remote-job test passed serially and under three-way concurrent load; a same-machine pre-fix counterfactual reproduced the quarantine-loss failure, while the fixed runs demonstrated canonical quarantine publication, replacement refusal, orphan recovery, and eventual safe cleanup. An initial pre-fix attempt encountered a transient startup failure, and an immediate isolated retry reached and reproduced the intended regression. Repository lint and full-suite validation were not run because this assigned test phase explicitly forbids lint and broad-suite execution.

Evidence: Serial end-to-end behavior transcript
ok - default queue and execution bounds independently cover long polls
ok - operator PATH excludes a symlinked local bin
ok - operator PATH honors nvm defaults with a deterministic fallback
ok - operator PATH resolves the authorized Nix profile bin link
ok - the worker preserves bounded argv and stdin in an empty environment
ok - active jobs keep the worker ready for concurrent requests
ok - ensure replaces a live worker after its code changes
ok - worker identity binds the canonical configured code root
ok - stale ownership is reclaimed without signaling a reused pid
ok - the worker enforces the job timeout and publishes its result
ok - the worker expires queued jobs before they can mutate
ok - queued jobs receive a fresh bounded execution window
ok - a queued short command preempts a running long poll instead of waiting its window
ok - a poll re-armed after preemption reads the same cursor with nothing lost
ok - sibling polls never preempt each other into a re-arm churn loop
ok - worker shutdown terminates the active command tree before replacement
ok - Linux supervision recovers crashes and stops orphaned commands
ok - pre-execution validation obeys the job timeout
ok - the worker drains bounded output without changing command results
ok - the worker refuses symlinked job fields before command execution
ok - failed shutdown quarantines ownership against replacement workers
ok - interrupted quarantine publication recovers and clears only after recorded execution has stopped
ALL TESTS PASSED
Evidence: Pre-fix deterministic regression transcript
ok - default queue and execution bounds independently cover long polls
ok - operator PATH excludes a symlinked local bin
ok - operator PATH honors nvm defaults with a deterministic fallback
ok - operator PATH resolves the authorized Nix profile bin link
ok - the worker preserves bounded argv and stdin in an empty environment
ok - active jobs keep the worker ready for concurrent requests
ok - ensure replaces a live worker after its code changes
ok - worker identity binds the canonical configured code root
ok - stale ownership is reclaimed without signaling a reused pid
ok - the worker enforces the job timeout and publishes its result
ok - the worker expires queued jobs before they can mutate
ok - queued jobs receive a fresh bounded execution window
ok - a queued short command preempts a running long poll instead of waiting its window
ok - a poll re-armed after preemption reads the same cursor with nothing lost
ok - sibling polls never preempt each other into a re-arm churn loop
ok - worker shutdown terminates the active command tree before replacement
ok - Linux supervision recovers crashes and stops orphaned commands
ok - pre-execution validation obeys the job timeout
ok - the worker drains bounded output without changing command results
ok - the worker refuses symlinked job fields before command execution
not ok - failed shutdown released worker ownership
Evidence: Concurrent run 1 transcript
ok - default queue and execution bounds independently cover long polls
ok - operator PATH excludes a symlinked local bin
ok - operator PATH honors nvm defaults with a deterministic fallback
ok - operator PATH resolves the authorized Nix profile bin link
ok - the worker preserves bounded argv and stdin in an empty environment
ok - active jobs keep the worker ready for concurrent requests
ok - ensure replaces a live worker after its code changes
ok - worker identity binds the canonical configured code root
ok - stale ownership is reclaimed without signaling a reused pid
ok - the worker enforces the job timeout and publishes its result
ok - the worker expires queued jobs before they can mutate
ok - queued jobs receive a fresh bounded execution window
ok - a queued short command preempts a running long poll instead of waiting its window
ok - a poll re-armed after preemption reads the same cursor with nothing lost
ok - sibling polls never preempt each other into a re-arm churn loop
ok - worker shutdown terminates the active command tree before replacement
ok - Linux supervision recovers crashes and stops orphaned commands
ok - pre-execution validation obeys the job timeout
ok - the worker drains bounded output without changing command results
ok - the worker refuses symlinked job fields before command execution
ok - failed shutdown quarantines ownership against replacement workers
ok - interrupted quarantine publication recovers and clears only after recorded execution has stopped
ALL TESTS PASSED
Evidence: Concurrent run 2 transcript
ok - default queue and execution bounds independently cover long polls
ok - operator PATH excludes a symlinked local bin
ok - operator PATH honors nvm defaults with a deterministic fallback
ok - operator PATH resolves the authorized Nix profile bin link
ok - the worker preserves bounded argv and stdin in an empty environment
ok - active jobs keep the worker ready for concurrent requests
ok - ensure replaces a live worker after its code changes
ok - worker identity binds the canonical configured code root
ok - stale ownership is reclaimed without signaling a reused pid
ok - the worker enforces the job timeout and publishes its result
ok - the worker expires queued jobs before they can mutate
ok - queued jobs receive a fresh bounded execution window
ok - a queued short command preempts a running long poll instead of waiting its window
ok - a poll re-armed after preemption reads the same cursor with nothing lost
ok - sibling polls never preempt each other into a re-arm churn loop
ok - worker shutdown terminates the active command tree before replacement
ok - Linux supervision recovers crashes and stops orphaned commands
ok - pre-execution validation obeys the job timeout
ok - the worker drains bounded output without changing command results
ok - the worker refuses symlinked job fields before command execution
ok - failed shutdown quarantines ownership against replacement workers
ok - interrupted quarantine publication recovers and clears only after recorded execution has stopped
ALL TESTS PASSED
Evidence: Concurrent run 3 transcript
ok - default queue and execution bounds independently cover long polls
ok - operator PATH excludes a symlinked local bin
ok - operator PATH honors nvm defaults with a deterministic fallback
ok - operator PATH resolves the authorized Nix profile bin link
ok - the worker preserves bounded argv and stdin in an empty environment
ok - active jobs keep the worker ready for concurrent requests
ok - ensure replaces a live worker after its code changes
ok - worker identity binds the canonical configured code root
ok - stale ownership is reclaimed without signaling a reused pid
ok - the worker enforces the job timeout and publishes its result
ok - the worker expires queued jobs before they can mutate
ok - queued jobs receive a fresh bounded execution window
ok - a queued short command preempts a running long poll instead of waiting its window
ok - a poll re-armed after preemption reads the same cursor with nothing lost
ok - sibling polls never preempt each other into a re-arm churn loop
ok - worker shutdown terminates the active command tree before replacement
ok - Linux supervision recovers crashes and stops orphaned commands
ok - pre-execution validation obeys the job timeout
ok - the worker drains bounded output without changing command results
ok - the worker refuses symlinked job fields before command execution
ok - failed shutdown quarantines ownership against replacement workers
ok - interrupted quarantine publication recovers and clears only after recorded execution has stopped
ALL TESTS PASSED

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.

  • git diff db7a847e0e3428b8bd34b046199be5ba380f678f..158fa396e10cd0da139a8d889841e171114a0751 -- bin/fm-remote-job-lib.sh bin/fm-remote-job-worker.sh tests/fm-remote-job.test.sh
  • bash tests/fm-remote-job.test.sh 2>&1 | tee /tmp/no-mistakes-evidence/01KZZNY93ZPT64T2FMQKG1QCYD/fm-remote-job-serial.log
  • Three simultaneous invocations of bash tests/fm-remote-job.test.sh, recorded as fm-remote-job-concurrent-{1,2,3}.log
  • Applied the implementation diff in reverse while retaining the new behavioral test, then ran timeout 90 bash tests/fm-remote-job.test.sh; it failed at the quarantine assertion as expected
  • git status --short && git diff --exit-code -- bin/fm-remote-job-lib.sh bin/fm-remote-job-worker.sh tests/fm-remote-job.test.sh
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@levelupself
levelupself merged commit a5fb89d into main Aug 14, 2026
14 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.

2 participants