SSH fleet sync
oooconf fleet sync pulls this repository's latest changes on SSH fleet hosts. It
runs locally and drives each host over ssh; the remote side needs only git,
sh, and oooconf.
oooconf fleet sync [HOST...] [--all] [--repo-path PATH] [--branch NAME] [--jobs N]
[--resolve] [--no-push] [--format text|json] [--dry-run]
HOST...: SSH config aliases. Without hosts and without--allit is a usage error.--all: every host alias from~/.ssh/config,~/.ssh/config.local, and recursivelyIncluded files. Comments are stripped, wildcard and negated patterns are skipped, and missing files are not an error. Aliases are deduped twice: repeated aliases and aliases whose configuredHostName/Portpair matches an earlier host collapse to the first occurrence, and each dropped alias is reported asskippedwith reasonduplicate of <alias>.--repo-path PATH: remote checkout path. Defaults to the host'soooconf --print-repo-root, then to~/src/ooodnakov-config.--branch NAME: remote branch. Defaults to the branch's upstream minusorigin/, then tomain.--jobs N: hosts synced in parallel (default 4).--resolve: after the fan-out, spawn oneompagent to repair hosts leftconflictorfailedbut reachable (see Two-phase fixing below).--no-push: never push commits that exist only on the host.--format text|json: text (the default) streams a progress line per host and ends with the summary (see Live progress); JSON prints only a versioned document (schema_version, per-host results includingreachable,fix, andskip_reason, and ok/conflict/failed/dry-run/skipped counts).--dry-run: inspect only; reports repo, branch, dirty state, and ahead/behind without fetching, stashing, pulling, pushing, or re-linking.
Preflight and host dedupe#
Host aliases are deduped before any ssh call: two aliases whose configured
HostName/Port pair is identical reach the same machine, so only the first is synced
and the rest are reported as skipped with reason duplicate of <alias>.
Each remaining host then gets exactly one preflight remote call through its persistent
session before any git command.
It reports the remote hostname, the login user, and whether the checkout exists
(--repo-path when given, otherwise ~/src/ooodnakov-config). Outcomes:
sshfails: the host isfailedwith errorssh <host>: ....- the login user is
root:skippedwith reasonroot user. - the checkout is missing:
skippedwith reason<path> not found. - the remote hostname is this machine's short hostname (case-insensitive, domain
stripped) or
localhost/127.0.0.1:skippedwith reasonlocal machine.
Skipped hosts issue no git or oooconf command at all and count as success for exit
codes. Preflight failures are ordinary failures, not skips.
Per-host pipeline#
- Preflight: verify
ssh, the login user, the checkout path, and machine identity. - Resolve the repo path and verify it is a git checkout.
- Resolve the branch and record whether the tree is dirty.
- Stash local work (
git stash push -u). git fetch --prune origin <branch>thengit pull --rebase origin <branch>.- On a pull failure, treat unmerged paths and an in-progress rebase as a conflict;
any other failure marks the host failed. The per-host pass never spawns an agent:
with
--resolveit still returnsconflict, and repair happens afterwards. - Restore the stash after a clean rebase, with the same conflict handling.
- Recompute ahead/behind; push commits that only exist on the host unless
--no-push. - Run
oooconf update --no-depsin the checkout so managed links are re-applied.
Every remote git command runs with GIT_TERMINAL_PROMPT=0, so a missing credential
fails the host instead of hanging the run.
SSH transport and retries#
Every remote script also prepends ~/.local/bin, ~/.bun/bin, ~/.cargo/bin,
~/.local/share/pnpm, and ~/bin to PATH, because a non-interactive login sh
often lacks the user bins that hold oooconf, omp, and bun — without it an agent
spawn would fail with omp: command not found.
Each host gets a single persistent login shell:
ssh -o ConnectTimeout=<n> -o ServerAliveInterval=15 -o ServerAliveCountMax=4 -- <host> sh -l
Every pipeline step for that host runs inside it, so a sync costs one handshake per host instead of one per command. The keepalive options keep an idle session alive while other hosts are being synced in parallel.
Each script is sent to that shell as UTF-8 bytes wrapped in a group with stdin detached:
{ <script>
} </dev/null 2>&1
printf '<token>%s\n' "$?"
The transport reads binary lines until the unique <token> sentinel, takes the exit code
from that line, and strips the sentinel from the captured output. stdout and stderr share
one merged stream, so ssh and git error text is captured even for non-zero exits.
Pipes are binary with bufsize=0, which keeps the wire format LF-only on Windows and
POSIX alike; lines are decoded with errors="replace". Because a login shell may print a
banner, the oooconf --print-repo-root lookup takes the last absolute-path line of its
output and ignores everything else.
A dropped connection is retried. When the merged output contains a transport-level
failure (ssh: connect to host, connection timed out, operation timed out,
timeout, server, connection refused, connection reset, no route to host,
network is unreachable, kex_exchange_identification, ssh_exchange_identification,
banner exchange, broken pipe, client_loop, connection to, connection closed,
session closed), the session is dropped and the same script is re-sent on a fresh one
after 0.4 * (attempt + 1) seconds. Extra attempts are bounded by connect_retries
(one by default); 0 means a single attempt. Ordinary remote failures — a git error, a
conflict, any other non-zero exit — are returned as-is and never retried, so a broken
pipeline step cannot silently run twice. Closing the run closes every session's stdin,
waits up to 5 seconds, then kills a shell that refuses to exit.
Live progress#
--format text reports while it works instead of printing a table at the end:
- a header line,
fleet sync: <n> host(s), jobs=<n>(plus(dry-run)when requested); - the current step of every working host (
checking ssh, user and checkout,preflight ok,resolving repo path,reading branch and working tree,fetching origin/<branch>,stashing local changes,pulling --rebase origin/<branch>,restoring stash,pushing <n> commit(s),running oooconf update --no-deps): on a terminal these animate as one in-place spinner line that is cleared before that host's status line, so a slowgit pullor link refresh never looks frozen; when the output is piped each step is printed as its own line so CI logs keep the activity; - one status line per host as soon as that host finishes — completion order under
--jobs > 1, input order at--jobs 1— carrying host, status, branch, repo, the dirty/stashed/behind/ahead/pushed/linked flags, conflicts,resolved, andfix; a failing host also gets an indentederror:line; - duplicate aliases are reported as
skippedwithreason=duplicate of <alias>after the fan-out, before the summary; - when
--resolvespawns an agent, aspawning …line, the agent's own output streamed line by line and rendered as Markdown (headings, lists, quotes, rules, fenced code with a gutter, tables, and inline emphasis drawn from the shared icon/color helpers; lines the agent already styled are passed through), andomp agent finished (exit N); the command waits for the agent to exit before it continues; - a separator, then exactly one summary line with the
ok/conflict/failed/skipped/dry-runcounts, plus there-run with --resolvehint when a conflict remains.
Spinner frames are braille glyphs on a capable terminal and |/-\\ sequences otherwise;
a non-terminal stream gets no carriage returns at all. PowerShell pipes a native
command's stdout, so isatty() is false there; the command detects the attached console
and writes progress through it, keeping colors, icons, and the spinner live. Set
OOOCONF_UI=stdout to force plain piped output, for example when redirecting to a file. Each status line starts with the
shared Nerd Font icon for its role (ok, warn, fail,
missing, info), or the ASCII fallback ([ok], [warn], [fail], ...) when the
terminal or OOOCONF_ASCII=1 cannot render Nerd Font glyphs. The per-host table is never
reprinted after the summary. A host repaired by --resolve is reported twice: once with
conflict when the fan-out ends, and again after repair with its final status and
fix=remote-agent or fix=local-agent.
--format json prints none of this: no header, no progress lines, no summary, no
separator — only the JSON document, so the output stays parseable when piped.
Two-phase fixing#
With --resolve and without --dry-run, the fan-out finishes first and apply_fixes
then repairs the hosts that are still broken. A host needs fixing when its status is
conflict, or failed while reachable (a host whose ssh preflight failed is left
alone).
- Exactly one host needs fixing:
omp -p <prompt>runs on that host. - Two or more hosts need fixing: one local
omp -p <prompt>runs in this repo and is told to drive each host overssh.
Either prompt embeds a status block per host: host, status, branch, repo, the
dirty/stashed/behind/ahead/pushed/linked flags, the error, the conflicting paths, and the
last 8 log lines. After the agent exits, each repaired host is completed here: the stash
is restored (git stash pop), commits that exist only on that host are pushed unless
--no-push, and oooconf update --no-deps re-applies managed links. A stash pop that
conflicts again leaves the host conflict with no push and no update. Results carry
fix=remote-agent or fix=local-agent (also in JSON).
Safety model#
- A host skipped by dedupe or preflight never runs git or
oooconf;--dry-run,--no-push, and--resolvedo not change that. - A conflict without
--resolveleaves the stash in place and performs no push and no link refresh; inspect the host, fix it, and re-run. - An
ompagent runs only when--resolveis passed, and only after the fan-out: the per-host pass itself never spawns one. One pending host is repaired byomp -pon that host; two or more are repaired by one localomp -pthatsshes into each of them. Both prompts embed a per-host status block (host, status, branch, repo, dirty/stashed/behind/ahead/pushed/linked, error, conflicts, last 8 log lines) and ask the agent to resolve conflicts, stage the files, finish the rebase or stash restore, push commits that only exist on the host, leave a clean tree, neverreset --hard, and never force-push. Completion then restores the stash, pushes host-only commits, and runsoooconf update --no-deps; a failing stash pop leaves the hostconflictwith no push and no update. The result recordsfix=remote-agentorfix=local-agent. - Pushing is limited to commits already made on that host; the sync itself never rewrites history.
--dry-runis read-only, and--no-pushkeeps the host's commits local.
Exit codes#
0: every host isok,dry-run, orskipped.2: at least one host isconflict.1: any hostfailed, or there was nothing to do.
The text summary ends with ok, conflict, failed, skipped, and dry-run counts;
JSON entries carry the same status values plus skip_reason.
Examples#
oooconf fleet sync --all --format json
oooconf fleet sync orange site
oooconf fleet sync --all --resolve