Skip to content

Commit 9219d1c

Browse files
docs: show subagent coordination before and after
1 parent ab6007c commit 9219d1c

5 files changed

Lines changed: 29 additions & 3 deletions

File tree

52.2 KB
Loading
2.29 MB
Binary file not shown.
47.5 KB
Loading

‎packages/client-runtime/src/state/threadCommunication.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,28 @@ it("reports a completed run that published nothing to the user", () => {
108108
).toBe(false);
109109
expect(finished([row({ type: "command_execution", input: "ls" })])).toBe(false);
110110
expect(finished([row({ type: "assistant_message", text: " " })])).toBe(false);
111+
expect(
112+
finished([
113+
row({ type: "user_message", runId: "run:request", communication: route("user.in") }),
114+
row({ type: "assistant_message", runId: "run:request", communication: route("user.out") }),
115+
row({
116+
type: "notification",
117+
summary: "Coordination activity",
118+
communication: route("internal.out"),
119+
}),
120+
]),
121+
).toBe(false);
122+
expect(
123+
finished([
124+
row({ type: "assistant_message", runId: "run:request", communication: route("user.out") }),
125+
row({ type: "user_message", runId: "run:next", communication: route("user.in") }),
126+
row({
127+
type: "notification",
128+
summary: "Coordination activity",
129+
communication: route("internal.out"),
130+
}),
131+
]),
132+
).toBe(true);
111133
expect(
112134
runFinishedWithoutUserUpdate(
113135
[row({ type: "assistant_message", text: "a" })],

‎packages/client-runtime/src/state/threadCommunication.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,13 @@ export function runFinishedWithoutUserUpdate(
143143
): boolean {
144144
if (runId == null || status !== "completed") return false;
145145
let hasUnpublishedOutput = false;
146-
for (const { item } of rows) {
147-
if (item.runId !== runId) continue;
146+
let latestHumanInput = -1;
147+
let latestPublishedOutput = -1;
148+
for (const [index, { item }] of rows.entries()) {
148149
const port = item.communication?.route.port;
150+
if (port === "user.in") latestHumanInput = index;
151+
if (port === "user.out") latestPublishedOutput = index;
152+
if (item.runId !== runId) continue;
149153
if (port === "user.out") return false;
150154
if (item.type === "notification" && port === "internal.out") {
151155
hasUnpublishedOutput = true;
@@ -154,7 +158,7 @@ export function runFinishedWithoutUserUpdate(
154158
if (item.type !== "assistant_message") continue;
155159
if (port === "internal.out" || item.text.trim() !== "") hasUnpublishedOutput = true;
156160
}
157-
return hasUnpublishedOutput;
161+
return hasUnpublishedOutput && latestPublishedOutput <= latestHumanInput;
158162
}
159163

160164
export const FINISHED_WITHOUT_USER_UPDATE_NOTICE =

0 commit comments

Comments
 (0)