DeepSeek V4 Pro · Heavy
anonymous-add-configurable-device-limit-grafana-codex
Grafana · Go · M · 100–299 lines · 6 files
The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Opus 5.5.
- Gold bugs found
- 2 of 5
- Comments published
- 4
- Comments matching a bug
- 2
- Comments not matching
- 2
- Cost of this PR
- $1.267
Published comments (4)
RowsAffected()==0 incorrectly treats unchanged existing device as over-limit — RowsAffected can be 0 when the UPDATE matched a row but wrote identical values, such as a same-second update stored to a second-precision updated_at column or MySQL without CLIENT_FOUND_ROWS. That makes an existing anonymous device look over-limit: CreateOrUpdateDevice returns ErrDeviceLimitReached and Anonymous.Authenticate now propagates it.
Device key remains cached after CreateOrUpdateDevice error — tagDeviceUI writes the device key into localCache before CreateOrUpdateDevice succeeds. Now that TagDevice propagates ErrDeviceLimitReached, the failed attempt leaves the key cached: a retry within the cache TTL returns early at impl.go:83, so the device is never persisted yet anonymous authentication succeeds, bypassing the device limit. **Also found in:** - `pkg/services/anonymous/anonimpl/client.go:44-47`
Device limit check and insert are not atomic under concurrency — The count and insert run as separate, non-transactional statements: two concurrent anonymous requests can both observe count < deviceLimit and both insert, exceeding the configured device limit. Wrap the count and insert in one transaction or add a DB-level constraint to enforce the limit atomically instead of check-then-act.
Synchronous TagDevice call adds DB round-trips to anonymous auth hot path — Every uncached anonymous login now blocks on a COUNT plus an INSERT/UPDATE against anon_device before the identity is returned, adding two DB round-trips to the auth hot path. Keep the normal tagging path asynchronous and perform the limit check separately, or otherwise avoid the blocking write on each uncached login.