perf(webui/session-load-latency) tier4: fix CI failures — lint B009/B905 + _emit_slow format args
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.
This commit is contained in:
1 parent
12a60a88b4
commit
e96318d2e5
2 files changed
+6
-5
No files matched your search
@@ -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
|
||||
|
||||
+2
-2
@@ -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" % (
|
||||
|
||||
Reference in new issue
Block a user