Skip to content

feat: agent health scores — per-agent sub-metric badges#27

Merged
JLRansom merged 2 commits into
masterfrom
feat/agent-health-metrics
Mar 18, 2026
Merged

feat: agent health scores — per-agent sub-metric badges#27
JLRansom merged 2 commits into
masterfrom
feat/agent-health-metrics

Conversation

@JLRansom
Copy link
Copy Markdown
Owner

Summary

  • Adds per-agent health sub-metrics (completion rate, throughput trend, error density, idle time) derived from taskRuns history with zero new DB tables or API routes
  • Surfaces metrics as a compact four-dot colour-coded badge on every agent row in the dashboard, updating with each SSE broadcast via a 30-second server-side TTL cache
  • Ships sub-metrics first (phased approach) — composite 0–100 score deferred until weights are validated with real usage data

Architecture

lib/health.ts — pure computeHealthMetrics(taskRuns, now?) function; injectable now makes every calculation fully testable without mocking Date.now(). Uses a 7-day rolling window (ROLLING_WINDOW_MS), a MIN_RUNS_THRESHOLD = 5 sparse-data guard, and simple linear regression for week-over-week throughput trend.

lib/health-cache.ts — module-level Map singleton (same pattern as broadcast.ts) with configurable TTL. Health metrics are never computed inside the SSE hot path — getStreamPayload() serves cached values and only recomputes on cache miss or expiry.

components/AgentHealthBadge.tsx — four coloured dots (C = Completion, T = Trend, E = Errors, I = Idle) with threshold-based green/yellow/red colouring and a hover tooltip showing actual values. Renders nothing on missing metrics; shows "Gathering data…" when hasEnoughData is false.

Failure mode handling

  • Agent deleted mid-broadcast → agentHealth?.[agent.id] returns undefined → badge renders nothing
  • Missing/malformed agentHealth field in older payload → StreamPayload.agentHealth is optional — existing clients degrade gracefully
  • Sparse history (< 5 runs in window) → explicit "Gathering data…" label, no misleading zeros

Files changed

File Action
lib/types.ts Add AgentHealthMetrics interface; extend StreamPayload.agentHealth?
lib/db/repositories/taskRunRepo.ts Add dbGetTaskRunsByAgent + dbGetRecentTaskRunsByAgent
lib/health.ts New — pure metrics calculation
lib/health-cache.ts New — 30-second TTL cache
lib/store.ts Wire health cache into getStreamPayload()
components/AgentHealthBadge.tsx New — four-dot badge component
components/AgentRow.tsx Add Health cell
components/AgentList.tsx Add "Health" column header
__tests__/unit/health.test.ts New — 13 unit tests (deterministic, injected now)
__tests__/unit/health-cache.test.ts New — 9 tests (TTL, DB reads, invalidation)

Test plan

  • npm run test:run — all 156 tests pass
  • Sparse-data guard: agents with < 5 runs in window show "Gathering data…" badge
  • Sufficient-data path: agents with ≥ 5 runs show four coloured dots
  • Hover tooltip shows Completion: X% · Trend: ±Y tasks/wk · Errors: Z% · Idle: Nm
  • Deleting an agent removes their row and badge with no JS errors
  • SSE payload includes agentHealth map; older clients without field ignore it gracefully

Depends on: PR #26 (fix/analytics-status-classification) — merge that first.

🤖 Generated with Claude Code

JLRansom and others added 2 commits March 17, 2026 20:28
… card modal

- MeetingView: always build the card description from all concluded agent
  messages (writer, researcher, coder, senior-coder, tester) rather than
  using only the tester output and falling back to everyone else
- TaskDetailModal: fetch project tags on open and replace the freetext
  input+Add button with a <select> dropdown; only unassigned project tags
  are shown; selected tag is appended and removed from the dropdown;
  existing tag pills now use the project tag's hex color when available

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add AgentHealthMetrics interface and extend StreamPayload with agentHealth map
- Add dbGetTaskRunsByAgent / dbGetRecentTaskRunsByAgent repo functions
- Implement computeHealthMetrics() in lib/health.ts (completion rate, throughput trend, error density, idle time with 7-day rolling window)
- Add TTL-based in-process cache in lib/health-cache.ts (30-second default TTL)
- Integrate health computation into getStreamPayload() in lib/store.ts
- Add AgentHealthBadge component (four-dot compact indicator)
- Wire badge into AgentRow and Health column header into AgentList
- 17 new unit tests covering health computation and cache behavior

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@JLRansom JLRansom merged commit a27e4a0 into master Mar 18, 2026
2 checks passed
@JLRansom JLRansom deleted the feat/agent-health-metrics branch March 18, 2026 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant