Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
Gate latest-turn completion UI on settled turn state
Julius Marminge709f961e1c92
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsxindex 2e1404f05..08a3a2155 100644--- a/apps/web/src/components/ChatView.tsx+++ b/apps/web/src/components/ChatView.tsx@@ -44,6 +44,7 @@ import {type PendingApproval,deriveWorkLogEntries,hasToolActivityForTurn,+ isLatestTurnSettled,formatElapsed,formatTimestamp,} from "../session-logic";@@ -382,10 +383,12 @@ export default function ChatView({ threadId }: ChatViewProps) {const diffOpen = diffSearch.diff === "1";const activeThreadId = activeThread?.id ?? null;const activeLatestTurn = activeThread?.latestTurn ?? null;+ const latestTurnSettled = isLatestTurnSettled(activeLatestTurn, activeThread?.session ?? null);const activeProject = state.projects.find((p) => p.id === activeThread?.projectId);useEffect(() => {if (!activeThread?.id) return;+ if (!latestTurnSettled) return;if (!activeLatestTurn?.completedAt) return;const turnCompletedAt = Date.parse(activeLatestTurn.completedAt);if (Number.isNaN(turnCompletedAt)) return;@@ -400,6 +403,7 @@ export default function ChatView({ threadId }: ChatViewProps) {activeThread?.id,activeThread?.lastVisitedAt,activeLatestTurn?.completedAt,+ latestTurnSettled,dispatch,]);@@ -483,6 +487,7 @@ export default function ChatView({ threadId }: ChatViewProps) {}, [inferredCheckpointTurnCountByTurnId, timelineEntries, turnDiffSummaryByAssistantMessageId]);const completionSummary = useMemo(() => {+ if (!latestTurnSettled) return null;if (!activeLatestTurn?.startedAt) return null;if (!activeLatestTurn.completedAt) return null;if (!latestTurnHasToolActivity) return null;@@ -493,8 +498,10 @@ export default function ChatView({ threadId }: ChatViewProps) {activeLatestTurn?.completedAt,activeLatestTurn?.startedAt,latestTurnHasToolActivity,+ latestTurnSettled,]);const completionDividerBeforeEntryId = useMemo(() => {+ if (!latestTurnSettled) return null;if (!activeLatestTurn?.startedAt) return null;if (!activeLatestTurn.completedAt) return null;if (!completionSummary) return null;@@ -521,6 +528,7 @@ export default function ChatView({ threadId }: ChatViewProps) {activeLatestTurn?.completedAt,activeLatestTurn?.startedAt,completionSummary,+ latestTurnSettled,timelineEntries,]);const gitCwd = activeThread?.worktreePath ?? activeProject?.cwd ?? null;diff --git a/apps/web/src/session-logic.test.ts b/apps/web/src/session-logic.test.tsindex cafaea5f9..dc74adc67 100644--- a/apps/web/src/session-logic.test.ts+++ b/apps/web/src/session-logic.test.ts@@ -5,6 +5,7 @@ import {derivePendingApprovals,deriveWorkLogEntries,hasToolActivityForTurn,+ isLatestTurnSettled,} from "./session-logic";function makeActivity(overrides: {@@ -151,3 +152,42 @@ describe("hasToolActivityForTurn", () => {expect(hasToolActivityForTurn(activities, TurnId.makeUnsafe("turn-2"))).toBe(false);});});++describe("isLatestTurnSettled", () => {+ const latestTurn = {+ turnId: TurnId.makeUnsafe("turn-1"),+ startedAt: "2026-02-27T21:10:00.000Z",+ completedAt: "2026-02-27T21:10:06.000Z",+ } as const;++ it("returns false while the same turn is still active in a running session", () => {+ expect(+ isLatestTurnSettled(latestTurn, {+ orchestrationStatus: "running",+ activeTurnId: TurnId.makeUnsafe("turn-1"),+ }),+ ).toBe(false);+ });++ it("returns true once the session is no longer running that turn", () => {+ expect(+ isLatestTurnSettled(latestTurn, {+ orchestrationStatus: "ready",+ activeTurnId: undefined,+ }),+ ).toBe(true);+ });++ it("returns false when turn timestamps are incomplete", () => {+ expect(+ isLatestTurnSettled(+ {+ turnId: TurnId.makeUnsafe("turn-1"),+ startedAt: null,+ completedAt: "2026-02-27T21:10:06.000Z",+ },+ null,+ ),+ ).toBe(false);+ });+});diff --git a/apps/web/src/session-logic.ts b/apps/web/src/session-logic.tsindex 4a4f60251..27d75ef6d 100644--- a/apps/web/src/session-logic.ts+++ b/apps/web/src/session-logic.ts@@ -1,5 +1,6 @@import {ApprovalRequestId,+ type OrchestrationLatestTurn,type OrchestrationThreadActivity,type ProviderKind,type TurnId,@@ -75,6 +76,18 @@ export function formatElapsed(startIso: string, endIso: string | undefined): strreturn formatDuration(endedAt - startedAt);}+export function isLatestTurnSettled(+ latestTurn: Pick<OrchestrationLatestTurn, "turnId" | "startedAt" | "completedAt"> | null,+ session: Pick<ThreadSession, "orchestrationStatus" | "activeTurnId"> | null,+): boolean {+ if (!latestTurn?.startedAt) return false;+ if (!latestTurn.completedAt) return false;+ if (!session) return true;+ return !(+ session.orchestrationStatus === "running" && session.activeTurnId === latestTurn.turnId+ );+}+export function derivePendingApprovals(activities: ReadonlyArray<OrchestrationThreadActivity>,): PendingApproval[] {