Skip unused MCP status snapshots after the first prompt

Read sign-in notices before collecting server statuses, and skip the snapshot once the startup notice is dismissed. Preserve startup settling and sign-in feedback. Call the session cost reset directly instead of forwarding through a wrapper.
This commit is contained in:
Esteban Suarez committed 2026-10-26 14:26:53 -03:00
1 parent a5824ef1f6
commit 9d17179ea4
2 files changed
+9 -14

No files matched your search

+7 -6
View File
@@ -153,8 +153,6 @@ pub const State = struct {
var arena: std.heap.ArenaAllocator = .init(std.heap.c_allocator);
defer arena.deinit();
const a = arena.allocator();
// The status line never shows sign-in state, so it doesn't wait for it.
const statuses = lease.host.runtime.statusesNow(a) catch return "";
sink.mutex.lockUncancelable(io_mod.getIo());
const news: ?[]const u8 = if (sink.news) |text|
(if (now_ms - sink.news_at_ms < mcp_menu.news_ms) a.dupe(u8, text) catch null else null)
@@ -165,10 +163,13 @@ pub const State = struct {
else
null;
sink.mutex.unlock(io_mod.getIo());
// After a prompt, and while servers start so the count shows once, not
// climbing, only a sign-in speaks up.
if (self.host_status_dismissed or
(self.host_started_ms != 0 and !mcp_menu.startupSettled(statuses, now_ms - self.host_started_ms)))
// After a prompt, only sign-in notices can use the slot; no server
// snapshot is needed.
if (self.host_status_dismissed)
return mcp_menu.statusLine(buf, &.{}, signing_in, news, 0);
const statuses = lease.host.runtime.statusesNow(a) catch return "";
// Wait for startup to settle so the attention count doesn't climb.
if (self.host_started_ms != 0 and !mcp_menu.startupSettled(statuses, now_ms - self.host_started_ms))
return mcp_menu.statusLine(buf, &.{}, signing_in, news, 0);
return mcp_menu.statusLine(buf, statuses, signing_in, news, lease.host.notes.len);
}
+2 -8
View File
@@ -1516,19 +1516,13 @@ pub fn Runtime(comptime App: type) type {
enableSubagentHostV2(app, v2);
}
/// The status line's cost counts from zero for the session now open;
/// it is kept in memory, not saved with it.
fn resetSessionUsage(app: *App) void {
app.session_persistence.resetCost();
}
pub fn beginFreshPersistedSession(app: *App) !void {
closeWritableSession(app);
// A fresh session starts with no usage, whether or not it persists.
app.total_input_tokens = 0;
app.total_output_tokens = 0;
app.total_web_search_requests = 0;
resetSessionUsage(app);
app.session_persistence.resetCost();
if (comptime runtime_profile.allows(App, .js_host_sessions)) {
try beginFreshJsHostSession(app);
}
@@ -2253,7 +2247,7 @@ pub fn Runtime(comptime App: type) type {
app.total_input_tokens = state.total_input_tokens;
app.total_output_tokens = state.total_output_tokens;
app.total_web_search_requests = 0;
resetSessionUsage(app);
app.session_persistence.resetCost();
var historical_labels = HistoricalSessionLabels{ .workspace_root = app.workspace_root };
defer historical_labels.deinit(app.alloc);