Skip to content

[AAASM-5159] ♻️ (costs): Restore Avg / agent today KPI and surface cost date - #1780

Merged
Chisanan232 merged 6 commits into
mainfrom
v0.0.1/AAASM-5159/fix/costs_avg_per_agent_kpi
Jul 28, 2026
Merged

[AAASM-5159] ♻️ (costs): Restore Avg / agent today KPI and surface cost date#1780
Chisanan232 merged 6 commits into
mainfrom
v0.0.1/AAASM-5159/fix/costs_avg_per_agent_kpi

Conversation

@Chisanan232

@Chisanan232 Chisanan232 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Description

Restores the fourth spec KPI on the Cost & Budget page — "Avg / agent today" (daily_spend / agentsTracked, captioned with costs.date) — from design/v1/hi-fi/costs.jsx:299-305. The shipped strip had Utilisation and Blocked-by-budget but was missing this card, and never surfaced CostSummary.date at all.

The computation lives in deriveCostKpis as a pure function with a divide-by-zero guard: a genuine zero-agent roster folds to not-evaluated (rendered as the canonical em-dash), never NaN or a fabricated $0.00 — the same false-negative the rest of the module exists to prevent. Any other absence in agentsTracked (outage, in-flight, no breakdown configured) propagates unchanged. The date sub-caption resolves independently, so it still renders even when the ratio is undefined.

ADR basis: ADR-0017 item 14 ratifies Utilisation and Blocked-by-budget as additive to the four spec KPIs — not replacements for one of them. The missing avg-per-agent card was therefore a genuine parity regression, and restoring it is purely additive, consistent with that recorded decision.

Type of Change

  • ♻️ Refactoring

Breaking Changes

  • No

Related Issues

Testing

  • Unit tests added / updated — costKpis.test.ts (divide, zero-guard, absence propagation) and CostsPage.test.tsx (render, em-dash, failure states)
  • Manual testing performed — Playwright review spec dashboard/tests/e2e/review-aaasm-5159.spec.ts drives both themes for the known-roster and zero-agent cases

Design verification: screenshots in dashboard/verify/5159/ (known + zero-agent, both themes) confirm all four spec KPI cards render, the avg-per-agent card shows $105.00 with 2026-05-13 as its sub-caption, and the zero-agent case renders an em-dash (not NaN / $0.00) while the date sub-caption still resolves.

Local checks (Node v22, pnpm): tsc --noEmit clean, eslint . clean, vitest run — 3066 passed.

Security: pure client-side arithmetic on already-fetched /costs data — no new network surface, no new inputs, no new trust boundary.

Checklist

  • Self-review of the diff completed
  • All CI checks passing (pending CI run)
  • Commits are small and follow the Gitmoji convention

Closes AAASM-5159

🤖 Generated with Claude Code

Chisanan232 and others added 6 commits July 28, 2026 14:10
…ro-guard

Compute the mock's fourth "Avg / agent today" KPI
(design/v1/hi-fi/costs.jsx:299-305). A genuine zero-agent roster folds to
`not-evaluated` rather than NaN or a fabricated $0.00; any other absence in
agentsTracked propagates unchanged.

Refs AAASM-5159
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Wire the restored fourth spec KPI into the Cost & Budget strip, captioned
with the summary's cost date. ADR-0017 item 14 ratifies Utilisation and
Blocked-by-budget as additive to the spec KPIs, not replacements for one of
its four cards, so the missing avg-per-agent card was a regression.

Refs AAASM-5159
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…gation

Refs AAASM-5159
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…e states

Refs AAASM-5159
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Drives both themes for the known-roster and zero-agent cases and captures
the review screenshots under dashboard/verify/5159/.

Refs AAASM-5159
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…t, both themes)

Refs AAASM-5159
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
dashboard/src/features/costs/costKpis.ts 85.71% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@sonarqubecloud

Copy link
Copy Markdown

@Chisanan232 Chisanan232 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — reviewed and approved by Claude Code

(COMMENT review because GitHub blocks self-approval; this is the sign-off of record.)

Requirement correctness — AAASM-5159

Restores the "Avg / agent today" KPI per design/v1/hi-fi/costs.jsx:299-305, cites ADR-0017 item 14 (Utilisation/Blocked are additive, not a replacement — so the missing 4th card was a real regression). avgPerAgent = daily.spend / agentsTracked folds a genuine measured zero to not-evaluated (not NaN/$0.00), and propagates every other absence state (unconfigured/unavailable/in-flight) through the Certain<> boundary — matching the module's truthfulness discipline exactly. The card renders usd(avgPerAgent) with costs.date as the sub-caption via mapCertain, so the date propagates its own absence. Tests cover the divide, the zero-agent not-evaluated case, the unconfigured/unavailable propagation, plus a page-level render assertion.

CI — all checks green (CI Success pass).

Security — pure client-side arithmetic on already-fetched cost data; no new backend surface.

Merging as org admin with a merge commit.

🤖 Reviewed with Claude Code

@Chisanan232
Chisanan232 merged commit fe6052f into main Jul 28, 2026
40 checks passed
@Chisanan232
Chisanan232 deleted the v0.0.1/AAASM-5159/fix/costs_avg_per_agent_kpi branch July 28, 2026 12:56
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