fix(cloud): shared-localstack health gate + db-create connect race - #109
Merged
Conversation
Two runtime bugs surfaced while exercising the cloud/resource stack on WSL2. 1. shared-localstack "unhealthy after 1 attempt". LocalStack 3.x reports each configured SERVICE as "available" on startup — a service only flips to "running" after its first request. The healthcheck greps solely for "running", so nothing ever matches, the container is permanently unhealthy, and the up saga aborts before any traffic can flip a service to "running" (a deadlock). Gate on `available|running` — the honest "edge up + providers loaded" signal. Verified live on localstack 3.8.1: the new check exits 0, the old one exits 1. Golden regenerated through the real render path; regression test added (internal/generate). 2. `db create` → "connect to shared postgres on 127.0.0.1:45432: read: connection reset by peer". The imperative resource path (and the up provision phase) publishes the engine's host port via an up-time compose overlay, and `compose up -d` recreates the container to bind it. For a second or two the Docker userland proxy accepts the TCP connection but Postgres isn't listening yet, so it RSTs the handshake. A single immediate connect loses the race. Add retryingPgConnect: a capped-backoff retry (30s budget) around the admin connect that retries only transient "just-restarted" errors (reset/refused/ EOF/starting-up) and fails fast on real errors (bad creds/unknown db). Wired into both the imperative registry and the saga provision phase. Unit + race tested with an injected clock/connector (no live server needed). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.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.
Two runtime bugs surfaced while exercising the cloud/resource stack live on WSL2. Both were invisible to the existing unit/golden tests because nothing drove these commands against a real daemon — the follow-up e2e pipeline (release gate) will.
1.
shared-localstackunhealthy →upabortsSymptom:
upfails withservice "shared-localstack" ... is unhealthy after 1 attempt(s)even though LocalStack logsReady.Root cause: LocalStack 3.x reports each configured
SERVICESentry as"available"on startup; a service only flips to"running"after its first request. The healthcheck greps solely forrunning, so it never matches on a fresh engine — the container is permanentlyunhealthy, and the up saga's health gate correctly aborts. It's a deadlock: nothing isrunninguntil traffic arrives, but traffic can't arrive until the engine is up.Fix: gate on
available|running(edge up + providers loaded). Verified against the live container: new check exits0, old exits1.templates/localstack/template.yamlhealthcheck updatedtemplates/localstack/golden.yamlregenerated through the real render path (only the healthcheck line changes)TestLocalStackHealthGatesOnAvailable2.
db create→connection reset by peeron127.0.0.1:45432Symptom:
db create <name>fails withconnect to shared postgres on 127.0.0.1:45432: ... read: connection reset by peer.Root cause: a readiness race. The imperative resource path (and the saga provision phase) publishes the engine's host port via an up-time compose overlay;
compose up -drecreates the container to bind it. For ~1–2s the Docker userland proxy accepts the TCP connection but Postgres isn't listening yet, so it RSTs the handshake. A single immediate connect loses the race.Fix:
retryingPgConnect— a capped-backoff retry (30s budget) around the admin connect that retries only transient just-restarted errors (reset / refused / EOF / "starting up") and fails fast on real errors (bad creds, unknown db). Wired into both the imperative registry and the saga provision phase. Unit + race tested with an injected clock/connector (no live server needed).Tests
internal/generate: golden + determinism green; new localstack regression testinternal/orchestrate: 6 new tests for the retry (classification, eventual success, fail-fast, budget bound, ctx cancel, nil passthrough) +-raceorchestrate,generate,cli) all green🤖 Generated with Claude Code