Skip to content

fix(stats): render Agents-running sparkline immediately on first paint#85

Merged
LakshmanTurlapati merged 2 commits into
mainfrom
fix/stats-agents-running-chart
May 27, 2026
Merged

fix(stats): render Agents-running sparkline immediately on first paint#85
LakshmanTurlapati merged 2 commits into
mainfrom
fix/stats-agents-running-chart

Conversation

@LakshmanTurlapati

Copy link
Copy Markdown
Collaborator

Summary

  • Bug: Visitors landed on /stats, switched to the "Agents running" tab, and saw a 360px black void for ~5 minutes before any line appeared. Headline row above ("20 active agents · 15,844 lifetime agents") populated instantly, so the network was healthy — only the chart canvas was empty.
  • Root cause: agentHistoryRing is a component-local buffer that starts empty on every mount. FSBTelemetryService polls every 5 min (POLL_INTERVAL_MS = 5 * 60 * 1000) and start() only fires ONE immediate refresh. So the ring had exactly 1 sample for the first 5 min. The fsb-agents-running chart config uses pointRadius: 0 (sparkline aesthetic), and Chart.js needs ≥2 points to stroke a line — a 1-point dataset with invisible points draws nothing.
  • Fix: Render-time fallback inside the fsb-agents-running switch case only — when ring.length < 2, synthesize [live, live] from the current active_agents_now headline value so the chart draws an immediate flat "currently N agents" line that gains real shape as the ring fills with subsequent samples.

Constraints respected

  • Scoped strictly to lines 1029-1059 of stats-page.component.ts (the fsb-agents-running switch arm).
  • Polling cadence in FSBTelemetryService untouched (out of scope; that's a privacy/cost-of-egress decision).
  • agentHistoryRing buffer untouched — no pre-seed, no localStorage, no shared service state.
  • Legend i18n marker SHOWCASE_STATS_FSB_CHART_AGENTS_RUNNING_LEGEND byte-identical.
  • No other tab's chart config touched.
  • When ring.length >= 2, behavior is byte-identical to pre-fix.
  • messages.xlf line-number context drift regenerated via ng extract-i18n so the CI "no diff" gate stays green.

Test plan

  • cd showcase/angular && npm run build — passes (11s, 30 routes prerendered).
  • npm run lint:i18n — 0 errors (one pre-existing unrelated warning on agents-page).
  • npx ng extract-i18n — only line-number context drift, no new/removed trans-units, no source text changes; regenerated file committed.
  • Manual: visit deployed /stats, click "Agents running" tab, confirm a flat horizontal line appears immediately at the current value (e.g. ~20 agents) instead of an empty 360px black void.
  • Manual: wait through one 5-min poll cycle, confirm the line transitions naturally from flat to varying as the second real sample arrives.

🤖 Generated with Claude Code

The fsb-agents-running chart fed Chart.js a 1-point line dataset for the
first 5 minutes after mount: agentHistoryRing starts empty, FSBTelemetryService
polls every 5 min, so only the immediate-fetch sample existed until the next
poll. With pointRadius:0 (sparkline aesthetic) a 1-point line draws literally
nothing — Chart.js needs >=2 points to stroke. Net effect: visitors landed
on /stats, switched to "Agents running", and saw a 360px void for 5 minutes.

Fix: render-time fallback inside the fsb-agents-running switch case only.
When ring.length < 2, synthesize [live, live] from the current
active_agents_now headline value so the chart draws a flat "currently N agents"
line from the first paint, gaining real shape as the ring fills.

Polling cadence, ring buffer, legend i18n marker, and all other tabs
untouched. Scoped to lines 1029-1059 of stats-page.component.ts.

messages.xlf line-number context drift regenerated via ng extract-i18n.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ac1c4da9d4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1047 to +1048
const live = headline?.active_agents_now ?? 0;
const data = ring.length >= 2 ? ring : [live, live];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid synthesizing zeros before FSB data exists

When the GitHub datasets have already put the page in ready but the FSB headline request is still pending or has failed, selecting the Agents running tab reaches this branch with latestFsbHeadline === null and an empty agentHistoryRing; the new fallback then renders [0, 0] as if there are zero active agents. The template intentionally hides the FSB headline while fsbHeadline is null, so this can show a misleading zero chart for the duration of a slow request or indefinitely after an FSB error instead of an empty/loading state. Only synthesize the two-point fallback once a real headline/ring sample exists.

Useful? React with 👍 / 👎.

Codex review on PR #85 flagged that when GitHub datasets flip viewState to
'ready' before the FSB headline endpoint resolves (or when it errors), the
first-paint fallback synthesizes [0, 0] -- a misleading flat-zero line as if
there were genuinely zero active agents.

Add a `!headline` gate around the fallback so the canvas stays empty until
at least one real FSB sample arrives. Once latestFsbHeadline is non-null,
onFsbHeadlineUpdate has atomically pushed onto the ring, so the live-value
seed is always backed by a real reading.

messages.xlf line-number context drift regenerated via ng extract-i18n.
@LakshmanTurlapati

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@LakshmanTurlapati LakshmanTurlapati merged commit 7689271 into main May 27, 2026
8 checks passed
@LakshmanTurlapati LakshmanTurlapati deleted the fix/stats-agents-running-chart branch May 27, 2026 14:48
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