Skip to content

A self-improving RLM agent for coding workflows and long-running autonomous tasks.

Rust

agents view: show the recorded model on inactive sessions (#2148)

Sebastian Müller163dd5798cd4
diff --git a/packages/coding-agent/.changes/res-1330-inactive-session-model.md b/packages/coding-agent/.changes/res-1330-inactive-session-model.md
new file mode 100644
index 0000000000..091894e1e2
--- /dev/null
+++ b/packages/coding-agent/.changes/res-1330-inactive-session-model.md
@@ -0,0 +1 @@
+- Added the recorded model to inactive session rows in the agents view instead of showing '-'.
diff --git a/packages/coding-agent/src/core/session-manager.ts b/packages/coding-agent/src/core/session-manager.ts
index dc7b593072..d918a1e068 100644
--- a/packages/coding-agent/src/core/session-manager.ts
+++ b/packages/coding-agent/src/core/session-manager.ts
@@ -243,12 +243,19 @@ export interface SessionContext {
model: { provider: string; modelId: string } | null;
}
+export interface SessionModelRef {
+ provider: string;
+ modelId: string;
+}
+
export interface SessionInfo {
path: string;
id: string;
cwd: string;
name?: string;
state?: SessionState;
+ /** Last model the session ran with, from model_change entries and assistant messages. */
+ model?: SessionModelRef;
parentSessionPath?: string;
rlmDepth: number;
created: Date;
@@ -1042,6 +1049,7 @@ function extractOversizedMessageSummary(line: string): {
interface SessionScanAccumulator {
header?: SessionHeader;
+ model?: SessionModelRef;
/** The first parsed entry was not a session header; appends cannot repair this. */
invalid: boolean;
messageCount: number;
@@ -1273,6 +1281,10 @@ function foldSessionScanLine(acc: SessionScanAccumulator, lineBuffer: Buffer): v
if (entry.type === "agent_status") {
acc.agentStatus = (entry as AgentStatusEntry).status;
}
+ if (entry.type === "model_change") {
+ const modelEntry = entry as ModelChangeEntry;
+ acc.model = { provider: modelEntry.provider, modelId: modelEntry.modelId };
+ }
if (entry.type === "child_usage_attributed") {
const attribution = entry as ChildUsageAttributionEntry;
if (acc.assistantUsageById.has(attribution.targetId)) {
@@ -1301,6 +1313,12 @@ function foldSessionScanLine(acc: SessionScanAccumulator, lineBuffer: Buffer): v
if (message.role === "assistant" && (message as { usage?: Usage }).usage) {
acc.assistantUsageById.set(entry.id, (message as { usage: Usage }).usage);
}
+ if (message.role === "assistant") {
+ const assistant = message as { provider?: string; model?: string };
+ if (typeof assistant.provider === "string" && typeof assistant.model === "string") {
+ acc.model = { provider: assistant.provider, modelId: assistant.model };
+ }
+ }
if (!isMessageWithContent(message)) return;
if (message.role !== "user" && message.role !== "assistant") return;
@@ -1348,6 +1366,7 @@ function snapshotSessionInfo(
cwd,
name: acc.name,
state: acc.state,
+ model: acc.model,
parentSessionPath,
rlmDepth,
created: new Date(header.timestamp),
diff --git a/packages/coding-agent/src/modes/agent-connection/types.ts b/packages/coding-agent/src/modes/agent-connection/types.ts
index e1955207a2..0ae4094b37 100644
--- a/packages/coding-agent/src/modes/agent-connection/types.ts
+++ b/packages/coding-agent/src/modes/agent-connection/types.ts
@@ -136,6 +136,8 @@ export interface AgentConnectionSavedSessionInfo {
allMessagesText: string;
agentStatus?: AgentConnectionAgentStatus;
usage?: SessionUsageSummary;
+ /** Last recorded provider/model selector; absent for sessions that never ran a model. */
+ model?: { provider: string; modelId: string };
}
export type AgentConnectionSessionListProgress = (loaded: number, total: number) => void;
diff --git a/packages/coding-agent/src/modes/agents-view/agents-view-mode.ts b/packages/coding-agent/src/modes/agents-view/agents-view-mode.ts
index 1433d107b3..7dd3e01e63 100644
--- a/packages/coding-agent/src/modes/agents-view/agents-view-mode.ts
+++ b/packages/coding-agent/src/modes/agents-view/agents-view-mode.ts
@@ -2576,7 +2576,7 @@ export class AgentsViewMode implements Component, Focusable {
const activity = [status, row.summary.summary].filter(Boolean).join(" · ");
const cells = [
formatTableCell(title, layout.nameWidth),
- formatTableCell(theme.fg("muted", formatSessionModel(row.summary)), layout.modelWidth),
+ formatTableCell(theme.fg("muted", formatSessionModel(row)), layout.modelWidth),
];
if (layout.activityWidth > 0) cells.push(formatTableCell(theme.fg("dim", activity), layout.activityWidth));
cells.push(theme.fg("muted", details));
@@ -2593,11 +2593,17 @@ export class AgentsViewMode implements Component, Focusable {
];
if (row) {
const model = row.summary.model;
+ const savedModel = row.record?.saved?.model;
+ const modelLabel = model
+ ? `${model.provider}/${model.id}`
+ : savedModel
+ ? `${savedModel.provider}/${savedModel.modelId}`
+ : "unknown";
const usage = row.summary.usage;
actions.push(
"",
row.title,
- `Model: ${model ? `${model.provider}/${model.id}` : "unknown"}${row.summary.thinkingLevel ? ` · ${row.summary.thinkingLevel}` : ""}`,
+ `Model: ${modelLabel}${row.summary.thinkingLevel ? ` · ${row.summary.thinkingLevel}` : ""}`,
`Directory: ${row.summary.cwd}`,
`Tokens: ${usage?.inputTokens ?? 0} in · ${usage?.outputTokens ?? 0} out`,
`Cost: $${(usage?.cost ?? 0).toFixed(2)} session · $${row.recursiveCost.toFixed(2)} including subagents`,
@@ -2830,10 +2836,7 @@ export function buildCompactAgentsViewLayout(rows: readonly AgentsViewRow[], wid
const ageWidth = entries.reduce((size, entry) => Math.max(size, visibleWidth(entry.age)), 3);
const detailsWidth = costWidth + 2 + ageWidth;
const available = Math.max(0, width - detailsWidth - 4);
- const desiredModelWidth = sessions.reduce(
- (size, row) => Math.max(size, visibleWidth(formatSessionModel(row.summary))),
- 12,
- );
+ const desiredModelWidth = sessions.reduce((size, row) => Math.max(size, visibleWidth(formatSessionModel(row))), 12);
const modelWidth = Math.min(desiredModelWidth, 32, Math.max(0, available - 12));
const nameWidth = Math.min(28, Math.max(0, available - modelWidth));
const activityWidth = Math.max(0, available - modelWidth - nameWidth - 2);
@@ -2871,8 +2874,8 @@ function formatTableCell(value: string, width: number): string {
return truncated + " ".repeat(Math.max(0, width - visibleWidth(truncated)));
}
-function formatSessionModel(summary: SessionSummary): string {
- return summary.model?.id ?? "-";
+function formatSessionModel(row: AgentsViewRow): string {
+ return row.summary.model?.id ?? row.record?.saved?.model?.modelId ?? "-";
}
function formatSessionDuration(summary: SessionSummary): string {
diff --git a/packages/coding-agent/src/modes/daemon/daemon-protocol.ts b/packages/coding-agent/src/modes/daemon/daemon-protocol.ts
index 557630b878..b864623536 100644
--- a/packages/coding-agent/src/modes/daemon/daemon-protocol.ts
+++ b/packages/coding-agent/src/modes/daemon/daemon-protocol.ts
@@ -73,8 +73,9 @@ export const DAEMON_COMMAND_ENVELOPE_MIN_PROTOCOL_VERSION = 7;
// Revision 25 adds capability-gated direct worker peer transport discovery.
// Revision 26 publishes own-session usage totals on session summary and saved-session rows.
// Revision 27 adds structured session_recovering failure info for known-but-unaddressable sessions.
-export const DAEMON_SCHEMA_REVISION = 27;
-export const DAEMON_SCHEMA_ID = "protocol-7-schema-27-962b8b4c5e35";
+// Revision 28 publishes the last recorded model on saved-session rows.
+export const DAEMON_SCHEMA_REVISION = 28;
+export const DAEMON_SCHEMA_ID = "protocol-7-schema-28-92bc5368a082";
export type DaemonProtocolName = typeof DAEMON_PROTOCOL_NAME;
export type DaemonProtocolVersion = number;
@@ -1079,6 +1080,8 @@ export interface DaemonSavedSessionInfo {
allMessagesText: string;
agentStatus?: AgentConnectionAgentStatus;
usage?: SessionUsageSummary;
+ /** Last recorded provider/model selector; absent for sessions that never ran a model. */
+ model?: { provider: string; modelId: string };
}
export type DaemonDeleteSavedSessionResult = DeleteSessionFileResult;
diff --git a/packages/coding-agent/src/modes/daemon/saved-session-info.ts b/packages/coding-agent/src/modes/daemon/saved-session-info.ts
index dfae72d707..e5713770a0 100644
--- a/packages/coding-agent/src/modes/daemon/saved-session-info.ts
+++ b/packages/coding-agent/src/modes/daemon/saved-session-info.ts
@@ -18,6 +18,7 @@ export function serializeSavedSessionInfo(session: SessionInfo): DaemonSavedSess
allMessagesText: session.allMessagesText,
agentStatus: session.agentStatus,
usage: session.usage,
+ model: session.model,
};
}
@@ -37,5 +38,6 @@ export function deserializeSavedSessionInfo(session: DaemonSavedSessionInfo): Ag
allMessagesText: session.allMessagesText,
agentStatus: session.agentStatus,
usage: session.usage,
+ model: session.model,
};
}
diff --git a/packages/coding-agent/test/agents-view-mode.test.ts b/packages/coding-agent/test/agents-view-mode.test.ts
index 243dfbd125..7ef077787d 100644
--- a/packages/coding-agent/test/agents-view-mode.test.ts
+++ b/packages/coding-agent/test/agents-view-mode.test.ts
@@ -816,6 +816,45 @@ describe("AgentsViewMode", () => {
}
});
+ it("shows the recorded model on inactive saved sessions and keeps '-' without one", () => {
+ const saved = (id: string, model?: { provider: string; modelId: string }) => ({
+ path: `/tmp/${id}.jsonl`,
+ id,
+ cwd: "/tmp",
+ created: new Date("2026-01-01T00:00:00Z"),
+ modified: new Date("2026-01-01T00:00:00Z"),
+ messageCount: 1,
+ firstMessage: "hello",
+ allMessagesText: "hello",
+ ...(model ? { model } : {}),
+ });
+ const records = reconcileUnifiedSessions(
+ [],
+ [saved("with-model", { provider: "prime-inference", modelId: "glm-4.7" }), saved("bare")],
+ );
+ const rows = buildAgentsViewRows(records);
+ const view = new AgentsViewMode({ config: {}, uiServices: createUiServices() }, {});
+ Reflect.set(view, "rows", rows);
+ Reflect.set(view, "selectedIndex", -1);
+ try {
+ const render = (id: string) =>
+ stripAnsi(invoke("renderRow", view, rows.find((row) => row.summary.sessionId === id)!, 120) as string);
+ expect(render("with-model")).toContain("glm-4.7");
+ expect(render("bare")).toMatch(/\s-\s/);
+ expect(render("bare")).not.toContain("glm-4.7");
+ // The actions panel shows the same recorded model instead of "unknown".
+ Reflect.set(
+ view,
+ "selectedIndex",
+ rows.findIndex((row) => row.summary.sessionId === "with-model"),
+ );
+ const actions = (invoke("renderActions", view, 120) as string[]).map(stripAnsi).join("\n");
+ expect(actions).toContain("Model: prime-inference/glm-4.7");
+ } finally {
+ stopThemeWatcher();
+ }
+ });
+
it("renders one column header across status groups without repeating subagent hints", () => {
const summaries = [
summary({
diff --git a/packages/coding-agent/test/session-manager/file-operations.test.ts b/packages/coding-agent/test/session-manager/file-operations.test.ts
index f26c1028bf..2872fb714e 100644
--- a/packages/coding-agent/test/session-manager/file-operations.test.ts
+++ b/packages/coding-agent/test/session-manager/file-operations.test.ts
@@ -827,6 +827,35 @@ describe("readSessionInfo incremental scans", () => {
});
const line = (entry: unknown) => `${JSON.stringify(entry)}\n`;
+ it("scans the last recorded model from model_change entries and assistant messages", async () => {
+ const file = join(tempDir, "model.jsonl");
+ writeFileSync(
+ file,
+ [
+ line(header),
+ line({ type: "model_change", id: "mc1", parentId: null, provider: "openai", modelId: "gpt-4o" }),
+ line(msg("m1", "mc1", "user", "hi")),
+ line({
+ type: "message",
+ id: "m2",
+ parentId: "m1",
+ message: {
+ role: "assistant",
+ content: "x",
+ timestamp: 1,
+ provider: "prime-inference",
+ model: "glm-4.7",
+ },
+ }),
+ ].join(""),
+ );
+ expect((await readSessionInfo(file))?.model).toEqual({ provider: "prime-inference", modelId: "glm-4.7" });
+
+ const bare = join(tempDir, "bare.jsonl");
+ writeFileSync(bare, line(header));
+ expect((await readSessionInfo(bare))?.model).toBeUndefined();
+ });
+
it("coalesces concurrent unchanged readers and gives post-append readers the fresh snapshot", async () => {
const file = join(tempDir, "serialized.jsonl");
let content = line(header);