The deploy failed with "curl: (7) Failed to connect to 127.0.0.1 port 8998
after 0 ms" on a service that was in fact running. "after 0 ms" is
connection-refused, not a timeout: the check fired before uvicorn had bound the
port. A fixed "sleep 3" followed by a single curl has no retry, so it fails the
whole deploy whenever startup runs a second long.
Raising the sleep would slow every deploy and still race on a bad day. This
polls once a second for up to 60s and exits as soon as the app answers, so a
fast start costs nothing and a slow one no longer fails.
On a genuine failure it now dumps systemctl status and the last 80 journal
lines, so the cause is visible without running a second deploy to go looking.
The heredoc is quoted so the loop's $i and $(seq) expand on the remote host
rather than in the runner's shell; that block has no local variables or
${{ }} expressions, so quoting is safe here.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HAH7vVtn7qbcn1EVheecHQ