TypeScript
fix(threads): side chats inherit parent permissions by default (#31114)
Exotic725cfc9c3d91
diff --git a/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts b/apps/server/src/orchestration-v2/ProviderTurnStartService.test.tsindex cdbd259440a..d1b51682588 100644--- a/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts+++ b/apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts@@ -302,6 +302,7 @@ function makeLocalCommandHarness(input: {readonly contextRun: "current" | "failed" | "cancelled" | "delivered";readonly nativeForkFrom?: "idle" | "busy";readonly switchedProvider?: boolean;+ readonly threadRuntimeMode?: OrchestrationV2ThreadProjection["thread"]["runtimeMode"];};}) {const settledRuns: Array<string> = [];@@ -566,7 +567,7 @@ function makeLocalCommandHarness(input: {...projection,thread: {...projection.thread,- runtimeMode: "full-access",+ runtimeMode: input.sideChat.threadRuntimeMode ?? "full-access",lineage: {parentThreadId,relationshipToParent: "fork",@@ -1260,16 +1261,22 @@ effectIt.effect("recovers an abandoned failed turn before continuing its native);effectIt.effect.each([- { contextRun: "current", runtimeMode: "approval-required", context: "SIDE_CHAT_CONTEXT" },- { contextRun: "failed", runtimeMode: "approval-required", context: "SIDE_CHAT_CONTEXT" },- { contextRun: "cancelled", runtimeMode: "approval-required", context: "SIDE_CHAT_CONTEXT" },+ { contextRun: "current", runtimeMode: "full-access", context: "SIDE_CHAT_CONTEXT" },+ { contextRun: "failed", runtimeMode: "full-access", context: "SIDE_CHAT_CONTEXT" },+ { contextRun: "cancelled", runtimeMode: "full-access", context: "SIDE_CHAT_CONTEXT" },{contextRun: "failed",switchedProvider: true,- runtimeMode: "approval-required",+ runtimeMode: "full-access",context: "SIDE_CHAT_CONTEXT",},{ contextRun: "delivered", runtimeMode: "full-access", context: "" },+ {+ contextRun: "current",+ threadRuntimeMode: "approval-required",+ runtimeMode: "approval-required",+ context: "SIDE_CHAT_CONTEXT",+ },] as const)("sends side chat context inline once, for the first turn that reaches the provider: %j",({ runtimeMode, context, ...sideChat }) =>@@ -1281,7 +1288,6 @@ effectIt.effect.each([yield* harness.start;- // The turn that delivers the context is clamped; a later one follows the thread's mode.expect(harness.open).toHaveBeenCalledWith(expect.objectContaining({ runtimePolicy: expect.objectContaining({ runtimeMode }) }),);diff --git a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts b/apps/server/src/orchestration-v2/ProviderTurnStartService.tsindex 1d6e34b4a86..54b16d7aa2a 100644--- a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts+++ b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts@@ -699,15 +699,9 @@ export const layer: Layer.Layer<});const { isCurrentAttemptInStatus } = runControls;- // A side chat shares its parent's worktree; the turn that gets its context asks before acting.const resolvedPolicy = yield* runtimePolicy.resolve({- thread:- projection.thread.lineage.sideChat === true &&- (sideChatHandoff !== undefined ||- !projection.runs.some((previous) => previous.ordinal < run.ordinal))- ? { ...projection.thread, runtimeMode: "approval-required" }- : projection.thread,+ thread: projection.thread,modelSelection: run.modelSelection,}).pipe(Effect.result);diff --git a/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts b/apps/server/src/orchestration-v2/ThreadFork.execution.test.tsindex d955755e921..41a1120620f 100644--- a/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts+++ b/apps/server/src/orchestration-v2/ThreadFork.execution.test.ts@@ -959,12 +959,37 @@ it.effect("a side chat of an idle parent still starts with the framing note", ()query.includes("FROM orchestration_v2_projection_context_transfers"),),);+ assert.equal(+ (yield* orchestrator.getThreadProjection(sideChatId)).thread.runtimeMode,+ "full-access",+ );+ yield* orchestrator.dispatch({+ type: "thread.runtime-mode.set",+ commandId: CommandId.make("side-chat-parent-mode-change"),+ threadId: parentId,+ runtimeMode: "approval-required",+ });+ assert.equal(+ (yield* orchestrator.getThreadProjection(sideChatId)).thread.runtimeMode,+ "full-access",+ );+ yield* orchestrator.dispatch({+ type: "thread.runtime-mode.set",+ commandId: CommandId.make("side-chat-child-mode-change"),+ threadId: sideChatId,+ runtimeMode: "auto",+ });yield* askSideChat(sideChatId, "side-chat-idle-first-message", {...forkCases[0]!.modelSelection,model: "side-chat-model",});const started = yield* orchestrator.getThreadProjection(sideChatId);+ assert.equal(started.thread.runtimeMode, "auto");+ assert.equal(+ (yield* orchestrator.getThreadProjection(parentId)).thread.runtimeMode,+ "approval-required",+ );assert.isNotNull(started.providerThreads[0]?.forkedFrom);// The side chat does not show the parent's run, so it is no baseline.assert.isFalse(@@ -1110,7 +1135,7 @@ it.effect("a side chat opened during the parent's first turn starts from a digesyield* fork("side-chat-busy-fork", parentId, sideChatId);const created = yield* orchestrator.getThreadProjection(sideChatId);assert.isTrue(created.thread.lineage.sideChat);- assert.equal(created.thread.runtimeMode, "approval-required");+ assert.equal(created.thread.runtimeMode, "full-access");assert.isNull(created.thread.forkedFrom);assert.deepEqual(created.contextTransfers[0]?.sourcePoint, { threadId: parentId });diff --git a/apps/server/src/orchestration-v2/ThreadForkService.test.ts b/apps/server/src/orchestration-v2/ThreadForkService.test.tsindex 5b35b5d195e..f9f6ff25b2f 100644--- a/apps/server/src/orchestration-v2/ThreadForkService.test.ts+++ b/apps/server/src/orchestration-v2/ThreadForkService.test.ts@@ -293,14 +293,31 @@ it.effect("rejects in-progress and rolled-back fork sources", () =>}),);-it.effect("marks only requested forks as supervised side chats", () =>+it.effect("marks only requested forks as side chats and inherits parent permissions", () =>Effect.gen(function* () {const sourceRun = makeSourceRun("completed");const sideChat = yield* planFork(sourceRun, makeSourceProjection(sourceRun), {sideChat: true,});assert.isTrue(sideChat.targetThread.lineage.sideChat);- assert.equal(sideChat.targetThread.runtimeMode, "approval-required");+ assert.equal(sideChat.targetThread.runtimeMode, "full-access");+ for (const runtimeMode of [+ "approval-required",+ "auto-accept-edits",+ "auto",+ "full-access",+ ] as const) {+ const source = makeSourceProjection(sourceRun);+ const inherited = yield* planFork(+ sourceRun,+ {+ ...source,+ thread: { ...source.thread, runtimeMode },+ },+ { sideChat: true },+ );+ assert.equal(inherited.targetThread.runtimeMode, runtimeMode);+ }const sideChatSource = makeSourceProjection(sourceRun);const sideChatProjection = {diff --git a/apps/server/src/orchestration-v2/ThreadForkService.ts b/apps/server/src/orchestration-v2/ThreadForkService.tsindex 6790a2917ae..1dc6d1eaf4a 100644--- a/apps/server/src/orchestration-v2/ThreadForkService.ts+++ b/apps/server/src/orchestration-v2/ThreadForkService.ts@@ -113,8 +113,6 @@ export const layer: Layer.Layer<ThreadForkServiceV2> = Layer.succeed(title: input.title ?? `${input.sourceProjection.thread.title} fork`,// The source's title job completes only on the source thread.titleRegeneration: null,- // Side chats share the parent's worktree, so they start supervised.- ...(input.sideChat ? { runtimeMode: "approval-required" as const } : {}),activeProviderThreadId: null,lineage: {parentThreadId: input.sourceProjection.thread.id,diff --git a/apps/web/src/components/chat/useSideChat.ts b/apps/web/src/components/chat/useSideChat.tsindex 7ac27f75826..15875265289 100644--- a/apps/web/src/components/chat/useSideChat.ts+++ b/apps/web/src/components/chat/useSideChat.ts@@ -11,7 +11,7 @@ import { useRef } from "react";import { newMessageId, newThreadId } from "~/lib/utils";import { useStableCallback } from "../../hooks/useStableCallback";import { useRightPanelStore } from "../../rightPanelStore";-import { waitForThreadShell } from "../../state/entities";+import { readThreadShell, waitForThreadShell } from "../../state/entities";import { threadEnvironment } from "../../state/threads";import { useAtomCommand } from "../../state/use-atom-command";import { useOrchestrationCommand } from "../../state/use-orchestration-command";@@ -55,22 +55,28 @@ export function useSideChat(input: {environmentId: threadRef.environmentId,input: { threadId: targetThreadId, onlyIfUnused: true },});- if (!(await waitForThreadShell(scopeThreadRef(threadRef.environmentId, targetThreadId)))) {+ const targetRef = scopeThreadRef(threadRef.environmentId, targetThreadId);+ if (!(await waitForThreadShell(targetRef))) {input.onError("The side chat was created, but it did not reach this client.");discard();return false;}+ const sideChat = readThreadShell(targetRef);+ if (sideChat === null) {+ input.onError("The side chat is no longer available.");+ discard();+ return false;+ }const text = prompt?.trim();// Send before showing the tab: closing a tab whose side chat has no run deletes it.if (text) {- // The server asks before edits on a side chat's first turn whatever mode is sent.const turn = await startThreadTurn({environmentId: threadRef.environmentId,input: {threadId: targetThreadId,message: { messageId: newMessageId(), role: "user", text, attachments: [] },titleSeed: deriveThreadTitleSeed({ text, attachments: [] }),- runtimeMode: "approval-required",+ runtimeMode: sideChat.runtimeMode,interactionMode: "default",createdAt: new Date().toISOString(),},diff --git a/docs/user/thread-sidebar.md b/docs/user/thread-sidebar.mdindex 6a3145d1751..6f848b67957 100644--- a/docs/user/thread-sidebar.md+++ b/docs/user/thread-sidebar.md@@ -300,9 +300,9 @@ You can also choose **Side chat** from the **+** menu in the right panel. The sichat opens as a tab there, with its own composer. Side chats do not show in thesidebar. Find one again under **Side chats** in thread details.-A side chat works in the same folder as the thread. Its first reply asks before it-edits files or runs commands. After that, it uses the permission mode you choose-in its composer.+A side chat works in the same folder as the thread and inherits its permissions+when created, including for its first reply. Change permissions for an individual+side chat in its composer. Later changes to the parent do not change existing side chats.To use what you learned, choose **Bring back**. The thread gets the side chat withyour next message there. Bring back is available while the thread is idle.