Skip to content

fix(dashboard): serve-stale brains and diagnostics for remote databases (3.9.1) - #203

Merged
acidkill merged 1 commit into
mainfrom
fix/dashboard-remote-latency
Sep 3, 2026
Merged

fix(dashboard): serve-stale brains and diagnostics for remote databases (3.9.1)#203
acidkill merged 1 commit into
mainfrom
fix/dashboard-remote-latency

Conversation

@acidkill

@acidkill acidkill commented Sep 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • /api/dashboard/brains no longer blocks on full-brain diagnostics: it returns as soon as per-brain counts are known (grade/purity render at defaults until computed) and serves the last computed table instantly on later loads, while a single background pass per cycle recomputes diagnostics and upgrades the grades in place.
  • _cached_health_report gained serve-stale-while-revalidate: an expired report is answered from the last-good cache and recomputed once in the background, so /stats and /health never re-block either. The TTL now paces the refresh instead of gating the caller.
  • Contract tests updated: counts stay live in the response, grades arrive via the background pass, and the brain-scope leak guards await the scheduled refresh before asserting isolation.
  • Version bump 3.9.0 → 3.9.1 everywhere.

Why

With the server running away from its database (k3s pod talking to SurrealDB over WebSocket), a cold DiagnosticsEngine.analyze costs ~100 s and a warm one ~10 s per /api/dashboard/brains load. The browser gives up long before either finishes, and the overview rendered "No brains found" over zero counters although the data was fine (measured live on the run-010 cluster: brains 200 in 99.8 s cold / 9.9 s warm, TTL 300 s). Serving stale values and moving the recompute to the background removes the stall for remote deployments without changing anything for local ones.

Test plan

  • env -u SURREALDB_URL … pytest tests/ -m "not stress" -q — 7238 passed, 108 skipped (live DB tests), 1 xfailed
  • New tests: cold response never waits for diagnostics; second request served from last-good; last-good survives an expired diagnostics cache; _cached_health_report serves stale and schedules exactly one refresh; the AST guard allowlist extended to the background refresh functions
  • ruff check src/ tests/ clean; ruff format clean; mypy src/ --ignore-missing-imports clean
  • python scripts/pre_ship.py --only versions — every file at 3.9.1

Verified by

@acidkill

With the server running away from its database (k3s pod over WebSocket),
/api/dashboard/brains computed full-brain diagnostics synchronously:
~100 s cold, ~10 s warm per load. The browser gives up long before that,
so the overview rendered "No brains found" over zero counters although
the data was fine.

/api/dashboard/brains now returns as soon as the per-brain counts are
known (grade/purity render at their defaults until computed) and serves
the last computed table instantly on later loads, while a single
background pass per cycle recomputes diagnostics and upgrades the grades
in place. _cached_health_report gained the same serve-stale behaviour:
an expired report is answered from the last-good cache and recomputed
once in the background, so /stats and /health never re-block either.
Contract tests updated: counts stay live in the response, grades arrive
via the background pass, and the brain-scope leak guards now await the
scheduled refresh before asserting isolation.

Bump 3.9.1.
@acidkill
acidkill force-pushed the fix/dashboard-remote-latency branch from c42beda to ec67eb9 Compare September 3, 2026 18:44
@acidkill
acidkill marked this pull request as ready for review September 3, 2026 18:44
@acidkill
acidkill merged commit 0f4c93b into main Sep 3, 2026
@acidkill
acidkill deleted the fix/dashboard-remote-latency branch September 3, 2026 18:45
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