Repository navigation
feat(bin): teleport a running task to a remote second mate and back - #65
Merged
Merged
Conversation
added 4 commits
October 16, 2026 09:55
bin/fm-teleport.sh moves a ship or scout worker into a remote second-mate home (default alwayson) and back with --back. The work travels as one WIP commit on fm/teleport/<task> built through a private index, the task's records travel path-mapped, and a Claude worker resumes its own transcript in the new worktree; other harnesses relaunch from the brief plus a generated progress note. The backlog item follows the task. Until the adopting home confirms its worker is alive, any failure rolls the adopting side back and leaves the sending task intact with its worker idle. fm-spawn.sh gains --teleport to restore the work into a fresh pooled worktree and resume the Claude session. The away-mode alert channels move into bin/fm-alert-lib.sh so `fm-teleport.sh remind` can raise the manual "N tasks running, teleport out?" notification through them.
alandomio
pushed a commit
that referenced
this pull request
Oct 20, 2026
Conflicts resolved keeping both sides: - bin/fm-brief.sh: upstream's shared infra rule, wait block and inbox section kept; the Haiku subagent section from #66 added after them. - bin/fm-spawn.sh: --teleport from #65 ported onto upstream's record-backed launch brief; the arrival note is published as the launch record and the Claude launch resumes the teleported session. - bin/fm-supervise-daemon.sh: wedge alarm helpers live in bin/fm-alert-lib.sh (#65); they were unchanged on our side since the merge base, so nothing is lost. Upstream's delivery-failure fields kept. - tests/fm-teleport.test.sh: covers the teleported Claude launch on the record-backed brief path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Implement "teleport" for firstmate: move a running task (worker) from this home to a remote second mate and back, per the captain's decisions (2026-10-15): the unit is a running ship or scout worker that continues on the remote; work travels via git as a WIP commit on fm/teleport/, pushed, the remote recreates the worktree from it and the WIP commit is dropped after takeover (no rsync); context travels by resuming the Claude transcript (~/.claude/projects//.jsonl, claude --resume) when the harness is claude, otherwise brief plus a generated progress note in the fm-control relaunch style; the transcript travels only over the existing fm-on.sh SSH channel and is deleted on the laptop after successful takeover; the remote second mate takes the task into its own backlog by reusing bin/fm-backlog-handoff.sh and supervises it; teleport back is the same mechanism reversed; default target is the alwayson second mate.
Deliver:
Do not run a real teleport against the live alwayson home; use test fixtures.
Implementation decisions a reviewer should know:
claude --resume <id>with an arrival note as the prompt. Refused with --relaunch, --secondmate, batch spawns, and the orca backend (orca owns its worktrees).fm-teleport.sh remind [--lid]reuses the same channels; remind is rate-limited and wired by the operator to a sleep hook (sleepwatcher, systemd system-sleep), since macOS offers no built-in pre-sleep hook to a script.What Changed
bin/fm-teleport.sh(plusbin/fm-teleport-lib.sh). It moves a running worker to a remote second mate (alwaysonby default) and brings it back with--back. The command stops the worker and snapshots its work as a WIP commit onfm/teleport/<task>through a private index, so the worker's HEAD, index and files never move. It sends the task records and transcript as sha256-checked chunks overfm-on.shand adopts the task on the remote. It then hands over the backlog item withfm-backlog-handoff.shand cleans up the local side only after the remote confirms takeover; if any step fails, the local task stays intact and runnable.fm-spawn.shgets a--teleportflag that restores the snapshot into a fresh pooled worktree and runsclaude --resumewith paths mapped to the new home (non-Claude harnesses get the brief plus a generated progress note).fm-supervise-daemon.shinto a sharedbin/fm-alert-lib.sh. This addsfm-teleport.sh remind [--lid], a rate-limited "N tasks running, teleport out?" notification meant to be hooked to sleep or lid-close.docs/remote-secondmates.md(individual workers can now move, plus a new teleport section) anddocs/wedge-alarm.md. Addstests/fm-teleport.test.shwith fixture homes covering WIP ref creation, refusal on a dirty remote, failure leaving the local task intact, teleporting back and the non-Claude fallback.🤖 Generated with Claude Code
Risk Assessment
✅ Low: The latest fix round only expands a warning string, the matching docs sentence, and one test assertion; all three agree and match the captain's instruction.
Testing
I ran the focused teleport suite. It drives the full CLI flows (out, --back, failure and rollback paths, the backlog hold and handoff warnings, a note round trip, and the sleep reminder) against fixture homes. All 14 scenarios pass. I also ran the daemon test as a regression check on the shared notification path, and it passes. No real teleport was run against the live alwayson home, as the intent requires. There is no UI surface, so the CLI test transcript is the evidence.
Evidence: fm-teleport test transcript
Source: fm-teleport test transcript
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 3 issues found → auto-fixed (3) ✅
bin/fm-teleport.sh:540- Rolling back the remote after a failed backlog handoff (teleport_out, the abort call at line 540) goes through retire_copy, and retire_copy refuses unless the remote worktree still equals the snapshot. The adopted worker is already alive at that point and may have edited files, so the abort fails. The result: the remote keeps a live copy, the local copy stays idle, and the only signal is a warning telling the operator to abort by hand. A narrower case to check: if fm-spawn --teleport fails after writing the meta but before restoring the work, the worktree never matched the snapshot, so cmd_adopt's abort also dies and the receiving home refuses later retries. Consider interrupting the adopted worker before the handoff, or running the handoff before the adopted worker launches.bin/fm-teleport.sh:383- For a non-Claude worker, or a Claude worker with no transcript, adopt appends a progress note to data/<task>/brief.md. The brief travels with the task, so each round trip (out then --back) adds another 'Teleport note' section and an older note can contradict the current state. Consider replacing an earlier teleport note instead of appending a new one.bin/fm-teleport.sh:527- When pack, transfer, or adopt fails, the pushed fm/teleport/<task> ref stays on origin and state/teleport/<task>/out stays on disk. Nothing breaks, because a retry force-pushes and recreates the staging directory, but the ref is left behind after a failed teleport.🔧 Fix: Keep remote ownership on handoff failure; dedupe teleport notes
1 warning still open:
bin/fm-teleport.sh:545- When fm-backlog-handoff fails before it stages an outbox, the item stays in the local backlog. It was reopened at line 540, so it sits in a dispatchable section. Release then tears down the local copy, and nothing marks the item as owned by the remote, so the local dispatcher can spawn the task again while the remote worker keeps running it. The only guard is the warning asking the operator to move it by hand. Possible remedy: put the item back in 'In flight' locally (or annotate it) on that path so it is not re-dispatched. This changes the backlog behaviour the captain specified, so it needs their decision.🔧 Fix: Hold local backlog item when teleport handoff fails early
1 info still open:
bin/fm-teleport.sh:548- When the handoff fails before staging, the local item gets a parked hold, and the warning tells the operator to runbin/fm-backlog-handoff.sh <sm> <task>by hand. That handoff moves the item along with its parked hold, and the manual path never runsbacklog-starton the remote. The second mate's backlog can therefore end up with the task parked and not in 'In flight', even though its worker is running. Consider having the warning also say to clear the hold (tasks-axi unhold) and mark the item in flight on the remote. Another option is a small recovery verb that does both.🔧 Fix: Spell out full recovery in early handoff failure warning
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
bash tests/fm-teleport.test.sh(14 scenarios: WIP ref creation without moving the worker, refusal on a dirty or occupied remote, a failed teleport leaving the local task intact, a full out move including transcript and backlog, --back, the non-Claude fallback and the Claude fallback with no transcript, a failed handoff after takeover warning instead of rolling back, an early handoff failure placing a parked hold, a round trip leaving one teleport note, refusal during validation, abort refusing a task this home did not adopt, rate-limited remind, fm-spawn --teleport refusals)bash tests/fm-daemon.test.sh(regression check after the alert channel code moved into fm-alert-lib)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.