The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 13:30 UTC
fix(web): opening a project or deleting the open thread skips delegated tasks (#30428)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
spoukyii committed
Nov 14, 2026 at 15:22 UTC
304dc136482408106cca572123d5477791c3f367
7 files changed
+52
-9
apps/web/src/components/CommandPalette.browser.test.tsx
+14
-2
@@ -1,3 +1,4 @@
1
+import { threadKey } from "@t3tools/client-runtime/state/entities";
2
import { EnvironmentId, ProjectId, ThreadId } from "@t3tools/contracts";
3
import { describe, expect, it, vi } from "vite-plus/test";
4
import { page, userEvent } from "vite-plus/test/browser";
@@ -14,20 +15,23 @@ import { CommandPalette } from "./CommandPalette";
15
const entities = vi.hoisted(() => ({
16
projects: [] as ReadonlyArray<Project>,
17
threads: [] as ReadonlyArray<Thread>,
18
+ delegatedUnderParent: new Set<string>() as ReadonlySet<string>,
19
}));
20
vi.mock("../state/entities", async (original) => ({
21
...(await original<typeof import("../state/entities")>()),
22
useProjects: () => entities.projects,
23
useVisibleThreadShells: () => entities.threads,
24
+ useDelegatedUnderParent: () => entities.delegatedUnderParent,
25
}));
26
24
-function setup(state: { projects?: ReadonlyArray<Project>; threads?: ReadonlyArray<Thread> } = {}) {
27
+function setup(state: Partial<typeof entities> = {}) {
28
// Earlier browser test files share this origin's localStorage; a remembered project
29
// that is not listed here hides the default "New thread in <project>" row.
30
removeLocalStorageItem(LAST_USED_PROJECT_STORAGE_KEY);
31
useCommandPaletteStore.setState(useCommandPaletteStore.getInitialState(), true);
32
entities.projects = state.projects ?? [];
33
entities.threads = state.threads ?? [];
34
+ entities.delegatedUnderParent = state.delegatedUnderParent ?? new Set();
35
}
36
37
describe("CommandPalette open intents", () => {
@@ -134,11 +138,13 @@ describe("CommandPalette open intents", () => {
138
await expect.element(input).toHaveValue("acme");
139
});
140
137
- it("opens a searched project's latest listed thread, not a newer subagent", async () => {
141
+ it("opens a searched project's latest listed thread, not a newer subagent or delegated task", async () => {
142
const environmentId = EnvironmentId.make("local");
143
const projectId = ProjectId.make("acme");
144
const parentId = ThreadId.make("parent");
145
+ const delegatedId = ThreadId.make("delegated");
146
setup({
147
+ delegatedUnderParent: new Set([threadKey({ environmentId, threadId: delegatedId })]),
148
projects: [
149
{
150
id: projectId,
@@ -170,6 +176,12 @@ describe("CommandPalette open intents", () => {
176
relationshipToParent: "subagent",
177
},
178
}),
179
+ makeThreadFixture({
180
+ id: delegatedId,
181
+ environmentId,
182
+ projectId,
183
+ latestUserMessageAt: "2026-03-04T00:00:00.000Z",
184
+ }),
185
],
186
});
187
await using screen = await render(<CommandPalette>{null}</CommandPalette>);
apps/web/src/components/CommandPalette.tsx
+12
-4
@@ -138,6 +138,7 @@ import {
138
} from "../state/environments";
139
import {
140
useAnyEnvironmentHiding,
141
+ useDelegatedUnderParent,
142
useHiddenThreadKeys,
143
useEnvironmentThreadRefs,
144
useProjects,
@@ -145,7 +146,7 @@ import {
146
useVisibleThreadShells,
147
waitForProject,
148
} from "../state/entities";
148
-import { visibleLinkedThreads } from "@t3tools/client-runtime/state/threads";
149
+import { isShownUnderParent, visibleLinkedThreads } from "@t3tools/client-runtime/state/threads";
150
import {
151
resolveThreadActionProjectRef,
152
startNewThreadFromContext,
@@ -229,7 +230,6 @@ import {
230
type SearchOverlayMode,
231
} from "./CommandPalette.logic";
232
import { resolveEnvironmentOptionLabel } from "./BranchToolbar.logic";
232
-import { isSidebarHiddenThread } from "./Sidebar.logic";
233
import { CommandPaletteContent, type PendingInputSelection } from "./CommandPaletteContent";
234
import {
235
selectCommandPaletteClientSettings,
@@ -516,8 +516,16 @@ function OpenCommandPaletteDialog(props: {
516
if (activeThreadReferenceCopyTarget === null) return;
517
await copyThreadReference(activeThreadReferenceCopyTarget);
518
};
519
- // Side chats and subagents open inside their parent, so opening a project never lands on one.
520
- const threads = useVisibleThreadShells().filter((thread) => !isSidebarHiddenThread(thread));
519
+ // Threads the sidebar shows under their parent open there, so opening a project never lands on one.
520
+ const delegatedUnderParent = useDelegatedUnderParent();
521
+ const threads = useVisibleThreadShells().filter(
522
+ (thread) =>
523
+ !isShownUnderParent(
524
+ { environmentId: thread.environmentId, threadId: thread.id },
525
+ thread.lineage,
526
+ delegatedUnderParent,
527
+ ),
528
+ );
529
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
530
const providersByEnvironment = useEnvironmentProviders();
531
const { changeThemeItem, changeAppearanceItem, themeEditorItem } = useCommandPaletteThemeItems();
apps/web/src/components/Sidebar.logic.test.ts
+9
@@ -1,4 +1,5 @@
1
import { presentThreadShell } from "@t3tools/client-runtime/state/models";
2
+import { threadKey } from "@t3tools/client-runtime/state/entities";
3
import { isThreadWorking as isSidebarThreadWorking } from "@t3tools/client-runtime/state/thread-inbox";
4
import * as DateTime from "effect/DateTime";
5
import { deriveActiveWorkStartedAt } from "../session-logic.ts";
@@ -678,6 +679,7 @@ describe("getFallbackThreadIdAfterDelete", () => {
679
deletedThreadIds: new Set([ThreadId.make("thread-active"), ThreadId.make("thread-newest")]),
680
sortOrder: "created_at",
681
now: "2026-03-09T10:10:00.000Z",
682
+ delegatedUnderParent: new Set(),
683
});
684
685
expect(fallbackThreadId).toBe(ThreadId.make("thread-next"));
@@ -688,6 +690,7 @@ describe("getFallbackThreadIdAfterDelete", () => {
690
"snoozed",
691
{ snoozedUntil: "2099-01-01T00:00:00.000Z", snoozedAt: "2026-03-09T10:06:00.000Z" },
692
],
693
+ ["delegated", { id: ThreadId.make("thread-delegated") }],
694
["settled", { settledOverride: "settled", settledAt: "2026-03-09T10:06:00.000Z" }],
695
[
696
"side chat",
@@ -733,6 +736,12 @@ describe("getFallbackThreadIdAfterDelete", () => {
736
deletedThreadId: ThreadId.make("thread-active"),
737
sortOrder: "created_at",
738
now: "2026-03-09T10:10:00.000Z",
739
+ delegatedUnderParent: new Set([
740
+ threadKey({
741
+ environmentId: localEnvironmentId,
742
+ threadId: ThreadId.make("thread-delegated"),
743
+ }),
744
+ ]),
745
});
746
747
expect(fallbackThreadId).toBe(ThreadId.make("thread-visible"));
apps/web/src/components/Sidebar.logic.ts
+10
-3
@@ -1319,15 +1319,18 @@ export function getFallbackThreadIdAfterDelete<
1319
"id" | "projectId" | "createdAt" | "updatedAt" | "settledOverride" | "lineage"
1320
> &
1321
ThreadSortInput &
1322
- ThreadSnoozeShell,
1322
+ ThreadSnoozeShell &
1323
+ Pick<Thread, "environmentId">,
1324
>(input: {
1325
threads: readonly T[];
1326
deletedThreadId: T["id"];
1327
sortOrder: SidebarThreadSortOrder;
1328
now: string;
1329
deletedThreadIds?: ReadonlySet<T["id"]>;
1330
+ delegatedUnderParent: ReadonlySet<string>;
1331
}): T["id"] | null {
1330
- const { deletedThreadId, deletedThreadIds, sortOrder, now, threads } = input;
1332
+ const { deletedThreadId, deletedThreadIds, sortOrder, now, threads, delegatedUnderParent } =
1333
+ input;
1334
const deletedThread = threads.find((thread) => thread.id === deletedThreadId);
1335
if (!deletedThread) {
1336
return null;
@@ -1342,7 +1345,11 @@ export function getFallbackThreadIdAfterDelete<
1345
!deletedThreadIds?.has(thread.id) &&
1346
thread.settledOverride !== "settled" &&
1347
!effectiveSnoozed(thread, { now }) &&
1345
- !isSidebarHiddenThread(thread),
1348
+ !isShownUnderParent(
1349
+ { environmentId: thread.environmentId, threadId: thread.id },
1350
+ thread.lineage,
1351
+ delegatedUnderParent,
1352
+ ),
1353
),
1354
sortOrder,
1355
)[0]?.id ?? null
apps/web/src/hooks/useThreadActions.permissions.test.ts
+1
@@ -142,6 +142,7 @@ vi.mock("../state/entities", () => ({
142
.filter((thread) => thread.environmentId === environmentId)
143
.map((thread) => ({ environmentId, threadId: thread.id })),
144
readProject: () => ({ workspaceRoot: "/project" }),
145
+ readDelegatedUnderParent: () => new Set(),
146
}));
147
vi.mock("../components/Sidebar.logic", () => ({
148
getFallbackThreadIdAfterDelete: () => null,
apps/web/src/hooks/useThreadActions.ts
+2
@@ -38,6 +38,7 @@ import { releaseComposerDraftUploads } from "../lib/composerDraftUploads";
38
import { announce } from "../lib/announce";
39
import { readLocalApi } from "../localApi";
40
import {
41
+ readDelegatedUnderParent,
42
readEnvironmentServerConfigLoaded,
43
readEnvironmentSupportsAutoSettleOptOut,
44
readEnvironmentThreadRefs,
@@ -593,6 +594,7 @@ export function useThreadActions() {
594
deletedThreadIds,
595
sortOrder: sidebarThreadSortOrder,
596
now: new Date().toISOString(),
597
+ delegatedUnderParent: readDelegatedUnderParent(),
598
});
599
let navigatedDuringDelete = false;
600
// The missing-thread redirect and the index draft replace this entry; any other history
apps/web/src/state/entities.ts
+4
@@ -385,6 +385,10 @@ export function readThreadShells(): ReadonlyArray<EnvironmentThreadShell> {
385
return appAtomRegistry.get(environmentThreadShells.threadShellsAtom);
386
}
387
388
+export function readDelegatedUnderParent(): ReadonlySet<string> {
389
+ return appAtomRegistry.get(environmentThreadShells.delegatedUnderParentAtom);
390
+}
391
+
392
function shellParentThreadId(
393
thread: Pick<OrchestrationV2ThreadShell, "forkedFrom" | "lineage">,
394
): ThreadId | null {