A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
generate recap summaries for subagents as well (#249)
kt0d957e914b0f
diff --git a/packages/coding-agent/src/modes/daemon/daemon-mode.ts b/packages/coding-agent/src/modes/daemon/daemon-mode.tsindex 927935848f..a38860114c 100644--- a/packages/coding-agent/src/modes/daemon/daemon-mode.ts+++ b/packages/coding-agent/src/modes/daemon/daemon-mode.ts@@ -180,7 +180,7 @@ export class AgentDaemon {private readonly cronStore: AgentCronJobStore;private readonly cronScheduler: AgentCronScheduler;private readonly summarizer = new DaemonSessionSummarizer(- () => [...this.sessions.values()].filter((state) => state.runtime.metadata.kind !== "subagent"),+ () => [...this.sessions.values()],(state) =>this.broadcastToSession(state, {type: "session_status",@@ -348,9 +348,9 @@ export class AgentDaemon {} catch {// Marking is best-effort; the session still works unrestored.}- // Restore the last persisted status so it shows before the first sweep.- this.summarizer.seed(state);}+ // Restore the last persisted status so it shows before the first sweep.+ this.summarizer.seed(state);return state;}diff --git a/packages/coding-agent/src/modes/daemon/daemon-session-summarizer.ts b/packages/coding-agent/src/modes/daemon/daemon-session-summarizer.tsindex 19998dff7c..6c106011d6 100644--- a/packages/coding-agent/src/modes/daemon/daemon-session-summarizer.ts+++ b/packages/coding-agent/src/modes/daemon/daemon-session-summarizer.ts@@ -204,9 +204,10 @@ function isSessionWorking(state: ActiveSessionState): boolean {}/**- * Background status summarization for daemon-hosted top-level sessions. A- * periodic sweep refreshes working sessions; debounced turn-end activity drives- * the idle verdict. Status lives in memory; settled idle verdicts are persisted.+ * Background status summarization for daemon-hosted sessions, top-level and+ * subagents alike. A periodic sweep refreshes working sessions; debounced+ * turn-end activity drives the idle verdict. Status lives in memory; settled+ * idle verdicts are persisted.*/export class DaemonSessionSummarizer {private interval: ReturnType<typeof setInterval> | undefined;@@ -217,7 +218,7 @@ export class DaemonSessionSummarizer {private readonly rerunRequested = new Set<string>();constructor(- private readonly listTopLevelSessions: () => readonly ActiveSessionState[],+ private readonly listSessions: () => readonly ActiveSessionState[],private readonly onStatusChanged?: (state: ActiveSessionState) => void,// Injectable for tests.private readonly generate: (@@ -230,7 +231,7 @@ export class DaemonSessionSummarizer {return;}this.interval = setInterval(() => {- for (const state of this.listTopLevelSessions()) {+ for (const state of this.listSessions()) {void this.summarize(state);}}, SWEEP_INTERVAL_MS);@@ -276,9 +277,6 @@ export class DaemonSessionSummarizer {/** Called when a session finishes a turn; debounce until the agent settles. */notifyActivity(state: ActiveSessionState): void {- if (state.runtime.metadata.kind === "subagent") {- return;- }const id = state.activeSessionId;const existing = this.debounceTimers.get(id);if (existing) {@@ -293,9 +291,6 @@ export class DaemonSessionSummarizer {}private async summarize(state: ActiveSessionState): Promise<void> {- if (state.runtime.metadata.kind === "subagent") {- return;- }const id = state.activeSessionId;if (this.inFlight.has(id)) {this.rerunRequested.add(id); // run once more after the current passdiff --git a/packages/coding-agent/test/daemon-session-summarizer-lifecycle.test.ts b/packages/coding-agent/test/daemon-session-summarizer-lifecycle.test.tsindex 1b06b6c2e7..9704d00a42 100644--- a/packages/coding-agent/test/daemon-session-summarizer-lifecycle.test.ts+++ b/packages/coding-agent/test/daemon-session-summarizer-lifecycle.test.ts@@ -6,13 +6,15 @@ import { DaemonSessionSummarizer } from "../src/modes/daemon/daemon-session-summ// SETTLE_DEBOUNCE_MS in the module).const SETTLE_MS = 2000;-function makeState(opts: { working?: boolean; messages?: number } = {}): ActiveSessionState {+function makeState(+ opts: { working?: boolean; messages?: number; kind?: "top-level" | "subagent"; persisted?: unknown } = {},+): ActiveSessionState {const appended: unknown[] = [];- return {+ const state = {activeSessionId: "a1",summaryState: undefined,runtime: {- metadata: { kind: "top-level" },+ metadata: { kind: opts.kind ?? "top-level" },session: {isStreaming: opts.working ?? false,isCompacting: false,@@ -20,10 +22,15 @@ function makeState(opts: { working?: boolean; messages?: number } = {}): ActiveSmessages: Array.from({ length: opts.messages ?? 2 }, () => ({ role: "user", content: "hi" })),state: { streamingMessage: undefined },modelRegistry: {},- sessionManager: { appendAgentStatus: (s: unknown) => appended.push(s) },+ sessionManager: {+ appendAgentStatus: (s: unknown) => appended.push(s),+ getLatestAgentStatus: () => opts.persisted,+ },},},} as unknown as ActiveSessionState;+ (state as unknown as { appendedStatuses: unknown[] }).appendedStatuses = appended;+ return state;}describe("DaemonSessionSummarizer lifecycle", () => {@@ -122,4 +129,27 @@ describe("DaemonSessionSummarizer lifecycle", () => {// Result is for an outdated turn → dropped, nothing persisted.expect(state.summaryState).toBeUndefined();});++ test("summarizes a subagent and persists its settled idle verdict", async () => {+ vi.useFakeTimers();+ const generate = vi.fn().mockResolvedValue({ summary: "Auditing the migration scripts", taskState: "completed" });+ const summarizer = new DaemonSessionSummarizer(() => [], undefined, generate);+ const state = makeState({ working: false, kind: "subagent" });++ summarizer.notifyActivity(state);+ await vi.advanceTimersByTimeAsync(SETTLE_MS + 500);++ expect(generate).toHaveBeenCalledOnce();+ expect(state.summaryState).toMatchObject({ summary: "Auditing the migration scripts", taskState: "completed" });+ expect((state as unknown as { appendedStatuses: unknown[] }).appendedStatuses).toHaveLength(1);+ });++ test("seeds a subagent's persisted recap into memory", () => {+ const summarizer = new DaemonSessionSummarizer(() => [], undefined, vi.fn());+ const persisted = { summary: "Reviewing the diff", taskState: "needs_input", basedOnMessageCount: 3 };+ const state = makeState({ kind: "subagent", persisted });++ summarizer.seed(state);+ expect(state.summaryState).toEqual(persisted);+ });});