Skip to content

Fix master agent launch race on cold tmux server - #68

Open
dpvlv wants to merge 1 commit into
unclebob:mainfrom
dpvlv:fix/master-agent-launch-race
Open

Fix master agent launch race on cold tmux server#68
dpvlv wants to merge 1 commit into
unclebob:mainfrom
dpvlv:fix/master-agent-launch-race

Conversation

@dpvlv

@dpvlv dpvlv commented Sep 1, 2026

Copy link
Copy Markdown

Fixes #67.

Problem

The first agent in a pack — always the master (e.g. specifier) that reads the board card and drives handoffs — intermittently never launches. Its pane is left at the shell prompt with the launch command typed but not executed (sometimes mangled into a broken continuation line), so no card is read and the whole pack idles waiting for a handoff that never comes.

Root cause

launch-role! delivers the command with a single tmux send-keys <command> "Enter". The master's pane is the first shell on a cold tmux server; with an async prompt (starship/powerlevel10k) the prompt is still initializing when the keys arrive, so the trailing Enter (and occasionally a character) is dropped during a prompt redraw. Later roles start on a warm server and succeed, so only the master fails. Because it depends on cold-server prompt timing, no fixed SWARMFORGE_AGENT_START_DELAY_MS is reliable — and that delay is currently skipped for index 0 ((when (pos? index) ...)) anyway.

Change

  • launch-role! now sends the command text and its Enter as separate keystrokes (after C-c/C-u to clear any partial line), then verifies the agent actually took over the pane via pane_current_command, re-sending until it does, up to a retry cap. This is adaptive to any prompt speed and self-heals a swallowed launch instead of leaving the master dead.
  • launch-roles! now delays before every role (including index 0) so the cold master shell gets the same head start as the others.
  • New helpers: shell-pane-commands, pane-current-command, send-role-launch-keys!.
  • New env knobs: SWARMFORGE_AGENT_LAUNCH_RETRIES (default 8), SWARMFORGE_AGENT_ENTER_DELAY_MS (default 400).

Verification

On macOS/zsh with starship, a cold ./swarm + Open Project now launches all four roles with pane_current_command = <agent> (no zsh left behind). The master (specifier) reads the board card, dry-checks it, and hands off to coder (card moves specifier → coder), which begins working — the full pipeline flows on the first try. File parses under bb and the built-in --test-agent-start-delay entrypoint still works.

No behavior change for roles that already launched correctly; the verify-and-retry succeeds on the first attempt for them.

The first (master) role starts in the very first shell on a cold tmux
server. With an async prompt (starship/powerlevel10k), the prompt is
still initializing when send-keys fires, so the trailing Enter is
swallowed (and sometimes a character is dropped, mangling the command).
The master never launches, so no board card is read and the whole pack
idles waiting for a handoff that never comes. Later roles start on a
warm server and succeed, so only the master fails.

Make launch delivery adaptive and self-healing: send the command and
its Enter as separate keystrokes, then verify the agent actually took
over the pane (pane_current_command is no longer a shell) and re-send
until it does, up to a retry cap. Also delay before every role
(including index 0) so the cold master shell gets the same head start.

New env knobs: SWARMFORGE_AGENT_LAUNCH_RETRIES (default 8) and
SWARMFORGE_AGENT_ENTER_DELAY_MS (default 400).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.

Master/first agent silently fails to launch — send-keys races cold-server prompt init; whole pack stalls

1 participant