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, 21:00 UTC
fix(contracts): side chats open after an abandoned worktree setup (#34686)
Julius Marminge committed
Nov 11, 2026 at 17:58 UTC
d63db064363e3ba9c12310ed5efb5c86c35d1caf
6 files changed
+83
-22
apps/mobile/src/state/use-thread-composer-state.ts
+1
-1
@@ -29,7 +29,6 @@ import {
29
DEFAULT_PROVIDER_INTERACTION_MODE,
30
MessageId,
31
PROVIDER_SEND_TURN_MAX_ATTACHMENTS,
32
- orchestrationV2WorktreePending,
32
type EnvironmentId,
33
type ModelSelection,
34
type RuntimeMode,
@@ -90,6 +89,7 @@ import {
89
useComposerDraftSettings,
90
} from "./use-composer-drafts";
91
import { isClearComposerCommand, parseSideChatCommand } from "@t3tools/shared/composerTrigger";
92
+import { orchestrationV2WorktreePending } from "@t3tools/shared/orchestrationV2ThreadError";
93
import {
94
compactionBlocksSteering,
95
resolveComposerDispatchMode,
apps/server/src/orchestration-v2/Orchestrator.ts
+1
-1
@@ -8,6 +8,7 @@ import type {
8
import {
9
latestExecutedRun,
10
latestRootProviderFailure,
11
+ orchestrationV2WorktreePending,
12
runRanAfter,
13
usageLimitBlockedRun,
14
} from "@t3tools/shared/orchestrationV2ThreadError";
@@ -62,7 +63,6 @@ import {
63
latestProviderTurnForAttempt,
64
parseGoalCommand,
65
orchestrationV2RunWorkStartedAt,
65
- orchestrationV2WorktreePending,
66
ProviderInstanceId,
67
ProviderInteractionMode,
68
isRuntimeModeAbove,
apps/server/src/orchestration-v2/ThreadFork.execution.test.ts
+61
-1
@@ -727,7 +727,12 @@ const writeParentRun = (input: {
727
queuePosition: null,
728
requestedAt: now,
729
startedAt: now,
730
- completedAt: input.status === "completed" ? now : null,
730
+ completedAt:
731
+ input.status === "preparing" ||
732
+ input.status === "running" ||
733
+ input.status === "queued"
734
+ ? null
735
+ : now,
736
checkpointId: input.stable ? CheckpointId.make(`${input.runId}:checkpoint`) : null,
737
contextHandoffId: null,
738
...(input.status === "preparing" ||
@@ -1029,6 +1034,61 @@ it.effect("a side chat waits for the parent's new worktree, also after its setup
1034
}).pipe(Effect.provide(forkCases[0]!.layer)),
1035
);
1036
1037
+it.effect("a side chat opens once a later run has worked in the project checkout", () =>
1038
+ Effect.gen(function* () {
1039
+ const orchestrator = yield* Orchestrator.OrchestratorV2;
1040
+ const parentId = ThreadId.make("side-chat-worktree-abandoned-parent");
1041
+ const sideChatId = ThreadId.make("side-chat-worktree-abandoned-child");
1042
+ yield* createParent(parentId);
1043
+ yield* writeParentRun({
1044
+ threadId: parentId,
1045
+ runId: RunId.make("side-chat-worktree-abandoned-run-1"),
1046
+ ordinal: 1,
1047
+ status: "interrupted",
1048
+ text: "Stopped during setup",
1049
+ });
1050
+ yield* writeParentRun({
1051
+ threadId: parentId,
1052
+ runId: RunId.make("side-chat-worktree-abandoned-run-2"),
1053
+ ordinal: 2,
1054
+ status: "completed",
1055
+ text: "Worked in the project checkout",
1056
+ stable: true,
1057
+ });
1058
+
1059
+ yield* forkSideChat("side-chat-worktree-abandoned-fork", parentId, sideChatId);
1060
+ assert.isNull((yield* orchestrator.getThreadProjection(sideChatId)).thread.deletedAt);
1061
+
1062
+ // A retried setup that is running again, or failed again, comes after the later run.
1063
+ for (const status of ["preparing", "failed"] as const) {
1064
+ const retriedParentId = ThreadId.make(`side-chat-worktree-retried-parent-${status}`);
1065
+ yield* createParent(retriedParentId);
1066
+ yield* writeParentRun({
1067
+ threadId: retriedParentId,
1068
+ runId: RunId.make(`side-chat-worktree-retried-run-2-${status}`),
1069
+ ordinal: 2,
1070
+ status: "completed",
1071
+ text: "Worked in the project checkout",
1072
+ stable: true,
1073
+ });
1074
+ yield* TestClock.adjust("1 second");
1075
+ yield* writeParentRun({
1076
+ threadId: retriedParentId,
1077
+ runId: RunId.make(`side-chat-worktree-retried-run-1-${status}`),
1078
+ ordinal: 1,
1079
+ status,
1080
+ text: "Retried setup",
1081
+ });
1082
+ const rejected = yield* forkSideChat(
1083
+ `side-chat-worktree-retried-fork-${status}`,
1084
+ retriedParentId,
1085
+ ThreadId.make(`side-chat-worktree-retried-child-${status}`),
1086
+ ).pipe(Effect.flip);
1087
+ assert.include(String(rejected.cause), "has no worktree yet", status);
1088
+ }
1089
+ }).pipe(Effect.provide(forkCases[0]!.layer)),
1090
+);
1091
+
1092
it.effect("closing a side chat deletes it only while unused; a deleted parent takes no more", () =>
1093
Effect.gen(function* () {
1094
const orchestrator = yield* Orchestrator.OrchestratorV2;
apps/web/src/components/ChatView.tsx
+1
-1
@@ -64,7 +64,6 @@ import {
64
type AssistantCitation,
65
type ChatFileAttachment,
66
isProviderNativeSubagentThread,
67
- orchestrationV2WorktreePending,
67
type EnvironmentId,
68
type MessageId,
69
type ModelSelection,
@@ -117,6 +116,7 @@ import {
116
import { formatModelSlugName, resolveSelectableModel } from "@t3tools/shared/model";
117
import { projectScriptCwd, resolveProjectScripts } from "@t3tools/shared/projectScripts";
118
import { resolveProjectSettings } from "@t3tools/shared/projectSettings";
119
+import { orchestrationV2WorktreePending } from "@t3tools/shared/orchestrationV2ThreadError";
120
import { resolveThreadReferenceCopyTarget } from "@t3tools/client-runtime/thread-reference";
121
import { resolveTerminalSessionLabel } from "@t3tools/shared/terminalLabels";
122
import { useAtomValue } from "@effect/atom-react";
packages/contracts/src/orchestrationV2.ts
-18
@@ -728,24 +728,6 @@ export function orchestrationV2RunWorkStartedAt(
728
return run.workStartedAt ?? run.startedAt ?? run.requestedAt;
729
}
730
731
-/**
732
- * Work started now would run in the project checkout, not the worktree the thread asked for. A
733
- * failed or interrupted setup leaves the request standing until a worktree exists.
734
- */
735
-export function orchestrationV2WorktreePending(
736
- worktreePath: string | null,
737
- runs: ReadonlyArray<Pick<OrchestrationV2Run, "status" | "workspacePreparation">>,
738
-): boolean {
739
- return (
740
- worktreePath === null &&
741
- runs.some(
742
- (run) =>
743
- (run.status === "preparing" || run.status === "failed" || run.status === "interrupted") &&
744
- run.workspacePreparation?.type === "worktree",
745
- )
746
- );
747
-}
748
-
731
export const OrchestrationV2RunAttempt = Schema.Struct({
732
id: RunAttemptId,
733
// Provider-thread rows can be reused after recovery; retain the native input destination.
packages/shared/src/orchestrationV2ThreadError.ts
+19
@@ -64,6 +64,25 @@ export function latestExecutedRun(
64
return latest;
65
}
66
67
+/**
68
+ * Work started now would run in the project checkout, not the worktree the thread asked for. A
69
+ * failed or interrupted setup leaves the request standing until a worktree exists or later work
70
+ * has run past it.
71
+ */
72
+export function orchestrationV2WorktreePending(
73
+ worktreePath: string | null,
74
+ runs: ReadonlyArray<OrchestrationV2Run>,
75
+): boolean {
76
+ const latest = latestExecutedRun(runs);
77
+ return (
78
+ worktreePath === null &&
79
+ (latest?.status === "preparing" ||
80
+ latest?.status === "failed" ||
81
+ latest?.status === "interrupted") &&
82
+ latest.workspacePreparation?.type === "worktree"
83
+ );
84
+}
85
+
86
/** Held queues can execute out of ordinal order; unfinished runs count as latest. */
87
export function runRanAfter(
88
run: Pick<OrchestrationV2Run, "ordinal" | "completedAt">,