mirror of
https://github.com/andrewyng/openworker.git
synced 2026-11-20 20:37:44 +00:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user