v0.50.263 — Context-window indicator hotfix
Fixes the misleading "100" / "890% used (context exceeded)" indicator on older sessions.
Fixed
-
Context-window indicator broken on older sessions (#1436) — sessions that pre-date #1318 (when
context_lengthwas added toSession) returnedcontext_length=0from/api/session, which combined with two cascading frontend fallbacks rendered the ring as100and the tooltip as890% used (context exceeded), 1.2M / 131.1k tokens used. #1356 fixed the same symptom on the live SSE path but missed the GET /api/session load path.Two-layer fix:
- Backend (
api/routes.py) — when persistedcontext_lengthis 0, resolve viaagent.model_metadata.get_model_context_length()using the session's model. Mirrors the SSE-path fallback inapi/streaming.py:2333-2342. Includes empty-model guard to avoid the 256K default-for-unknown trap. - Frontend (
static/ui.js:1269) — drop theusage.input_tokensfallback forpromptTok. Cumulativeinput_tokensis fundamentally wrong for "context window % used" — it sums input across all turns. Older sessions withoutlast_prompt_tokensnow render·+ "tokens used" (honest no-data) on the ring instead of a misleading >100% percentage.
Empirical scope on the dev server before the fix: 23 of 75 sessions were rendering >100%. After: every previously-broken session resolves correctly; healthy sessions are unaffected.
10 regression tests in
tests/test_issue1436_context_indicator_load_path.pypin both layers + the empty-model edge case + exception-swallowing on older agent builds.Reported by @AvidFuturist.
- Backend (