Repository navigation
feat(perf): turn log records how busy the model server was - #5285
Conversation
The turn log said how long each model call took, but not how much of that the server spent computing, so "is GAIA keeping the backend busy?" had no answer. With GAIA_TURN_LOG set, each local model call now carries llama.cpp's own prefill/decode time and cache reuse (from the stream's timings) and the time GAIA spent before the request reached the server: model-slot lease, request lock, status probe, stats fetch. Each turn reports server compute, non-model time, named spans (memory recall, post-init upkeep, eviction, tool logging) and what filled the gaps between model calls; work after the answer is a second gaia.turn_post/1 line. - gaia.utils.perf_trace: thread-local hooks the LLM client reports into, one attribute read when recording is off. - The flagship sidecar serves the last records at GET /v1/gaia/debug/turns while recording is on (off the published contract; hidden routes no longer count in the capability matrix). - util/perf_turns.py drives /v1/gaia/query and samples the llama.cpp server (/slots, /metrics, per-process GPU utilization on Windows). - The TUI gains --pprof <loopback host:port>. - Memory's tool-history logging failures log a warning instead of debug.
… fragment A changed system prompt between two turns of one chat makes Gemma-4 re-read the whole prompt; the record now carries its hash and each mixin fragment's size, so the fragment that changed is named instead of guessed.
|
Verdict: Approve with suggestions With
Real-world evidenceN/A: no evidence bundle was produced for this run. The changed surfaces are a dev-only HTTP route, a dev-only TUI flag and a measurement script, all opt-in. The PR description reports Strix Halo timings but doesn't paste a captured 🔍 Technical detailsIssues found 🟢 The client-side wait wiring has no test ( 🟢 (Use whatever local holds the composed prompt here, since 🟢 Strengths
|
…path - The prompt fingerprint uses SHA-256; Bandit blocks SHA-1 (B324). - A test now drives LemonadeClient._model_slot_lease and _ensure_model_loaded under an active recorder, with another request holding the lock, so the lock, lease and status-probe waits are proven to land on the open call rather than only when fed in by hand. - prompt.fragments counts only fragments present in the prompt that was sent. - dev.mdx says /debug/turns returns every session's records. - test_wait_tools patched the global time.sleep, so on Windows the rotating log handler's lock-retry sleep was counted as a nap and the "already stopped" test failed intermittently; the fixture now patches only the tool's clock.
# Conflicts: # src/gaia/agents/base/memory.py
# Conflicts: # hub/agents/gaia/python/tests/test_server_query.py # src/gaia/llm/lemonade_client.py
|
Verdict: Approve with suggestions With Before merge:
Real-world evidenceN/A: no 🔍 Technical details🟡 No pasted output for the new route or flag (PR description) 🟢 Missing word (docs/reference/dev.mdx, "Is GAIA keeping the model server busy?") 🟢 The docstring promises a "foreign": bool(agent) and req_delta > agent["llm_calls"],or reword the docstring to say the delta is recorded for the reader to compare. Checked and fine
Strengths
|
# Conflicts: # src/gaia/llm/lemonade_client.py
- Each perf_turns record now sets `foreign` when Lemonade served more requests during the turn than the agent's own model calls, so a run that shared the server with another client is marked. It is null when the sidecar returned no turn record to compare with. - dev.mdx: restore the missing word in the shared-machine warning.
The turn log said how long each model call took but not how much of that the model server spent computing, so "is GAIA keeping the backend busy?" had no answer. With
GAIA_TURN_LOGset, every local model call now records the server's own prefill, decode and cache-reuse figures, plus the time GAIA spent before the request reached the server. Each turn reports its server compute, its non-model time, what filled the gaps between model calls, and a fingerprint of the system prompt, so a cache-breaking prompt change is named rather than guessed.First readings on Gemma-4-E4B (Strix Halo, idle GPU): a warm "hello" is 3.4–3.9 s, of which 0.45 s is non-model time. Between model calls GAIA's own work costs under 30 ms; the rest of the gap is tool I/O. The seconds go to the server, and much of that to re-reading prompts it should have kept cached. Those fixes follow in separate PRs.
util/perf_turns.pydrives/v1/gaia/queryand samples the llama.cpp server behind Lemonade (/slotsbusy time and idle gaps,/metrics, per-process GPU use on Windows). It waits for an idle GPU before each session and flags runs where the model reloaded or another client sent requests.GET /v1/gaia/debug/turnswhile recording is on. The route is off the published contract, and the capability matrix now skips routes hidden from the schema.--pprof <loopback host:port>for startup and render profiles.Test plan
python -m pytest tests/unit/test_turn_metrics_spans.py tests/unit/test_turn_metrics.py tests/unit/test_turn_metrics_wire.py hub/agents/gaia/python/tests/test_server_query.py hub/agents/gaia/python/tests/test_capability_matrix.py -qcd tui && go test ./internal/cli/ -run PprofGAIA_TURN_LOG=turns.jsonl, start the sidecar and send one query. Its record hasllm_calls[].server.compute_s,totals.non_model_s,gapsandprompt.system_sha, andGET /v1/gaia/debug/turnsreturns it.GAIA_TURN_LOG,/v1/gaia/debug/turnsanswers 404 and no record file is written.🔍 Captured output (Gemma-4-E4B, sidecar from this branch, query "hello")
GET /v1/gaia/debug/turns?limit=1withGAIA_TURN_LOGset, trimmed to the new fields:{ "schema": "gaia.turn/1", "total_s": 4.112, "steps": 1, "totals": { "llm_s": 3.911, "overhead_s": 0.201, "server_compute_s": 3.608, "non_model_s": 0.504, "input_tokens_cached_server": 19335, "client_waits_s": {"lease_wait_s": 0.0, "lock_wait_s": 0.0, "ensure_loaded_s": 0.0171} }, "gaps": [], "llm_calls": [{ "step": 1, "wall_s": 3.9109, "server": {"prompt_n": 45, "prompt_ms": 1074.886, "cache_n": 19335, "predicted_n": 85, "predicted_ms": 2532.745, "compute_s": 3.6076}, "client": {"lease_wait_s": 0.0, "lock_wait_s": 0.0, "ensure_loaded_s": 0.0171} }], "prompt": {"system_sha": "6f7d0ea7ac22", "system_tokens": 5843, "tool_schema_tokens": 14499, "tools_sent": 95, "fragments": {"get_memory_system_prompt": 1722, "get_skill_catalog_system_prompt": 5786, "...": "..."}} }Without
GAIA_TURN_LOG: the route answersHTTP 404 {"detail":"Turn recording is off. Set GAIA_TURN_LOG=<path> before starting the agent to record turns."}and a query writes no record file.TUI: