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
5 changes: 2 additions & 3 deletions apps/web/src/components/chat/ThreadActivityBanners.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,14 @@ export function goalNowItem(input: {
title: (
<Popover>
<PopoverTrigger openOnHover render={<InlineButton />}>
{presentation.title}
{presentation.usage === null ? null : ` · ${presentation.usage}`}
{`${presentation.title}: ${presentation.objective}`}
</PopoverTrigger>
<PopoverPopup side="top" width="md" padding="compact" aria-label="Goal objective">
<p className="whitespace-pre-wrap wrap-anywhere text-sm">{presentation.objective}</p>
</PopoverPopup>
</Popover>
),
description: presentation.objective,
description: presentation.usage ?? undefined,
// Clear stops goal work; Resume would stop unrelated work, so it waits.
actions: (
<>
Expand Down
42 changes: 37 additions & 5 deletions packages/client-runtime/src/state/threadExecution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,38 @@ import {

const now = DateTime.makeUnsafe("2026-07-28T10:00:00.000Z");

describe("provider goal usage", () => {
it("labels goal tokens as excluding cache and identifies the elapsed duration", () => {
expect(
presentProviderGoal(
{
objective: "keep going",
status: "active",
tokensUsed: 30_072_613,
timeUsedSeconds: 230_271,
},
true,
).usage,
).toBe("30.1m uncached tokens · 63h 57m 51s elapsed");
});

it("uses the same token accounting label for a goal budget", () => {
expect(
presentProviderGoal(
{ objective: "Ship it", status: "paused", tokensUsed: 12_000, tokenBudget: 50_000 },
false,
).usage,
).toBe("12k / 50k uncached tokens");
});

it("keeps Claude checks and goals without usage independent of token accounting", () => {
expect(
presentProviderGoal({ objective: "Ship it", status: "active", checks: 2 }, true).usage,
).toBe("2 checks");
expect(presentProviderGoal({ objective: "Ship it", status: "active" }, false).usage).toBeNull();
});
});

function request(
id: string,
status: OrchestrationV2RuntimeRequest["status"],
Expand Down Expand Up @@ -727,10 +759,10 @@ describe("presentProviderGoal", () => {
{ objective: "Ship the feature", status: "active", tokensUsed, tokenBudget: 2_000_000 },
true,
).usage;
expect(usage(999_499)).toBe("999k / 2m tokens");
expect(usage(999_500)).toBe("1m / 2m tokens");
expect(usage(999_999)).toBe("1m / 2m tokens");
expect(usage(1_000_000)).toBe("1m / 2m tokens");
expect(usage(999_499)).toBe("999k / 2m uncached tokens");
expect(usage(999_500)).toBe("1m / 2m uncached tokens");
expect(usage(999_999)).toBe("1m / 2m uncached tokens");
expect(usage(1_000_000)).toBe("1m / 2m uncached tokens");
expect(
presentProviderGoal(
{
Expand All @@ -741,7 +773,7 @@ describe("presentProviderGoal", () => {
},
false,
).usage,
).toBe("1m / 1m tokens");
).toBe("1m / 1m uncached tokens");
});
});

Expand Down
7 changes: 4 additions & 3 deletions packages/client-runtime/src/state/threadExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,14 +672,15 @@ export function presentProviderGoal(
): ProviderGoalPresentation {
const usage: Array<string> = [];
if (goal.tokensUsed !== undefined && goal.tokensUsed > 0) {
// Codex goal accounting excludes cached input, unlike total thread usage.
usage.push(
goal.tokenBudget == null
? `${formatGoalTokens(goal.tokensUsed)} tokens`
: `${formatGoalTokens(goal.tokensUsed)} / ${formatGoalTokens(goal.tokenBudget)} tokens`,
? `${formatGoalTokens(goal.tokensUsed)} uncached tokens`
: `${formatGoalTokens(goal.tokensUsed)} / ${formatGoalTokens(goal.tokenBudget)} uncached tokens`,
);
}
if (goal.timeUsedSeconds !== undefined && goal.timeUsedSeconds >= 60) {
usage.push(formatDuration(goal.timeUsedSeconds * 1_000));
usage.push(`${formatDuration(goal.timeUsedSeconds * 1_000)} elapsed`);
}
if (goal.checks !== undefined && goal.checks > 0) {
usage.push(`${goal.checks} ${goal.checks === 1 ? "check" : "checks"}`);
Expand Down
Loading