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)

highbugpkg/services/anonymous/anonimpl/anonstore/database.go:95-97

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.

highbugpkg/services/anonymous/anonimpl/impl.go:144-148

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`

highbugpkg/services/anonymous/anonimpl/anonstore/database.go:109-118

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.

mediumperformancepkg/services/anonymous/anonimpl/client.go:44

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.

Gold bugs found (2)

highThe device limit check counts devices and then inserts in separate non-atomic steps, so concurrent requests from new devices can all pass the check and exceed the configured limit.
hightagDeviceUI caches the device key before CreateOrUpdateDevice; when the store returns ErrDeviceLimitReached the entry stays, so the next request from the same device skips the limit check and authenticates for up to 29 minutes.

Gold bugs missed (3)

highThe new auth.anonymous device_limit setting has no entry in conf/defaults.ini, so the GF_AUTH_ANONYMOUS_DEVICE_LIMIT environment override is ignored and the limit stays 0.
mediumupdateDevice prepends the query to the captured args inside the retried DB callback, so a SQLite lock retry runs Exec with the query duplicated in the arguments and the update fails.
highClaims a client disconnect cancels the context, TagDevice fails with context.Canceled, and Authenticate still succeeds without counting the device, bypassing the limit.