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
This commit is contained in:
1 parent
273ac5fbae
commit
08ea222735
3 files changed
+61
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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): str
|
||||
return 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[] {
|
||||
|
||||
Reference in new issue
Block a user