Patch dashboard runs from SSE payloads instead of full refetch (BEN-49)#53
Merged
benSepanski merged 1 commit intomainfrom May 4, 2026
Merged
Patch dashboard runs from SSE payloads instead of full refetch (BEN-49)#53benSepanski merged 1 commit intomainfrom
benSepanski merged 1 commit intomainfrom
Conversation
The dashboard refetched `/api/runs` and `/api/events/recent` on every SSE event except usage/tick/settings, so a live run with frequent turn events caused per-event table rebuilds, flicker, and wasted bandwidth. Add a small pure reducer in `src/web/dashboardEvents.ts` (`applyTurnEvent` / `applyRunFinishedEvent` / `replaceRun` / `hasRun`) and rewire `Dashboard.tsx` so: - `turn` increments `turnCount` on the matching row in-memory; only falls back to a full `/api/runs` if the runId is unknown (stale tab). - `runFinished` stamps `status` + `finishedAt` immediately for instant feedback, then a single `/api/runs/:id` fills in the authoritative token + cost totals via `replaceRun`. Also refreshes the recent-events feed once. - `runStarted` falls back to `/api/runs` (rare, payload is `Issue`-shaped not `ApiRun`-shaped). Adds 11 unit tests in `dashboardEvents.test.ts` and documents the SSE-to-state convention in `docs/FRONTEND.md`. `pnpm all` green (131 unit + 5 eval); `pnpm build:web` 184ms.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
BEN-49:
src/web/Dashboard.tsxrefetched/api/runsand/api/events/recenton every SSE event except usage/tick/settings, so a live run with frequentturnevents caused per-event table rebuilds, flicker, and wasted bandwidth.TL;DR
Patch the dashboard runs list in-memory from the SSE event payload; only fall back to
/api/runsfor unknown runIds, and use/api/runs/:idto top up token totals when a run finishes.Summary
src/web/dashboardEvents.ts— pure helpersapplyTurnEvent,applyRunFinishedEvent,replaceRun,hasRun. No React deps. 11 unit tests indashboardEvents.test.ts.src/web/Dashboard.tsx::useEventStream—turnincrementsturnCounton the matching row in-memory; only falls back toGET /api/runsif the runId is unknown (stale tab).runFinishedstampsstatus+finishedAtimmediately for instant feedback, then a singleGET /api/runs/:idfills in authoritative tokens + cost viareplaceRun. Recent-events feed is refreshed once per finish (so new error rows surface).runStartedkeeps the existingGET /api/runsfallback (rare event; SSE payload isIssue-shaped, notApiRun-shaped).docs/FRONTEND.mddocuments the new SSE → state convention next to the data-sources table.Demo
n/a — automated cron run; no browser MCP in this environment. Manual smoke-test:
pnpm dev WORKFLOW.md --mock, open the dashboard during a long mock run, verify devtools Network shows noGET /api/runsperturnSSE event (only onrunFinished→ one/api/runs/:idplus/api/events/recent), and the runs<tbody>no longer flickers / scroll-jumps as turns stream in.Alternatives
runIdwe need./api/runs/:idon everyturn— rejected:turnevents fire many times per second per agent; we'd just be moving the load from/api/runsto/api/runs/:id. Pure in-memoryturnCount++is enough; authoritative tokens land atrunFinished.useState<ApiRun[]>plus pure reducer matches the dashboard's existing patterns.Test Plan
pnpm all— typecheck + fmt:check + lint + test + eval (131 unit + 5 eval, all green)pnpm build:web— bundle builds (184ms)dashboardEvents.test.tscovers turn-increment, no-op when runId is missing, finished-status update, finishedAt-preservation when already set, replaceRun by id, andhasRunlookups.Generated by Claude Code