Skip to content

perf(gateway): serve display-only toolset availability from a TTL cache so resume stops blowing the 30s budget - #144138

Open
ppuup7777 wants to merge 2 commits into
NousResearch:mainfrom
ppuup7777:perf/tool-availability-ttl-cache
Open

ppuup7777 wants to merge 2 commits into
NousResearch:mainfrom
ppuup7777:perf/tool-availability-ttl-cache

Conversation

@ppuup7777

Copy link
Copy Markdown

Stopgap for #141422 (and takes the deterministic amplifier out of #144133's repro): session.resume runs the banner's display-only tool-availability computation inline, and that computation runs live check_fn network probes for web / image_gen / video_gen / connections — measured 21–36 s on a slow-egress host, on every resume (three consecutive calls in one process: 30.99 / 30.51 / 30.49 s; per-toolset: web 15.2 s, connections 5.2 s, video_gen 5.1 s, image_gen 5.1 s). The Desktop's session-class RPC budget is a fixed 30 s, so an affected profile can never be resumed in the UI: the owner finishes ~10–40 s after the client has gone, and the reply is dropped (tui_gateway.ws: ws response send failed peer=… method=session.resume). Field measurements: #141422 (comment)

What this does

gateway/session_local_inventory.py now serves info["tool_availability"] from a process-wide TTL cache filled by a background thread:

  • cold cache → answers {} immediately (what the banner shows before its first availability check anyway) while a daemon thread probes;
  • warm cache → instant, no probe;
  • expired → keeps serving the stale value, refreshes in the background;
  • a failed probe keeps the warm value and clears the inflight key.

HERMES_TOOL_AVAILABILITY_TTL_S tunes the window (default 600 s, 0 = always recompute in the background, never block). Measured after the patch: cold 0.00 s -> {}, warm 0.00 s -> {3 unavailable toolsets}.

Why this is safe

Nothing gates runtime behaviour on this map — agent_init reads check_toolset_requirements(); the availability dict only colours banner rows. A seconds-old or briefly empty snapshot changes banner colouring, nothing else.

Scope / framing

This is deliberately a stopgap, not the long-term answer — #141422's async-resume direction is the real fix for "resume waits on inventory at all". The TTL cache removes the deterministic 30 s budget breach today, cheaply (+56/−2 in the gateway file). Independently worth bounding later: the check_fn probes themselves (e.g. check_web_api_key spending 16.7 s when the web backend is unreachable) — they also cost the CLI banner and hermes doctor.

Tests: tests/gateway/test_tool_availability_ttl_cache.py pins the contract — cold never blocks (with a probe that would hang the test if awaited), warm serves without reprobing, expired serves stale while refreshing, failed probe keeps the warm value and unwedges the key.

zzmsms added 2 commits October 25, 2026 03:51
…-wide TTL cache

session_inventory ran live check_fn probes for web/image_gen/video_gen/connections
on every Desktop session.resume (~28-36s on a slow-network host), blowing the
client's 30s request budget (tui_gateway.ws: ws response send failed ... session.resume).
Cache is filled by a background thread; first resume after gateway start answers
from the warm value or {}. Nothing gates behaviour on the map (display-only banner
colouring). HERMES_TOOL_AVAILABILITY_TTL_S tunes the window (0 = never block).
Follow-up to 94feca8 (loop-liveness family). Unregistered-workspace cleanup.
Four tests for _cached_tool_availability (carried in ecaa99744a, until now
verified only by manual import + asserts): cold cache answers {} without
blocking on the 28-36s live probe, warm value serves within TTL without
reprobing, an expired entry serves stale while the background thread
refreshes, and a crashed probe keeps the warm value and clears the inflight
key. pytest lands on this host with this commit (uv pip install pytest 9.1.1
into the active venv).
@alt-glitch alt-glitch added area/sessions Session lifecycle, resume, persistence, history comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists type/bug Something isn't working labels Oct 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sessions Session lifecycle, resume, persistence, history comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants