perf(serve): cache the /api/status profile-gateway topology scan (salvage #71396) - #76969
Merged
kshitijk4poor merged 1 commit intoAug 2, 2026
Conversation
/api/status is the desktop's boot liveness probe (polled ~1/s) but since NousResearch#60537 every call ran a full topology scan — per-profile yaml.safe_load (pure-Python loader), psutil process probes, realpath walks — in the default executor. On multi-profile installs concurrent polls pile up and hold the GIL 14-16s, starving the event loop: the WS sidecar cannot flush gateway.ready, the desktop times out into the next stall, and boot escalates to the 'Hermes couldn't start' overlay (NousResearch#60800). Memoize the scan behind a 10s TTL with a collapse lock so concurrent polls share one scan. Topology only changes on gateway start/stop, so a <=10s stale badge is an acceptable trade for not starving the loop. The cache also keys on the collector's identity: tests monkeypatch _collect_profile_gateway_topology per case, and the identity check keeps them hermetic (a swapped collector is a miss) without a reset hook. py-spy captures during a failing boot land in _profile_platform_ports -> yaml.safe_load on executor threads (7 profiles, Windows). After: one cold-start scan, zero recurring stalls, desktop boots.
kshitijk4poor
enabled auto-merge (rebase)
August 2, 2026 17:37
Closed
13 tasks
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.
Salvages #71396 by @lost9999 — commit cherry-picked to preserve authorship. Merges clean; no changes to the contribution.
Context — honest premise update
The PR was written against a desktop-boot GIL-starvation symptom: the desktop polled
/api/status~1/s during boot, each uncached_collect_profile_gateway_topologycall walks 7+ profile homes (yaml.safe_load + psutil + realpath) in the executor, and concurrent polls piled up holding the GIL for 14-16s, starvinggateway.ready. Since then, 23cb26c moved desktop boot readiness to/api/health, so the boot symptom itself no longer occurs on current desktops.The cache still carries real value, which is why we're landing it:
/api/statusremains polled by the web sidebar every 10s, the statusbar every 60s, Hermes Cloud Portal, multiple desktop windows, and the legacy boot-fallback for pre-0.19.0 backends. The topology scan is genuinely expensive and identical across concurrent callers — a 10s TTL with a collapse lock deduplicates all of it.What the fix does
10s-TTL double-checked-locking cache around the topology scan, with a function-identity guard that makes monkeypatched collectors an automatic cache miss (test hermeticity without reset hooks).
Verification
Closes #71396 (superseded by this salvage — original author credited via cherry-pick authorship).