A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
fix(coding-agent): suppress rlm_child_update emits with an unchanged snapshot (#1944)
Sebastian Müller6179a608f394
diff --git a/packages/coding-agent/.changes/relay-hygiene.md b/packages/coding-agent/.changes/relay-hygiene.mdnew file mode 100644index 0000000000..c3324a85dc--- /dev/null+++ b/packages/coding-agent/.changes/relay-hygiene.md@@ -0,0 +1 @@+- Stopped re-emitting `rlm_child_update` events whose child snapshot did not change; identical per-token progress updates no longer reach attached clients.diff --git a/packages/coding-agent/src/core/agent-session.ts b/packages/coding-agent/src/core/agent-session.tsindex 922136b768..f2a7068e0a 100644--- a/packages/coding-agent/src/core/agent-session.ts+++ b/packages/coding-agent/src/core/agent-session.ts@@ -916,6 +916,7 @@ interface RlmChildRun {completeDeletion?: () => Promise<void>;reportDeletionCleanupFailure?: (error: unknown) => Promise<void>;emitUpdate?: () => void;+ lastEmittedUpdate?: string;unsubscribe?: () => void;}@@ -10467,7 +10468,11 @@ export class AgentSession {this._activeRlmChildRuns.set(run.id, run);this._unsettledRlmChildRuns.add(run);const emitChildUpdate = () => {- this._emit({ type: "rlm_child_update", child: this._rlmChildSnapshotForRun(run) });+ const child = this._rlmChildSnapshotForRun(run);+ const serialized = JSON.stringify(child);+ if (serialized === run.lastEmittedUpdate) return;+ run.lastEmittedUpdate = serialized;+ this._emit({ type: "rlm_child_update", child });};run.emitUpdate = emitChildUpdate;emitChildUpdate();diff --git a/packages/coding-agent/test/agent-session-recursion.test.ts b/packages/coding-agent/test/agent-session-recursion.test.tsindex d492e1bbc4..579ad3fc5a 100644--- a/packages/coding-agent/test/agent-session-recursion.test.ts+++ b/packages/coding-agent/test/agent-session-recursion.test.ts@@ -102,6 +102,8 @@ interface InspectableRlmRun {settled: boolean;error?: string;abandonedForQuiescence?: boolean;+ activity?: { kind: string };+ emitUpdate?: () => void;publication?: { promise: Promise<void>; resolve(): void; reject(error: Error): void };settlement?: { promise: Promise<void>; resolve(): void; reject(error: Error): void };detachedDeletion?: Awaited<ReturnType<AgentSession["listRlmSubagents"]>>["subagents"][number];@@ -2374,6 +2376,44 @@ describe("AgentSession rlm recursion", () => {await waitFor(() => rootRun.status === "done");});+ it("suppresses repeated child updates whose snapshot did not change", async () => {+ let releaseChild: () => void = () => {};+ const release = new Promise<void>((resolve) => {+ releaseChild = resolve;+ });+ let childStarted = false;+ const root = createSession({+ streamFn: (_model, context) => {+ const text = userText(context);+ const stream = createAssistantMessageEventStream();+ childStarted = true;+ void release.then(() => {+ stream.push({ type: "done", reason: "stop", message: assistantMessage(`child answer: ${text}`) });+ });+ return stream;+ },+ });+ let updates = 0;+ root.subscribe((event) => {+ if (event.type === "rlm_child_update") updates += 1;+ });++ await root.runRlmChild("slow shard");+ await waitFor(() => childStarted);+ const run = [...(root as unknown as InspectableRlmSession)._activeRlmChildRuns.values()][0];+ if (!run?.emitUpdate || !run.session) throw new Error("Missing child run emit");+ await waitFor(() => run.activity?.kind === "waiting");+ const before = updates;+ run.emitUpdate();+ run.emitUpdate();+ expect(updates).toBe(before);+ run.session.setCurrentRecap("changed recap");+ await waitFor(() => updates === before + 1);++ releaseChild();+ await waitFor(() => run.status === "done");+ });+it("runs a child agent without requiring ripgrep", async () => {const streamFn = vi.fn((_model, context: Context) => streamAnswer(`child answer: ${userText(context)}`));const root = createSession({ streamFn });