You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ci: quarantine chronic Anthropic-5xx integration test flakes (admin-merge-with-known-failures is a blind spot) #3695
Four integration tests fail intermittently on main with `AssertionError: expected 500 to be 200` because they exercise real Anthropic API calls and Anthropic occasionally 5xx's:
The current pattern: an admin sees these failing on a PR they're about to merge, recognizes them as the chronic flake set, admin-merges anyway. This pattern was used on #3627, #3643, #3646, #3663, #3681, #3691.
Admin-merge-with-known-flakes is a security smell. `brand-classifier`, `brand-enrichment`, `prospect-triage` exercise real Anthropic API calls; "chronic 5xx" is indistinguishable from "we shipped a regression and the LLM is now refusing inputs." A real prompt-injection or schema regression in those three handlers ships under cover of "Anthropic flake" — that is a blind spot, not a hypothetical one.
Fix
Two-track:
Quarantine: rename or tag these tests to `:flaky` (or move to a separate `tests/integration-flaky/` directory). Run them on a separate CI job that uses retry logic and doesn't block PR merges. The deterministic suite blocks merges.
Stabilize over time: each of these tests' failure modes has a real fix:
Make the production code retry with backoff on Anthropic 5xx (the SDK supports this; check whether the test fixture is configured for it)
Or test against a recorded fixture / `anthropic-mock` server for the deterministic shape, and exercise the real API only in a separate smoke-test job
Done state
Tests quarantined; PR-blocking CI runs only deterministic suites
Quarantined tests run on schedule (nightly?) with retry; failures over a threshold open an issue
Classification: Bug Bucket(s): infra/agents (CI / build tooling — no matching label exists; noted in run summary) Status: ready-for-human
What the experts said:
dx-expert: Root cause diagnosis in the issue is wrong. All four tests mock @anthropic-ai/sdk via vi.hoisted + vi.mock(FakeAnthropic) — no real Anthropic network call is possible. The 500s come from the pool singleton being torn down mid-run: closeDatabase() in one file's afterAll sets the module-level pool to null while a parallel file is mid-query; getPool() throws "Database not initialized" and Express returns 500. Fix: fileParallelism: false in server/vitest.config.ts. No quarantine job, no retry logic needed.
code-reviewer: Confirms. pool is a module-level singleton with no worker isolation in vitest.config.ts (no pool, poolOptions, or fileParallelism set — all defaults). The prospect-triage-function polling loop also has a secondary flake mode under DB contention. Retry-on-5xx logic would not fix anything — the 500 is a local crash, not a transient Anthropic error. Also flagged an orphaned-row cleanup nit in brand-enrichment-route.test.ts.
My take: The security concern about admin-merge-with-known-failures masking regressions is real and worth fixing. But the root cause is Vitest parallel file execution racing on a shared DB pool, not Anthropic 5xx. The fix is a two-line change to server/vitest.config.ts, not quarantine infrastructure. Flagging because this is the infra/agents bucket; the fix itself is trivial and the file is not restricted.
The fix — add to the test: block in server/vitest.config.ts:
This serializes integration test files, eliminating the pool-teardown race and migration contention in one change. No CI workflow changes required. Once the tests stop flaking, the admin-merge habit loses its excuse.
@bokelley, your call: apply the one-liner above, or if you'd prefer to keep parallel execution, extract the pool singleton into worker-local scope instead (heavier, but preserves parallelism).
Reporter's diagnosis is wrong — the 500s are not Anthropic flakes. Per dx-expert + code-reviewer: all four affected tests mock @anthropic-ai/sdk via vi.hoisted + vi.mock(FakeAnthropic), so no real Anthropic call is reachable. The 500 is a local crash: pool is a module-level singleton, closeDatabase() in one file's afterAll nulls it while a parallel test file is mid-query, getPool() throws "Database not initialized", Express returns 500.
Implementation:
Set fileParallelism: false in server/vitest.config.ts. That's the entire fix.
Rename the issue in the closing comment so it's not surfaced later as an Anthropic-flake search hit. Suggested closing title in the PR / commit message: fix(test): disable file parallelism to prevent pool-singleton teardown races.
Address the secondary flake in the prospect-triage-function polling loop only if it persists after (1) — likely won't.
Fix the orphaned-row cleanup nit in brand-enrichment-route.test.ts flagged by code-reviewer (same PR or a small follow-up; your call).
Do NOT add retry-on-5xx logic or a quarantine job — both would mask the local crash, not fix it. Default-deny on scope creep.
Activity
bokelley commentedon Apr 30, 2026
Triage
Classification: Bug
Bucket(s): infra/agents (CI / build tooling — no matching label exists; noted in run summary)
Status: ready-for-human
What the experts said:
@anthropic-ai/sdkviavi.hoisted+vi.mock(FakeAnthropic)— no real Anthropic network call is possible. The 500s come from the pool singleton being torn down mid-run:closeDatabase()in one file'safterAllsets the module-levelpooltonullwhile a parallel file is mid-query;getPool()throws "Database not initialized" and Express returns 500. Fix:fileParallelism: falseinserver/vitest.config.ts. No quarantine job, no retry logic needed.poolis a module-level singleton with no worker isolation in vitest.config.ts (nopool,poolOptions, orfileParallelismset — all defaults). Theprospect-triage-functionpolling loop also has a secondary flake mode under DB contention. Retry-on-5xx logic would not fix anything — the 500 is a local crash, not a transient Anthropic error. Also flagged an orphaned-row cleanup nit inbrand-enrichment-route.test.ts.My take: The security concern about admin-merge-with-known-failures masking regressions is real and worth fixing. But the root cause is Vitest parallel file execution racing on a shared DB pool, not Anthropic 5xx. The fix is a two-line change to
server/vitest.config.ts, not quarantine infrastructure. Flagging because this is the infra/agents bucket; the fix itself is trivial and the file is not restricted.The fix — add to the
test:block inserver/vitest.config.ts:test: { globals: true, environment: 'node', root: __dirname, setupFiles: ['./tests/setup/revenue-tracking-env.ts'], testTimeout: 30000, + fileParallelism: false, },This serializes integration test files, eliminating the pool-teardown race and migration contention in one change. No CI workflow changes required. Once the tests stop flaking, the admin-merge habit loses its excuse.
@bokelley, your call: apply the one-liner above, or if you'd prefer to keep parallel execution, extract the pool singleton into worker-local scope instead (heavier, but preserves parallelism).
Triaged by Claude Code. Session: https://claude.ai/code/${CLAUDE_CODE_REMOTE_SESSION_ID}
Generated by Claude Code
bokelley commentedon May 13, 2026
/triage execute
Reporter's diagnosis is wrong — the 500s are not Anthropic flakes. Per dx-expert + code-reviewer: all four affected tests mock
@anthropic-ai/sdkviavi.hoisted+vi.mock(FakeAnthropic), so no real Anthropic call is reachable. The 500 is a local crash:poolis a module-level singleton,closeDatabase()in one file'safterAllnulls it while a parallel test file is mid-query,getPool()throws "Database not initialized", Express returns 500.Implementation:
fileParallelism: falseinserver/vitest.config.ts. That's the entire fix.fix(test): disable file parallelism to prevent pool-singleton teardown races.prospect-triage-functionpolling loop only if it persists after (1) — likely won't.brand-enrichment-route.test.tsflagged by code-reviewer (same PR or a small follow-up; your call).Do NOT add retry-on-5xx logic or a quarantine job — both would mask the local crash, not fix it. Default-deny on scope creep.
fix(test): disable file parallelism to prevent pool-singleton teardow…
fix(test): disable file parallelism to prevent pool-singleton teardow…