Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/coding-agent/.changes/relay-hygiene.md
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 6 additions & 1 deletion packages/coding-agent/src/core/agent-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,7 @@ interface RlmChildRun {
completeDeletion?: () => Promise<void>;
reportDeletionCleanupFailure?: (error: unknown) => Promise<void>;
emitUpdate?: () => void;
lastEmittedUpdate?: string;
unsubscribe?: () => void;
}

Expand Down Expand Up @@ -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();
Expand Down
40 changes: 40 additions & 0 deletions packages/coding-agent/test/agent-session-recursion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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 });
Expand Down
Loading