Skip to content

Commit 0e6f80e

Browse files
fix(chat): smooth worktree setup status
1 parent bba79cc commit 0e6f80e

14 files changed

Lines changed: 341 additions & 89 deletions

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

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { ProviderIcon } from "../../components/ProviderIcon";
3737
import { SymbolView } from "../../components/AppSymbol";
3838
import { AppText as Text } from "../../components/AppText";
3939
import { COMPOSER_LAYOUT_TRANSITION, ComposerSurface } from "./ThreadComposer";
40+
import { ShimmeringWorkContent } from "./thread-work-log";
4041
import { ComposerCommandPopover } from "./ComposerCommandPopover";
4142
import { useComposerCommandMenu } from "./use-composer-command-menu";
4243
import {
@@ -364,7 +365,8 @@ export function NewTaskDraftScreen(props: {
364365
};
365366
}, [props.pendingTaskId, cancelEditingPendingTask]);
366367

367-
const foregroundColor = useUniwindTheme()["--color-foreground"];
368+
const theme = useUniwindTheme();
369+
const foregroundColor = theme["--color-foreground"];
368370
const regularFontFamily = useFontFamily("regular");
369371
const bodyText = useScaledTextRole("body");
370372

@@ -1094,31 +1096,50 @@ export function NewTaskDraftScreen(props: {
10941096

10951097
const workspaceControls = (
10961098
<View className="flex-row items-center gap-1 px-2">
1097-
<ComposerInlineControl
1098-
accessibilityHint={`Switches to ${flow.workspaceMode === "local" ? "a new worktree" : "the current checkout"}`}
1099-
accessibilityLabel={workspaceLabel}
1100-
disabled={isComposerInteractionLocked || voiceInput.isBusy}
1101-
iconNode={
1102-
<NewTaskWorkspaceIcon
1103-
workspaceMode={flow.workspaceMode}
1104-
worktreePath={flow.selectedWorktreePath}
1099+
{flow.submitting && environmentConnected && flow.workspaceMode === "worktree" ? (
1100+
<View
1101+
accessible
1102+
accessibilityLabel="Setting up worktree…"
1103+
className="h-11 w-full max-w-[260px] flex-row items-center px-2"
1104+
>
1105+
<ShimmeringWorkContent
1106+
icon="arrow.triangle.branch"
1107+
iconSubtleColor={theme["--color-icon-subtle"]}
1108+
label="Setting up worktree…"
1109+
showIcon
1110+
/>
1111+
</View>
1112+
) : (
1113+
<>
1114+
<ComposerInlineControl
1115+
accessibilityHint={`Switches to ${flow.workspaceMode === "local" ? "a new worktree" : "the current checkout"}`}
1116+
accessibilityLabel={workspaceLabel}
1117+
disabled={isComposerInteractionLocked || voiceInput.isBusy}
1118+
iconNode={
1119+
<NewTaskWorkspaceIcon
1120+
workspaceMode={flow.workspaceMode}
1121+
worktreePath={flow.selectedWorktreePath}
1122+
/>
1123+
}
1124+
label={workspaceLabel}
1125+
maxWidth={flow.workspaceMode === "local" ? 220 : 148}
1126+
onPress={() =>
1127+
flow.setWorkspaceMode(flow.workspaceMode === "local" ? "worktree" : "local")
1128+
}
1129+
showChevron={false}
11051130
/>
1106-
}
1107-
label={workspaceLabel}
1108-
maxWidth={flow.workspaceMode === "local" ? 220 : 148}
1109-
onPress={() => flow.setWorkspaceMode(flow.workspaceMode === "local" ? "worktree" : "local")}
1110-
showChevron={false}
1111-
/>
11121131

1113-
<ComposerInlineControl
1114-
accessibilityLabel={`${flow.workspaceMode === "worktree" ? "Base branch" : "Branch"}: ${selectedBranchLabel}`}
1115-
chevronDirection="right"
1116-
disabled={isComposerInteractionLocked}
1117-
icon="arrow.triangle.branch"
1118-
label={showBranchLoading ? "Loading branches…" : selectedBranchLabel}
1119-
maxWidth={190}
1120-
onPress={() => openContextPicker("NewTaskBranch")}
1121-
/>
1132+
<ComposerInlineControl
1133+
accessibilityLabel={`${flow.workspaceMode === "worktree" ? "Base branch" : "Branch"}: ${selectedBranchLabel}`}
1134+
chevronDirection="right"
1135+
disabled={isComposerInteractionLocked}
1136+
icon="arrow.triangle.branch"
1137+
label={showBranchLoading ? "Loading branches…" : selectedBranchLabel}
1138+
maxWidth={190}
1139+
onPress={() => openContextPicker("NewTaskBranch")}
1140+
/>
1141+
</>
1142+
)}
11221143
</View>
11231144
);
11241145

‎apps/mobile/src/features/threads/thread-work-log.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function ShimmerWorkContent(props: {
7878
);
7979
}
8080

81-
function ShimmeringWorkContent(props: {
81+
export function ShimmeringWorkContent(props: {
8282
readonly icon: AppSymbolName;
8383
readonly iconSubtleColor: ColorValue;
8484
readonly label: string;

‎apps/mobile/src/lib/threadActivity.test.ts‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,83 @@ function makeThread(
234234
}
235235

236236
describe("buildThreadFeed", () => {
237+
it("keeps setup failures visible without routine setup notices before or after a turn", () => {
238+
const thread = makeThread({
239+
id: ThreadId.make("thread-worktree-setup"),
240+
projectId: ProjectId.make("project-1"),
241+
title: "Worktree setup",
242+
activities: [
243+
makeActivity({
244+
id: EventId.make("setup-requested"),
245+
kind: "setup-script.requested",
246+
summary: "Starting setup script",
247+
createdAt: "2026-08-30T00:00:00.000Z",
248+
}),
249+
makeActivity({
250+
id: EventId.make("setup-started"),
251+
kind: "setup-script.started",
252+
summary: "Setup script started",
253+
createdAt: "2026-08-30T00:00:01.000Z",
254+
}),
255+
makeActivity({
256+
id: EventId.make("setup-failed"),
257+
kind: "setup-script.failed",
258+
summary: "Setup script failed to start",
259+
createdAt: "2026-08-30T00:00:02.000Z",
260+
tone: "error",
261+
payload: { detail: "Setup command was not found" },
262+
}),
263+
],
264+
});
265+
const latestTurn = {
266+
turnId: TurnId.make("turn-after-setup"),
267+
state: "running" as const,
268+
requestedAt: "2026-08-30T00:00:03.000Z",
269+
startedAt: "2026-08-30T00:00:04.000Z",
270+
completedAt: null,
271+
assistantMessageId: null,
272+
};
273+
274+
for (const currentTurn of [null, latestTurn]) {
275+
const feed = buildThreadFeed({ ...thread, latestTurn: currentTurn });
276+
expect(feed).toMatchObject([
277+
{
278+
type: "activity-group",
279+
activities: [{ id: "setup-failed", status: "failure" }],
280+
},
281+
]);
282+
const group = feed[0];
283+
if (group?.type !== "activity-group") throw new Error("Expected the setup failure group");
284+
expect(group.activities[0]?.getCopyText()).toContain("Setup command was not found");
285+
}
286+
});
287+
288+
it.each(["setup-script.requested", "setup-script.started"])(
289+
"keeps error-toned %s notices visible",
290+
(kind) => {
291+
const feed = buildThreadFeed(
292+
makeThread({
293+
id: ThreadId.make("thread-setup-error"),
294+
projectId: ProjectId.make("project-1"),
295+
title: "Setup error",
296+
activities: [
297+
makeActivity({
298+
id: EventId.make("setup-error"),
299+
kind,
300+
summary: "Setup failed",
301+
createdAt: "2026-08-30T00:00:00.000Z",
302+
tone: "error",
303+
}),
304+
],
305+
}),
306+
);
307+
308+
expect(feed).toMatchObject([
309+
{ type: "activity-group", activities: [{ id: "setup-error", status: "failure" }] },
310+
]);
311+
},
312+
);
313+
237314
it("keeps older local feedback before newer messages returned by the server", () => {
238315
const submission = {
239316
id: MessageId.make("feedback-command-ordering"),

‎apps/mobile/src/lib/threadActivity.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
} from "@t3tools/contracts";
1515
import { formatDuration } from "@t3tools/shared/orchestrationTiming";
1616
import {
17+
isWorktreeSetupActivity,
1718
normalizeCompactToolLabel,
1819
omitSupersededLifecycleMarkers,
1920
summarizeToolGroup,
@@ -343,6 +344,7 @@ function deriveWorkLogEntries(
343344
const ordered = Arr.sort(activities, activityOrder);
344345
const entries: DerivedWorkLogEntry[] = [];
345346
for (const activity of ordered) {
347+
if (activity.tone !== "error" && isWorktreeSetupActivity(activity.kind)) continue;
346348
if (activity.kind === "tool.started") continue;
347349
if (activity.kind === "task.started") continue;
348350
// Terminal bypassed updates pass: Codex children's only terminal signal.

‎apps/web/src/components/ChatView.logic.test.ts‎

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ describe("draft hero submission transition", () => {
115115
expect(
116116
resolveDraftPromotionNavigationTarget({
117117
serverThreadRef: { environmentId, threadId },
118-
serverThreadStarted: true,
118+
serverThread: makeThread({ latestTurn: completedTurn }),
119119
backgroundSubmissionPending: true,
120120
}),
121121
).toBeNull();
@@ -316,6 +316,66 @@ const readySession = {
316316
updatedAt: "2026-03-29T00:00:10.000Z",
317317
};
318318

319+
describe("draft promotion during worktree setup", () => {
320+
const serverThreadRef = { environmentId, threadId };
321+
322+
it.each([null, "idle", "starting", "ready"] as const)(
323+
"keeps the draft mounted while the first turn waits with session %s",
324+
(status) => {
325+
const serverThread = makeThread({
326+
messages: [
327+
{
328+
id: MessageId.make("submitted-message"),
329+
role: "user",
330+
text: "Start in a new worktree",
331+
turnId: null,
332+
createdAt: now,
333+
updatedAt: now,
334+
streaming: false,
335+
},
336+
],
337+
session: status ? { ...readySession, status } : null,
338+
});
339+
340+
expect(
341+
resolveDraftPromotionNavigationTarget({
342+
serverThreadRef,
343+
serverThread,
344+
backgroundSubmissionPending: false,
345+
}),
346+
).toBeNull();
347+
},
348+
);
349+
350+
it("promotes when the provider starts the first turn", () => {
351+
const latestTurn = { ...completedTurn, state: "running" as const, completedAt: null };
352+
353+
expect(
354+
resolveDraftPromotionNavigationTarget({
355+
serverThreadRef,
356+
serverThread: makeThread({
357+
latestTurn,
358+
session: { ...readySession, status: "running", activeTurnId: latestTurn.turnId },
359+
}),
360+
backgroundSubmissionPending: false,
361+
}),
362+
).toEqual(serverThreadRef);
363+
});
364+
365+
it.each(["error", "stopped", "interrupted"] as const)(
366+
"promotes a startup that ends as %s before a turn starts",
367+
(status) => {
368+
expect(
369+
resolveDraftPromotionNavigationTarget({
370+
serverThreadRef,
371+
serverThread: makeThread({ session: { ...readySession, status } }),
372+
backgroundSubmissionPending: false,
373+
}),
374+
).toEqual(serverThreadRef);
375+
},
376+
);
377+
});
378+
319379
describe("buildLoadingThreadFromShell", () => {
320380
it("preserves shell metadata and supplies empty detail collections", () => {
321381
const shell = {

‎apps/web/src/components/ChatView.logic.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,19 @@ export function resolveDraftHeroState(input: {
110110

111111
export function resolveDraftPromotionNavigationTarget(input: {
112112
serverThreadRef: ScopedThreadRef | null;
113-
serverThreadStarted: boolean;
113+
serverThread: Pick<Thread, "latestTurn" | "session"> | null | undefined;
114114
backgroundSubmissionPending: boolean;
115115
}): ScopedThreadRef | null {
116116
if (input.backgroundSubmissionPending) {
117117
return null;
118118
}
119-
return input.serverThreadStarted ? input.serverThreadRef : null;
119+
const sessionStatus = input.serverThread?.session?.status;
120+
const turnStarted = input.serverThread?.latestTurn?.startedAt != null;
121+
const startupStopped =
122+
sessionStatus === "error" || sessionStatus === "stopped" || sessionStatus === "interrupted";
123+
// Keep local preparation feedback mounted until the server can render the
124+
// running turn or its startup error on the canonical thread route.
125+
return turnStarted || startupStopped ? input.serverThreadRef : null;
120126
}
121127

122128
export function scheduleEnvironmentReconnectWarning(showWarning: () => void): () => void {

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ import {
5353
createModelSelection,
5454
resolvePromptInjectedEffort,
5555
} from "@t3tools/shared/model";
56-
import { CHAT_LIST_ANCHOR_OFFSET } from "@t3tools/shared/chatList";
5756
import { projectScriptCwd, projectScriptRuntimeEnv } from "@t3tools/shared/projectScripts";
5857
import { truncate } from "@t3tools/shared/String";
5958
import {
@@ -108,7 +107,11 @@ import {
108107
isLatestTurnSettled,
109108
} from "../session-logic";
110109
import { type LegendListRef } from "@legendapp/list/react";
111-
import { getAnchoredTurnMetrics, type TimelineScrollMode } from "./chat/timelineScrollAnchoring";
110+
import {
111+
CHAT_TIMELINE_ANCHOR_OFFSET,
112+
getAnchoredTurnMetrics,
113+
type TimelineScrollMode,
114+
} from "./chat/timelineScrollAnchoring";
112115
import {
113116
buildPendingUserInputAnswers,
114117
derivePendingUserInputProgress,
@@ -4110,7 +4113,7 @@ function ChatViewContent(props: ChatViewProps) {
41104113
state,
41114114
anchorIndex,
41124115
composerOverlayHeight,
4113-
anchorOffset: CHAT_LIST_ANCHOR_OFFSET,
4116+
anchorOffset: CHAT_TIMELINE_ANCHOR_OFFSET,
41144117
});
41154118
},
41164119
[composerOverlayHeight],
@@ -4138,7 +4141,7 @@ function ChatViewContent(props: ChatViewProps) {
41384141
const realContentBottom = lastRowTop + Math.max(1, lastRowHeight);
41394142
const visibleScrollLength = Math.max(
41404143
0,
4141-
(state.scrollLength ?? 0) - composerOverlayHeight - CHAT_LIST_ANCHOR_OFFSET,
4144+
(state.scrollLength ?? 0) - composerOverlayHeight - CHAT_TIMELINE_ANCHOR_OFFSET,
41424145
);
41434146
return realContentBottom > visibleScrollLength;
41444147
},
@@ -4326,7 +4329,7 @@ function ChatViewContent(props: ChatViewProps) {
43264329
index: anchorIndex,
43274330
animated: true,
43284331
viewPosition: 0,
4329-
viewOffset: CHAT_LIST_ANCHOR_OFFSET,
4332+
viewOffset: CHAT_TIMELINE_ANCHOR_OFFSET,
43304333
})
43314334
.then(() => {
43324335
if (positionedTimelineAnchorRef.current !== messageId) {
@@ -6146,7 +6149,6 @@ function ChatViewContent(props: ChatViewProps) {
61466149
: {}),
61476150
}
61486151
: undefined;
6149-
beginLocalDispatch({ preparingWorktree: false });
61506152
const backgroundThreadRef =
61516153
resolvedSubmissionIntent === "background"
61526154
? scopeThreadRef(activeThread.environmentId, threadIdForSend)
@@ -7225,6 +7227,7 @@ function ChatViewContent(props: ChatViewProps) {
72257227
onOpenAgents={addAgentsSurface}
72267228
key={activeThread.id}
72277229
isWorking={isWorking}
7230+
isPreparingWorktree={isPreparingWorktree}
72287231
activeTurnStartedAt={activeWorkStartedAt}
72297232
listRef={legendListRef}
72307233
timelineEntries={timelineEntries}

0 commit comments

Comments
 (0)