From 0b07d0b5a062b9c0750d8bf92e44b26b30f85c56 Mon Sep 17 00:00:00 2001 From: Zachary Lowden Date: Sun, 1 Nov 2026 23:22:00 -0600 Subject: [PATCH 1/2] test(api): preflightStore.NameExists answers from its rows (fix 1-in-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) --- internal/api/kickoff_preflight_test.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/internal/api/kickoff_preflight_test.go b/internal/api/kickoff_preflight_test.go index bfb2620f..fffe0ae1 100644 --- a/internal/api/kickoff_preflight_test.go +++ b/internal/api/kickoff_preflight_test.go @@ -120,7 +120,24 @@ func (s *preflightStore) Create(_ context.Context, a agents.Agent) (agents.Agent return a, nil } -func (s *preflightStore) NameExists(context.Context, string) (bool, error) { return false, nil } +// NameExists answers from the rows this fixture has created, as PGStore's does +// from live rows, so BuildUniqueAgentName redraws on a taken name here too. +// +// It used to answer false unconditionally. The name pool is 16x16 = 256, so two +// dispatches in one test drew the SAME name about once in 256 runs, and a test +// that then looked a row up by name (pageablePreflight.GetByName, behind +// GET /agents/) got the first of the two —TestAPoolWorkerIsVisibleWhereAgentsAreListed failed in CI that way, its +// pool-less control page rendering the pooled agent's chip. +func (s *preflightStore) NameExists(_ context.Context, name string) (bool, error) { + s.mu.Lock() + defer s.mu.Unlock() + for _, a := range s.created { + if a.Name == name { + return true, nil + } + } + return false, nil +} func (s *preflightStore) List(context.Context) ([]agents.Agent, error) { s.mu.Lock() From 1fdc6967ad81c41e1337c9b1989b61dc5de12176 Mon Sep 17 00:00:00 2001 From: Zachary Lowden Date: Sun, 1 Nov 2026 23:35:39 -0600 Subject: [PATCH 2/2] test(api): tidy the NameExists fixture comment (audit r1 nit) Co-Authored-By: Claude Opus 5.5 (1M context) --- internal/api/kickoff_preflight_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/api/kickoff_preflight_test.go b/internal/api/kickoff_preflight_test.go index fffe0ae1..9233c5e0 100644 --- a/internal/api/kickoff_preflight_test.go +++ b/internal/api/kickoff_preflight_test.go @@ -126,8 +126,9 @@ func (s *preflightStore) Create(_ context.Context, a agents.Agent) (agents.Agent // It used to answer false unconditionally. The name pool is 16x16 = 256, so two // dispatches in one test drew the SAME name about once in 256 runs, and a test // that then looked a row up by name (pageablePreflight.GetByName, behind -// GET /agents/) got the first of the two —TestAPoolWorkerIsVisibleWhereAgentsAreListed failed in CI that way, its -// pool-less control page rendering the pooled agent's chip. +// GET /agents/) got the first of the two. That is how +// TestAPoolWorkerIsVisibleWhereAgentsAreListed failed in CI: its pool-less +// control page rendered the pooled agent's chip. func (s *preflightStore) NameExists(_ context.Context, name string) (bool, error) { s.mu.Lock() defer s.mu.Unlock()