Skip to content

Commit 1fe6f41

Browse files
committed
fix: cover fork entry points and side chat guards flagged in review
Reject side chat on threads without fork lineage, show the fork origin header on empty forks, let any-turn providers fork after an interrupted or failed latest turn, add fork and side chat actions to the sidebar context menu, guard against double forks while a request is in flight, disable terminal creation from an embedded side chat, and repaint mobile rows when the latest turn or fork capability changes. Implemented by GPT-5.6 Sol via Codex.
1 parent f447539 commit 1fe6f41

10 files changed

Lines changed: 222 additions & 108 deletions

File tree

‎apps/mobile/src/features/threads/ThreadFeed.tsx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,6 +2353,10 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
23532353
reviewCommentColors,
23542354
userBubbleColor,
23552355
viewportWidth,
2356+
forkCapability: props.forkCapability,
2357+
latestTurnIdentity: props.latestTurn
2358+
? `${props.latestTurn.turnId}:${props.latestTurn.state}:${props.latestTurn.completedAt ?? ""}`
2359+
: null,
23562360
}),
23572361
[
23582362
copiedRowId,
@@ -2363,6 +2367,10 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
23632367
reviewCommentColors,
23642368
userBubbleColor,
23652369
viewportWidth,
2370+
props.forkCapability,
2371+
props.latestTurn?.completedAt,
2372+
props.latestTurn?.state,
2373+
props.latestTurn?.turnId,
23662374
],
23672375
);
23682376
const reportHeaderMaterialVisibility = useCallback(

‎apps/mobile/src/features/threads/ThreadRouteScreen.tsx‎

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ function ThreadRouteContent(
343343
latestForkTurnRef.current = selectedThread?.latestTurn ?? null;
344344
const forkThreadRef = useRef(forkThread);
345345
forkThreadRef.current = forkThread;
346+
const forkInFlightRef = useRef(false);
346347
const navigationRef = useRef(navigation);
347348
navigationRef.current = navigation;
348349

@@ -565,32 +566,38 @@ function ThreadRouteContent(
565566
) {
566567
return;
567568
}
568-
const nextThreadId = ThreadId.make(uuidv4());
569-
const result = await forkThreadRef.current({
570-
environmentId: sourceThread.environmentId,
571-
input: {
572-
threadId: nextThreadId,
573-
sourceThreadId: sourceThread.id,
574-
sourceTurnId: input.turnId,
575-
sourceMessageId: input.messageId,
576-
sideChat: input.sideChat,
577-
createdAt: new Date().toISOString(),
578-
},
579-
});
580-
if (result._tag === "Failure") {
581-
if (!isAtomCommandInterrupted(result)) {
582-
const error = squashAtomCommandFailure(result);
583-
Alert.alert(
584-
input.sideChat ? "Could not open side chat" : "Could not fork thread",
585-
error instanceof Error ? error.message : "An error occurred.",
586-
);
569+
if (forkInFlightRef.current) return;
570+
forkInFlightRef.current = true;
571+
try {
572+
const nextThreadId = ThreadId.make(uuidv4());
573+
const result = await forkThreadRef.current({
574+
environmentId: sourceThread.environmentId,
575+
input: {
576+
threadId: nextThreadId,
577+
sourceThreadId: sourceThread.id,
578+
sourceTurnId: input.turnId,
579+
sourceMessageId: input.messageId,
580+
sideChat: input.sideChat,
581+
createdAt: new Date().toISOString(),
582+
},
583+
});
584+
if (result._tag === "Failure") {
585+
if (!isAtomCommandInterrupted(result)) {
586+
const error = squashAtomCommandFailure(result);
587+
Alert.alert(
588+
input.sideChat ? "Could not open side chat" : "Could not fork thread",
589+
error instanceof Error ? error.message : "An error occurred.",
590+
);
591+
}
592+
return;
587593
}
588-
return;
594+
navigationRef.current.navigate("Thread", {
595+
environmentId: String(sourceThread.environmentId),
596+
threadId: String(nextThreadId),
597+
});
598+
} finally {
599+
forkInFlightRef.current = false;
589600
}
590-
navigationRef.current.navigate("Thread", {
591-
environmentId: String(sourceThread.environmentId),
592-
threadId: String(nextThreadId),
593-
});
594601
},
595602
[],
596603
);

‎apps/server/src/orchestration/decider.fork.test.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ it.layer(NodeServices.layer)("thread fork decider", (it) => {
172172
}),
173173
);
174174

175-
it.effect("promotes a side chat through thread.meta.update", () =>
175+
it.effect("allows clearing side chat metadata on any thread", () =>
176176
Effect.gen(function* () {
177177
const event = yield* decideOrchestrationCommand({
178178
command: {
@@ -189,4 +189,20 @@ it.layer(NodeServices.layer)("thread fork decider", (it) => {
189189
expect(updated.payload.sideChat).toBe(false);
190190
}),
191191
);
192+
193+
it.effect("rejects turning an ordinary thread into a side chat", () =>
194+
Effect.gen(function* () {
195+
const error = yield* decideOrchestrationCommand({
196+
command: {
197+
type: "thread.meta.update",
198+
commandId: CommandId.make("cmd-hide-ordinary-thread"),
199+
threadId: SOURCE_THREAD_ID,
200+
sideChat: true,
201+
},
202+
readModel: makeReadModel(),
203+
}).pipe(Effect.flip);
204+
expect(error._tag).toBe("OrchestrationCommandInvariantError");
205+
expect(error.message).toContain("is not a fork");
206+
}),
207+
);
192208
});

‎apps/server/src/orchestration/decider.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
863863
command,
864864
threadId: command.threadId,
865865
});
866+
if (command.sideChat === true && thread.fork == null) {
867+
return yield* new OrchestrationCommandInvariantError({
868+
commandType: command.type,
869+
detail: `Thread '${command.threadId}' is not a fork and cannot become a side chat.`,
870+
});
871+
}
866872
const branch =
867873
command.branch !== undefined &&
868874
command.expectedBranch !== undefined &&

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4041,7 +4041,15 @@ function ChatViewContent(props: ChatViewProps) {
40414041
}
40424042
}, [activeThreadRef]);
40434043
const addTerminalSurface = useCallback(() => {
4044-
if (!panelActionThreadRef || !activeThreadRef || !activeThreadId || !activeProject) return;
4044+
if (
4045+
embeddedSideChat ||
4046+
!panelActionThreadRef ||
4047+
!activeThreadRef ||
4048+
!activeThreadId ||
4049+
!activeProject
4050+
) {
4051+
return;
4052+
}
40454053
const cwd = gitCwd ?? activeProject.workspaceRoot;
40464054
const terminalId = nextTerminalId(allocatableActiveTerminalIds);
40474055
useRightPanelStore.getState().openTerminal(panelActionThreadRef, terminalId);
@@ -4065,6 +4073,7 @@ function ChatViewContent(props: ChatViewProps) {
40654073
activeThreadRef,
40664074
activeThreadWorktreePath,
40674075
allocatableActiveTerminalIds,
4076+
embeddedSideChat,
40684077
gitCwd,
40694078
openTerminal,
40704079
panelActionThreadRef,

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

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
scopeThreadRef,
3030
scopedThreadKey,
3131
} from "@t3tools/client-runtime/environment";
32-
import type { ScopedThreadRef, ThreadId } from "@t3tools/contracts";
32+
import { ThreadId, type ScopedThreadRef } from "@t3tools/contracts";
3333
import type { TimestampFormat } from "@t3tools/contracts/settings";
3434
import {
3535
AlarmClockIcon,
@@ -99,6 +99,7 @@ import {
9999
import { legacyProjectCwdPreferenceKey, useUiStateStore } from "../uiStateStore";
100100
import { useThreadSelectionStore } from "../threadSelectionStore";
101101
import { useThreadActions } from "../hooks/useThreadActions";
102+
import { useThreadForkActions } from "../hooks/useThreadFork";
102103
import { useHandleNewThread } from "../hooks/useHandleNewThread";
103104
import { openCommandPalette } from "../commandPaletteBus";
104105
import { startNewThreadFromContext } from "../lib/chatThreadActions";
@@ -107,7 +108,7 @@ import { useCopyToClipboard } from "../hooks/useCopyToClipboard";
107108
import { useLocalStorage } from "../hooks/useLocalStorage";
108109
import { useNowMinute } from "../hooks/useNowMinute";
109110
import { useEnvironments, usePrimaryEnvironmentId } from "../state/environments";
110-
import { useProjects, useThreadShells } from "../state/entities";
111+
import { readSideChatsByParent, useProjects, useThreadShells } from "../state/entities";
111112
import { environmentServerConfigsAtom, primaryServerKeybindingsAtom } from "../state/server";
112113
import { vcsEnvironment } from "../state/vcs";
113114
import { threadEnvironment } from "../state/threads";
@@ -119,8 +120,10 @@ import {
119120
resolveThreadRouteTarget,
120121
} from "../threadRoutes";
121122
import { formatRelativeTimeLabel, parseTimestampDate } from "../timestampFormat";
123+
import { resolveForkEntryAvailability } from "../threadForking.logic";
122124
import type { SidebarThreadSummary } from "../types";
123125
import { cn } from "~/lib/utils";
126+
import { useRightPanelStore } from "../rightPanelStore";
124127
import { buildThreadActionMenuItems } from "./threadActionMenu.logic";
125128
import {
126129
animatePinnedLayoutChanges,
@@ -1767,6 +1770,7 @@ export default function Sidebar() {
17671770
archiveThread,
17681771
deleteThread,
17691772
} = useThreadActions();
1773+
const threadFork = useThreadForkActions(null);
17701774
const updateThreadMetadata = useAtomCommand(threadEnvironment.updateMetadata, {
17711775
reportFailure: false,
17721776
});
@@ -3114,6 +3118,16 @@ export default function Sidebar() {
31143118
const isSettled = settledThreadKeysRef.current.has(threadKey);
31153119
const isSnoozed = snoozedThreadKeysRef.current.has(threadKey);
31163120
const isPinned = thread.pinnedAt != null;
3121+
const providerInstanceId =
3122+
thread.session?.providerInstanceId ?? thread.modelSelection.instanceId;
3123+
const forkCapability = serverConfigs
3124+
.get(thread.environmentId)
3125+
?.providers.find((provider) => provider.instanceId === providerInstanceId)?.sessionFork;
3126+
const forkEntry = resolveForkEntryAvailability({
3127+
capability: forkCapability,
3128+
latestTurn: thread.latestTurn,
3129+
});
3130+
const sideChats = readSideChatsByParent(threadRef);
31173131
// Presets resolve at menu-open time (same as the popover).
31183132
const snoozePresets = resolveSnoozePresets(new Date(), timestampFormat);
31193133
const clicked = await settlePromise(() =>
@@ -3133,6 +3147,11 @@ export default function Sidebar() {
31333147
pinning: supportsPinning,
31343148
titleRegeneration: supportsTitleRegeneration,
31353149
},
3150+
forking: {
3151+
enabled: forkEntry.enabled,
3152+
disabledReason: forkEntry.disabledReason,
3153+
sideChats,
3154+
},
31363155
snoozePresets,
31373156
}),
31383157
position,
@@ -3146,6 +3165,15 @@ export default function Sidebar() {
31463165
if (preset) attemptSnooze(threadRef, preset);
31473166
return;
31483167
}
3168+
if (clicked.value?.startsWith("open-existing-side-chat:")) {
3169+
useRightPanelStore
3170+
.getState()
3171+
.openSideChat(
3172+
threadRef,
3173+
ThreadId.make(clicked.value.slice("open-existing-side-chat:".length)),
3174+
);
3175+
return;
3176+
}
31493177
switch (clicked.value) {
31503178
case "project-settings": {
31513179
const projectGroup = projectGroupsRef.current.find((group) =>
@@ -3181,6 +3209,16 @@ export default function Sidebar() {
31813209
}
31823210
return;
31833211
}
3212+
case "open-side-chat":
3213+
if (forkEntry.target) {
3214+
void threadFork.forkTarget(thread, forkEntry.target, true);
3215+
}
3216+
return;
3217+
case "fork-thread":
3218+
if (forkEntry.target) {
3219+
void threadFork.forkTarget(thread, forkEntry.target, false);
3220+
}
3221+
return;
31843222
case "settle":
31853223
attemptSettle(threadRef);
31863224
return;
@@ -3321,6 +3359,7 @@ export default function Sidebar() {
33213359
projectCwdByKey,
33223360
serverConfigs,
33233361
startThreadRename,
3362+
threadFork.forkTarget,
33243363
updateThreadMetadata,
33253364
timestampFormat,
33263365
],

‎apps/web/src/components/chat/MessagesTimeline.tsx‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -723,12 +723,17 @@ export const MessagesTimeline = memo(function MessagesTimeline({
723723
);
724724

725725
if (rows.length === 0 && !isWorking) {
726-
if (hideEmptyPlaceholder) {
726+
if (hideEmptyPlaceholder && !transcriptHeader) {
727727
return null;
728728
}
729729
return (
730-
<div className="flex h-full items-center justify-center">
731-
<p className="text-placeholder text-sm">Send a message to start the conversation.</p>
730+
<div className="flex h-full min-h-0 flex-col overflow-y-auto px-3 sm:px-5">
731+
{transcriptHeader}
732+
<div className="flex min-h-0 flex-1 items-center justify-center">
733+
{hideEmptyPlaceholder ? null : (
734+
<p className="text-placeholder text-sm">Send a message to start the conversation.</p>
735+
)}
736+
</div>
732737
</div>
733738
);
734739
}

0 commit comments

Comments
 (0)