fix(dashboard): ctx·Nk card badge showed 0k — use context_tokens()

/api/dashboard-state reported ctx_tokens from raw ctx_usage.input_tokens,
which is only the *uncached* input. With prompt caching the bulk of the
prompt is cache-read, so input_tokens is ~0 and every SW4RM card showed
'ctx·0k'. Use ctx_usage.context_tokens() (input + cache-read + cache-creation
= the real window size) to match the agent page (ships the full ctx_usage)
and turn.rs's cache-TTL check. Doc comment updated.
This commit is contained in:
iris 2026-06-21 21:27:28 +02:00 committed by mara
commit 5eacc99146

View file

@ -664,8 +664,9 @@ struct DashboardState {
/// `None` when no status is set.
#[serde(skip_serializing_if = "Option::is_none")]
status_set_at: Option<i64>,
/// Input token count from the most recent completed turn (`ctx_usage.input_tokens`).
/// `None` until the first turn finishes.
/// Full context-window size from the most recent completed turn
/// (`ctx_usage.context_tokens()` = input + cache-read + cache-creation).
/// `None` until the first turn finishes. Drives the `ctx·Nk` card badge.
#[serde(skip_serializing_if = "Option::is_none")]
ctx_tokens: Option<u64>,
/// Effective context-window budget for the current model. Same
@ -714,7 +715,12 @@ async fn api_dashboard_state(State(state): State<AppState>) -> axum::Json<Dashbo
.bus
.api_context_window()
.unwrap_or_else(|| crate::events::context_window_tokens(&model));
let ctx_tokens = state.bus.last_ctx_usage().map(|u| u.input_tokens);
// Full context-window size = input + cache-read + cache-creation. Using
// raw `input_tokens` here reported only the *uncached* sliver, which is
// ~0 once prompt caching kicks in — so every card showed `ctx·0k`. Match
// the agent page (which ships the whole `ctx_usage` and sums it) and the
// cache-TTL logic in turn.rs, both of which use `context_tokens()`.
let ctx_tokens = state.bus.last_ctx_usage().map(|u| u.context_tokens());
axum::Json(DashboardState {
status_text,
status_set_at,