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 23, 20:30 UTC
fix(web): new worktree threads no longer flicker while starting (#15019)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Theo Browne committed
Oct 2, 2026 at 21:37 UTC
3a7058da50c91906158c89fc3f845e6c04379414
6 files changed
+72
-17
apps/web/src/components/ChatView.logic.test.ts
+24
@@ -628,6 +628,30 @@ describe("hasServerAcknowledgedLocalDispatch", () => {
628
).toBe(true);
629
});
630
631
+ it("holds a first send while the thread shell still reports a preparing run", () => {
632
+ // The draft had no run. The server thread's shell shows the new run before
633
+ // the detail projection behind `phase` loads.
634
+ const localDispatch = createLocalDispatchSnapshot(makeThread());
635
+ const preparingRun = {
636
+ ...completedTurn,
637
+ status: "preparing" as const,
638
+ startedAt: null,
639
+ completedAt: null,
640
+ };
641
+
642
+ expect(
643
+ hasServerAcknowledgedLocalDispatch({
644
+ localDispatch,
645
+ phase: "disconnected",
646
+ latestRun: preparingRun,
647
+ runtime: { ...readySession, status: "preparing", activeRunId: preparingRun.runId },
648
+ hasPendingApproval: false,
649
+ hasPendingUserInput: false,
650
+ threadError: null,
651
+ }),
652
+ ).toBe(false);
653
+ });
654
+
655
it("waits for the matching running turn before acknowledging", () => {
656
const localDispatch = createLocalDispatchSnapshot(
657
makeThread({ latestRun: completedTurn, runtime: readySession }),
apps/web/src/components/ChatView.logic.ts
+5
-2
@@ -57,7 +57,7 @@ import { stripInlineContextReferences } from "~/lib/composerContextReferences";
57
import type { DraftThreadEnvMode } from "../composerDraftStore";
58
import { collapseExpandedComposerCursor, type ComposerSubmissionIntent } from "../composer-logic";
59
import type { ReviewCommentContext } from "../reviewCommentContext";
60
-import type { TimelineEntry } from "../session-logic";
60
+import { derivePhase, type TimelineEntry } from "../session-logic";
61
import type { PreviewMiniPlayerSource } from "../previewMiniPlayerStore";
62
import type { DesktopPreviewOverlay } from "../previewStateStore";
63
import type { RightPanelSurface } from "../rightPanelStore";
@@ -1248,7 +1248,10 @@ export function hasServerAcknowledgedLocalDispatch(input: {
1248
if (input.hasPendingApproval || input.hasPendingUserInput || Boolean(input.threadError)) {
1249
return true;
1250
}
1251
- if (input.phase === "connecting") {
1251
+ // The thread shell can report a preparing or starting run before the detail
1252
+ // projection behind `phase` loads, so either source still connecting holds
1253
+ // the send.
1254
+ if (input.phase === "connecting" || derivePhase(input.runtime ?? null) === "connecting") {
1255
return false;
1256
}
1257
apps/web/src/components/ChatView.tsx
+4
-1
@@ -6396,6 +6396,9 @@ export default function ChatView(props: ChatViewProps) {
6396
optimisticUserMessages,
6397
]);
6398
6399
+ // Keyed on the thread, not the draft: a draft's promotion to its server
6400
+ // route keeps this instance and drops `draftId`, and the send it is still
6401
+ // dispatching must survive that swap.
6402
useEffect(() => {
6403
setOptimisticUserMessages((existing) => {
6404
for (const message of existing) {
@@ -6405,7 +6408,7 @@ export default function ChatView(props: ChatViewProps) {
6408
});
6409
resetLocalDispatch();
6410
setExpandedImage(null);
6408
- }, [draftId, resetLocalDispatch, threadId]);
6411
+ }, [resetLocalDispatch, threadId]);
6412
6413
const closeExpandedImage = useCallback(() => {
6414
setExpandedImage(null);
apps/web/src/components/chat/MessagesTimeline.logic.test.ts
+16
@@ -4625,6 +4625,22 @@ it("keeps the working header in place across worktree setup handoff", () => {
4625
expect(handoffRows.map((row) => row.kind)).toEqual(["message", "working", "worktree-setup"]);
4626
expect(handoffRows[2]).toMatchObject({ kind: "worktree-setup", embedded: false });
4627
4628
+ // A clean finish before the turn is live keeps that same layout, so the card
4629
+ // does not jump above the header in the gap before the run starts.
4630
+ const settledRows = deriveMessagesTimelineRows({
4631
+ timelineEntries: [userEntry],
4632
+ isWorking: true,
4633
+ activeTurnStartedAt: "2026-01-01T00:00:00Z",
4634
+ turnDiffSummaries: [],
4635
+ supportsConversationRollback: false,
4636
+ worktreeSetup: {
4637
+ ...snapshot,
4638
+ phase: "done",
4639
+ stages: [stage("setup-script", "done"), stage("agent", "done")],
4640
+ },
4641
+ });
4642
+ expect(settledRows.map((row) => row.kind)).toEqual(["message", "working", "worktree-setup"]);
4643
+
4644
// A script that already finished has nothing left to show once the turn is live.
4645
const finishedRows = deriveMessagesTimelineRows({
4646
timelineEntries: [userEntry],
apps/web/src/components/chat/MessagesTimeline.logic.ts
+12
-6
@@ -1673,7 +1673,11 @@ export function deriveMessagesTimelineRows(input: {
1673
input.worktreeSetup !== undefined &&
1674
worktreeSetupAgentStarted(input.worktreeSetup) &&
1675
input.latestRun?.startedAt != null;
1676
- const setupRunning = !setupHandedOff && input.worktreeSetup?.phase === "running";
1676
+ // A finished setup keeps the slot until the turn is live, so the card does
1677
+ // not jump above the working header in the gap before the run starts.
1678
+ const setupOwnsWorkingSlot =
1679
+ !setupHandedOff &&
1680
+ (input.worktreeSetup?.phase === "running" || input.worktreeSetup?.phase === "done");
1681
if (input.worktreeSetup && (!setupHandedOff || input.worktreeSetup.phase !== "running")) {
1682
const setupRow = {
1683
kind: "worktree-setup",
@@ -1688,7 +1692,9 @@ export function deriveMessagesTimelineRows(input: {
1692
// While the setup runs, the working header leads the card in the same
1693
// slot it keeps once the agent's own turn takes over. The main pass may
1694
// already have placed that header (a bootstrap counts as working).
1691
- const workingRowIndex = setupRunning ? nextRows.findIndex((row) => row.kind === "working") : -1;
1695
+ const workingRowIndex = setupOwnsWorkingSlot
1696
+ ? nextRows.findIndex((row) => row.kind === "working")
1697
+ : -1;
1698
if (workingRowIndex >= 0) {
1699
nextRows.splice(workingRowIndex + 1, 0, setupRow);
1700
} else {
@@ -1696,7 +1702,7 @@ export function deriveMessagesTimelineRows(input: {
1702
nextRows.splice(
1703
insertAt,
1704
0,
1699
- ...(setupRunning
1705
+ ...(setupOwnsWorkingSlot
1706
? [
1707
{
1708
kind: "working",
@@ -1710,15 +1716,15 @@ export function deriveMessagesTimelineRows(input: {
1716
}
1717
}
1718
1713
- // A running setup owns the working slot above its card and shows no
1714
- // activity row of its own; every other state gets the usual tail.
1719
+ // A setup that owns the working slot sits under it and shows no activity
1720
+ // row of its own; every other state gets the usual tail.
1721
const hasWorkingRow = nextRows.some((row) => row.kind === "working");
1722
if (input.isWorking && !hasWorkingRow && activeTurnHeaderIndex === timelineEntries.length) {
1723
appendWorkingRow();
1724
}
1725
if (
1726
input.isWorking &&
1721
- !setupRunning &&
1727
+ !setupOwnsWorkingSlot &&
1728
!hasActiveCompaction &&
1729
(!hasActivityRow || latestToolFailed)
1730
) {
apps/web/src/components/chat/WorktreeSetupCard.tsx
+11
-8
@@ -356,17 +356,20 @@ export function WorktreeSetupCard({
356
const setupStage = snapshot.stages.find((stage) => stage.id === "setup-script");
357
const showTerminal = onOpenTerminal && setupStage && setupStage.status !== "pending";
358
const collapsed = embedded && !running;
359
- // While running, the timeline's working row above the card carries the
360
- // "Setting up worktree…" label (and keeps that slot when the agent takes
361
- // over). The card only brings its own header for a settled outcome that
362
- // has no working row to sit under.
363
- const showHeader = !embedded && !running;
359
+ // While running, and after a clean finish until the agent's turn is live,
360
+ // the timeline's working row above the card carries the label (and keeps
361
+ // that slot when the agent takes over). The card only brings its own
362
+ // header for a failed or cancelled setup that has no working row above it.
363
+ const showHeader = !embedded && !running && snapshot.phase !== "done";
364
// The tail box is part of the script row's footprint while the script runs
365
// (and after it failed, so the last lines explain the failure). It mounts
366
- // as soon as the script is running, empty lines and all, so the card takes
367
- // its final height once instead of growing with each output line.
366
+ // with the first output line at its full fixed height, so the card grows
367
+ // once instead of with each line. A script that ends before printing
368
+ // anything never flashes an empty box.
369
const showTail =
369
- setupStage !== undefined && (setupStage.status === "running" || setupStage.status === "failed");
370
+ setupStage !== undefined &&
371
+ (setupStage.status === "failed" ||
372
+ (setupStage.status === "running" && setupStage.tail.length > 0));
373
374
return (
375
<section aria-label="Worktree setup" data-worktree-setup-phase={snapshot.phase}>