Skip to content

fix(dashboard): route /api/status and SSE status through the shared off-loop count cache - #10907

Merged
iamwhatever merged 1 commit into
kirodotdev:mainfrom
jeeshofone:fix/10890-status-counts-off-loop
Sep 17, 2026
Merged

iamwhatever merged 1 commit into
kirodotdev:mainfrom
jeeshofone:fix/10890-status-counts-off-loop

Conversation

@jeeshofone

@jeeshofone jeeshofone commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

DashboardState.status_snapshot() defaults its lessons and cron_jobs fields inline: a JSONL read plus a SQLite COUNT(*) under the vector store's shared connection lock, and a crons.json parse. #7236 moved the WebSocket status pusher off the event loop through a gateway-wide single-flight cache in ws.py and recorded the other two emitters as a follow-up. That follow-up never landed: api_status (handlers_system.py) and the SSE dashboard writer (handlers/updates.py) still call status_snapshot(**status_update_fields()) with no counts, so the inline fallback runs on the loop for every /api/status poll and every SSE tick, and each open SSE tab is an independent contender on the sqlite lock. Reported as #10890.

Why it matters

A busy-timeout read holding _db_lock for seconds blocks every loop-thread reader while it does — the freeze class no-blocking-call-on-event-loop exists to prevent. The project already decided this shape is wrong and fixed one of three callers for that reason; leaving the other two is an inconsistency that gets worse with every additional dashboard tab.

What changed (motivation → approach → change)

Motivation: all three emitters should read the SAME cached pair, with the same TTL, fallback and warning semantics — a second cache per caller would recreate the lock-contention the first one was built to avoid.

Approach: ws.py imports status_update_fields from handlers/updates.py, so updates.py cannot import ws.py back. The cache therefore moves out of ws.py into a module both can import.

Change:

  • New src/kiro_crew/dashboard/status_counts.py holds the moved machinery (_counts_cache* globals, _counts_refresh_decision, _warn_counts_failure, _load_status_counts, _refresh_status_counts) with behaviour unchanged, plus one funnel async cached_status_snapshot(state) that awaits the shared refresh, reads the update fields from status_update_fields() itself (lazy import — handlers/updates.py imports this module at module level), and passes both straight into status_snapshot. No emitter can forget either half.
  • DashboardState.status_snapshot loses its inline defaults (len(self.crons.list_jobs()), self._count_lessons()): after this change they had zero production callers, so the counts are now emitted verbatim as passed and None means unknown end to end (rendered as a skeleton, never an authoritative 0). _count_lessons stays — the cache's off-loop loader uses it.
  • ws._status_frame becomes async and delegates to the funnel (adds version/platform as before); the pusher awaits it.
  • api_status and the SSE dashboard writer call await cached_status_snapshot(state).
  • cron_jobs rides along for free: the cache already carried both counts.
  • One sentence in docs/system-specs/modules/learn-cron-dashboard.md now names status_counts.py as the cache's home.
  • Rider, a separate fix carried in the same commit: kirocrew status in cli_server.py read a crons key that /api/status never published, so its cron line was always 0. It now reads the cron_jobs key the snapshot serves, and renders an unknown count as — via a new _format_count helper instead of printing None.
  • The StatusData comment in website/src/types/index.ts no longer claims HTTP/SSE always send numbers: all three transports read the same cache and may send null (the type and StatCard already handled it).

Tests

Each new test's docstring states how it fails on the previous shape.

  • test_api_status_serves_warm_cache_without_inline_counts — /api/status with a warm cache returns the cached lessons/cron_jobs and never calls state._count_lessons or crons.list_jobs (both patched to record).
  • test_sse_dashboard_event_serves_warm_cache_without_inline_counts — the same for the SSE dashboard event.
  • test_api_status_warm_cache_none_yields_null_not_fallback — a cached (None, None) yields null for both keys, not a fallback count.
  • test_cached_status_snapshot_publishes_null_for_unknown_counts and the rewritten async test_status_frame_publishes_null_for_unknown_counts pin that an unknown cached count ships as null.
  • TestStatusCountLines (4 tests) — _format_count prints numbers, a dash for null or a missing key, and kirocrew status reads cron_jobs; the dash and key tests fail on main.
  • test_no_counts_emits_none_without_blocking_calls — a bare status_snapshot() emits None for both keys and never calls _count_lessons or crons.list_jobs (both patched to raise); fails on main.
  • test_ws_offload.py's cache-policy tests are retargeted from ws globals to status_counts globals; the AST call-site gate in test_dashboard_status_snapshot.py now fails on any status_snapshot( call outside status_counts.py (bypassing the funnel is red). The per-emitter "spreads status_update_fields()" source checks are gone — the funnel joins the fields itself, pinned by test_the_funnel_joins_every_update_field_into_the_snapshot.
  • test_dashboard_updates_coverage.py and test_chat_send_echo_scope.py seed a warm cache so the funnel-routed SSE frame serves serializable counts from their mock states.

992 passed across test_ws_offload.py, test_dashboard_status_snapshot.py, test_dashboard_updates_coverage.py, test_chat_send_echo_scope.py and every test module referencing status_snapshot, api_status, status_update_fields or _status_frame; black (line-length 100), isort, flake8, mypy clean on the touched files; check_black_formatting, check_comment_history, check_brand_name, check_agent_sdk_boundary and check_sync_io_in_async (whole tree) pass; no .github/ diff.

Manual verification

N/A — unit coverage sufficient: the change is a call-site redirection into an already-tested cache, and test_chat_send_echo_scope.py drives the real TestServer + live SSE stream end-to-end through the new funnel.

Consumers of the two counts, audited in-tree: website/src/pages/OverviewPage.tsx (StatCard, typed number | null in website/src/types/index.ts since #7236 and rendering a skeleton for null), and kirocrew status (_format_count, this PR). cli_doctor.py and the design_critique built-in app call /api/status but read neither field. The WebSocket frame has published null for these keys since #7236, so a consumer of that transport already meets the value; what this PR changes is that HTTP and SSE now can too. Whether an out-of-tree HTTP or SSE consumer assumes an integer cannot be checked from this repository and needs a maintainer's confirmation.

Related Issues

Fixes #10890. Follow-up promised in #7236.

Pattern harvest

Rule candidate: review-prompt — when a PR offloads ONE of several callers of a blocking helper and lists the rest under "deliberately not changed", the remaining callers must be filed as a tracked issue in the same PR, or a call-site gate added that fails when a caller reaches the helper without the offloaded path. Here the promise lived only in a merged PR body, and a fourth caller shape could have appeared unnoticed; the AST gate in test_dashboard_status_snapshot.py now makes any status_snapshot call outside the funnel a red test, and the inline fallback itself no longer exists to be reached.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@jeeshofone
jeeshofone requested review from a team and cixuuz September 15, 2026 00:00
@github-actions github-actions Bot added the fork Pull request from a fork (external contributor) label Sep 15, 2026
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 15, 2026
@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings

Reviewed e30a5c018aeaafd6065dbefa99fbb319c93ece86 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] e30a5c0

@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — ✅ PASS

Design-level review of e30a5c018aeaafd6065dbefa99fbb319c93ece86 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Confirm no out-of-tree HTTP/SSE consumer assumes integer counts — /api/status and SSE now publish null and 30s-stale values where fresh numbers were guaranteed.

[DESIGN-REVIEWED] e30a5c0

@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — ✅ PASS

Premise-level review of e30a5c018aeaafd6065dbefa99fbb319c93ece86 via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: PASS

Confirm the author's own open question — that no out-of-tree HTTP/SSE consumer assumes integer counts — before null starts shipping on those two transports.

Not justified as shipped

  • Item 6 — rides along: declared rider ("a separate fix carried in the same commit") fixing the CLI's dead crons key; the dash half is required anyway once these counts can be null, and its test fails on main. No premise risk.
  • Item 7 — undeclared: the cron.py count_enabled_from_disk docstring rewrite appears nowhere in the description; it corrects a stale claim that base list_jobs's own docstring ("CACHE-ONLY, never touches disk") already contradicts, so it carries no premise risk. Note the same overstatement survives in the description and two new comments, which attribute a crons.json parse to an inline default that was len(list_jobs()), cache-only — the blocking harm rests on the _count_lessons half, which is real and sufficient.

What this change ships

Inventory (9 items) — 7 justified

Intent: FIX — stop /api/status and the SSE status tick computing lesson/cron counts inline on the event loop, by routing both through the cache #7236 built for the WebSocket pusher (reported as #10890, promised follow-up of #7236).

  1. /api/status counts now come from the shared 30s cache and may be null — justified
  2. The SSE dashboard event serves the same cached, nullable counts — justified
  3. The WebSocket frame drops its sentinel-0-plus-overwrite machinery and uses the same funnel — justified
  4. A bare status_snapshot() now emits None instead of computing counts inline (fallback deleted; 0 production callers remained, counted: 3 emitter call sites → 1 funnel) — justified
  5. Cache machinery moved from ws.py into new status_counts.py with one funnel, 3 counted consumers; the import cycle (ws.py → updates.py) is the derived cause — justified
  6. kirocrew status reads cron_jobs (was crons, always 0) and prints — for unknown — rides along (declared, own failing-on-main test)
  7. count_enabled_from_disk's docstring rationale rewritten from timer-safety to cross-process freshness — undeclared (corrects a claim base list_jobs already contradicts)
  8. Frontend type comment no longer claims HTTP/SSE always send numbers — justified
  9. Spec names status_counts.py as the cache's home, same commit — justified

[FIRST-PRINCIPLES-REVIEWED] e30a5c0

@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review (fork) — ✅ no blocking findings

Reviewed e30a5c018aeaafd6065dbefa99fbb319c93ece86 via the fork AI-review pipeline; updated in place on each push.

Review details

Based on my independent analysis of the diff:

  • status_snapshot no longer computes cron_jobs/lessons inline — now caller-supplied, defaulting to None. I verified all three production callers of DashboardState.status_snapshot (ws.py, handlers_system.py:api_status, handlers/updates.py:api_stream) now route through cached_status_snapshot, which supplies both counts off-loop. The platform/tunnel status_snapshot methods are unrelated provider methods. No other production caller relies on the inline default.
  • no_crons is a plain --no-crons bool (state.py:4197), not derived from the cron count, so a None count doesn't affect it.
  • None propagation is handled end to end: CLI _format_count → dash, frontend cron_jobs/lessons: number | null → skeleton.
  • No import cycle: status_counts → state (module), status_counts → updates (lazy), updates → status_counts (module) — the back-edge is deferred.
  • _counts_refresh_inflight is set with no await before the try; finally clears it even on CancelledError, so no wedge. _load_status_counts catches only Exception, letting cancellation propagate.
  • /api/status and SSE first-call triggers a real off-loop refresh (stale cache), so they still serve real numbers; the change removes a blocking-call-on-loop rather than adding one, and gracefully degrades a failing store to null instead of a 500.

The discovery pass reported no candidates, and my own falsification pass produced no grounded defect at the required bar.

No findings.

[OPUS-REVIEWED] e30a5c0

@jeeshofone
jeeshofone force-pushed the fix/10890-status-counts-off-loop branch from 59f4fba to 6dab83c Compare September 15, 2026 00:33
@jeeshofone

Copy link
Copy Markdown
Contributor Author

59f4fba11 → 6dab83c92. Both advisory findings upheld and fixed at class level.

First Principles — inline fallbacks kept alive. Correct: after this PR DashboardState.status_snapshot had zero production callers reaching len(self.crons.list_jobs()) / self._count_lessons() (the tunnel provider's status_snapshot() is an unrelated method). The two else arms are deleted; the counts are emitted exactly as passed and None means unknown end to end. cached_status_snapshot now passes the cached pair straight through — the sentinel-0 and the two-key overwrite, and the "overwrite half is load-bearing" note, are gone with the hazard they papered over. _count_lessons stays because the cache's off-loop loader is its consumer. New test_no_counts_emits_none_without_blocking_calls pins a bare status_snapshot() to None/None with both count sources patched to raise — it fails on main. The six test files that leaned on the inline default are retargeted to _count_lessons() directly or to the funnel, keeping what each pinned; test_dashboard_state_ws.py (baselined) is a one-line edit.

Design — gate does not pin funnel routing. Correct. The AST gate in test_dashboard_status_snapshot.py now fails on any status_snapshot( call under dashboard/ whose file is not status_counts.py, in addition to the status_update_fields() spread check; a bypass injected into ws.py turns it red (verified, reverted). PR description's Tests and Pattern-harvest sections updated to say exactly that. The suggestion to home the cache on DashboardState (removing the module globals and the fixture seeding) is a fair follow-on but a wider refactor than this fix; noted, not taken here.

992 across every module touching status_snapshot / api_status / status_update_fields / _status_frame; black/isort/flake8/mypy, black-formatting, comment-history, agent-sdk-boundary and sync-io-in-async (whole tree) gates green; no .github/ diff.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 15, 2026
@jeeshofone
jeeshofone force-pushed the fix/10890-status-counts-off-loop branch from 6dab83c to 8337a16 Compare September 15, 2026 00:52
@jeeshofone
jeeshofone requested a review from a team September 15, 2026 00:52
@jeeshofone

Copy link
Copy Markdown
Contributor Author

6dab83c92 → 8337a1601. Both lanes' Watch/Item-9 finding upheld: the def test_update_available_passthrough line was swallowed when the new snapshot test was inserted above it — an authoring accident, not a decision. The def is restored, so the update-verdict tri-state pin and test_no_counts_emits_none_without_blocking_calls are separately named tests again (34 passed in that module; both names present).

Design's second Watch also upheld: website/src/types/index.ts said "HTTP/SSE paths always send numbers", which this PR makes false. The comment now says all three transports read the same cache and may send null. Comment-only change on the frontend — tsc and eslint clean; no runtime or test behaviour touched, so vitest was not rerun for it.

No source changes beyond those two lines; Python floor unchanged from the previous head; no .github/ diff. The previous head's cancelled check-runs were duplicate triggers (body edit + push seconds apart) with later successes for every name; this push supersedes them.

@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Fable 5, fork) — ✅ PASS

UX-level review of e30a5c018aeaafd6065dbefa99fbb319c93ece86 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

UX-Verdict: PASS

Verify the CLI's — (em dash) prints cleanly on non-UTF-8 Windows consoles; nothing else user-facing changed.

[UX-REVIEWED] e30a5c0

@jeeshofone
jeeshofone force-pushed the fix/10890-status-counts-off-loop branch from 8337a16 to 16c6f6f Compare September 15, 2026 01:21
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 15, 2026
@jeeshofone

Copy link
Copy Markdown
Contributor Author

16c6f6ff8 → fddb67882. First Principles Item 5 upheld: cached_status_snapshot's **extra was filled identically by all three callers, so the funnel now reads status_update_fields() itself (function-level import — handlers/updates.py imports this module at module level, so a module-level import would cycle) and every call site is await cached_status_snapshot(state). handlers_system.py drops its now-unused updates import. The AST gate's cached_status_snapshot arm and the per-emitter "spreads status_update_fields()" source checks (test_ws_uses_the_shared_reader, test_system_api_uses_the_shared_reader) are deleted — a caller that cannot forget the fields needs no test that it didn't. What remains: the arm that fails on any status_snapshot( call outside status_counts.py, the reader-keys ⊆ signature pin, and new test_the_funnel_joins_every_update_field_into_the_snapshot (patches the reader to a sentinel dict of the real keys and asserts each surfaces from the funnel).

Frontend Lint red on the previous head is main-side: the i18n manifest-sync gate fails on origin/main itself (#10938, fix in #10940) while this branch passes it locally against its base. Backend shard 3 inherits #10768 the same way.

992 across every module touching status_snapshot / api_status / status_update_fields / _status_frame; black/isort/flake8/mypy and the black-formatting, comment-history, agent-sdk-boundary and sync-io-in-async gates green; import-cycle smoke clean; no .github/ diff.

@jeeshofone
jeeshofone force-pushed the fix/10890-status-counts-off-loop branch from 16c6f6f to fddb678 Compare September 15, 2026 02:14
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Sep 15, 2026
@jeeshofone

Copy link
Copy Markdown
Contributor Author

fddb67882 → 05b5ad493. Design Watch upheld: kirocrew status is the one non-dashboard reader of lessons/cron_jobs (grepped src/ for other /api/status count consumers — none), and with the counts now nullable it would have printed Lessons: None. New _format_count renders null or a missing key as —, the same "unknown, not zero" the dashboard skeleton expresses. While there, the same line read a crons key the snapshot never publishes, so Cron jobs was always 0; it now reads cron_jobs. TestStatusCountLines (4 tests); the dash and key tests fail on main. Stale-for-up-to-30s is the WS pusher's existing contract extended to HTTP, and I have left it as is; the suggestion to bust the cache from the cron/lesson mutation handlers is a fair follow-on if the lag is felt.

114 across the cli_server suites; black/isort/flake8/mypy and the black-formatting, comment-history and agent-sdk-boundary gates green; no .github/ diff.

@jeeshofone
jeeshofone force-pushed the fix/10890-status-counts-off-loop branch from fddb678 to 05b5ad4 Compare September 15, 2026 02:31
@iamwhatever

Copy link
Copy Markdown
Contributor

Reviewed on the current head for approval. readiness: passed is green because whole-design CONCERNS are advisory server-side; they still need an answer before a human approval lands. Fork-risk scan (CI, install, deps, network, subprocess, eval): clean. Holding on the items below.

  • Two GPT 5.6 FINDINGs on head a1b2c16 have no disposition: status_counts.py:150 ships a paragraph claiming list_jobs calls _sync(), contradicting the cache-only implementation; handlers_system.py:193 uses a function-local import with no cycle to justify it.
  • First Principles "Not justified as shipped" Item 7: the crons -> cron_jobs key rename in cli_server.py is a rider the body never names (it is a real fix, so just declare it).
  • Design and First Principles both ask for a human confirmation that no out-of-tree /api/status consumer assumes integer counts now that all three transports can serve null and up to 30s-stale values.

@jeeshofone

Copy link
Copy Markdown
Contributor Author

a1b2c1613 -> 070e282b7, rebased onto main (+197).

  • fixed status_counts.py:150: the NOTE claimed list_jobs calls _sync() -> _load() -> _arm_timer(). It is cache-only on main (cron.py:4403). The NOTE now gives the real reason for count_enabled_from_disk: the snapshot lags a write from another process by up to a timer tick and is documented as loop-side, while the disk read is current and thread-safe. The same stale sentence lived in count_enabled_from_disk's own docstring in cron.py, which is where the NOTE was copied from, so I corrected it there as well.
  • fixed handlers_system.py:193: the function-local import is hoisted to the module level. status_counts imports only dashboard.state, so there is no cycle; the import passes isort as placed.
  • fixed First Principles item 7: the crons -> cron_jobs rename in cli_server.py is declared in the body as a rider, with what it fixes.
  • answered the integer-count consumer question in the body's Manual verification: in-tree readers are OverviewPage.tsx (typed number | null since fix: report the JSONL+vector lesson total from the WS status pusher (#7204) #7236) and kirocrew status (this PR); cli_doctor.py and the design_critique app poll /api/status and read neither key; the WebSocket frame has carried null since fix: report the JSONL+vector lesson total from the WS status pusher (#7204) #7236. Out-of-tree HTTP/SSE consumers cannot be checked from the repository, so that confirmation stays with you.

@jeeshofone
jeeshofone force-pushed the fix/10890-status-counts-off-loop branch from a1b2c16 to 070e282 Compare September 17, 2026 04:29
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 17, 2026
@jeeshofone

Copy link
Copy Markdown
Contributor Author

070e282b7 -> cc06f930e.

  • fixed test_dashboard_status_snapshot.py:360: the ratchet counts calls instead of trusting a filename. It collects every status_snapshot(...) call in the dashboard package with its enclosing function, asserts there is exactly one, that it sits in status_counts.cached_status_snapshot, and that its keywords spread status_update_fields(). Probed by appending a second call to status_counts.py: the test fails naming both sites.
  • fixed state.py:4702: the docstring names count_enabled_from_disk as the cron read an inline computation would run, in present tense, with no claim about list_jobs.

@jeeshofone
jeeshofone force-pushed the fix/10890-status-counts-off-loop branch from 070e282 to cc06f93 Compare September 17, 2026 05:11
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 17, 2026
…e shared off-loop count cache

status_snapshot() defaults its lessons and cron_jobs fields inline (JSONL read,
sqlite COUNT(*) under the vector store lock, crons.json parse). kirodotdev#7236 moved the
WebSocket pusher off the event loop through a gateway-wide single-flight cache
in ws.py and left /api/status and the SSE dashboard writer as a follow-up, so
both still ran the inline fallback on the loop every poll and every tick.

Move the cache into dashboard/status_counts.py -- ws.py imports from
handlers/updates.py, so updates.py cannot import ws.py back -- and add one
funnel, cached_status_snapshot(), that every status emitter uses: it awaits the
shared refresh, suppresses the inline default with a sentinel, then overwrites
both keys with the raw cached values so an unknown count ships as null rather
than a false 0. ws._status_frame delegates to it; api_status and the SSE writer
await it.

Fixes kirodotdev#10890
@jeeshofone
jeeshofone force-pushed the fix/10890-status-counts-off-loop branch from cc06f93 to e30a5c0 Compare September 17, 2026 06:38
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 17, 2026
@iamwhatever
iamwhatever merged commit f51378d into kirodotdev:main Sep 17, 2026
86 checks passed
@jeeshofone
jeeshofone deleted the fix/10890-status-counts-off-loop branch September 17, 2026 21:27
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 17, 2026
amadsalmon pushed a commit to amadsalmon/KiroCrew that referenced this pull request Sep 22, 2026
…e shared off-loop count cache (kirodotdev#10907)

status_snapshot() defaults its lessons and cron_jobs fields inline (JSONL read,
sqlite COUNT(*) under the vector store lock, crons.json parse). kirodotdev#7236 moved the
WebSocket pusher off the event loop through a gateway-wide single-flight cache
in ws.py and left /api/status and the SSE dashboard writer as a follow-up, so
both still ran the inline fallback on the loop every poll and every tick.

Move the cache into dashboard/status_counts.py -- ws.py imports from
handlers/updates.py, so updates.py cannot import ws.py back -- and add one
funnel, cached_status_snapshot(), that every status emitter uses: it awaits the
shared refresh, suppresses the inline default with a sentinel, then overwrites
both keys with the raw cached values so an unknown count ships as null rather
than a false 0. ws._status_frame delegates to it; api_status and the SSE writer
await it.

Fixes kirodotdev#10890
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dashboard: /api/status and SSE still count lessons inline on the event loop (follow-up from #7236)

2 participants