Kimi K3.1 Pro · Balanced

unified-storage-performance-optimizations-grafana-codex

Grafana · Go · S · 30–99 lines · 5 files

The normal review, with one generalist agent. Judge: Claude Haiku 5.5.

Gold bugs found
2 of 3
Comments published
3
Comments matching a bug
2
Comments not matching
1
Cost of this PR
$0.694

Published comments (3)

highbugpkg/storage/unified/resource/search.go:216

TotalDocs can race with event-driven cache writes — `TotalDocs` iterates `bleveBackend.cache` without `cacheMu.RLock`, so an event reaching `BuildIndex` can write `b.cache[key]` during iteration and crash the process with a concurrent map iteration/write. Hold the cache read lock throughout `TotalDocs`, or compute the count before starting the event goroutine.

mediumbugpkg/storage/unified/search/bleve.go:137-139

Concurrent same-key builds can overwrite the cached index — Concurrent `getOrCreateIndex` calls for one uncached key can leave callers using different indexes and make file-backed builders contend for the same Bleve directory. Use per-key single-flight, or lock and recheck `b.cache[key]`, so only one build populates each key while different keys still build in parallel.

mediumbugpkg/storage/unified/resource/server.go:258-262

Failed initialization leaks the search watcher and lifecycle backend — If `initWatcher` fails after `search.init` starts its watcher, construction returns without stopping the watcher or lifecycle backend, leaving goroutines and database polling alive. Clean up the partially initialized server before returning and cancel the search watcher through a server-owned context.

Gold bugs found (2)

mediumBuildIndex now locks only the final cache assignment, so concurrent callers for the same uncached key all build the same expensive index in parallel and the last one overwrites the others.
highThe new startup log calls TotalDocs, which iterates the index cache without a lock, after the event goroutine that can add indexes has started, so a concurrent map read and write can crash the process.

Gold bugs missed (1)

mediumThe PR skips the storage-server module integration test on postgres instead of fixing the failure, removing coverage of the new eager initialization on postgres.