Skip to content

Commit 3712656

Browse files
PR Batch Testersaphidclaude
committed
feat(web): side chats, ask about a thread without interrupting it
Revives saphid's #14220 onto current main. A side chat is an ordinary V2 thread with a sideChat flag: it opens in the right panel, stays out of the sidebar, and forks the parent at its last finished run. Co-authored-by: saphid <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent ed0f7b9 commit 3712656

47 files changed

Lines changed: 2112 additions & 116 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/server/src/environment/ServerEnvironment.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ it.layer(NodeServices.layer)("ServerEnvironmentLive", (it) => {
221221
expect(second.capabilities.threadTitleRegeneration).toBe(true);
222222
expect(second.capabilities.threadPullRequests).toBe(true);
223223
expect(second.capabilities.threadPullRequestLinking).toBe(true);
224+
expect(second.capabilities.threadSideChats).toBe(true);
224225
expect(second.capabilities.serverResolvedCommandContext).toBe(true);
225226
expect(second.capabilities.agentActivityPublishing).toBe(false);
226227
}),

‎apps/server/src/environment/ServerEnvironment.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ export const make = Effect.gen(function* () {
249249
threadPullRequestWatch: true,
250250
pullRequestStackActions: true,
251251
threadPullRequestLinking: true,
252+
threadSideChats: true,
252253
serverResolvedCommandContext: true,
253254
environmentIcon: true,
254255
projectCloneTracking: true,

‎apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts‎

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { assert, it } from "@effect/vitest";
22
import {
3+
CheckpointId,
34
CommandId,
45
MessageId,
56
EventId,
@@ -624,3 +625,164 @@ it.effect("keeps delegated child pull-request links independent of the parent",
624625
assert.deepEqual(parentAfterChildLink.thread.pullRequests, parent.thread.pullRequests);
625626
}).pipe(Effect.provide(layerTest)),
626627
);
628+
629+
it.effect("links a side chat under its parent without claiming a fork, and promotes it", () =>
630+
Effect.gen(function* () {
631+
const orchestrator = yield* Orchestrator.OrchestratorV2;
632+
const projections = yield* ProjectionStore.ProjectionStoreV2;
633+
const projectId = ProjectId.make("project:side-chat");
634+
const parentId = ThreadId.make("thread:side-chat-parent");
635+
const sideChatId = ThreadId.make("thread:side-chat-child");
636+
const base = {
637+
projectId,
638+
modelSelection,
639+
runtimeMode: "approval-required",
640+
interactionMode: "default",
641+
branch: null,
642+
worktreePath: null,
643+
createdBy: "user",
644+
creationSource: "web",
645+
} as const;
646+
yield* orchestrator.dispatch({
647+
type: "thread.create",
648+
commandId: CommandId.make("create-side-chat-parent"),
649+
threadId: parentId,
650+
title: "Parent",
651+
...base,
652+
});
653+
yield* orchestrator.dispatch({
654+
type: "thread.create",
655+
commandId: CommandId.make("create-side-chat-child"),
656+
threadId: sideChatId,
657+
title: "Side chat",
658+
parentThreadId: parentId,
659+
sideChat: true,
660+
...base,
661+
});
662+
663+
const child = yield* projections.getThread(sideChatId);
664+
assert.deepEqual(child.lineage, {
665+
parentThreadId: parentId,
666+
relationshipToParent: null,
667+
rootThreadId: parentId,
668+
});
669+
assert.isNull(child.forkedFrom);
670+
assert.equal(child.sideChat, true);
671+
assert.equal((yield* projections.getThreadShell(sideChatId))?.sideChat, true);
672+
assert.isUndefined((yield* projections.getThread(parentId)).sideChat);
673+
674+
yield* orchestrator.dispatch({
675+
type: "thread.metadata.update",
676+
commandId: CommandId.make("promote-side-chat"),
677+
threadId: sideChatId,
678+
sideChat: false,
679+
});
680+
assert.equal((yield* projections.getThread(sideChatId)).sideChat, false);
681+
assert.equal((yield* projections.getThreadShell(sideChatId))?.sideChat, false);
682+
683+
const crossProject = yield* Effect.exit(
684+
orchestrator.dispatch({
685+
type: "thread.create",
686+
commandId: CommandId.make("create-side-chat-cross-project"),
687+
threadId: ThreadId.make("thread:side-chat-cross-project"),
688+
title: "Elsewhere",
689+
parentThreadId: parentId,
690+
sideChat: true,
691+
...base,
692+
projectId: ProjectId.make("project:side-chat-other"),
693+
}),
694+
);
695+
assert.equal(crossProject._tag, "Failure");
696+
}).pipe(Effect.provide(layerTest)),
697+
);
698+
699+
it.effect("forks a side chat from the last finished run while the source is mid-run", () =>
700+
Effect.gen(function* () {
701+
const orchestrator = yield* Orchestrator.OrchestratorV2;
702+
const projections = yield* ProjectionStore.ProjectionStoreV2;
703+
const projectId = ProjectId.make("project:side-chat-active");
704+
const sourceId = ThreadId.make("thread:side-chat-active-source");
705+
const targetId = ThreadId.make("thread:side-chat-active-target");
706+
const now = yield* DateTime.now;
707+
yield* orchestrator.dispatch({
708+
type: "thread.create",
709+
commandId: CommandId.make("create-side-chat-active-source"),
710+
threadId: sourceId,
711+
projectId,
712+
title: "Busy parent",
713+
modelSelection,
714+
runtimeMode: "full-access",
715+
interactionMode: "default",
716+
branch: null,
717+
worktreePath: null,
718+
createdBy: "user",
719+
creationSource: "web",
720+
});
721+
const run = (ordinal: number, status: "completed" | "running") => ({
722+
id: RunId.make(`run:side-chat-active-${ordinal}`),
723+
threadId: sourceId,
724+
ordinal,
725+
providerInstanceId: instanceId,
726+
modelSelection,
727+
providerThreadId: null,
728+
userMessageId: MessageId.make(`message:side-chat-active-${ordinal}`),
729+
rootNodeId: null,
730+
activeAttemptId: null,
731+
status,
732+
requestedAt: now,
733+
startedAt: now,
734+
completedAt: status === "completed" ? now : null,
735+
checkpointId:
736+
status === "completed" ? CheckpointId.make(`checkpoint:side-chat-${ordinal}`) : null,
737+
contextHandoffId: null,
738+
});
739+
for (const next of [run(1, "completed"), run(2, "running")]) {
740+
yield* projections.apply({
741+
id: EventId.make(`event:side-chat-active-${next.ordinal}`),
742+
type: "run.updated",
743+
threadId: sourceId,
744+
runId: next.id,
745+
providerInstanceId: instanceId,
746+
occurredAt: now,
747+
payload: next,
748+
});
749+
}
750+
751+
yield* orchestrator.dispatch({
752+
type: "thread.fork",
753+
commandId: CommandId.make("fork-side-chat-active"),
754+
sourceThreadId: sourceId,
755+
targetThreadId: targetId,
756+
sourcePoint: { type: "latest_stable" },
757+
sideChat: true,
758+
runtimeMode: "approval-required",
759+
createdBy: "user",
760+
creationSource: "web",
761+
});
762+
763+
const target = yield* projections.getThread(targetId);
764+
assert.deepEqual(target.forkedFrom, {
765+
type: "run",
766+
threadId: sourceId,
767+
runId: RunId.make("run:side-chat-active-1"),
768+
});
769+
assert.equal(target.sideChat, true);
770+
assert.equal(target.runtimeMode, "approval-required");
771+
assert.equal(target.lineage.relationshipToParent, "fork");
772+
773+
// Pinning the run that is still streaming is refused: it is not a stable point.
774+
const midRun = yield* Effect.exit(
775+
orchestrator.dispatch({
776+
type: "thread.fork",
777+
commandId: CommandId.make("fork-side-chat-mid-run"),
778+
sourceThreadId: sourceId,
779+
targetThreadId: ThreadId.make("thread:side-chat-active-refused"),
780+
sourcePoint: { type: "run", runId: RunId.make("run:side-chat-active-2") },
781+
sideChat: true,
782+
createdBy: "user",
783+
creationSource: "web",
784+
}),
785+
);
786+
assert.equal(midRun._tag, "Failure");
787+
}).pipe(Effect.provide(layerTest)),
788+
);

‎apps/server/src/orchestration-v2/Orchestrator.ts‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,6 +2207,30 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
22072207
"orchestration_v2.driver": command.modelSelection.instanceId,
22082208
});
22092209

2210+
// A linked thread records its parent but transfers no context, so the
2211+
// relationship stays null instead of claiming a fork.
2212+
const parentThread =
2213+
command.parentThreadId === undefined
2214+
? null
2215+
: yield* projectionStore
2216+
.getThread(command.parentThreadId)
2217+
.pipe(
2218+
Effect.mapError(
2219+
(cause) =>
2220+
new OrchestratorProjectionError({ threadId: command.parentThreadId!, cause }),
2221+
),
2222+
);
2223+
if (
2224+
parentThread !== null &&
2225+
(parentThread.deletedAt !== null || parentThread.projectId !== command.projectId)
2226+
) {
2227+
return yield* new OrchestratorDispatchError({
2228+
commandId: command.commandId,
2229+
commandType: command.type,
2230+
cause: `Parent thread ${parentThread.id} is deleted or belongs to another project.`,
2231+
});
2232+
}
2233+
22102234
const now = yield* DateTime.now;
22112235
const emitEvent = emit(events, command);
22122236
const thread: OrchestrationV2AppThread = {
@@ -2222,10 +2246,11 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
22222246
branch: command.branch,
22232247
worktreePath: command.worktreePath,
22242248
activeProviderThreadId: null,
2249+
...(command.sideChat === undefined ? {} : { sideChat: command.sideChat }),
22252250
lineage: {
2226-
parentThreadId: null,
2251+
parentThreadId: parentThread?.id ?? null,
22272252
relationshipToParent: null,
2228-
rootThreadId: command.threadId,
2253+
rootThreadId: parentThread?.lineage.rootThreadId ?? command.threadId,
22292254
},
22302255
forkedFrom: null,
22312256
createdAt: now,
@@ -2946,6 +2971,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
29462971
return {
29472972
...thread,
29482973
...(command.title === undefined ? {} : { title: command.title }),
2974+
...(command.sideChat === undefined ? {} : { sideChat: command.sideChat }),
29492975
...(command.limitRecovery === undefined ? {} : { limitRecovery }),
29502976
...(command.limitRecovery !== undefined &&
29512977
limitRecovery?.snooze === true &&
@@ -3585,6 +3611,8 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
35853611
transferId,
35863612
targetThreadId: command.targetThreadId,
35873613
...(command.title === undefined ? {} : { title: command.title }),
3614+
...(command.sideChat === undefined ? {} : { sideChat: command.sideChat }),
3615+
...(command.runtimeMode === undefined ? {} : { runtimeMode: command.runtimeMode }),
35883616
createdBy: command.createdBy,
35893617
creationSource: command.creationSource,
35903618
createdAt: now,

‎apps/server/src/orchestration-v2/ProjectionStore.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,7 @@ export function threadShellFromProjection(
14801480
...(projection.thread.activeOrderKey === undefined
14811481
? {}
14821482
: { activeOrderKey: projection.thread.activeOrderKey }),
1483+
...(projection.thread.sideChat === undefined ? {} : { sideChat: projection.thread.sideChat }),
14831484
lineage: projection.thread.lineage,
14841485
forkedFrom: projection.thread.forkedFrom,
14851486
activeProviderThreadId: projection.thread.activeProviderThreadId,
@@ -1748,6 +1749,7 @@ function shellFromState(input: {
17481749
...(input.state.thread.activeOrderKey === undefined
17491750
? {}
17501751
: { activeOrderKey: input.state.thread.activeOrderKey }),
1752+
...(input.state.thread.sideChat === undefined ? {} : { sideChat: input.state.thread.sideChat }),
17511753
lineage: input.state.thread.lineage,
17521754
forkedFrom: input.state.thread.forkedFrom,
17531755
activeProviderThreadId: input.state.thread.activeProviderThreadId,

‎apps/server/src/orchestration-v2/SubagentProjection.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,23 @@ it("keeps a subagent child awake when its parent thread is snoozed", () => {
117117
});
118118
});
119119

120+
it("never makes a subagent of a side chat a side chat", () => {
121+
const childThread = makeSubagentChildThread({
122+
parentThread: { ...makeParentThread(), sideChat: true },
123+
childThreadId,
124+
parentNodeId: NodeId.make("node:subagent-side-chat-parent"),
125+
activeProviderThreadId: null,
126+
providerInstanceId: childProviderInstanceId,
127+
modelSelection: childModelSelection,
128+
title: "Side chat subagent",
129+
now: childCreatedAt,
130+
createdBy: "agent",
131+
creationSource: "provider",
132+
});
133+
134+
assert.isFalse(childThread.sideChat);
135+
});
136+
120137
it("attributes native subagent prompts to their parent thread", () => {
121138
for (const role of ["user", "assistant"] as const) {
122139
const artifacts = makeSubagentConversationArtifacts({

‎apps/server/src/orchestration-v2/ThreadForkService.test.ts‎

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,24 @@ function makeSourceProjection(sourceRun: OrchestrationV2Run): OrchestrationV2Thr
106106
};
107107
}
108108

109-
const planFork = (sourceRun: OrchestrationV2Run) =>
109+
const planFork = (
110+
sourceRun: OrchestrationV2Run,
111+
options: {
112+
readonly sideChat?: boolean;
113+
readonly runtimeMode?: OrchestrationV2AppThread["runtimeMode"];
114+
readonly sourceThread?: OrchestrationV2AppThread;
115+
} = {},
116+
) =>
110117
Effect.gen(function* () {
111118
const service = yield* ThreadForkService.ThreadForkServiceV2;
119+
const sourceProjection = makeSourceProjection(sourceRun);
112120
return yield* service.plan({
113-
sourceProjection: makeSourceProjection(sourceRun),
121+
...(options.sideChat === undefined ? {} : { sideChat: options.sideChat }),
122+
...(options.runtimeMode === undefined ? {} : { runtimeMode: options.runtimeMode }),
123+
sourceProjection:
124+
options.sourceThread === undefined
125+
? sourceProjection
126+
: { ...sourceProjection, thread: options.sourceThread },
114127
sourceRun,
115128
sourceProviderThread: undefined,
116129
canonicalSourcePoint: {
@@ -191,3 +204,26 @@ it.effect("rejects in-progress and rolled-back fork sources", () =>
191204
}
192205
}),
193206
);
207+
208+
it.effect("marks a side-chat fork and can narrow its runtime mode", () =>
209+
Effect.gen(function* () {
210+
const result = yield* planFork(makeSourceRun("completed"), {
211+
sideChat: true,
212+
runtimeMode: "approval-required",
213+
});
214+
assert.isTrue(result.targetThread.sideChat);
215+
assert.equal(result.targetThread.runtimeMode, "approval-required");
216+
// Lineage still says fork: presentation is a separate fact.
217+
assert.equal(result.targetThread.lineage.relationshipToParent, "fork");
218+
}),
219+
);
220+
221+
it.effect("does not carry a side-chat source's flag into an ordinary fork", () =>
222+
Effect.gen(function* () {
223+
const result = yield* planFork(makeSourceRun("completed"), {
224+
sourceThread: { ...makeSourceThread(), sideChat: true },
225+
});
226+
assert.isFalse(result.targetThread.sideChat);
227+
assert.equal(result.targetThread.runtimeMode, "full-access");
228+
}),
229+
);

‎apps/server/src/orchestration-v2/ThreadForkService.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ export interface ThreadForkServiceV2Shape {
6262
readonly transferId: ContextTransferId;
6363
readonly targetThreadId: ThreadId;
6464
readonly title?: string;
65+
readonly sideChat?: boolean;
66+
readonly runtimeMode?: OrchestrationV2AppThread["runtimeMode"];
6567
readonly createdBy: OrchestrationV2Actor;
6668
readonly creationSource: OrchestrationV2CreationSource;
6769
readonly createdAt: DateTime.Utc;
@@ -91,6 +93,9 @@ export const layer: Layer.Layer<ThreadForkServiceV2> = Layer.succeed(
9193
creationSource: input.creationSource,
9294
id: input.targetThreadId,
9395
title: input.title ?? `${input.sourceProjection.thread.title} fork`,
96+
// The spread would otherwise carry a side-chat source's flag into the fork.
97+
sideChat: input.sideChat === true,
98+
...(input.runtimeMode === undefined ? {} : { runtimeMode: input.runtimeMode }),
9499
activeProviderThreadId: null,
95100
lineage: {
96101
parentThreadId: input.sourceProjection.thread.id,

0 commit comments

Comments
 (0)