Amazon Ergo 1.0 · 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
- 6
- Comments matching a bug
- 2
- Comments not matching
- 4
- Cost of this PR
- $3.018
Published comments (6)
updateDevice anchors its activity window to caller-controlled UpdatedAt — A stale caller-supplied `device.UpdatedAt` can make an active device miss the update window, producing `ErrDeviceLimitReached` and an auth failure in `client.go`. Anchor both the update and limit-count windows to one `time.Now().UTC()` value, passing `from`/`to` into `updateDevice`.
Device-limit rejection is bypassed while the device stays cached — `tagDeviceUI` caches the device ID before `CreateOrUpdateDevice`, so a rejected device can use the cache fast path and gain anonymous access for the remaining TTL. Mark the device as tagged only after a successful store, or call `a.localCache.Delete(deviceID)` when the store returns an error.
Device-limit check races with concurrent inserts — Concurrent inserts can all observe the same below-limit `CountDevices` result and then insert, allowing active devices to exceed `s.deviceLimit`. Enforce the check and write atomically with a suitably locked transaction or a database-side mechanism.
No-op device updates incorrectly return ErrDeviceLimitReached — On MySQL, `RowsAffected() == 0` also occurs when a row matches but no values change, so a legitimate no-op update is misreported as `ErrDeviceLimitReached`. Detect whether the device row matched independently of changed values, such as with found-rows semantics, and reserve `ErrDeviceLimitReached` for the actual limit.
Device limit test does not verify updates to existing devices — Changing `DeviceID` to `keep` exercises only new-device rejection, so broken updates could lock out known devices while this test still passes. At the limit, update the original `DeviceID` and assert `NoError`, persisted fields, and one stored device; separately assert that a new `DeviceID` returns `ErrDeviceLimitReached`.
Service tests do not cover device-limit config wiring — These tests use `setting.NewCfg()` with a zero limit, so failing to pass `cfg.AnonymousDeviceLimit` into `ProvideAnonDBStore` would silently disable the feature. Add a service-level case with `cfg.AnonymousDeviceLimit = 1`, tag two distinct devices via `TagDevice`, and assert the second returns `ErrDeviceLimitReached`.