fix(dashboard): serve-stale brains and diagnostics for remote databases (3.9.1) - #203
Merged
Conversation
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
force-pushed
the
fix/dashboard-remote-latency
branch
from
September 3, 2026 18:44
c42beda to
ec67eb9
Compare
acidkill
marked this pull request as ready for review
September 3, 2026 18:44
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.
Summary
/api/dashboard/brainsno 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_reportgained serve-stale-while-revalidate: an expired report is answered from the last-good cache and recomputed once in the background, so/statsand/healthnever re-block either. The TTL now paces the refresh instead of gating the caller.Why
With the server running away from its database (k3s pod talking to SurrealDB over WebSocket), a cold
DiagnosticsEngine.analyzecosts ~100 s and a warm one ~10 s per/api/dashboard/brainsload. 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_cached_health_reportserves stale and schedules exactly one refresh; the AST guard allowlist extended to the background refresh functionsruff check src/ tests/clean;ruff formatclean;mypy src/ --ignore-missing-importscleanpython scripts/pre_ship.py --only versions— every file at 3.9.1Verified by
@acidkill