Repository navigation
fix(training-agent): retry durable reporting startup before failing the boot - #9125
Conversation
…he boot
Deploy run 44652866138's green machines show why the rollouts fail: the
durable reporting store's first PostgreSQL connection does not complete
within the 10 s connect budget while a rollout is under way
("PostgresReportingManagedDeliveryStore database connection failed" <-
"Connection terminated due to connection timeout"), and the boot exits.
Retry startup six times, waiting 1, 2, 4, 8 and 16 s (about 90 s with the
connect budget), on a fresh pool each time; the failed attempt's pool is
closed first, so retries do not stack connections. Every failure logs the
cause chain with its attempt number. If all attempts fail, the boot fails
as before: durable reporting stays fail-closed.
Committed with --no-verify (maintainer-approved): the hook failed on
unrelated suites under host load; this change's suite passes 17/17 and
tsc is clean.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Ladon verdict: Approve
Approve — clean operational-readiness fix, no blocking or medium findings.
This PR adds bounded retry-with-backoff to initializeTrainingGcsReporting (6 attempts, delays [1,2,4,8,16]s, ~90s budget). The reviewer verified correct loop termination, a fresh Pool per attempt with db.end() on every failure (no connection held across waits), fail-closed boot on exhaustion, warn-on-recovery, retained per-attempt connect + 10s Storage timeouts, and bounded retry budget with attempt metadata logged. Tests cover retry-then-succeed, exhaustion, default budget, and empty-array fast-fail.
No protocol surface touched: no static/schemas/source/**, docs/reference/**, dist/**, changeset, or migration changes — only server/src/training-agent/gcs-reporting.ts and its unit test. So no schema↔docs coherence, changeset, oneOf, or artifact-immutability gates apply. Not high-risk, not gated-paths, no author team gate.
One non-blocking note from the reviewer: the loop retries on all failure causes, so a genuine misconfiguration takes the full ~90s before boot fails rather than fast-failing. Bounded and deliberate per the inline comment; worth a follow-up if fast crash-loop detection on Fly matters, but not a defect.
No critical/high/medium findings → decision table falls through to row 9 (approve). review_decision is REVIEW_REQUIRED but gated_paths is false, so row 2 does not fire.
Why
Production deploys keep failing in the bluegreen rollout. With #9117's logging, the capture for deploy run 44652866138 (head
752a5ae89d, 20 Nov 01:20Z) names the cause. Every new machine's boot dies in durable reporting startup:So it isn't GCS credentials or bucket policy. The reporting store's first Postgres connection doesn't complete within 10 s while a rollout is under way. One green machine crash-looped 11 times in about 10 minutes, the other two never came up, and the old machines kept serving. The 19 Nov 19:34Z deploy succeeded between failures, so it is intermittent.
What
initializeTrainingGcsReporting()retries before failing the boot:attempt,attemptsandretryInMs. A later success logs a warning naming the attempt.Connection capacity
If the database is out of capacity, retries alone won't fix it. Per process, the server holds up to:
DATABASE_POOL_MAX, default 8,min0, opened on demand)/readyhealth clientgetDedicatedClient()connectionsThat's roughly 13 per process. Production runs 2 web and 1 worker machines (the pre-deploy machine list), so about 39 connections at steady state. A bluegreen web rollout adds 2 green web machines, about 65 at peak, plus the release-command machine.
A server that's out of slots refuses immediately with
too many clients. Here the connect timed out instead, which points to a pooler queueing new clients, or a database slow to accept them, rather than a hard slot limit. To settle it, compareSHOW max_connectionsandpg_stat_activity(or the pooler's pool size) during a rollout against those figures. That's on the database side, which this PR leaves alone.Tests
training-gcs-reporting-startup: 17/17, with three new cases.The existing single-attempt cases pass
[]to keep their focus. Type check clean.🤖 Generated with Claude Code