Fix master agent launch race on cold tmux server - #68
Open
dpvlv wants to merge 1 commit into
Open
Conversation
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>
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.
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 singletmux 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 trailingEnter(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 fixedSWARMFORGE_AGENT_START_DELAY_MSis reliable — and that delay is currently skipped for index 0 ((when (pos? index) ...)) anyway.Change
launch-role!now sends the command text and itsEnteras separate keystrokes (afterC-c/C-uto clear any partial line), then verifies the agent actually took over the pane viapane_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.shell-pane-commands,pane-current-command,send-role-launch-keys!.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 withpane_current_command = <agent>(nozshleft behind). The master (specifier) reads the board card, dry-checks it, and hands off tocoder(card movesspecifier → coder), which begins working — the full pipeline flows on the first try. File parses underbband the built-in--test-agent-start-delayentrypoint still works.No behavior change for roles that already launched correctly; the verify-and-retry succeeds on the first attempt for them.