fix(training-agent): InMemoryReplayStore fallback when no Postgres pool#3379
Merged
Conversation
#3351 swapped to PostgresReplayStore to close the cross-instance replay gap (#3338). Worked in production but broke the storyboard runner: CI runs the full server in-process without initializing a Postgres pool, and getReplayStore() was unconditionally calling getPool() which throws "Database not initialized." Symptom (#3373 storyboards CI): signed_requests ✗ 3P / 28F / 9S (every positive vector returned 401 because PostgresReplayStore .insert rejected on the unavailable pool, verifier failed closed) Fix: - getReplayStore() falls back to InMemoryReplayStore when getPool() throws — gated on NODE_ENV !== 'production' so a misconfigured prod still fails loudly (preserves the multi-instance protection). - startReplayCacheSweeper() is a silent no-op when no pool is initialized. - resetRequestSigning() now also clears the cached _replayStore so test suites that swap process state stay coherent. Verified locally: signed_requests ✓ 31P / 9S / 0N/A (recovered) Production unaffected — prod always has a pool, so PostgresReplayStore is used and cross-instance replay protection holds. Confirmed via adcp grade --only 016-replayed-nonce → still PASS. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced Apr 29, 2026
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.
What this fixes
#3351 swapped to
PostgresReplayStoreto close the cross-instance replay gap (#3338). Worked in production but broke the storyboard runner: CI runs the full server in-process without initializing a Postgres pool, andgetReplayStore()was unconditionally callinggetPool()which throws "Database not initialized."Symptom (visible on #3373 CI):
Every positive vector returned 401 because
PostgresReplayStore.insertrejected on the unavailable pool, and the verifier failed closed.Fix
Three small changes to
server/src/training-agent/request-signing.ts:getReplayStore()falls back toInMemoryReplayStorewhengetPool()throws — gated onNODE_ENV !== 'production'so a misconfigured prod still fails loudly (preserves the multi-instance protection on production).startReplayCacheSweeper()is a silent no-op when no pool is initialized — nothing to sweep.resetRequestSigning()clears the cached_replayStoreand stops the sweeper so test suites that swap process state stay coherent.Verified locally
Before fix:
After fix:
(Other 12 storyboard failures are pre-existing fixture issues in
sales_broadcast_tv/sales_guaranteed— unrelated.)Production unaffected
Prod always has a Postgres pool initialized before the verifier ever runs, so
PostgresReplayStoreis used and cross-instance replay protection holds. Confirmed:Owe a correction on my last response in #3351 — the post-deploy verification check there was on the grader against prod (which passed), but the storyboard runner is a separate test surface that I missed. The feedback flagging the regression was correct in mechanism; I just misread which test surface it was talking about.