Skip to content

Commit 302c870

Browse files
committed
fix(web): subagent banner stays visible while a follow-up turn runs
Fixes #23827
1 parent ed3f965 commit 302c870

4 files changed

Lines changed: 54 additions & 10 deletions

File tree

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
snapshotComposerSend,
77
withMessageContext,
88
deriveAvailableRevertTurnCounts,
9+
deriveThreadPendingBackgroundTasks,
910
deriveWorkspaceMutationId,
1011
} from "./ChatView.logic";
1112
import { recallCheckoutIsRepo, rememberCheckoutIsRepo } from "./ChatView.logic";
@@ -1214,6 +1215,38 @@ describe("deriveAvailableRevertTurnCounts", () => {
12141215
});
12151216
});
12161217

1218+
describe("deriveThreadPendingBackgroundTasks", () => {
1219+
function projection(subagentRunOrdinal: number) {
1220+
const base = makeThreadProjectionFixture();
1221+
return {
1222+
...base,
1223+
runs: [
1224+
{ id: RunId.make("run-1"), ordinal: 1, status: "completed" },
1225+
{ id: RunId.make("run-2"), ordinal: 2, status: "running" },
1226+
],
1227+
turnItems: [
1228+
{
1229+
id: TurnItemId.make("subagent"),
1230+
runId: RunId.make(`run-${subagentRunOrdinal}`),
1231+
type: "subagent",
1232+
status: "running",
1233+
title: "Review",
1234+
},
1235+
],
1236+
} as unknown as ReturnType<typeof makeThreadProjectionFixture>;
1237+
}
1238+
1239+
it("keeps an earlier turn's subagent while a follow-up turn runs", () => {
1240+
expect(deriveThreadPendingBackgroundTasks(projection(1))).toEqual([
1241+
{ taskId: "subagent", kind: "subagent", description: "Review" },
1242+
]);
1243+
});
1244+
1245+
it("leaves the running turn's own subagents to the timeline", () => {
1246+
expect(deriveThreadPendingBackgroundTasks(projection(2))).toEqual([]);
1247+
});
1248+
});
1249+
12171250
describe("deriveWorkspaceMutationId", () => {
12181251
const item = (id: string, type: string, status: string) =>
12191252
({

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,23 +1680,34 @@ export function presentThreadShellFromProjection(
16801680
};
16811681
}
16821682

1683-
/** Background work the provider still runs after the latest run ended. */
1683+
const UNSETTLED_RUN_STATUSES = new Set(["queued", "preparing", "starting", "running"]);
1684+
1685+
/**
1686+
* Background work the provider still runs after the latest settled run ended. A follow-up turn
1687+
* keeps it listed; work the follow-up itself starts stays in the timeline until it ends.
1688+
*/
16841689
export function deriveThreadPendingBackgroundTasks(projection: ThreadStructure | null) {
16851690
if (projection === null) return [];
1691+
const unsettledRunIds = new Set(
1692+
projection.runs.filter((run) => UNSETTLED_RUN_STATUSES.has(run.status)).map((run) => run.id),
1693+
);
1694+
const runs = projection.runs.filter((run) => !unsettledRunIds.has(run.id));
1695+
const turnItems = projection.turnItems.filter(
1696+
(item) => item.runId === null || !unsettledRunIds.has(item.runId),
1697+
);
16861698
const sessionError =
16871699
projection.providerSessions.findLast(
16881700
(session) => session.providerInstanceId === projection.thread.providerInstanceId,
16891701
)?.lastError ?? null;
16901702
const latestRun =
1691-
usageLimitRunPresentedAsLatest(projection.runs, projection.turnItems, sessionError) ??
1692-
latestUnheldRun(projection.runs);
1703+
usageLimitRunPresentedAsLatest(runs, turnItems, sessionError) ?? latestUnheldRun(runs);
16931704
return [
16941705
...derivePendingBackgroundWork({
16951706
latestRun,
16961707
providerThreads: projection.providerThreads,
1697-
turnItems: projection.turnItems,
1708+
turnItems,
16981709
activeProviderThreadId: projection.thread.activeProviderThreadId,
1699-
runs: projection.runs,
1710+
runs,
17001711
pullRequests: projection.thread.pullRequests,
17011712
}),
17021713
];

‎apps/web/src/components/chat/ThreadActivityBanners.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export function goalBannerItem(input: {
9494
export function backgroundWorkBannerItem(input: {
9595
readonly threadId: ThreadId;
9696
readonly tasks: ReadonlyArray<OrchestrationV2PendingBackgroundTask>;
97+
readonly isWorking: boolean;
9798
readonly stopDisabled: boolean;
9899
readonly stopping: boolean;
99100
readonly onStop: () => Promise<void>;
@@ -145,7 +146,8 @@ export function backgroundWorkBannerItem(input: {
145146
</Fragment>
146147
);
147148
}),
148-
actions: (
149+
// Stop interrupts the whole thread, so during a turn the composer's own Stop owns that.
150+
actions: input.isWorking ? undefined : (
149151
<Button
150152
size="xs"
151153
variant="ghost"

‎apps/web/src/components/chat/useThreadLifecycle.tsx‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,6 @@ export function useThreadLifecycle(input: ThreadLifecycleInput) {
383383
const handleSwitchCheckoutToThreadStable = useStableCallback(() => {
384384
void handleSwitchCheckoutToThread();
385385
});
386-
// The interrupt path also accepts a completed run while its provider still
387-
// has background work.
388-
const activeBackgroundTasks = !isWorking && activeThread ? pendingBackgroundTasks : [];
389386
const [stoppingBackgroundWorkKey, setStoppingBackgroundWorkKey] = useState<string | null>(null);
390387
const isStoppingBackgroundWork =
391388
stoppingBackgroundWorkKey === `${environmentId}:${activeThreadId}`;
@@ -525,7 +522,8 @@ export function useThreadLifecycle(input: ThreadLifecycleInput) {
525522
const backgroundWorkBanner = activeThread
526523
? backgroundWorkBannerItem({
527524
threadId: activeThread.id,
528-
tasks: activeBackgroundTasks,
525+
tasks: pendingBackgroundTasks,
526+
isWorking,
529527
stopDisabled: !canOperateThread || isStoppingBackgroundWork,
530528
stopping: isStoppingBackgroundWork,
531529
onStop: handleStopBackgroundWorkStable,

0 commit comments

Comments
 (0)