Skip to content

fix(daemon): make build-staleness checks non-blocking on status hot paths - #35

Merged
wangxingjun778 merged 1 commit into
mainfrom
feat/stream_loop
Aug 9, 2026
Merged

fix(daemon): make build-staleness checks non-blocking on status hot paths#35
wangxingjun778 merged 1 commit into
mainfrom
feat/stream_loop

Conversation

@wangxingjun778

Copy link
Copy Markdown
Member
  • Non-blocking staleness checks on status hot paths: status() and DashboardServer._server_info() no longer await is_stale() directly, eliminating two git shell-outs per call that could exceed caller deadlines under load or CI parallelism (fixes timeout in test_status_returns_while_deferred_db_worker_is_busy, which requires status() to return within 0.1s while a deferred DB worker is busy).

  • New StalenessMonitor (leapflow.utils.build_info): TTL-cached, non-blocking wrapper around staleness detection.

    • current() returns instantly — None on first use signals "unknown, still checking".
    • Schedules a fire-and-forget background refresh once the TTL elapses.
    • refresh() retained for deterministic callers (startup warmup, tests).
  • Wired into runtime + dashboard: Integrated with RuntimeLeapService.status() and DashboardServer._server_info(); cancel_pending() invoked from both shutdown paths.

  • Test-double compatibility preserved: Checker is passed at call time (not bound at construction), so existing monkeypatch.setattr(module, "is_stale", ...) doubles keep working.

  • Test updates:

    • Two tests asserting on synchronously-patched stale verdicts now force one deterministic refresh() first.
    • Dedicated StalenessMonitor coverage added in test_build_info.py.

…aths

status() and the dashboard's _server_info() awaited is_stale() directly,
which shells out to git twice per call. Under load (or in CI parallelism)
that can exceed a caller's own deadline, which
test_daemon_event_loop_blocking.py::test_status_returns_while_deferred_db_worker_is_busy
caught: status() must return within 0.1s even while a deferred DB worker
is busy, and it was timing out instead.

Add StalenessMonitor (leapflow.utils.build_info): a TTL-cached,
non-blocking wrapper. current() always returns instantly (None on first
use = 'unknown, still checking') and schedules a fire-and-forget
background refresh once the TTL elapses; refresh() stays available for
deterministic callers (startup warmup, tests). Wire it into
RuntimeLeapService.status() and DashboardServer._server_info(), with
cancel_pending() invoked from both shutdown paths. checker is passed at
call time (not bound at construction) so existing
monkeypatch.setattr(module, "is_stale", ...) test doubles keep working.

Updates the two tests that asserted on a synchronously-patched stale
verdict to force one deterministic refresh() first, and adds dedicated
StalenessMonitor coverage in test_build_info.py.
@wangxingjun778
wangxingjun778 merged commit d923422 into main Aug 9, 2026
2 checks passed
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