Skip to main content
← Back to list
01Issue
BugShippedSwamp Club
Assigneeskeeb

Relationships

#1092 swamp-club: /api/whoami 500s on fresh install — ensureIndexes {id:1} conflicts with migration 012 id_lookup index

Opened by keeb · 7/11/2026· Shipped 7/11/2026

Description

On a fresh swamp-club deployment, the first authenticated GET /api/whoami returns HTTP 500, which makes swamp auth login fail entirely ("Whoami request failed (HTTP 500)").

Root cause: two code paths create an index on organization { id: 1 } with different names:

  1. migrations/012-auth-hot-path-indexes.ts creates it with name id_lookup at startup (#921)
  2. BetterAuthCollectiveQueries.ensureIndexes (lib/infrastructure/better-auth-collective-queries.ts) creates it with the default name id_1 — added in 0b9bb80 (ClickHouse read-path overhaul), which runs lazily on the first whoami via getCollectiveQueryService

Mongo rejects the second createIndex with code 85 IndexOptionsConflict: Index already exists with a different name: id_lookup. Migration 013's header comment even notes the id_lookup index must not be duplicated.

Steps to Reproduce

  1. Start swamp-club against an empty Mongo (migrations run, id_lookup created)
  2. Sign up + verify a user
  3. swamp auth login --server <url> --username <email> --password <pw> --no-browser

Observed: login exits 1 with "Whoami request failed (HTTP 500)"; server log shows MongoServerError code 85 at BetterAuthCollectiveQueries.ensureIndexes → getDefaultDeps → handleGetWhoami.

Impact

All CLI authentication against a fresh install is broken; the entire club UAT suite fails at the first auth step.

Suggested Fix

Pass the matching name in ensureIndexes so createIndex is idempotent: createIndex({ id: 1 }, { name: "id_lookup" }) Verified locally: with this change auth login exits 0 and the extensions UAT flow passes 9/9.

Environment

swamp-club main (0abbb2f), fresh Mongo 7, Linux x86_64

02Bog Flow
OPENTRIAGEDIN PROGRESSSHIPPED+ 1 MOREASSIGNED+ 5 MOREREVIEW+ 4 MOREPR_MERGED+ 1 MORENOTIFICATION_SKIPPED

Shipped

7/11/2026, 5:22:45 PM

Click a lifecycle step above to view its details.

03Sludge Pulse
keeb assigned keeb7/11/2026, 4:53:29 PM

Sign in to post a ripple.