From e96318d2e59183a46463a5935e8465f8d657121e Mon Sep 17 00:00:00 2001 From: Konstantin M Date: Thu, 9 Jul 2026 04:22:21 +0000 Subject: [PATCH] =?UTF-8?q?perf(webui/session-load-latency)=20tier4:=20fix?= =?UTF-8?q?=20CI=20failures=20=E2=80=94=20lint=20B009/B905=20+=20=5Femit?= =?UTF-8?q?=5Fslow=20format=20args?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three fixes for the CI failures (lint + test shard 1): 1. B009 lint fix (api/routes.py:6281): Replace getattr(session, 'profile') with session.profile — the guard on line 6275 already ensures it exists. 2. B905 lint fix (api/routes.py:13843): Add strict=True to zip() of _draft_stages slices. Both sides are always the same length (shifted by one), so strict=True is correct. 3. _emit_slow format-arg fix (api/request_diagnostics.py:186-195): Keep the prefix in the format string and pass the JSON payload as a separate positional argument. The test at test_issue1855_request_diagnostics.py:33 does json.loads(caplog.records[0].args[0]) and the old code embedded the prefix in the payload string, breaking the JSON parse. Now self.logger.warning("%s %s", prefix, payload) — wait, actually self.logger.warning(f"{prefix} %s", payload) — so args[0] is the raw JSON string, same as the pre-_emit_slow code. --- api/request_diagnostics.py | 7 ++++--- api/routes.py | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/api/request_diagnostics.py b/api/request_diagnostics.py index 7c1b2536..2199567c 100644 --- a/api/request_diagnostics.py +++ b/api/request_diagnostics.py @@ -184,15 +184,16 @@ class RequestDiagnostics: self._current_stage_started = now def _emit_slow(self, prefix: str, record: dict) -> None: - payload = f"{prefix} {json.dumps(record, sort_keys=True)}" + payload = json.dumps(record, sort_keys=True) + log_msg = f"{prefix} %s" if self._print_fn is not None: try: - self._print_fn(payload) + self._print_fn(log_msg % payload) except Exception: # print_fn is best-effort; never break a request thread. pass else: - self.logger.warning("%s", payload) + self.logger.warning(log_msg, payload) def finish(self) -> None: record = None diff --git a/api/routes.py b/api/routes.py index 73f4a452..3df40cae 100644 --- a/api/routes.py +++ b/api/routes.py @@ -6278,7 +6278,7 @@ def _read_profile_model_config( try: from api.profiles import get_hermes_home_for_profile - _profile_name = str(getattr(session, "profile") or "") + _profile_name = str(session.profile or "") _profile_home = get_hermes_home_for_profile(_profile_name) _profile_cfg_path = os.path.join(str(_profile_home), "config.yaml") if not os.path.isfile(_profile_cfg_path): @@ -13840,7 +13840,7 @@ def handle_post(handler, parsed) -> bool: if _draft_stages[-1][1] - _draft_t0 > 0.2: parts = " ".join( f"{n}={((t - prev[1]) * 1000):.1f}ms" - for (n, t), prev in zip(_draft_stages[1:], _draft_stages[:-1]) + for (n, t), prev in zip(_draft_stages[1:], _draft_stages[:-1], strict=True) ) handler._safe_webui_print( "[SLOW] /api/session/draft total=%.1fms stages: %s" % (