Skip to content

fix(bin): stop task workers inheriting the primary home and pooled slots - #1092

Closed
willchen95 wants to merge 6 commits into
kunchenguid:mainfrom
willchen95:fm/fm-dispatch-main-home-isolation-q2
Closed

willchen95 wants to merge 6 commits into
kunchenguid:mainfrom
willchen95:fm/fm-dispatch-main-home-isolation-q2

Conversation

@willchen95

@willchen95 willchen95 commented Jul 27, 2026 •

Copy link
Copy Markdown

What

Task workers could inherit the operational home that launched them, be trusted from a stale record about where they were running, and release a pooled worktree slot another task still held. Three defects were observed live and drive this change.

  1. Home inheritance. An audit worker inherited the launching primary's exported FM_HOME, so every firstmate script it ran resolved that primary's state directory. It took the primary's own session-owner record, and the real primary came back from a suspend/resume locked out of its home with monitoring stopped.
  2. Restore did not preserve isolation. After a reboot the session provider restored every pane by resuming its recorded agent session but resolved each working directory back to the repository the worktree was derived from, collapsing 17 of 17 isolated worktrees onto their origin, four into the primary checkout. A spawn-time assertion does not survive a restore.
  3. worktree= is not ownership. Ten pooled slots were recorded by more than one task. The hazard fired: tearing down one task released a lease a still-live quarantined-paused task also recorded, and the pool reissued that slot to a new spawn.

A fourth finding corrected the investigation method itself: a pane listing reported a worker's cwd as the primary checkout while /proc showed it correctly isolated, so /proc/<agent-pid>/cwd is the check of record and pane cwd is only a hint.

How

Four mechanisms, one owner each, documented in docs/worker-isolation.md.

  • bin/fm-worker-isolation-lib.sh declares the owning home at launch, so ownership is never inferred downstream from cwd, pane, or process tree. A crewmate carries no home; a secondmate carries only its own. fm-lock, fm-primary-scope-lib, fm-spawn, and fm-teardown consume the declaration and refuse, which also keeps project-local startup and turn-end adapters inert for workers.
  • bin/fm-agent-cwd-lib.sh makes the agent process's own cwd authoritative. A pane field can name a different process, so it stays a hint; a provider with no per-pane process id reports unknown rather than degrading to a pane path. tmux targets resolve to a stable window id first, because display-message given an unknown window name silently answers for the active client's window.
  • bin/fm-slot-owner-lib.sh gates slot release on positive evidence of a conflict. A contested lease is retired, not returned, and --force does not waive it: --force is authority over this task's work, never another task's slot.
  • bin/fm-isolation-sweep.sh re-establishes isolation at session start, surfacing ISOLATION: findings beside the existing TANGLE: check.

Verification

tests/fm-worker-isolation.test.sh (30 checks) covers the declaration for every verified harness, each consuming refusal, the process-cwd method of record against a deliberately lying pane path, the per-provider matrix, all slot-conflict forms, and the sweep outcomes. Orca and secondmate-home refusals are covered in the suites that own those fixtures.

bin/fm-lint.sh, bin/fm-doc-audience-check.sh, and the CI test-partition coverage guard are clean.

Two suites fail identically on base a5fe1bc and are unrelated to this change: fm-session-start.test.sh (Herdr husk emits an unexpected SECONDMATE_LIVENESS: line) and fm-calm-pi-extension.test.sh (a Pi version pin wanting 0.81.1/0.82.0 against an installed 0.82.1).

Note

Opened from a fork because the author lacks write access to this repository. CI may need maintainer approval to run.

Pipeline

Updates from git push no-mistakes

Run 01KYG7DCY2VTZX20CN8WH89KSF on this branch, gates in order:

Step Result
intent completed
rebase completed
review completed after two fix rounds, 7 findings resolved
test completed, 90 suites run, 88 pass
document completed, 2 informational findings
lint completed clean (bin/fm-lint.sh)
push failed: HTTP 403, no write access to this repository

Every validation gate passed. The pipeline's own push step could not publish because the author lacks write access here, so the validated branch was pushed to the author's fork and this PR was raised from it by hand. The commits are exactly the ones the pipeline produced, unchanged:

d1834ab no-mistakes(document): fix stale isolation, primary-scope, and teardown documentation
326f95c no-mistakes(test): link newly sourced teardown libs in fm-gotmp fake root
7e83139 no-mistakes(review): keep refused teardowns from clearing the slot stamp
fc15161 no-mistakes(review): fix worker-isolation sweep, slot-lease, and teardown scope defects
7ac5b34 fix(bin): stop task workers inheriting the primary home and pooled slots

A launched agent inherited the launching home's exported environment, so
every firstmate script it ran resolved that home's state directory. An
audit worker took the primary's own session-owner record and the real
primary came back from a suspend locked out of its home, monitoring
stopped. Two further defects shared the same root cause: an assertion made
once at launch, and a record trusted as if it were live evidence.

Four mechanisms, one owner each:

- bin/fm-worker-isolation-lib.sh declares the owning home at launch, so
  ownership is never inferred downstream from cwd, pane, or process tree.
  A crewmate carries no home; a secondmate carries only its own. fm-lock,
  fm-primary-scope-lib, fm-spawn, and fm-teardown consume the declaration
  and refuse, which also keeps project-local startup and turn-end adapters
  inert for workers.
- bin/fm-agent-cwd-lib.sh makes the agent process's own cwd the method of
  record. A pane field can name an entirely different process, so it stays
  a hint; a provider with no per-pane process id reports unknown rather
  than degrading to its pane path.
- bin/fm-slot-owner-lib.sh gates slot release on positive evidence of a
  conflict. A contested lease is retired, not returned, and --force does
  not waive it: it is authority over this task's work, not another task's
  slot.
- bin/fm-isolation-sweep.sh re-establishes isolation at session start,
  because a restore resumed every recorded session but resolved worktrees
  back onto their origin. Findings surface as ISOLATION lines beside
  TANGLE.

docs/worker-isolation.md owns how the four fit together;
docs/verification/worker-isolation.md holds the dated evidence.

tests/fm-worker-isolation.test.sh covers the declaration for every
verified harness, each refusal, the process reading against a deliberately
lying pane path, the provider matrix, all three slot-conflict forms, and
the four sweep outcomes. The Orca and secondmate-home refusals are covered
in the suites that own those fixtures.
@willchen95

Copy link
Copy Markdown
Author

Captain approve-all requested. Blockers for willchen95 (read-only on this repo):

  1. Fork PR needs maintainer Approve and run workflows
  2. Merge requires write/maintain on kunchenguid/firstmate
  3. Cannot self-approve own PR

no-mistakes gates passed (review/test/document/lint). Pipeline marker is in the PR body. Please approve workflows + merge when ready.

@kunchenguid

kunchenguid commented Jul 28, 2026 •

Copy link
Copy Markdown
Owner

Automated reminder: thanks for the PR! This branch currently has a merge conflict with the base branch.

When you get a chance, please rebase onto (or merge) the latest base branch, resolve the conflict, and push. After that, checks will re-run and the PR will get looked at again.

Noted for firstmate#1092 at c24f585c.

@willchen95

Copy link
Copy Markdown
Author

Closing: captain local-only; this PR was an unintended public leftover.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants