fix(daemon): make build-staleness checks non-blocking on status hot paths - #35
Merged
Conversation
…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.
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.
Non-blocking staleness checks on status hot paths:
status()andDashboardServer._server_info()no longer awaitis_stale()directly, eliminating two git shell-outs per call that could exceed caller deadlines under load or CI parallelism (fixes timeout intest_status_returns_while_deferred_db_worker_is_busy, which requiresstatus()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 —Noneon first use signals "unknown, still checking".refresh()retained for deterministic callers (startup warmup, tests).Wired into runtime + dashboard: Integrated with
RuntimeLeapService.status()andDashboardServer._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:
refresh()first.StalenessMonitorcoverage added intest_build_info.py.