Teleporting a child to another machine

agent_teleport carries a child to another machine and restarts it there under the same child id, whether the child is live or stopped. Use it when a child needs more memory or CPU than its machine has, or when its machine is about to go down and the child's work should carry over instead of starting again.

agent_teleport child=worker machine=hawthorne cwd=/home/me/Source/repo/main reason="needs more memory"
bellwether teleport worker --to hawthorne --cwd /home/me/Source/repo/main --reason "needs more memory"

Leave out machine when the parent's machine knows exactly one other machine. local refers to the parent's own machine. Leave out cwd when the child resumes at the same path it runs in now, which must exist at the destination.

What Bellwether does

Bellwether performs three steps and no others.

  1. At the destination, the child starts in a directory that already exists there and resumes its session. Bellwether copies the harness session and checks every byte of the copy, as agent_move does.

  2. Proof of life is the child's model reading the notice and starting a turn. When no turn follows, Bellwether falls back to herdr detecting the harness on the same session in the new pane, and the record labels that weaker proof detected.

  3. Before its first turn, the child hears about the teleport. The notice arrives as a message in the child's session, never as keystrokes in its pane. It gives both machines and both directories, who asked and why, and what didn't cross.

Preparing the destination

Whoever asks for the teleport prepares the destination before the child arrives, including any folder, worktree or assets the child needs. Bellwether never copies a worktree or creates a directory, and it moves only the conversation. Shell jobs and files outside the session stay on the source machine, and so does the worktree.

A child that teleports itself

A child Bellwether started can teleport itself. It calls agent_teleport with no child, naming machine and cwd. The reply comes first and says where the child goes. Then the daemon waits for the turn to end, within the 5 minutes a self-restart waits, because a teleport never cuts a turn short and the child is mid-turn when it asks.

After herdr reports the turn over, the daemon teleports the child as its parent would, and the notice says the child asked: at your own request. On the record, self is the teleport's by. A child stays where it is when its turn doesn't end within the bound, or when the daemon refuses its teleport at run time. Its record keeps the reason under teleportStalled, and bellwether doctor prints a warn line.

If the daemon stops during the wait, the request stays on the record, and the child's session arms it again when it reconnects.

For a child whose parent runs on another machine, self-teleport is not available yet. That machine's daemon doesn't keep the child's record, so the request must cross the relay to the parent's daemon. Until then, the child asks its parent through parent_report.

Live and stopped children

The notice

The resumed session reads the notice as its first input, after Bellwether answers its startup dialogs. When the child has a brief it never read, that brief follows the notice in the same message, so nothing lands between them. A parent message sent during the teleport waits behind the notice.

When the session receives the notice but its model never starts a turn on it, the child keeps running at the destination, because the session is intact and stopping it would lose more than it saves. The reply's first line says the child wasn't told. Bellwether keeps the reason under notice.undelivered, logs teleported-untold in teleport.log, and the daemon offers the notice again when the child's session next connects. It never types the notice.

What it refuses

Bellwether checks every condition below before it changes anything on either machine. Each refusal says what failed:

Recovering from a failed start

A daemon that stops in the middle of a teleport leaves a mark on the record, and the next daemon finishes or undoes the teleport, as moving.md describes. When it finishes one, the record keeps the notice as undelivered, because the daemon that sent it stopped before it saw the notice taken.

When the destination can't start the child, Bellwether removes the copy there. It restarts a live child on its source, from the session still there. A stopped child keeps its record as it was and stays stopped.

The record

Each child record keeps a teleports list, newest last. An entry gives the time, who asked and why, whether the child was live or stopped, the source and destination with their directories and panes, the session file and its size, how the notice arrived, and the proof that the child is alive. Bellwether writes one line per outcome to teleport.log in the Bellwether home.

bellwether doctor prints an info line for a teleport in the last day. Until the child reads its notice, doctor prints a warn line instead, with the reason Bellwether recorded.

Limits

A parent session can't teleport, because its registry, spool, outbox and relay connections belong to the daemon on its own machine. Teleporting a parent would hand that daemon's registry to another daemon, a design question of its own (#235).