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 25, 16:00 UTC
Gate latest-turn completion UI on settled turn state
- Add `isLatestTurnSettled` to avoid treating an active running turn as complete - Use the guard in `ChatView` for visited timestamps and completion summary/divider rendering - Add unit tests covering running, ready, and incomplete-timestamp cases
Julius Marminge committed
Feb 27, 2026 at 14:54 UTC
709f961e1c9261efd43673a0e802c6cd0bfca8f1
3 files changed
+61
apps/web/src/components/ChatView.tsx
+8
@@ -44,6 +44,7 @@ import {
44
type PendingApproval,
45
deriveWorkLogEntries,
46
hasToolActivityForTurn,
47
+ isLatestTurnSettled,
48
formatElapsed,
49
formatTimestamp,
50
} from "../session-logic";
@@ -382,10 +383,12 @@ export default function ChatView({ threadId }: ChatViewProps) {
383
const diffOpen = diffSearch.diff === "1";
384
const activeThreadId = activeThread?.id ?? null;
385
const activeLatestTurn = activeThread?.latestTurn ?? null;
386
+ const latestTurnSettled = isLatestTurnSettled(activeLatestTurn, activeThread?.session ?? null);
387
const activeProject = state.projects.find((p) => p.id === activeThread?.projectId);
388
389
useEffect(() => {
390
if (!activeThread?.id) return;
391
+ if (!latestTurnSettled) return;
392
if (!activeLatestTurn?.completedAt) return;
393
const turnCompletedAt = Date.parse(activeLatestTurn.completedAt);
394
if (Number.isNaN(turnCompletedAt)) return;
@@ -400,6 +403,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
403
activeThread?.id,
404
activeThread?.lastVisitedAt,
405
activeLatestTurn?.completedAt,
406
+ latestTurnSettled,
407
dispatch,
408
]);
409
@@ -483,6 +487,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
487
}, [inferredCheckpointTurnCountByTurnId, timelineEntries, turnDiffSummaryByAssistantMessageId]);
488
489
const completionSummary = useMemo(() => {
490
+ if (!latestTurnSettled) return null;
491
if (!activeLatestTurn?.startedAt) return null;
492
if (!activeLatestTurn.completedAt) return null;
493
if (!latestTurnHasToolActivity) return null;
@@ -493,8 +498,10 @@ export default function ChatView({ threadId }: ChatViewProps) {
498
activeLatestTurn?.completedAt,
499
activeLatestTurn?.startedAt,
500
latestTurnHasToolActivity,
501
+ latestTurnSettled,
502
]);
503
const completionDividerBeforeEntryId = useMemo(() => {
504
+ if (!latestTurnSettled) return null;
505
if (!activeLatestTurn?.startedAt) return null;
506
if (!activeLatestTurn.completedAt) return null;
507
if (!completionSummary) return null;
@@ -521,6 +528,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
528
activeLatestTurn?.completedAt,
529
activeLatestTurn?.startedAt,
530
completionSummary,
531
+ latestTurnSettled,
532
timelineEntries,
533
]);
534
const gitCwd = activeThread?.worktreePath ?? activeProject?.cwd ?? null;
apps/web/src/session-logic.test.ts
+40
@@ -5,6 +5,7 @@ import {
5
derivePendingApprovals,
6
deriveWorkLogEntries,
7
hasToolActivityForTurn,
8
+ isLatestTurnSettled,
9
} from "./session-logic";
10
11
function makeActivity(overrides: {
@@ -151,3 +152,42 @@ describe("hasToolActivityForTurn", () => {
152
expect(hasToolActivityForTurn(activities, TurnId.makeUnsafe("turn-2"))).toBe(false);
153
});
154
});
155
+
156
+describe("isLatestTurnSettled", () => {
157
+ const latestTurn = {
158
+ turnId: TurnId.makeUnsafe("turn-1"),
159
+ startedAt: "2026-02-27T21:10:00.000Z",
160
+ completedAt: "2026-02-27T21:10:06.000Z",
161
+ } as const;
162
+
163
+ it("returns false while the same turn is still active in a running session", () => {
164
+ expect(
165
+ isLatestTurnSettled(latestTurn, {
166
+ orchestrationStatus: "running",
167
+ activeTurnId: TurnId.makeUnsafe("turn-1"),
168
+ }),
169
+ ).toBe(false);
170
+ });
171
+
172
+ it("returns true once the session is no longer running that turn", () => {
173
+ expect(
174
+ isLatestTurnSettled(latestTurn, {
175
+ orchestrationStatus: "ready",
176
+ activeTurnId: undefined,
177
+ }),
178
+ ).toBe(true);
179
+ });
180
+
181
+ it("returns false when turn timestamps are incomplete", () => {
182
+ expect(
183
+ isLatestTurnSettled(
184
+ {
185
+ turnId: TurnId.makeUnsafe("turn-1"),
186
+ startedAt: null,
187
+ completedAt: "2026-02-27T21:10:06.000Z",
188
+ },
189
+ null,
190
+ ),
191
+ ).toBe(false);
192
+ });
193
+});
apps/web/src/session-logic.ts
+13
@@ -1,5 +1,6 @@
1
import {
2
ApprovalRequestId,
3
+ type OrchestrationLatestTurn,
4
type OrchestrationThreadActivity,
5
type ProviderKind,
6
type TurnId,
@@ -75,6 +76,18 @@ export function formatElapsed(startIso: string, endIso: string | undefined): str
76
return formatDuration(endedAt - startedAt);
77
}
78
79
+export function isLatestTurnSettled(
80
+ latestTurn: Pick<OrchestrationLatestTurn, "turnId" | "startedAt" | "completedAt"> | null,
81
+ session: Pick<ThreadSession, "orchestrationStatus" | "activeTurnId"> | null,
82
+): boolean {
83
+ if (!latestTurn?.startedAt) return false;
84
+ if (!latestTurn.completedAt) return false;
85
+ if (!session) return true;
86
+ return !(
87
+ session.orchestrationStatus === "running" && session.activeTurnId === latestTurn.turnId
88
+ );
89
+}
90
+
91
export function derivePendingApprovals(
92
activities: ReadonlyArray<OrchestrationThreadActivity>,
93
): PendingApproval[] {