Skip to content

test(api): fix 1-in-256 name-collision flake in TestAPoolWorkerIsVisibleWhereAgentsAreListed - #398

Merged
ZacxDev merged 2 commits into
mainfrom
fix/flake-pool-worker-visible
Nov 2, 2026
Merged

ZacxDev merged 2 commits into
mainfrom
fix/flake-pool-worker-visible

Conversation

@ZacxDev

@ZacxDev ZacxDev commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Flake

TestAPoolWorkerIsVisibleWhereAgentsAreListed failed once in CI on #387 (run 41274534531, attempt 1, job "test (postgres)"):

worker_pool_form_test.go:62: /agents/spry-newt carries 1 pool chips, want 0:

Root cause (test fixture, not production)

internal/api/kickoff_preflight_test.go:123 (origin/main): preflightStore.NameExists returned false unconditionally, so agents.BuildUniqueAgentName (internal/agents/names.go:207) never redrew. The pool is 16 adjectives x 16 nouns = 256 names, so the test's two dispatches drew the same name about once in 256 runs. pageablePreflight.GetByName (worker_pool_form_test.go) returns the first row with that name, so the pool-less control's page (plain, line 54) rendered the pooled agent with its chip, and the assertion at line 62 failed.

Production is fine: PGStore.NameExists checks live rows plus the retired-names ledger, so a real deployment redraws.

Fix

preflightStore.NameExists now answers from the rows the fixture has created, the way PGStore does. No retry, no sleep. nameExistsNever in officers_test.go stays as it is on purpose: it samples the generator and creates no rows.

Evidence

go test ./internal/api -run '^TestAPoolWorkerIsVisibleWhereAgentsAreListed$', with counts taken from --- PASS/--- FAIL lines:

tree mode FAIL PASS
origin/main 0a2ef0e natural, -count=3000 9 2991
HEAD natural, -count=3000 0 3000
origin/main fixture + generateName pinned to one name (uncommitted) forced collision, -count=200 200 0
HEAD fixture + same pin forced collision, -count=200 0 200
HEAD -race -cpu 1,4 -count=500 0 1000

The natural rate of 9/3000 matches the expected 3000/256 ≈ 11.7.

Full suite, run as CI does (go test -race -cover -timeout 20m -json ./... piped to tests/verdict.py with the three --requires, against a local Postgres 17): internal/api ok, 0 skipped, 3/3 required tests passed. go vet ./... is clean. My local run also showed failures in internal/connectors and internal/db. Both come from the local environment, and this diff doesn't touch either package (it changes one internal/api _test.go file):

  • connectors (a wrong password connected): my pg_hba first used trust. With scram it passes.
  • db: DROP DATABASE … WITH (FORCE) hit statement timeouts under full parallel -race load. The same tests pass when run alone.

🤖 Generated with Claude Code

ZacxDev and others added 2 commits November 1, 2026 23:22
…256 flake)

TestAPoolWorkerIsVisibleWhereAgentsAreListed failed once in CI (PR #387,
run 41274534531 attempt 1): "/agents/spry-newt carries 1 pool chips, want 0".

Root cause is the fixture, not production: preflightStore.NameExists returned
false unconditionally, so BuildUniqueAgentName never redrew. The name pool is
16 adjectives x 16 nouns = 256, so the test's two dispatches shared a name about
once per 256 runs, and pageablePreflight.GetByName then resolved the pool-less
control's page to the first (pooled) row. PGStore.NameExists consults live
rows, so production redraws; the fixture now does the same.

Matrix (go test ./internal/api -run '^TestAPoolWorkerIsVisibleWhereAgentsAreListed$'):
- natural rate, origin/main, -count=3000: 9 FAIL / 2991 PASS
- natural rate, HEAD,        -count=3000: 0 FAIL / 3000 PASS
- forced collision (generateName pinned to one name, uncommitted),
  old fixture -count=200: 200 FAIL; new fixture -count=200: 0 FAIL
- HEAD, -race -cpu 1,4 -count=500: 1000 PASS / 0 FAIL

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ZacxDev

ZacxDev commented Nov 2, 2026

Copy link
Copy Markdown
Owner Author

Audit ladder: round 0 = proceed (0 deletion candidates); round 1 = no 🔴/🟡, one 🟢 (comment wording) fixed in 1fdc696 without re-audit. Red/green independently reproduced: base 5/1500 and 8/2000 FAIL, HEAD 0/1500 and 0/2000; forced collision 50/50 FAIL at base, 0/50 at HEAD.

1. preflightStore.NameExists answers from the fixture's created rows instead of false unconditionally, so BuildUniqueAgentName redraws on a taken name
2. TestAPoolWorkerIsVisibleWhereAgentsAreListed no longer fails about 1 run in 256 when two dispatches draw the same name

@ZacxDev
ZacxDev marked this pull request as ready for review November 2, 2026 05:35
@ZacxDev
ZacxDev merged commit 094c96c into main Nov 2, 2026
19 checks passed
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