Python
fix(observability): keep the per-turn usage's model spelling the golden corpus defines (T3-4)
Devika Vermac1dd0ed2baeb
diff --git a/coworker/observability/calculator.py b/coworker/observability/calculator.pyindex 452db233..674a7f09 100644--- a/coworker/observability/calculator.py+++ b/coworker/observability/calculator.py@@ -10,8 +10,6 @@ from __future__ import annotationsfrom 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 += tp = 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) + tu = attrs["usage"]if u.get("cache_read") is not None: # a call with no cache count stays out of the sharediff --git a/tests/test_observability_phase3_manual_fixes.py b/tests/test_observability_phase3_manual_fixes.pyindex 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()