DeepSeek V4.1 Flash · 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 Haiku 5.5.
- Gold bugs found
- 1 of 2
- Comments published
- 7
- Comments matching a bug
- 1
- Comments not matching
- 6
- Cost of this PR
- $0.234
Published comments (7)
Synchronous TagDevice adds DB round trip to anonymous auth — Every anonymous request that misses the cache now blocks the auth middleware on `CountDevices` and an `anon_device` upsert, and a stalled database stalls auth with no timeout or `recover()`. Move `TagDevice` back to the fire-and-forget goroutine with its own timeout and panic recovery.
Device limit keyed on spoofable client-supplied ID enables auth DoS — `DeviceID` comes from the spoofable `X-Grafana-Device-Id` header, so random IDs fill the 30-day `updated_at` window and deny anonymous auth instance-wide for up to 30 days. Bind the quota to a server-side signal such as IP or a rate limiter instead of the client-supplied identifier.
ProvideAnonDBStore's new int64 param breaks wire DI registration — Wire still registers `ProvideAnonDBStore`, whose new `int64` dependency the container cannot supply, so generation fails wherever `anonstore.AnonStore` is resolved. Remove that provider from the set in `pkg/server/wire.go` since `ProvideAnonymousDeviceService` now builds the store inline.
Test never exercises successful update at device limit — The test only submits nonexistent `device_id` "keep", so `updateDevice`'s UPDATE always affects 0 rows and a broken update path would still pass. Add a step re-submitting "32mdo31deeqwes" with a new IP and assert `ListDevices` returns one device with the updated `ClientIP`.
anonymousDeviceLimit inferred as undefined-only instead of number | undefined — Without an annotation `anonymousDeviceLimit` is inferred as the literal `undefined`, but `GrafanaConfig` declares `number | undefined`, so the numeric limit from the backend cannot be represented. Annotate it as `number | undefined` like the sibling `loginError` field.
Device-limit rejection bypassed by cache set before device insert — `tagDeviceUI` writes the cache key before `CreateOrUpdateDevice`, so a device rejected with `ErrDeviceLimitReached` is cached as tagged and slips through on the next request within the TTL. Set the cache entry only after the insert succeeds, or delete the key on rejection.
Device limit check races with insert, allowing too many devices — `CountDevices` and the INSERT run in separate statements, so two concurrent new devices both see limit-1 and the table exceeds `deviceLimit`. Perform the count and insert under one lock or enforce the cap inside the insert statement.