From 39d67dbc20ff58ec1591e24f71a7efd4185899f1 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 6 Nov 2026 03:29:32 +0000 Subject: [PATCH 1/4] test(server): subagent and side-chat threads refuse thread.pin (reproduces #31787) Thread lists never show subagents or side chats, yet the orchestrator accepts thread.pin for them, so a pin reports success and the thread never appears. These tests fail on main until the pin is refused; unpin stays allowed as the way out for threads already pinned. Co-Authored-By: Claude Opus 5.5 --- .../src/orchestration-v2/runtimeLayer.test.ts | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/apps/server/src/orchestration-v2/runtimeLayer.test.ts b/apps/server/src/orchestration-v2/runtimeLayer.test.ts index 83f77d0073001..113a470a01622 100644 --- a/apps/server/src/orchestration-v2/runtimeLayer.test.ts +++ b/apps/server/src/orchestration-v2/runtimeLayer.test.ts @@ -2799,6 +2799,77 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => { }), ); + it.effect.each([ + { kind: "subagent", relationshipToParent: "subagent", sideChat: undefined }, + { kind: "side chat", relationshipToParent: "fork", sideChat: true }, + ] as const)( + "refuses to pin a $kind thread, which no thread list shows, but still unpins it", + ({ kind, relationshipToParent, sideChat }) => + Effect.gen(function* () { + const orchestrator = yield* Orchestrator.OrchestratorV2; + const eventSink = yield* EventSink.EventSinkV2; + const now = yield* DateTime.now; + const slug = kind.replace(" ", "-"); + const parentThreadId = ThreadId.make(`runtime-layer-pin-${slug}-parent`); + const childThreadId = ThreadId.make(`runtime-layer-pin-${slug}-child`); + yield* orchestrator.dispatch({ + type: "thread.create", + createdBy: "user", + creationSource: "web", + commandId: CommandId.make(`runtime-layer-pin-${slug}-create-parent`), + threadId: parentThreadId, + projectId: ProjectId.make(`runtime-layer-pin-${slug}-project`), + title: "Parent", + modelSelection, + runtimeMode: "full-access", + interactionMode: "default", + branch: null, + worktreePath: null, + }); + const parent = yield* orchestrator.getThreadProjection(parentThreadId); + yield* eventSink.write({ + events: [ + { + id: EventId.make(`runtime-layer-pin-${slug}-child-created`), + type: "thread.created", + threadId: childThreadId, + occurredAt: now, + payload: { + ...parent.thread, + id: childThreadId, + title: `Child ${kind}`, + lineage: { + parentThreadId, + rootThreadId: parentThreadId, + relationshipToParent, + ...(sideChat === undefined ? {} : { sideChat }), + }, + }, + }, + ], + }); + + const accepted = yield* orchestrator + .dispatch({ + type: "thread.pin", + commandId: CommandId.make(`runtime-layer-pin-${slug}-pin`), + threadId: childThreadId, + }) + .pipe( + Effect.as(true), + Effect.catchTags({ OrchestratorDispatchError: () => Effect.succeed(false) }), + ); + assert.isFalse(accepted, `thread.pin was accepted for a ${kind} thread`); + assert.isNull((yield* orchestrator.getThreadProjection(childThreadId)).thread.pinnedAt); + + yield* orchestrator.dispatch({ + type: "thread.unpin", + commandId: CommandId.make(`runtime-layer-pin-${slug}-unpin`), + threadId: childThreadId, + }); + }), + ); + it.effect("keeps the branch pull request when linking another pull request", () => Effect.gen(function* () { const orchestrator = yield* Orchestrator.OrchestratorV2; From 451f6b3e92f5ecd367053e7bb4f5ac331679c548 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 6 Nov 2026 03:41:47 +0000 Subject: [PATCH 2/4] fix(server,web): subagent and side-chat threads can no longer be pinned Thread lists never show subagents or side chats, so pinning one succeeded with no visible effect. The orchestrator now refuses thread.pin for them (unpin still works, so already-pinned ones have a way out), the thread action menu offers only Unpin for them, and the pin shortcut no longer pins them. Fixes pingdotgg/t3code#31787 Co-Authored-By: Claude Opus 5.5 --- apps/server/src/orchestration-v2/Orchestrator.ts | 9 +++++++++ .../src/orchestration-v2/runtimeLayer.test.ts | 2 +- .../web/src/components/chat/useThreadLifecycle.tsx | 2 ++ .../src/components/threadActionMenu.logic.test.ts | 11 +++++++++++ apps/web/src/components/threadActionMenu.logic.ts | 14 +++++++------- apps/web/src/hooks/useThreadActionMenu.test.ts | 1 + apps/web/src/hooks/useThreadActionMenu.ts | 2 ++ 7 files changed, 33 insertions(+), 8 deletions(-) diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index d40ca624a11d2..8ffaffe88f3bc 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -64,6 +64,7 @@ import { orchestrationV2WorktreePending, ProviderInstanceId, ProviderInteractionMode, + isListedThreadLineage, isRuntimeModeAbove, resolveProviderInstanceEnabled, resolveProjectProviderInstanceEnabled, @@ -3398,6 +3399,14 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio cause: `Thread ${command.threadId} is archived.`, }); } + // Unpin stays allowed so threads pinned before this check still have a way out. + if (command.type === "thread.pin" && !isListedThreadLineage(thread.lineage)) { + return yield* new OrchestratorDispatchError({ + commandId: command.commandId, + commandType: command.type, + cause: `Thread ${command.threadId} is a subagent or side chat, which thread lists do not show; it cannot be pinned.`, + }); + } // Reject reorder after unpin so a raced request cannot restore a cleared pin. if (command.type === "thread.pin.reorder" && thread.pinnedAt == null) { return yield* new OrchestratorDispatchError({ diff --git a/apps/server/src/orchestration-v2/runtimeLayer.test.ts b/apps/server/src/orchestration-v2/runtimeLayer.test.ts index 113a470a01622..30e11f0542294 100644 --- a/apps/server/src/orchestration-v2/runtimeLayer.test.ts +++ b/apps/server/src/orchestration-v2/runtimeLayer.test.ts @@ -2860,7 +2860,7 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => { Effect.catchTags({ OrchestratorDispatchError: () => Effect.succeed(false) }), ); assert.isFalse(accepted, `thread.pin was accepted for a ${kind} thread`); - assert.isNull((yield* orchestrator.getThreadProjection(childThreadId)).thread.pinnedAt); + assert.notExists((yield* orchestrator.getThreadProjection(childThreadId)).thread.pinnedAt); yield* orchestrator.dispatch({ type: "thread.unpin", diff --git a/apps/web/src/components/chat/useThreadLifecycle.tsx b/apps/web/src/components/chat/useThreadLifecycle.tsx index 50ed46ae671f9..89d08d1200719 100644 --- a/apps/web/src/components/chat/useThreadLifecycle.tsx +++ b/apps/web/src/components/chat/useThreadLifecycle.tsx @@ -18,6 +18,7 @@ import { AuthOrchestrationOperateScope, AuthSourceControlWriteScope, type EnvironmentId, + isListedThreadLineage, type ScopedThreadRef, type ThreadId, ProviderInteractionMode, @@ -673,6 +674,7 @@ export function useThreadLifecycle(input: ThreadLifecycleInput) { } if (!readEnvironmentScope(environmentId, AuthOrchestrationOperateScope)) return false; if (!activeThreadShell || !activeThreadRef || !serverConfigLoaded) return; + if (!activeThreadPinned && !isListedThreadLineage(activeThreadShell.lineage)) return; void ( activeThreadPinned ? confirmAndUnpinThread(activeThreadRef) : pinThread(activeThreadRef) ).then( diff --git a/apps/web/src/components/threadActionMenu.logic.test.ts b/apps/web/src/components/threadActionMenu.logic.test.ts index bd9dfdcdcc4b6..f092d0fe6d126 100644 --- a/apps/web/src/components/threadActionMenu.logic.test.ts +++ b/apps/web/src/components/threadActionMenu.logic.test.ts @@ -65,6 +65,17 @@ describe("buildThreadActionMenuItems", () => { }, ); + it.each([false, true])( + "offers no pin for a subagent or side chat but keeps unpin (pinned: %s)", + (isPinned) => { + const ids = buildThreadActionMenuItems({ ...baseState, isPinned, isUnlisted: true }).map( + (item) => item.id, + ); + expect(ids).not.toContain("pin"); + expect(ids.includes("unpin")).toBe(isPinned); + }, + ); + it("disables archive and turning into a project while the thread is running", () => { const items = buildThreadActionMenuItems({ ...baseState, diff --git a/apps/web/src/components/threadActionMenu.logic.ts b/apps/web/src/components/threadActionMenu.logic.ts index ac4ef649ed07c..9a0c3bdf22848 100644 --- a/apps/web/src/components/threadActionMenu.logic.ts +++ b/apps/web/src/components/threadActionMenu.logic.ts @@ -76,6 +76,8 @@ export interface ThreadActionMenuState { readonly isActive: boolean; } | null; readonly isPinned: boolean; + /** Subagents and side chats have no list row, so pinning one would show nothing. */ + readonly isUnlisted?: boolean; readonly isSettled: boolean; readonly autoSettleEnabled: boolean; readonly isSnoozed: boolean; @@ -129,13 +131,11 @@ export function buildThreadActionMenuItems( }, ] : []), - ...(state.supports.pinning - ? [ - state.isPinned - ? { id: "unpin" as const, label: "Unpin thread", icon: "pin-off" } - : { id: "pin" as const, label: "Pin thread", icon: "pin" }, - ] - : []), + ...(state.supports.pinning && state.isPinned + ? [{ id: "unpin" as const, label: "Unpin thread", icon: "pin-off" }] + : state.supports.pinning && !state.isUnlisted + ? [{ id: "pin" as const, label: "Pin thread", icon: "pin" }] + : []), ...(state.supports.settlement ? [ state.isSettled diff --git a/apps/web/src/hooks/useThreadActionMenu.test.ts b/apps/web/src/hooks/useThreadActionMenu.test.ts index 3c8255b04c088..52eaf1897d3d2 100644 --- a/apps/web/src/hooks/useThreadActionMenu.test.ts +++ b/apps/web/src/hooks/useThreadActionMenu.test.ts @@ -56,6 +56,7 @@ vi.mock("../state/entities", () => ({ title: "Thread", branch: "main", worktreePath: null, + lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: "thread" }, runtime: null, latestRun: null, }), diff --git a/apps/web/src/hooks/useThreadActionMenu.ts b/apps/web/src/hooks/useThreadActionMenu.ts index d22b1d9cf6c4f..882674d884769 100644 --- a/apps/web/src/hooks/useThreadActionMenu.ts +++ b/apps/web/src/hooks/useThreadActionMenu.ts @@ -10,6 +10,7 @@ import { import { canSnooze, effectiveSnoozed } from "@t3tools/client-runtime/state/thread-settled"; import { AuthOrchestrationOperateScope, + isListedThreadLineage, type ScopedThreadRef, type ThreadId, } from "@t3tools/contracts"; @@ -139,6 +140,7 @@ export function useThreadActionMenu(input: { branch: thread.branch ?? null, projectFilter: null, isPinned: thread.pinnedAt != null, + isUnlisted: !isListedThreadLineage(thread.lineage), isSettled: supports.settlement && thread.settledOverride === "settled", autoSettleEnabled: thread.autoSettleDisabledAt == null, isSnoozed: supports.snooze && effectiveSnoozed(thread, { now: now.toISOString() }), From bb7adf00e52ab8ff7c8f53b6cc78eae176a75cdf Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 6 Nov 2026 03:54:31 +0000 Subject: [PATCH 3/4] fix(web): undo no longer re-pins a subagent or side chat The server now refuses to pin unlisted threads, so unpinning one offers no Undo and a settle's Undo restores everything but the pin. Co-Authored-By: Claude Opus 5.5 --- .../useThreadActions.permissions.test.ts | 2 ++ apps/web/src/hooks/useThreadActions.ts | 5 ++- .../src/hooks/useThreadActions.undo.test.ts | 32 +++++++++++++++++++ .../client-runtime/src/state/threadUndo.ts | 9 +++++- 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/apps/web/src/hooks/useThreadActions.permissions.test.ts b/apps/web/src/hooks/useThreadActions.permissions.test.ts index de5056c4af696..04e5dbb725426 100644 --- a/apps/web/src/hooks/useThreadActions.permissions.test.ts +++ b/apps/web/src/hooks/useThreadActions.permissions.test.ts @@ -33,6 +33,7 @@ const state = vi.hoisted(() => ({ worktreePath: string | null; session: { status: "ready" | "stopped" } | null; latestTurn: null; + lineage: { parentThreadId: null; relationshipToParent: null; rootThreadId: ThreadId }; }[], requests: [] as { action: string; environmentId: string; input: { threadId?: string } }[], localEffects: [] as string[], @@ -240,6 +241,7 @@ beforeEach(() => { worktreePath: null, session: null, latestTurn: null, + lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: target.threadId }, }, ]; state.requests = []; diff --git a/apps/web/src/hooks/useThreadActions.ts b/apps/web/src/hooks/useThreadActions.ts index 904b94ebfc5c5..71aa8f91dc6fd 100644 --- a/apps/web/src/hooks/useThreadActions.ts +++ b/apps/web/src/hooks/useThreadActions.ts @@ -12,6 +12,7 @@ import { AuthSourceControlWriteScope, EnvironmentAuthorizationError, EnvironmentId, + isListedThreadLineage, type ScopedThreadRef, ThreadId, sessionGrantsScope, @@ -730,7 +731,9 @@ export function useThreadActions() { environmentId: target.environmentId, input: { threadId: target.threadId }, }); - if (result._tag === "Success" && action.isCurrent()) { + // The server refuses to re-pin a subagent or side chat, so its unpin offers no Undo. + const canUndo = thread == null || isListedThreadLineage(thread.lineage); + if (result._tag === "Success" && canUndo && action.isCurrent()) { showThreadUndoNotice({ action: "Unpinned", claim: action, diff --git a/apps/web/src/hooks/useThreadActions.undo.test.ts b/apps/web/src/hooks/useThreadActions.undo.test.ts index 5ec8f1fc64304..8e98fbc1ae603 100644 --- a/apps/web/src/hooks/useThreadActions.undo.test.ts +++ b/apps/web/src/hooks/useThreadActions.undo.test.ts @@ -50,6 +50,11 @@ const threadShell = vi.hoisted(() => ({ pinOrderKey: "a0", pinnedAt: null as string | null, snoozedUntil: null as string | null, + lineage: { + parentThreadId: null as string | null, + relationshipToParent: null as "subagent" | null, + rootThreadId: "thread", + }, projectId: "project", environmentId: "undo-env", session: null, @@ -108,6 +113,8 @@ beforeEach(() => { router.state.matches[0]!.params = {}; threadShell.pinnedAt = null; threadShell.snoozedUntil = null; + threadShell.lineage.parentThreadId = null; + threadShell.lineage.relationshipToParent = null; shellLoaded.current = true; }); afterEach(() => { @@ -140,6 +147,15 @@ describe("concurrent thread action Undo", () => { }); describe("unpin Undo", () => { + it("offers no Undo for a subagent pinned before the server refused to pin one", async () => { + threadShell.pinnedAt = "2026-01-01T00:00:00.000Z"; + threadShell.lineage.parentThreadId = "parent"; + threadShell.lineage.relationshipToParent = "subagent"; + await useThreadActions().unpinThread(target); + expect(commands.unpin).toHaveBeenCalledOnce(); + expect(useThreadUndoNotice.getState().notice).toBeNull(); + }); + it("restores the original snooze after restoring the pin", async () => { threadShell.pinnedAt = "2026-01-01T00:00:00.000Z"; threadShell.snoozedUntil = "2030-01-01T09:00:00.000Z"; @@ -270,6 +286,22 @@ describe("settle and snooze Undo", () => { }); }); + it("restores a settled subagent's snooze without the pin the server now refuses", async () => { + const snoozedUntil = "2030-01-01T09:00:00.000Z"; + threadShell.pinnedAt = "2026-01-01T00:00:00.000Z"; + threadShell.snoozedUntil = snoozedUntil; + threadShell.lineage.parentThreadId = "parent"; + threadShell.lineage.relationshipToParent = "subagent"; + await useThreadActions().settleThread(target); + await currentUndo()(); + expect(commands.unsettle).toHaveBeenCalledOnce(); + expect(commands.pin).not.toHaveBeenCalled(); + expect(commands.snooze).toHaveBeenCalledExactlyOnceWith({ + environmentId: target.environmentId, + input: { threadId: target.threadId, snoozedUntil }, + }); + }); + it("stops settle restoration if restoring the pin fails", async () => { threadShell.pinnedAt = "2026-01-01T00:00:00.000Z"; threadShell.snoozedUntil = "2030-01-01T09:00:00.000Z"; diff --git a/packages/client-runtime/src/state/threadUndo.ts b/packages/client-runtime/src/state/threadUndo.ts index c9a8ac402bee5..ca9faf91bd58c 100644 --- a/packages/client-runtime/src/state/threadUndo.ts +++ b/packages/client-runtime/src/state/threadUndo.ts @@ -1,3 +1,5 @@ +import { isListedThreadLineage, type OrchestrationV2AppThreadLineage } from "@t3tools/contracts"; + // Shared across hook instances so sidebar, header and menu actions invalidate each other. const currentActions = new Map(); const listeners = new Set<() => void>(); @@ -49,6 +51,7 @@ export function planThreadUndo( readonly pinnedAt?: string | null; readonly pinOrderKey?: string | null; readonly snoozedUntil?: string | null; + readonly lineage?: OrchestrationV2AppThreadLineage; } | null, ): ThreadUndoPlan { if (action === "snooze") return [{ action: "unsnooze" }]; @@ -62,7 +65,11 @@ export function planThreadUndo( ? [{ action: "snooze" as const, snoozedUntil: thread.snoozedUntil }] : []; if (action === "unpin") return [pin, ...snooze]; - return [{ action: "unsettle" }, ...(thread?.pinnedAt != null ? [pin] : []), ...snooze]; + // The server refuses to pin subagents and side chats, so a pin from before that rule stays cleared. + const repin = + thread?.pinnedAt != null && + (thread.lineage === undefined || isListedThreadLineage(thread.lineage)); + return [{ action: "unsettle" }, ...(repin ? [pin] : []), ...snooze]; } export async function executeThreadUndo( From bbd5c45d5a2bae2bc2db33b7fbb269442ec9af25 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Tue, 10 Nov 2026 21:28:18 +0000 Subject: [PATCH 4/4] test(web): drop the duplicate lineage the main merge left in the permissions test AI-assisted; verified with the tests and tools listed above. --- apps/web/src/hooks/useThreadActions.permissions.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/web/src/hooks/useThreadActions.permissions.test.ts b/apps/web/src/hooks/useThreadActions.permissions.test.ts index 546e267d9e9bc..58bc33cd0d645 100644 --- a/apps/web/src/hooks/useThreadActions.permissions.test.ts +++ b/apps/web/src/hooks/useThreadActions.permissions.test.ts @@ -36,7 +36,6 @@ const state = vi.hoisted(() => ({ lineage: { parentThreadId: ThreadId | null; sideChat?: boolean }; session: { status: "ready" | "stopped" } | null; latestTurn: null; - lineage: { parentThreadId: null; relationshipToParent: null; rootThreadId: ThreadId }; }[], familyThreads: [] as { id: ThreadId; @@ -269,7 +268,6 @@ beforeEach(() => { lineage: { parentThreadId: null }, session: null, latestTurn: null, - lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: target.threadId }, }, ]; state.requests = [];