Skip to content

Commit 12d0972

Browse files
fix(web): keep notifying id-less subagent requests
Subagent and side-chat requests carry no request id, so their attention key is the same for every such request in a run. Remembering keys seen in the stretch silenced a second subagent approval after the thread went back to its own question. The seen-in-stretch suppression now applies only to attention with a request id; id-less attention notifies whenever the key changes, as before. AI-assisted; verified with the tests and tools listed above.
1 parent 1f1e60e commit 12d0972

3 files changed

Lines changed: 39 additions & 14 deletions

File tree

‎apps/web/src/components/ThreadNotificationCoordinator.logic.test.ts‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import {
77

88
const working: ThreadNotificationObservation = {
99
attention: null,
10+
requestId: null,
1011
settled: false,
1112
completedAt: null,
1213
};
1314
const completed = (at: number): ThreadNotificationObservation => ({
1415
attention: null,
16+
requestId: null,
1517
settled: true,
1618
completedAt: at,
1719
});
@@ -57,19 +59,32 @@ describe("createThreadNotificationGate", () => {
5759
it("notifies each attention once per stretch and still notifies the subsequent completion", () => {
5860
const { notify, observe } = harness();
5961
observe(working);
60-
const attention = { attention: "run-1:approval:a", settled: false, completedAt: null };
62+
const attention = {
63+
attention: "run-1:approval:a",
64+
requestId: "a",
65+
settled: false,
66+
completedAt: null,
67+
};
6168
observe(attention);
6269
expect(notify.mock.calls).toEqual([["thread", "input"]]);
6370
observe({ ...attention });
6471
expect(notify).toHaveBeenCalledTimes(1);
65-
observe({ ...attention, attention: "run-1:approval:b" });
72+
observe({ ...attention, attention: "run-1:approval:b", requestId: "b" });
6673
observe(attention);
6774
expect(notify).toHaveBeenCalledTimes(2);
6875
observe(working);
6976
observe(attention);
77+
expect(notify).toHaveBeenCalledTimes(3);
78+
const subagent = { ...attention, attention: "run-1:approval:", requestId: null };
79+
observe(subagent);
80+
observe(attention);
81+
observe(subagent);
82+
expect(notify).toHaveBeenCalledTimes(5);
7083
observe(working);
7184
observe(completed(1));
7285
expect(notify.mock.calls).toEqual([
86+
["thread", "input"],
87+
["thread", "input"],
7388
["thread", "input"],
7489
["thread", "input"],
7590
["thread", "input"],
@@ -81,7 +96,7 @@ describe("createThreadNotificationGate", () => {
8196
const { notify, observe } = harness();
8297
observe(working);
8398
observe(completed(1));
84-
observe({ attention: "run-1:limited", settled: false, completedAt: null });
99+
observe({ attention: "run-1:limited", requestId: null, settled: false, completedAt: null });
85100
observe(completed(1));
86101
expect(notify.mock.calls).toEqual([
87102
["thread", "completion"],

‎apps/web/src/components/ThreadNotificationCoordinator.logic.ts‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ export type ThreadNotificationKind = "input" | "completion";
33
export interface ThreadNotificationObservation {
44
/** Run, status and request key while the thread needs attention, otherwise null. */
55
readonly attention: string | null;
6+
/** The pending request's id, when it has one; null whenever attention is. */
7+
readonly requestId: string | null;
68
/** The thread is idle and its latest run completed. */
79
readonly settled: boolean;
810
/** When the latest run completed, if it did. */
@@ -17,17 +19,22 @@ export function createThreadNotificationGate<Key>(
1719
const skip = (key: Key, at: number | null) => {
1820
if (at !== null && at > (handled.get(key) ?? -Infinity)) handled.set(key, at);
1921
};
20-
// Attention keys seen since the thread last stopped needing attention.
22+
// Attention keys with a request id seen since the thread last stopped needing attention.
2123
const attended = new Map<Key, Set<string>>();
22-
const attend = (key: Key, attention: string | null): boolean => {
23-
if (attention === null) {
24+
const attend = (
25+
key: Key,
26+
prior: ThreadNotificationObservation | undefined,
27+
next: ThreadNotificationObservation,
28+
): boolean => {
29+
if (next.attention === null) {
2430
attended.delete(key);
2531
return false;
2632
}
33+
if (next.requestId === null) return next.attention !== prior?.attention;
2734
const seen = attended.get(key);
28-
if (seen?.has(attention)) return false;
29-
if (seen) seen.add(attention);
30-
else attended.set(key, new Set([attention]));
35+
if (seen?.has(next.attention)) return false;
36+
if (seen) seen.add(next.attention);
37+
else attended.set(key, new Set([next.attention]));
3138
return true;
3239
};
3340
return {
@@ -39,7 +46,7 @@ export function createThreadNotificationGate<Key>(
3946
): void {
4047
// The first sighting, archived threads, and stopped or silent runs never notify completion.
4148
if (!prior || options.archived || options.quiet) skip(key, next.completedAt);
42-
const fresh = attend(key, next.attention);
49+
const fresh = attend(key, prior, next);
4350
if (!prior || options.archived) return;
4451
if (fresh) {
4552
notify(key, "input");

‎apps/web/src/components/ThreadNotificationCoordinator.tsx‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,16 @@ export function startThreadNotifications(
253253
const thread = presentThreadShell(environmentId, rawThread, subagentRequest);
254254
let status = resolveSidebarThreadStatus(thread);
255255
if (status === "ready" && thread.latestRun?.status === "failed") status = "failed";
256-
const attention =
256+
const needsAttention =
257257
status === "input" ||
258258
status === "request" ||
259259
status === "approval" ||
260260
status === "failed" ||
261-
status === "limited"
262-
? `${thread.latestRun?.runId ?? ""}:${status}:${resolveBackgroundThreadRequest(thread).requestId ?? ""}`
263-
: null;
261+
status === "limited";
262+
const requestId = needsAttention ? resolveBackgroundThreadRequest(thread).requestId : null;
263+
const attention = needsAttention
264+
? `${thread.latestRun?.runId ?? ""}:${status}:${requestId ?? ""}`
265+
: null;
264266
const completedAt = Date.parse(thread.latestRun?.completedAt ?? "");
265267
const settled = status === "ready" && thread.latestRun?.status === "completed";
266268
const state = {
@@ -269,6 +271,7 @@ export function startThreadNotifications(
269271
thread,
270272
status,
271273
attention,
274+
requestId,
272275
settled,
273276
completedAt: settled && Number.isFinite(completedAt) ? completedAt : null,
274277
};

0 commit comments

Comments
 (0)