fix(display): retain provider provenance for persisted fallback readings

This commit is contained in:
Teknium
2026-09-07 03:43:12 -07:00
parent b4e2ae9e76
commit 62f64ae5b0
2 changed files with 6 additions and 1 deletions

View File

@@ -97,7 +97,7 @@ def context_display_source(compressor: Any) -> str:
"""
real = getattr(compressor, "last_real_prompt_tokens", None)
shown = getattr(compressor, "last_prompt_tokens", 0) or 0
return "local_estimate" if isinstance(real, (int, float)) and shown != real else "provider_usage"
return "local_estimate" if isinstance(real, (int, float)) and shown > 0 and shown != real else "provider_usage"
def context_usage_fields(compressor: Any) -> Dict[str, Any]:

View File

@@ -36,3 +36,8 @@ def test_preflight_seed_does_not_label_actual_usage_estimated():
comp.update_from_response({"prompt_tokens": 1234, "completion_tokens": 20})
assert _get_usage(agent).get("context_estimated") is False
assert _get_usage(agent)["context_used"] == 1234
comp.last_prompt_tokens = -1
assert "context_used" not in _get_usage(agent)
from agent.context_breakdown import context_display_source
# A cleared live gauge must not re-label a persisted provider fallback.
assert context_display_source(comp) == "provider_usage"