Amazon Ergo 1.0 · Balanced
anonymous-add-configurable-device-limit-grafana-codex
Grafana · Go · M · 100–299 lines · 6 files
The normal review, with one generalist agent. Judge: Claude Opus 5.5.
- Gold bugs found
- 2 of 5
- Comments published
- 3
- Comments matching a bug
- 2
- Comments not matching
- 1
- Cost of this PR
- $1.563
Published comments (3)
Device limit is bypassed because the cache key is set before the store call — When `CreateOrUpdateDevice` fails with `ErrDeviceLimitReached`, `localCache.SetDefault` has already cached `key`, so retries and parallel requests pass `tagDeviceUI` and authenticate. Call `localCache.SetDefault` only after a successful store, or delete `key` on failure.
Concurrent device creations can exceed the configured device limit — Two concurrent requests can both pass the non-atomic `CountDevices` check and insert, exceeding `s.deviceLimit`. Enforce the limit atomically with a serializable transaction, locking, or a counter row if it must be a hard bound.
Anonymous auth blocks on device tagging when device limits are disabled — With `device_limit=0`, synchronously awaiting `TagDevice` adds a DB write to every uncached anonymous authentication without rejecting anything. Keep the previous asynchronous path when `AnonymousDeviceLimit` is zero, and block only when enforcement is needed.