GLM-5.3 · 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 Haiku 5.5.
- Gold bugs found
- 1 of 2
- Comments published
- 4
- Comments matching a bug
- 1
- Comments not matching
- 3
- Cost of this PR
- $0.921
Published comments (4)
Over-limit device is cached on failed write and bypasses the limit for 29 minutes — In `tagDeviceUI` (impl.go), the device key is cached before `CreateOrUpdateDevice` runs, so an over-limit rejection still leaves it in `localCache` and the cache hit makes `TagDevice` return nil on later requests. Move `a.localCache.SetDefault` after a successful `CreateOrUpdateDevice`, or evict the key on error.
Anonymous device limit bypassable by omitting X-Grafana-Device-Id header — `TagDevice` (impl.go) returns nil when the header is missing, so clients that omit or rotate `X-Grafana-Device-Id` authenticate freely and never count against the quota. Anchor enforcement to a server-side signal, or document that the cap only meters cooperative frontends.
Count-then-insert race in `CreateOrUpdateDevice` exceeds the device limit — In `CreateOrUpdateDevice`, `CountDevices` and the insert run as separate statements with no lock, so concurrent requests each see `count < deviceLimit` and all insert, exceeding the cap. Make the check atomic with a transaction that locks the counting range, or a conditional insert that re-checks the count.
TagDevice runs synchronously on the auth path, blocking every anonymous request — Auth now waits on a device round-trip for every anonymous request, amplifying latency on the hottest path. Run `TagDevice` asynchronously so authentication doesn't depend on it.