Skip to content

Commit 023bb60

Browse files
committed
fix(web): a thread that left a shell running shows its unseen completion
1 parent bf7121d commit 023bb60

8 files changed

Lines changed: 208 additions & 37 deletions

File tree

‎apps/mobile/src/features/threads/threadListV2.test.ts‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { presentThreadShell } from "@t3tools/client-runtime/state/models";
2+
import * as DateTime from "effect/DateTime";
13
import { planPinnedMove } from "@t3tools/client-runtime/state/thread-sort";
24
import {
35
createPendingThreadOrder,
@@ -23,7 +25,7 @@ import {
2325
import { describe, expect, it, vi } from "vite-plus/test";
2426

2527
import type { PendingNewTask } from "../../state/use-pending-new-tasks";
26-
import { makeThreadShellFixture } from "../../test-fixtures";
28+
import { makeRawThreadShell, makeThreadShellFixture } from "../../test-fixtures";
2729
import { threadJumpTarget } from "../keyboard/threadKeyboardShortcuts";
2830
import {
2931
buildThreadListV2Items,
@@ -36,6 +38,7 @@ import {
3638
resolveThreadListV2SwipeActions,
3739
sortThreadsForListV2,
3840
threadListV2ListItemsAreEqual,
41+
threadHasUnseenCompletion,
3942
type ThreadListV2ListItem,
4043
} from "./threadListV2";
4144

@@ -160,9 +163,7 @@ describe("resolveThreadListV2Status", () => {
160163
makeThread({
161164
id: ThreadId.make("t"),
162165
title: "t",
163-
pendingBackgroundTasks: [
164-
{ taskId: "bg-1", description: "Run Codex review", kind: "command" },
165-
],
166+
pendingBackgroundTasks: [{ taskId: "bg-1", description: "Watch build", kind: "monitor" }],
166167
runtime: {
167168
status: "idle",
168169
activeRunId: null,
@@ -176,6 +177,28 @@ describe("resolveThreadListV2Status", () => {
176177
).toBe("waiting");
177178
});
178179

180+
it.each([
181+
{ kind: "command", status: "ready" },
182+
{ kind: "monitor", status: "waiting" },
183+
] as const)(
184+
"presents an unseen completion with a $kind roster as $status",
185+
({ kind, status }) => {
186+
const thread = presentThreadShell(
187+
environmentId,
188+
makeRawThreadShell({
189+
latestRunId: RunId.make("run-background-completion"),
190+
status: "completed",
191+
latestRunCompletedAt: DateTime.makeUnsafe(NOW),
192+
lastVisitedAt: DateTime.makeUnsafe("2026-06-01T23:59:00.000Z"),
193+
pendingBackgroundTasks: [{ taskId: "background-work", kind }],
194+
}),
195+
);
196+
197+
expect(resolveThreadListV2Status(thread)).toBe(status);
198+
expect(threadHasUnseenCompletion(thread)).toBe(true);
199+
},
200+
);
201+
179202
it("resolves ready for quiescent threads", () => {
180203
expect(resolveThreadListV2Status(makeThread({ id: ThreadId.make("t"), title: "t" }))).toBe(
181204
"ready",

‎apps/mobile/src/features/threads/threadListV2.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ export function resolveThreadListV2ProviderDrivers(
6262
* failures. Ready is the unlabeled resting state; waiting (runtime status "idle") is the agent
6363
* parked on open background tasks, grey like working rather than a false Done.
6464
* The orchestrator v2 presentation bridge parks runtime at idle when the
65-
* post-settlement background roster is nonempty.
65+
* post-settlement background roster holds the run's completion (subagents,
66+
* monitors); commands left running, such as a dev server, read as ready.
6667
*/
6768
export type ThreadListV2Status =
6869
| "approval"

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { presentThreadShell } from "@t3tools/client-runtime/state/models";
2+
import * as DateTime from "effect/DateTime";
13
import { deriveActiveWorkStartedAt } from "../session-logic.ts";
24
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
35
import { defaultAnimateLayoutChanges, type AnimateLayoutChanges } from "@dnd-kit/sortable";
@@ -1254,7 +1256,7 @@ describe("resolveThreadStatusPill", () => {
12541256
resolveThreadStatusPill({
12551257
thread: {
12561258
...baseThread,
1257-
pendingBackgroundTasks: [{ taskId: "bg-1", description: "sleep 20", kind: "command" }],
1259+
pendingBackgroundTasks: [{ taskId: "bg-1", description: "Watch build", kind: "monitor" }],
12581260
runtime: {
12591261
...baseThread.runtime,
12601262
status: "idle",
@@ -2053,6 +2055,39 @@ describe("navigation after parking a thread", () => {
20532055
);
20542056
});
20552057

2058+
describe("unseen completion with background work", () => {
2059+
it.each([
2060+
{ kind: "command", status: "ready", topStatus: "done", receded: false, pill: "Completed" },
2061+
{ kind: "monitor", status: "waiting", topStatus: "waiting", receded: true, pill: "Waiting" },
2062+
] as const)("presents a completed thread with a $kind roster", (expected) => {
2063+
const thread = presentThreadShell(localEnvironmentId, {
2064+
...makeThreadFixture().source,
2065+
latestRunId: RunId.make("run-background-completion"),
2066+
status: "completed",
2067+
latestRunCompletedAt: DateTime.makeUnsafe("2026-06-20T01:00:00.000Z"),
2068+
lastVisitedAt: DateTime.makeUnsafe("2026-06-20T00:59:00.000Z"),
2069+
pendingBackgroundTasks: [{ taskId: "background-work", kind: expected.kind }],
2070+
});
2071+
const status = resolveSidebarThreadStatus(thread);
2072+
const isUnread = hasUnseenCompletion(thread);
2073+
2074+
expect(isUnread).toBe(true);
2075+
expect(status).toBe(expected.status);
2076+
expect(resolveSidebarV2TopStatus({ status, isUnread, isWoke: false })).toBe(expected.topStatus);
2077+
expect(
2078+
shouldRecedeSidebarThread({
2079+
status,
2080+
isUnread,
2081+
isWoke: false,
2082+
isActive: false,
2083+
isSelected: false,
2084+
}),
2085+
).toBe(expected.receded);
2086+
expect(isSidebarThreadWorking(thread)).toBe(expected.receded);
2087+
expect(resolveThreadStatusPill({ thread })).toMatchObject({ label: expected.pill });
2088+
});
2089+
});
2090+
20562091
describe("Working shelf (beta)", () => {
20572092
const runtime = {
20582093
status: "running" as const,
@@ -2062,7 +2097,7 @@ describe("Working shelf (beta)", () => {
20622097
lastError: null,
20632098
updatedAt: "2026-03-09T10:00:00.000Z",
20642099
};
2065-
const backgroundTask = { taskId: "bg-1", description: "sleep 20", kind: "command" as const };
2100+
const backgroundTask = { taskId: "bg-1", description: "Watch build", kind: "monitor" as const };
20662101
const idle = {
20672102
hasActionableProposedPlan: false,
20682103
hasPendingApprovals: false,

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { resolveThreadWorkingStartedAt } from "@t3tools/client-runtime/state/models";
2+
import { backgroundWorkHoldsCompletion } from "@t3tools/shared/orchestrationV2PendingBackgroundWork";
23
import { threadPullRequestSearchTerms } from "@t3tools/shared/threadPullRequests";
34
import * as React from "react";
45
import {
@@ -910,9 +911,10 @@ export function resolveThreadRowClassName(input: {
910911
// (approval), "in motion" (working), and "broken" (failed). Ready is the
911912
// unlabeled resting state — the agent stopped and is waiting on the user,
912913
// whether it finished, asked a question, or proposed a plan. Waiting
913-
// (runtime status "idle") is the agent stopped with background tasks still
914-
// open: not the user's turn yet, so it renders grey like working, not as a
915-
// false Done.
914+
// (runtime status "idle") is the agent stopped with background work that will
915+
// wake it (subagents, monitors): not the user's turn yet, so it renders grey
916+
// like working, not as a false Done. Commands it left running, such as a dev
917+
// server, do not hold the thread; it reads as ready.
916918
// Unread completion is tracked separately: it describes whether a ready
917919
// thread needs attention, not what the thread is currently doing.
918920
export type SidebarThreadStatus =
@@ -1007,8 +1009,8 @@ export function shouldShowSidebarV2Duration(status: SidebarThreadStatus): boolea
10071009
}
10081010

10091011
/** Working beta: threads busy with work that does not need the user fold into
1010-
the Working shelf: a running run, or one stopped with background tasks
1011-
still open. Approvals, questions, plan prompts, and failures stay in the
1012+
the Working shelf: a running run, or one stopped with background work
1013+
that will wake it. Approvals, questions, plan prompts, and failures stay in the
10121014
inbox. */
10131015
export function isSidebarThreadWorking(thread: ThreadStatusInput): boolean {
10141016
const status = resolveSidebarThreadStatus(thread);
@@ -1210,7 +1212,7 @@ export function resolveThreadStatusPill(input: {
12101212
};
12111213
}
12121214

1213-
if ((thread.pendingBackgroundTasks?.length ?? 0) > 0) {
1215+
if (backgroundWorkHoldsCompletion(thread.pendingBackgroundTasks ?? [])) {
12141216
return {
12151217
label: "Waiting",
12161218
colorClass: "text-sidebar-muted-foreground",

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { presentThreadShell } from "@t3tools/client-runtime/state/models";
22
import { useAtomValue } from "@effect/atom-react";
33
import { useNavigate, useParams } from "@tanstack/react-router";
44
import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
5-
import { backgroundWorkHoldsCompletion } from "@t3tools/shared/orchestrationV2PendingBackgroundWork";
65
import * as Option from "effect/Option";
76
import {
87
CircleAlertIcon,
@@ -126,12 +125,11 @@ function EnvironmentNotifications({
126125
? `${thread.latestRun?.runId ?? ""}:${status}`
127126
: null;
128127
const completedAt = Date.parse(thread.latestRun?.completedAt ?? "");
129-
// Waiting only on commands (a dev server) is done; subagents and monitors wake the agent.
130-
const settled =
131-
status === "ready" ||
132-
(status === "waiting" && !backgroundWorkHoldsCompletion(thread.pendingBackgroundTasks));
128+
// Commands left running (a dev server) read as ready; subagents and monitors wait.
133129
const completion =
134-
settled && thread.latestRun?.status === "completed" && Number.isFinite(completedAt)
130+
status === "ready" &&
131+
thread.latestRun?.status === "completed" &&
132+
Number.isFinite(completedAt)
135133
? completedAt
136134
: (prior?.completion ?? null);
137135
next.set(thread.id, { attention, completion });

0 commit comments

Comments
 (0)