Persist 'last run per repo' so dashboard isn't red during quiet periods #9

Open
opened 2026-04-17 22:18:55 -07:00 by nelsong6 · 1 comment
nelsong6 commented 2026-04-17 22:18:55 -07:00 (Migrated from github.com)

Context

diagrams#6 fixed the visual bug — "no recent runs" no longer renders as green, it goes red (broken). Working as intended.

But the underlying reason the dashboard goes red most of the time is that packages/routes/ci.js prunes runs older than 2h on every webhook event. Practical effect: outside an active cascade window, every repo shows "No recent runs" and the node goes red. The dashboard is effectively "is something happening RIGHT NOW", not "are we in a healthy state".

Problem

Red when nothing is wrong is false-alarm noise. The dashboard loses its signal — users learn to ignore it because red is the steady state during business-as-usual quiet periods.

Proposed fix

Add a persistent lastRun map (keyed by repo) that stores only the latest workflow run per repo, never pruned. Webhook events update it. Backfill on cold start seeds it.

Schema (additive, in-memory alongside existing Maps):

// Map<repo, { status, conclusion, updatedAt, htmlUrl, workflow, commitMessage }>
const lastRuns = new Map()
  • runs Map stays as-is for the "currently in-flight" semantics (still 2h pruned, drives cascade-active edges and in-progress badges).
  • lastRuns is new and keeps indefinitely. Only the most recent run per repo.
  • Webhook handler for workflow_run updates both.

Frontend change

CIFztView.tsx#checkGrammar + CIApiContainerView.tsx#checkApiGrammar — instead of checking reposWithRuns (from the 2h-pruned map), check reposWithLastRuns (from the new persistent map). The demote-to-broken logic becomes "no run has ever been observed for this repo" rather than "no run in last 2h" — that's the signal we actually want.

The existing runs Map still drives active state for in-flight cascades (amber edges).

Side benefit

lastRuns also unblocks diagrams#7 (producer amber bleed) — that fix needs "is this specific node actively running" which is a runs-Map question, while node color for healthy/broken uses lastRuns. Two Maps, two semantics, clean separation.

Cold start

backfillFromGitHub() already fetches the 5 most recent main-branch runs per repo. Extend it to populate lastRuns from the single most recent run regardless of branch (or keep main-only if preferred). One extra API call per repo on first SSE connection.

Persistence

In-memory only is fine for v1 (matches existing Maps). If the API restarts, lastRuns re-hydrates from the next cold-start backfill. If we later want survival across restarts, back it with Cosmos DB — same pattern as existing route-package versions.

Where

Acceptance

Dashboard reads green during quiet periods (last known good state) instead of red, unless a version mismatch or genuinely-never-ran repo is present. Red retains meaning: something is actually wrong.

## Context [diagrams#6](https://github.com/nelsong6/diagrams/issues/6) fixed the visual bug — "no recent runs" no longer renders as green, it goes red (broken). Working as intended. But the underlying reason the dashboard goes red *most of the time* is that [packages/routes/ci.js](https://github.com/nelsong6/diagrams/blob/main/packages/routes/ci.js) prunes runs older than 2h on every webhook event. Practical effect: outside an active cascade window, every repo shows "No recent runs" and the node goes red. The dashboard is effectively "is something happening RIGHT NOW", not "are we in a healthy state". ## Problem Red when nothing is wrong is false-alarm noise. The dashboard loses its signal — users learn to ignore it because red is the steady state during business-as-usual quiet periods. ## Proposed fix Add a persistent `lastRun` map (keyed by repo) that stores only the latest workflow run per repo, never pruned. Webhook events update it. Backfill on cold start seeds it. Schema (additive, in-memory alongside existing Maps): ```js // Map<repo, { status, conclusion, updatedAt, htmlUrl, workflow, commitMessage }> const lastRuns = new Map() ``` - `runs` Map stays as-is for the "currently in-flight" semantics (still 2h pruned, drives cascade-active edges and in-progress badges). - `lastRuns` is new and keeps indefinitely. Only the most recent run per repo. - Webhook handler for `workflow_run` updates both. ## Frontend change [CIFztView.tsx#checkGrammar](https://github.com/nelsong6/diagrams/blob/main/frontend/src/components/CIFztView.tsx) + [CIApiContainerView.tsx#checkApiGrammar](https://github.com/nelsong6/diagrams/blob/main/frontend/src/components/CIApiContainerView.tsx) — instead of checking `reposWithRuns` (from the 2h-pruned map), check `reposWithLastRuns` (from the new persistent map). The demote-to-broken logic becomes "no run has ever been observed for this repo" rather than "no run in last 2h" — that's the signal we actually want. The existing `runs` Map still drives `active` state for in-flight cascades (amber edges). ## Side benefit `lastRuns` also unblocks [diagrams#7](https://github.com/nelsong6/diagrams/issues/7) (producer amber bleed) — that fix needs "is this specific node actively running" which is a `runs`-Map question, while node color for healthy/broken uses `lastRuns`. Two Maps, two semantics, clean separation. ## Cold start `backfillFromGitHub()` already fetches the 5 most recent main-branch runs per repo. Extend it to populate `lastRuns` from the single most recent run regardless of branch (or keep main-only if preferred). One extra API call per repo on first SSE connection. ## Persistence In-memory only is fine for v1 (matches existing Maps). If the API restarts, `lastRuns` re-hydrates from the next cold-start backfill. If we later want survival across restarts, back it with Cosmos DB — same pattern as existing route-package versions. ## Where - [packages/routes/ci.js](https://github.com/nelsong6/diagrams/blob/main/packages/routes/ci.js) — add `lastRuns` Map, update webhook handler to write it, include in `init`/`status`/`versions` SSE snapshots - [frontend/src/hooks/useSSE.ts](https://github.com/nelsong6/diagrams/blob/main/frontend/src/hooks/useSSE.ts) — expose `lastRuns` alongside `runs` - [CIFztView.tsx](https://github.com/nelsong6/diagrams/blob/main/frontend/src/components/CIFztView.tsx) + [CIApiContainerView.tsx](https://github.com/nelsong6/diagrams/blob/main/frontend/src/components/CIApiContainerView.tsx) — use `lastRuns` for "has any run ever happened" check ## Acceptance Dashboard reads green during quiet periods (last known good state) instead of red, unless a version mismatch or genuinely-never-ran repo is present. Red retains meaning: something is actually wrong.
nelsong6 commented 2026-04-17 22:21:37 -07:00 (Migrated from github.com)

Correction

Re-reading packages/routes/ci.js:469-482, the 2h prune does keep the latest run per repo, so the premise of this issue (dashboard goes red during quiet periods) is wrong.

The actual cause of repos showing 'No recent runs' turns out to be narrower: backfill hardcodes ?branch=main at line 267, and llm-explorer uses master as its default branch. So its runs are silently filtered out during cold-start backfill, and unless/until a webhook arrives, the API has zero runs for it.

Narrower fix

Remove the branch=main filter entirely (or make it default-branch-aware):

- `https://api.github.com/repos/nelsong6/${repo}/actions/runs?per_page=5&branch=main`
+ `https://api.github.com/repos/nelsong6/${repo}/actions/runs?per_page=5`

Tradeoff: without the filter, noisy PR branches could theoretically crowd out the most recent main-branch run in the 5-result window. In practice, for this ecosystem, PRs are rare and mostly Dependabot (already filtered in-code). Safe to drop.

Alternative: use the GitHub API's repos/:owner/:repo to discover each repo's default_branch, then pass that. One extra API call per repo on cold start. Cleanest but more code.

Persistent lastRuns map

Still worth considering as a separate enhancement — it survives API restarts and makes 'has this repo ever run' a cheap lookup rather than dependent on the prune logic being correct — but it's a nice-to-have, not the fix for the immediate llm-explorer symptom.

## Correction Re-reading [packages/routes/ci.js:469-482](https://github.com/nelsong6/diagrams/blob/main/packages/routes/ci.js#L469-L482), the 2h prune **does** keep the latest run per repo, so the premise of this issue (dashboard goes red during quiet periods) is wrong. The actual cause of repos showing 'No recent runs' turns out to be narrower: backfill hardcodes `?branch=main` at [line 267](https://github.com/nelsong6/diagrams/blob/main/packages/routes/ci.js#L267), and `llm-explorer` uses `master` as its default branch. So its runs are silently filtered out during cold-start backfill, and unless/until a webhook arrives, the API has zero runs for it. ## Narrower fix Remove the `branch=main` filter entirely (or make it default-branch-aware): ```diff - `https://api.github.com/repos/nelsong6/${repo}/actions/runs?per_page=5&branch=main` + `https://api.github.com/repos/nelsong6/${repo}/actions/runs?per_page=5` ``` Tradeoff: without the filter, noisy PR branches could theoretically crowd out the most recent main-branch run in the 5-result window. In practice, for this ecosystem, PRs are rare and mostly Dependabot (already filtered in-code). Safe to drop. Alternative: use the GitHub API's `repos/:owner/:repo` to discover each repo's `default_branch`, then pass that. One extra API call per repo on cold start. Cleanest but more code. ## Persistent `lastRuns` map Still worth considering as a separate enhancement — it survives API restarts and makes 'has this repo ever run' a cheap lookup rather than dependent on the prune logic being correct — but it's a nice-to-have, not the fix for the immediate llm-explorer symptom.
Commenting is not possible because the repository is archived.
No milestone
No project
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
romaine-life/diagrams#9
No description provided.