Skip to content

Commit b0ab35c

Browse files
jeremyederclaude
authored andcommitted
fix(backend): address CodeRabbit review feedback on perf PR
- Fix misleading "LRU eviction" comment to "random eviction" (Go map iteration order is undefined) - Fix data race in BenchmarkEnrichAgentStatus_Concurrent: each RunParallel goroutine now gets its own session struct - Fix BenchmarkEnrichAgentStatus_ListPage/uncached: clear cache before each session so every call is a true cache miss Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 96d0e18 commit b0ab35c

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

components/backend/handlers/agent_status_bench_test.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,13 @@ func BenchmarkEnrichAgentStatus_Concurrent(b *testing.B) {
141141

142142
b.ResetTimer()
143143
b.RunParallel(func(pb *testing.PB) {
144-
i := 0
144+
// Each goroutine gets its own session to avoid racing on AgentStatus mutation
145+
session := &types.AgenticSession{
146+
Metadata: map[string]interface{}{"name": "bench-session"},
147+
Status: &types.AgenticSessionStatus{Phase: "Running"},
148+
}
145149
for pb.Next() {
146-
enrichAgentStatus(sessions[i%20])
147-
i++
150+
enrichAgentStatus(session)
148151
}
149152
})
150153
}
@@ -172,12 +175,12 @@ func BenchmarkEnrichAgentStatus_ListPage(b *testing.B) {
172175

173176
b.Run("uncached", func(b *testing.B) {
174177
for i := 0; i < b.N; i++ {
175-
// Clear cache
176-
agentStatusCache.Lock()
177-
agentStatusCache.entries = make(map[string]agentStatusCacheEntry)
178-
agentStatusCache.Unlock()
179-
180178
for j := range sessions {
179+
// Clear cache before each session to force a file scan every time
180+
agentStatusCache.Lock()
181+
delete(agentStatusCache.entries, "bench-session")
182+
agentStatusCache.Unlock()
183+
181184
enrichAgentStatus(&sessions[j])
182185
}
183186
}

components/backend/handlers/ssar_cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func init() {
1818
// RBAC changes take at most this long to take effect.
1919
const ssarCacheTTL = 30 * time.Second
2020

21-
// ssarCacheMaxSize is the maximum number of entries before LRU eviction.
21+
// ssarCacheMaxSize is the maximum number of entries before random eviction.
2222
const ssarCacheMaxSize = 10000
2323

2424
// ssarCacheEntry holds a cached SSAR result with expiry.

0 commit comments

Comments
 (0)