Skip to content

Commit 756e351

Browse files
committed
fix(state): metrics.turns populates from emu.context_update
Last remaining stuck-at-zero from the round-5 audit. The emu typed handler and apply_unknown branch both extracted turn_estimate for display_value but never wrote it to metrics.turns. SESSION METRICS "Turns" cell was decoded from metrics.turns and stayed at the default (0, 0) for the lifetime of every session. Both paths now set \`metrics.turns = (turn_estimate, 3)\` where 3 is the hardcoded ±uncertainty band the renderer expects. Typed-variant path also gates on non-negative i64 to stay defensive against bad wire data. Tests: 80/0 lib green; release build clean.
1 parent 76ecad0 commit 756e351

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

inspector/src/state.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,11 +1335,19 @@ impl AppState {
13351335

13361336
// ---- per-plugin display updates ----------------------------
13371337
Event::EmuContextUpdate(p) => {
1338-
let turn = p.extra.get("turn_estimate")
1338+
let turn_n = p
1339+
.extra
1340+
.get("turn_estimate")
13391341
.and_then(|v| v.as_i64())
1342+
.filter(|n| *n >= 0)
1343+
.map(|n| n as u32);
1344+
let turn_str = turn_n
13401345
.map(|n| n.to_string())
13411346
.unwrap_or_else(|| "?".into());
1342-
self.set_plugin_display("emu", format!("{turn}±3"));
1347+
self.set_plugin_display("emu", format!("{turn_str}±3"));
1348+
if let Some(n) = turn_n {
1349+
self.metrics.turns = (n, 3);
1350+
}
13431351
if let Some(ctx) = p.extra.get("context_size").and_then(|v| v.as_u64()) {
13441352
self.push_plugin_usage("emu", ctx);
13451353
}
@@ -1776,13 +1784,14 @@ impl AppState {
17761784
// Round-3 fix A: when emu.context_update arrives via the
17771785
// Unknown fallback path (shape variation, downgraded enum),
17781786
// mirror the typed handler — bump calls, set last_event,
1779-
// refresh display from `turn_estimate`.
1787+
// refresh display from `turn_estimate`, write metrics.turns.
17801788
let turn = p
17811789
.extra
17821790
.get("turn_estimate")
17831791
.and_then(|v| v.as_u64())
1784-
.unwrap_or(25);
1792+
.unwrap_or(25) as u32;
17851793
self.set_plugin_display("emu", format!("{turn}±3 turns"));
1794+
self.metrics.turns = (turn, 3);
17861795
if let Some(idx) = self.plugin_index_by_name("emu") {
17871796
let plug = &mut self.plugins[idx];
17881797
plug.calls = plug.calls.saturating_add(1);

0 commit comments

Comments
 (0)