Skip to content

fix(training-agent): retry durable reporting startup before failing the boot - #9125

Merged
bokelley merged 1 commit into
mainfrom
fix/gcs-reporting-init-retry
Nov 20, 2026
Merged

bokelley merged 1 commit into
mainfrom
fix/gcs-reporting-init-retry

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

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:

Durable GCS reporting initialization failed
  failure: PostgresReportingManagedDeliveryStore database connection failed
    cause: Connection terminated due to connection timeout      (pg-pool, 10 s DATABASE_CONNECTION_TIMEOUT_MS)
      cause: Connection terminated unexpectedly                 (pg client)

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:

  • Six attempts, waiting 1, 2, 4, 8 and 16 s between them. With the 10 s connect budget each, that's about 90 s.
  • A fresh pool per attempt. A failed attempt's pool is closed before the wait, so retries never stack connections.
  • Logging: each failed attempt logs fix(training-agent): log why durable GCS reporting failed to start #9117's cause chain with attempt, attempts and retryInMs. A later success logs a warning naming the attempt.
  • Fail-closed, unchanged: if every attempt fails, the boot fails with the same error as today. Durable reporting is never skipped or made optional.

Connection capacity

If the database is out of capacity, retries alone won't fix it. Per process, the server holds up to:

Pool Max connections
Main pool (DATABASE_POOL_MAX, default 8, min 0, opened on demand) 8
Durable reporting pool 4
Dedicated /ready health client 1
getDedicatedClient() connections occasional

That'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, compare SHOW max_connections and pg_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.

  • Two failures then a success: three pools, the failed two closed, each failure logged with its attempt number and backoff, then a recovery warning.
  • Every attempt fails: the boot still fails, every pool is closed, and the last log carries no backoff.
  • The default schedule stays within about 90 s.

The existing single-attempt cases pass [] to keep their focus. Type check clean.

🤖 Generated with Claude Code

…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>

@aao-secretariat aao-secretariat Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bokelley
bokelley merged commit e2f384d into main Nov 20, 2026
56 checks passed
@bokelley
bokelley deleted the fix/gcs-reporting-init-retry branch November 20, 2026 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant