Files
hermes-webui/api
Konstantin M 5f167b23f9 perf(webui/session-load-latency) tier2c-followup: route slow logs through _safe_webui_print
Tier 2c added per-stage instrumentation on /api/session and added
'GET /api/session' to the RequestDiagnostics allowlist, but the
structured log emitted by RequestDiagnostics.finish() and the
pre-existing [SLOW] line both call logger.warning() — which the
WebUI process silently drops because the root logger has no handler
configured at boot.

The per-request 'ms' line has worked all along because it goes
through handler._safe_webui_print(), which writes directly to the
systemd journal socket.

This commit:
  - adds a print_fn= parameter to RequestDiagnostics.__init__ and
    RequestDiagnostics.maybe_start. When provided, finish() and
    _on_timeout() route through it instead of self.logger.warning.
  - routes the [SLOW] line in routes.py through handler._safe_webui_print
    instead of logger.warning.
  - passes print_fn=handler._safe_webui_print from the /api/session
    handler to RequestDiagnostics.maybe_start.

After this fix, every slow /api/session request (and the existing
[SLOW] line) actually lands in the journal — the very data Tier 2c
was supposed to produce. Without this, the allowlist + handler
instrumentation would be a no-op in production despite the code
being present.

Measured: the same 2.97s /api/session call (sid 295592fd560e,
m=1 ml=30) which produced a per-request ms line but no [SLOW] line
before this fix, now produces both lines with full per-stage breakdown.

No public API change. The new print_fn parameter is optional and
defaults to None, preserving the existing logger.warning behavior
for any caller that hasn't been updated.
2026-07-08 22:39:09 +00:00
..
2026-05-28 17:47:33 +00:00