Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions apps/web/src/session-logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { describe, expect, it } from "vitest";
import {
deriveActiveWorkStartedAt,
deriveActivePlanState,
derivePhase,
PROVIDER_OPTIONS,
derivePendingApprovals,
derivePendingUserInputs,
Expand All @@ -21,6 +22,7 @@ import {
hasToolActivityForTurn,
isLatestTurnSettled,
} from "./session-logic";
import type { ThreadSession } from "./types";

function makeActivity(overrides: {
id?: string;
Expand Down Expand Up @@ -174,6 +176,21 @@ describe("derivePendingApprovals", () => {
});
});

describe("derivePhase", () => {
it("treats errored sessions as disconnected instead of ready", () => {
const session: ThreadSession = {
provider: "codex",
status: "error",
orchestrationStatus: "error",
createdAt: "2026-02-23T00:00:00.000Z",
updatedAt: "2026-02-23T00:00:01.000Z",
lastError: "Provider crashed",
};

expect(derivePhase(session)).toBe("disconnected");
});
});

describe("derivePendingUserInputs", () => {
it("tracks open structured prompts and removes resolved ones", () => {
const activities: OrchestrationThreadActivity[] = [
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/session-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,9 @@ export function inferCheckpointTurnCountByTurnId(
}

export function derivePhase(session: ThreadSession | null): SessionPhase {
if (!session || session.status === "closed") return "disconnected";
if (!session || session.status === "closed" || session.status === "error") {
return "disconnected";
}
if (session.status === "connecting") return "connecting";
if (session.status === "running") return "running";
return "ready";
Expand Down