fix(training-agent): defer pickTaskRegistry pool lookup so prod uses Postgres on cold boot#4073
Merged
Merged
Conversation
…tually uses Postgres on cold boot Same boot-ordering issue the state-store fix in #4072 closed: `mountTenantRoutes()` runs before `initializeDatabase()`, so `getPool()` at construction threw "Database not initialized." `pickTaskRegistry`'s try/catch silently downgraded to the in-memory registry — every cold-booted production machine has been running with `InMemoryTaskRegistry` since #463 shipped, defeating the whole point of `adcp_decisioning_tasks`. Buyer creates a media buy on machine A, polls on machine B, sees "task not found" with ~50% probability. Surfaced by #4067's diagnostic logging — the post-#4072 deploy log showed "Database not initialized" at pickTaskRegistry (registry.js:124) immediately followed by the success path (state-store now lazy, so init completed, but task registry was already in-memory). Wrap the pool in the same lazy `PgQueryable` adapter `pickStateStore` uses. `getPool()` runs at first query; the Postgres backend now actually gets used in production. Co-Authored-By: Claude Opus 4.7 (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.
Summary
The diagnostic logging from #4067 + the state-store fix in #4072 surfaced a long-standing silent regression:
Same root cause as #4072.
mountTenantRoutes()runs beforeinitializeDatabase(), sogetPool()at construction throws.pickTaskRegistry's try/catch silently downgrades toInMemoryTaskRegistry— meaning every cold-booted production machine has been running with the in-memory registry since #463 shipped, defeating the whole point ofadcp_decisioning_tasks. Buyer creates a media buy on machine A, polls on machine B, sees "task not found" with ~50% probability.What changed
Wrap the pool in the same lazy
PgQueryableadapterpickStateStoreuses (#4072).getPool()runs at first query, not at construction; by then the DB is initialized.Drops the try/catch entirely — there's no scenario where construction can fail now, and a real DB error at first query should surface, not be swallowed.
Test plan
npx tsc -p server/tsconfig.json --noEmitcleanTenant registry initializedwith no precedingDatabase not initializedfrom pickTaskRegistry🤖 Generated with Claude Code