Skip to content
Open
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
25 changes: 25 additions & 0 deletions apps/web/src/components/ChatView.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,31 @@ describe("deriveThreadPendingBackgroundTasks", () => {
},
);

it("keeps a live command with a separate native task id out of the background list", () => {
expect(
deriveThreadPendingBackgroundTasks(
projection({
runs: [run(1, "completed"), run(2, "running")],
thread: { ...base.thread, activeProviderThreadId: "pt" },
providerThreads: [
{
id: "pt",
pendingBackgroundTasks: [
{
taskId: "session/task-2",
nativeItemId: "call-2",
kind: "command",
awaited: true,
},
],
},
],
turnItems: [item(2, "command_execution", "call-2", "pnpm test")],
}),
),
).toEqual([]);
});

it("does not list a live run's child from the provider roster as background", () => {
// The roster is not run-tied; Muse keys it by the child session id its rows carry.
expect(
Expand Down
6 changes: 5 additions & 1 deletion apps/web/src/components/ChatView.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,7 @@ export function deriveThreadPendingBackgroundTasks(projection: ThreadStructure |
const foregroundTaskIds = new Set<string>();
for (const item of projection.turnItems) {
if (item.runId === null || !liveRunIds.has(item.runId)) continue;
foregroundTaskIds.add(item.id);
if (item.nativeItemRef?.nativeId) foregroundTaskIds.add(item.nativeItemRef.nativeId);
}
const latestRun =
Expand All @@ -1605,7 +1606,10 @@ export function deriveThreadPendingBackgroundTasks(projection: ThreadStructure |
providerThreads: projection.providerThreads.map((thread) => ({
...thread,
pendingBackgroundTasks: thread.pendingBackgroundTasks?.filter(
(task) => !foregroundTaskIds.has(task.taskId),
(task) =>
!foregroundTaskIds.has(task.taskId) &&
(task.nativeItemId === undefined || !foregroundTaskIds.has(task.nativeItemId)) &&
(task.itemId === undefined || !foregroundTaskIds.has(task.itemId)),
),
})),
turnItems: projection.turnItems.filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ it("opens full command details for short labels and keeps pending tasks current"
description?: string,
status: "running" | "completed" = "completed",
explicitItem = true,
nativeItemId?: string,
) => (
<ThreadNow
attention={null}
Expand All @@ -47,7 +48,8 @@ it("opens full command details for short labels and keeps pending tasks current"
threadId: ThreadId.make("thread"),
tasks: [
{
taskId: "native-task",
taskId: nativeItemId ? "session/task-9" : "native-task",
nativeItemId,
itemId: explicitItem ? TurnItemId.make("bash-1") : undefined,
kind: "command",
description,
Expand Down Expand Up @@ -92,6 +94,10 @@ it("opens full command details for short labels and keeps pending tasks current"
await expect.element(page.getByText("Command output stream")).toBeVisible();
await screen.rerender(view("Native fallback", "completed", false));
await expect.element(page.getByText("Command output stream")).toBeVisible();
await screen.rerender(view("Run tests", "completed", false, "native-task"));
const dialog = page.getByRole("dialog");
await expect.element(dialog.getByRole("heading", { name: "Run tests" })).toBeVisible();
await expect.element(dialog.getByText("Command output stream")).toBeVisible();
await page.getByRole("button", { name: "Close", exact: true }).click();
await expect.element(page.getByRole("dialog")).not.toBeInTheDocument();
});
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/components/chat/BackgroundWorkDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export function BackgroundWorkDetails(props: {
{props.tasks.map((task) => {
const item = props.turnItems.findLast((candidate) =>
task.itemId === undefined
? (candidate.nativeItemRef?.nativeId || candidate.id) === task.taskId
? (candidate.nativeItemRef?.nativeId || candidate.id) ===
(task.nativeItemId ?? task.taskId)
: candidate.id === task.itemId,
);
const command =
Expand Down
60 changes: 34 additions & 26 deletions packages/shared/src/orchestrationV2PendingBackgroundWork.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,32 +177,40 @@ describe("derivePendingBackgroundWork", () => {
expect(tasks).toEqual([{ taskId: "cmd-1", description: "npm test", kind: "command" }]);
});

it("dedupes roster entries against turn items by native task id", () => {
const tasks = derivePendingBackgroundWork({
latestRun: { id: "run-1" as never, ordinal: 1, status: "completed" },
providerThreads: [
{
id: "pt-1" as never,
pendingBackgroundTasks: [
{ taskId: "task-9", description: "Agent review", kind: "background_task" },
],
},
],
turnItems: [
{
id: "item-sub" as never,
type: "subagent",
status: "running",
title: "Agent review",
nativeItemRef: { nativeId: "task-9" },
prompt: "review the plan",
},
],
});
expect(tasks).toEqual([
{ taskId: "task-9", description: "Agent review", kind: "background_task" },
]);
});
it.each([
{
identity: "matching task ID",
runStatus: "completed",
task: { taskId: "task-9", description: "Agent review", kind: "background_task" },
item: { type: "subagent", nativeItemRef: { nativeId: "task-9" }, prompt: "review the plan" },
},
{
identity: "distinct native tool call ID",
runStatus: "failed",
task: {
taskId: "session/task-9",
nativeItemId: "call-9",
description: "Verify",
kind: "command",
awaited: true,
},
item: {
type: "command_execution",
nativeItemRef: { nativeId: "call-9" },
input: "pnpm test",
},
},
] as const)(
"retains the roster entry for a running turn item with a $identity",
({ runStatus, task, item }) => {
const tasks = derivePendingBackgroundWork({
latestRun: { id: "run-1" as never, ordinal: 1, status: runStatus },
providerThreads: [{ id: "pt-1" as never, pendingBackgroundTasks: [task] }],
turnItems: [{ ...item, id: "item-9", status: "running", title: task.description }],
});
expect(tasks).toEqual([task]);
},
);

it("excludes Grok persistent monitors", () => {
const tasks = derivePendingBackgroundWork({
Expand Down
5 changes: 4 additions & 1 deletion packages/shared/src/orchestrationV2PendingBackgroundWork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ export function derivePendingBackgroundWork(input: {
}

const byTaskId = new Map<string, PendingBackgroundWorkTask>();
const rosterItemIds = new Set<string>();

const providerThreads =
input.activeProviderThreadId === undefined || input.activeProviderThreadId === null
Expand All @@ -296,6 +297,8 @@ export function derivePendingBackgroundWork(input: {
if (task.taskId.length === 0 || byTaskId.has(task.taskId)) {
continue;
}
if (task.nativeItemId !== undefined) rosterItemIds.add(task.nativeItemId);
if (task.itemId !== undefined) rosterItemIds.add(task.itemId);
const { description: rawDescription, ...named } = task;
const description = rawDescription?.trim();
byTaskId.set(task.taskId, {
Expand All @@ -310,7 +313,7 @@ export function derivePendingBackgroundWork(input: {

for (const item of pendingBackgroundTurnItems(input)) {
const taskId = nativeTaskIdFromTurnItem(item);
if (byTaskId.has(taskId)) {
if (byTaskId.has(taskId) || rosterItemIds.has(taskId) || rosterItemIds.has(item.id)) {
continue;
}

Expand Down
Loading