Skip to content

Commit 35aced3

Browse files
fix(web): retire the worktree setup row after the first turn
A failed setup script's row was kept for the thread's whole life, so it rode along on every follow-up turn. The setup belongs to the first turn: once the user sends another message, every settled outcome is history and nothing is shown again. Only a script that is still running survives a follow-up. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent b4a5156 commit 35aced3

3 files changed

Lines changed: 48 additions & 13 deletions

File tree

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

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2536,10 +2536,20 @@ describe("worktree setup visibility", () => {
25362536

25372537
it("shows a running setup and drops a clean one once the turn started", () => {
25382538
const visible = (snapshot: WorktreeSetupSnapshot | null, turnStarted: boolean) =>
2539-
resolveVisibleWorktreeSetup({ live: null, recorded: snapshot, turnStarted });
2540-
expect(resolveVisibleWorktreeSetup({ live: base, recorded: null, turnStarted: false })).toEqual(
2541-
base,
2542-
);
2539+
resolveVisibleWorktreeSetup({
2540+
live: null,
2541+
recorded: snapshot,
2542+
turnStarted,
2543+
followUpSent: false,
2544+
});
2545+
expect(
2546+
resolveVisibleWorktreeSetup({
2547+
live: base,
2548+
recorded: null,
2549+
turnStarted: false,
2550+
followUpSent: false,
2551+
}),
2552+
).toEqual(base);
25432553
expect(visible(settledDone, false)).toEqual(settledDone);
25442554
expect(visible(settledDone, true)).toBeNull();
25452555
expect(visible(null, true)).toBeNull();
@@ -2550,18 +2560,35 @@ describe("worktree setup visibility", () => {
25502560
...settledDone,
25512561
stages: [stage("checkout", "done"), stage("setup-script", "failed"), stage("agent", "done")],
25522562
};
2553-
const visible = (snapshot: WorktreeSetupSnapshot) =>
2554-
resolveVisibleWorktreeSetup({ live: null, recorded: snapshot, turnStarted: true });
2563+
const visible = (snapshot: WorktreeSetupSnapshot, followUpSent = false) =>
2564+
resolveVisibleWorktreeSetup({
2565+
live: null,
2566+
recorded: snapshot,
2567+
turnStarted: true,
2568+
followUpSent,
2569+
});
25552570
expect(visible(scriptFailed)).toEqual(scriptFailed);
25562571
const failed = { ...settledDone, phase: "failed" as const, error: "git exploded" };
25572572
expect(visible(failed)).toEqual(failed);
25582573
const cancelled = { ...settledDone, phase: "cancelled" as const };
25592574
expect(visible(cancelled)).toEqual(cancelled);
2575+
2576+
// The setup belongs to the first turn. A follow-up send retires every
2577+
// settled outcome; only a script that is still running stays.
2578+
expect(visible(scriptFailed, true)).toBeNull();
2579+
expect(visible(failed, true)).toBeNull();
2580+
expect(visible(cancelled, true)).toBeNull();
2581+
expect(visible(settledDone, true)).toBeNull();
2582+
const stillRunning = {
2583+
...base,
2584+
stages: [stage("checkout", "done"), stage("setup-script", "running"), stage("agent", "done")],
2585+
};
2586+
expect(visible(stillRunning, true)).toEqual(stillRunning);
25602587
});
25612588

25622589
it("prefers whichever snapshot is newer by sequence", () => {
25632590
const pick = (live: WorktreeSetupSnapshot | null, recorded: WorktreeSetupSnapshot | null) =>
2564-
resolveVisibleWorktreeSetup({ live, recorded, turnStarted: false });
2591+
resolveVisibleWorktreeSetup({ live, recorded, turnStarted: false, followUpSent: false });
25652592
expect(pick({ ...base, sequence: 3 }, { ...settledDone, sequence: 7 })).toEqual({
25662593
...settledDone,
25672594
sequence: 7,

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,23 +278,30 @@ export function findRecordedWorktreeSetup(
278278
/**
279279
* Which setup snapshot the timeline shows, if any. The live stream wins while
280280
* it has a newer sequence; the recorded activity covers everything else. A
281-
* running, failed, or cancelled setup always shows. A clean finish leaves no
282-
* trace once the turn is live: the setup is a means to the reply, not part of
283-
* the conversation. Before the turn is live it stays so nothing collapses in
284-
* the handoff gap. A failed script stays for good, so its exit code and
285-
* terminal remain reachable; visibility never depends on whether some later
286-
* turn happens to be running, which would make the row come and go.
281+
* running setup always shows. The setup belongs to the thread's first turn:
282+
* once the user has sent a follow-up it is history and nothing about it is
283+
* shown again, whatever its outcome. Within that first turn, a clean finish
284+
* leaves no trace once the turn is live (the setup is a means to the reply,
285+
* not part of the conversation), while a failed script, a failed setup, or a
286+
* cancelled one stays so the outcome, exit code, and terminal are reachable.
287+
* Before the turn is live everything stays so nothing collapses in the
288+
* handoff gap. Visibility never depends on whether a turn happens to be
289+
* running, which would make the row come and go.
287290
*/
288291
export function resolveVisibleWorktreeSetup(input: {
289292
live: WorktreeSetupSnapshot | null;
290293
recorded: WorktreeSetupSnapshot | null;
291294
turnStarted: boolean;
295+
/** The user sent a message after the one that created the worktree. */
296+
followUpSent: boolean;
292297
}): WorktreeSetupSnapshot | null {
293298
const snapshot =
294299
input.live && (!input.recorded || input.live.sequence >= input.recorded.sequence)
295300
? input.live
296301
: input.recorded;
297302
if (!snapshot) return null;
303+
if (snapshot.phase === "running") return snapshot;
304+
if (input.followUpSent) return null;
298305
if (snapshot.phase !== "done") return snapshot;
299306
if (!input.turnStarted) return snapshot;
300307
return snapshot.stages.some((stage) => stage.status === "failed") ? snapshot : null;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3529,6 +3529,7 @@ export default function ChatView(props: ChatViewProps) {
35293529
live: liveWorktreeSetup,
35303530
recorded: recordedWorktreeSetup,
35313531
turnStarted: activeThread?.latestTurn?.startedAt != null,
3532+
followUpSent: (serverMessages?.filter((message) => message.role === "user").length ?? 0) > 1,
35323533
});
35333534
// Sends wait for the agent handoff, not for the setup script: an async
35343535
// script keeps the snapshot running while the agent already works, and a

0 commit comments

Comments
 (0)