From c1dd0ed2baeba61ee975e83b37c3bed08e55cb89 Mon Sep 17 00:00:00 2001 From: Devika Verma Date: Thu, 5 Nov 2026 16:37:06 +0530 Subject: [PATCH] fix(observability): keep the per-turn usage's model spelling the golden corpus defines (T3-4) calculator.usage by_model is part of the shared golden corpus, which keeps the recorded spelling (openai:gpt-5.1); faeb7022 changed it and three golden screen-number cases failed. The GUI never shows that map; the session usage table (by_model_parts), the ledger grouping and the turn lists still read one name per model. --- coworker/observability/calculator.py | 4 +--- tests/test_observability_phase3_manual_fixes.py | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/coworker/observability/calculator.py b/coworker/observability/calculator.py index 452db233..674a7f09 100644 --- a/coworker/observability/calculator.py +++ b/coworker/observability/calculator.py @@ -10,8 +10,6 @@ from __future__ import annotations from typing import Any, Iterable, Optional -from .model_names import canonical_model - BUCKET_ORDER = ["waiting", "tools", "model", "auto_approver", "summary", "sandbox"] @@ -62,7 +60,7 @@ def usage(recording: dict[str, Any], session_id: Optional[str] = None, total += t p = attrs.get("purpose") or "unattributed" # the format's word for a call with no purpose (V3-19) by_purpose[p] = by_purpose.get(p, 0) + t - key = canonical_model(attrs.get("model") or "?") + ("" if p == "main" else f" ({p})") # T3-4 + key = attrs.get("model", "?") + ("" if p == "main" else f" ({p})") by_model[key] = by_model.get(key, 0) + t u = attrs["usage"] if u.get("cache_read") is not None: # a call with no cache count stays out of the share diff --git a/tests/test_observability_phase3_manual_fixes.py b/tests/test_observability_phase3_manual_fixes.py index 52f6d0b5..5d5d4581 100644 --- a/tests/test_observability_phase3_manual_fixes.py +++ b/tests/test_observability_phase3_manual_fixes.py @@ -243,6 +243,7 @@ def test_one_model_is_read_and_grouped_under_one_name(tmp_path): heavy = usage_api.heaviest(store, start=span[0], end=span[1])["turns"] assert sorted(m for t in heavy for m in t["model_ids"]) == ["anthropic:model-y", "model-x", "model-x"] rec = store.load_recording("s1") - assert calculator.usage(rec)["by_model"] == {"model-x": 220, "anthropic:model-y": 110} + # the per-turn usage keeps the recorded spelling: the golden corpus defines it + assert calculator.usage(rec)["by_model"] == {"openai:model-x": 110, "model-x": 110, "anthropic:model-y": 110} assert set(read_api.usage(rec, "s1")["by_model_parts"]) == {"model-x", "anthropic:model-y"} store.close()