GLM-5.3 Flash · 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
- 5
- Comments matching a bug
- 2
- Comments not matching
- 3
- Cost of this PR
- $0.077
Published comments (5)
Cached device key persists after tagging failure, bypassing device limit — An over-limit device gets cached anyway, so retries within the ~29-minute cache TTL return nil and `Anonymous.Authenticate` grants access without ever seeing `ErrDeviceLimitReached`. Move `localCache.SetDefault` to after `CreateOrUpdateDevice` succeeds, or invalidate the key on failure.
Device limit check is not atomic, allowing the limit to be exceeded — Concurrent first-tag requests, including across instances in HA where the dedupe cache is per-instance, can all see `CountDevices` below the limit and all upsert. Run the count and insert in one transaction with a lock, or bound the row count inside the upsert itself.
Stale device rows (30-61 days old) can never be refreshed once limit is reached — A device last seen 30–61 days ago keeps a row that `CountDevices` no longer counts but `updateDevice` still refuses to refresh, locking it out until the count drops. Drop the `updated_at BETWEEN` condition on the `device_id` match, or delete and reinsert the expired row.
Device-limit enforcement bypassed when X-Grafana-Device-Id header is omitted — Any client that omits the header — scripts, bots, curl — skips `TagDevice` entirely and is never counted or blocked by `ErrDeviceLimitReached`, defeating the cap. Derive the device identity server-side, e.g. from client IP and user agent, instead of trusting the client-controlled header.
Per-device full COUNT in auth path scales O(N) per fresh device — Every uncached device tag runs `CountDevices` over the full 30-day active set in the auth path, so a burst of N fresh devices costs O(N²) aggregate work and adds latency under load. Track the count incrementally, or enforce the limit inside the upsert statement itself.