Repository navigation
fix(dashboard): route /api/status and SSE status through the shared off-loop count cache - #10907
Conversation
GPT 5.6 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Design Review (Fable 5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Confirm no out-of-tree HTTP/SSE consumer assumes integer counts — [DESIGN-REVIEWED] e30a5c0 |
First Principles Review (Fable 5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Confirm the author's own open question — that no out-of-tree HTTP/SSE consumer assumes integer counts — before Not justified as shipped
What this change shipsInventory (9 items) — 7 justifiedIntent: FIX — stop
[FIRST-PRINCIPLES-REVIEWED] e30a5c0 |
Opus 4.8 Review (fork) — ✅ no blocking findingsReviewed Review detailsBased on my independent analysis of the diff:
The discovery pass reported no candidates, and my own falsification pass produced no grounded defect at the required bar. No findings. [OPUS-REVIEWED] e30a5c0 |
59f4fba to
6dab83c
Compare
|
First Principles — inline fallbacks kept alive. Correct: after this PR Design — gate does not pin funnel routing. Correct. The AST gate in 992 across every module touching |
6dab83c to
8337a16
Compare
|
Design's second Watch also upheld: No source changes beyond those two lines; Python floor unchanged from the previous head; no |
UX Review (Fable 5, fork) — ✅ PASSUX-level review of UX-Verdict: PASS Verify the CLI's [UX-REVIEWED] e30a5c0 |
8337a16 to
16c6f6f
Compare
|
Frontend Lint red on the previous head is main-side: the i18n 992 across every module touching |
16c6f6f to
fddb678
Compare
|
114 across the cli_server suites; black/isort/flake8/mypy and the black-formatting, comment-history and agent-sdk-boundary gates green; no |
fddb678 to
05b5ad4
Compare
|
Reviewed on the current head for approval.
|
|
|
a1b2c16 to
070e282
Compare
|
|
070e282 to
cc06f93
Compare
…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
cc06f93 to
e30a5c0
Compare
…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
Problem / Motivation
DashboardState.status_snapshot()defaults itslessonsandcron_jobsfields inline: a JSONL read plus a SQLiteCOUNT(*)under the vector store's shared connection lock, and acrons.jsonparse. #7236 moved the WebSocket status pusher off the event loop through a gateway-wide single-flight cache inws.pyand recorded the other two emitters as a follow-up. That follow-up never landed:api_status(handlers_system.py) and the SSEdashboardwriter (handlers/updates.py) still callstatus_snapshot(**status_update_fields())with no counts, so the inline fallback runs on the loop for every/api/statuspoll 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_lockfor seconds blocks every loop-thread reader while it does — the freeze classno-blocking-call-on-event-loopexists 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.pyimportsstatus_update_fieldsfromhandlers/updates.py, soupdates.pycannot importws.pyback. The cache therefore moves out ofws.pyinto a module both can import.Change:
src/kiro_crew/dashboard/status_counts.pyholds the moved machinery (_counts_cache*globals,_counts_refresh_decision,_warn_counts_failure,_load_status_counts,_refresh_status_counts) with behaviour unchanged, plus one funnelasync cached_status_snapshot(state)that awaits the shared refresh, reads the update fields fromstatus_update_fields()itself (lazy import —handlers/updates.pyimports this module at module level), and passes both straight intostatus_snapshot. No emitter can forget either half.DashboardState.status_snapshotloses 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 andNonemeans unknown end to end (rendered as a skeleton, never an authoritative0)._count_lessonsstays — the cache's off-loop loader uses it.ws._status_framebecomesasyncand delegates to the funnel (addsversion/platformas before); the pusher awaits it.api_statusand the SSEdashboardwriter callawait cached_status_snapshot(state).cron_jobsrides along for free: the cache already carried both counts.docs/system-specs/modules/learn-cron-dashboard.mdnow namesstatus_counts.pyas the cache's home.kirocrew statusincli_server.pyread acronskey that/api/statusnever published, so its cron line was always0. It now reads thecron_jobskey the snapshot serves, and renders an unknown count as—via a new_format_counthelper instead of printingNone.StatusDatacomment inwebsite/src/types/index.tsno longer claims HTTP/SSE always send numbers: all three transports read the same cache and may sendnull(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/statuswith a warm cache returns the cachedlessons/cron_jobsand never callsstate._count_lessonsorcrons.list_jobs(both patched to record).test_sse_dashboard_event_serves_warm_cache_without_inline_counts— the same for the SSEdashboardevent.test_api_status_warm_cache_none_yields_null_not_fallback— a cached(None, None)yieldsnullfor both keys, not a fallback count.test_cached_status_snapshot_publishes_null_for_unknown_countsand the rewritten asynctest_status_frame_publishes_null_for_unknown_countspin that an unknown cached count ships asnull.TestStatusCountLines(4 tests) —_format_countprints numbers, a dash fornullor a missing key, andkirocrew statusreadscron_jobs; the dash and key tests fail on main.test_no_counts_emits_none_without_blocking_calls— a barestatus_snapshot()emitsNonefor both keys and never calls_count_lessonsorcrons.list_jobs(both patched to raise); fails on main.test_ws_offload.py's cache-policy tests are retargeted fromwsglobals tostatus_countsglobals; the AST call-site gate intest_dashboard_status_snapshot.pynow fails on anystatus_snapshot(call outsidestatus_counts.py(bypassing the funnel is red). The per-emitter "spreadsstatus_update_fields()" source checks are gone — the funnel joins the fields itself, pinned bytest_the_funnel_joins_every_update_field_into_the_snapshot.test_dashboard_updates_coverage.pyandtest_chat_send_echo_scope.pyseed 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.pyand every test module referencingstatus_snapshot,api_status,status_update_fieldsor_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_boundaryandcheck_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.pydrives the realTestServer+ live SSE stream end-to-end through the new funnel.Consumers of the two counts, audited in-tree:
website/src/pages/OverviewPage.tsx(StatCard, typednumber | nullinwebsite/src/types/index.tssince #7236 and rendering a skeleton fornull), andkirocrew status(_format_count, this PR).cli_doctor.pyand thedesign_critiquebuilt-in app call/api/statusbut read neither field. The WebSocket frame has publishednullfor 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.pynow makes anystatus_snapshotcall outside the funnel a red test, and the inline fallback itself no longer exists to be reached.Checklist