Skip to content

fix(training-agent): InMemoryReplayStore fallback when no Postgres pool#3379

Merged
bokelley merged 1 commit into
mainfrom
bokelley/fix-replay-store-fallback
Apr 28, 2026
Merged

fix(training-agent): InMemoryReplayStore fallback when no Postgres pool#3379
bokelley merged 1 commit into
mainfrom
bokelley/fix-replay-store-fallback

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

What this fixes

#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 (visible on #3373 CI):

signed_requests  ✗ 3P / 28F / 9S

Every positive vector returned 401 because PostgresReplayStore.insert rejected on the unavailable pool, and the verifier failed closed.

Fix

Three small changes to server/src/training-agent/request-signing.ts:

  1. 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 on production).
  2. startReplayCacheSweeper() is a silent no-op when no pool is initialized — nothing to sweep.
  3. resetRequestSigning() clears the cached _replayStore and stops the sweeper so test suites that swap process state stay coherent.

Verified locally

Before fix:

signed_requests  ✗ 3P / 28F / 9S / 0N/A

After fix:

signed_requests  ✓ 31P / 9S / 0N/A

(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 PostgresReplayStore is used and cross-instance replay protection holds. Confirmed:

npx adcp grade request-signing https://agenticadvertising.org/api/training-agent/mcp-strict --transport mcp --skip-rate-abuse --only 016-replayed-nonce
→ PASS  401 request_signature_replayed

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.

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