Skip to content

ci: quarantine chronic Anthropic-5xx integration test flakes (admin-merge-with-known-failures is a blind spot) #3695

Closed

Description

@bokelley

Spun out of #3691 expert review.

What

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:

  • `server/tests/integration/brand-classifier-route.test.ts`
  • `server/tests/integration/brand-enrichment-route.test.ts`
  • `server/tests/integration/prospect-triage-function.test.ts`
  • `server/tests/integration/property-enhancement-function.test.ts`

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.

Why this matters

Per security review on #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:

  1. 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.

  2. 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
  • Once stabilized, un-quarantine

Refs

Activity

  1. added
    claude-triaging
    on Apr 30, 2026
  2. bokelley commented on Apr 30, 2026

    @bokelley
    ContributorAuthor

    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:

    • 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:

      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

  3. added
    bug
    claude-triaged
    and removed
    claude-triaging
    on Apr 30, 2026
  4. bokelley commented on May 13, 2026

    @bokelley
    ContributorAuthor

    /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/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:

    1. Set fileParallelism: false in server/vitest.config.ts. That's the entire fix.
    2. 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.
    3. Address the secondary flake in the prospect-triage-function polling loop only if it persists after (1) — likely won't.
    4. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugclaude-triaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions