Skip to content
TypeScript

fix(client-runtime): goal token counts no longer read 1000k (#21594)

Marcel Jiron · MarMarLabsa0d6cc8ba9ed
diff --git a/packages/client-runtime/src/state/threadExecution.test.ts b/packages/client-runtime/src/state/threadExecution.test.ts
index 3f8ef2a7f9d..81afabbe8aa 100644
--- a/packages/client-runtime/src/state/threadExecution.test.ts
+++ b/packages/client-runtime/src/state/threadExecution.test.ts
@@ -25,6 +25,7 @@ import {
deriveRunlessWorkStartedAt,
deriveThreadActivityRun,
deriveThreadRuntime,
+ presentProviderGoal,
presentRunStop,
threadRuntimeHasInterruptibleRun,
} from "./threadExecution.ts";
@@ -462,3 +463,28 @@ describe("provider-reported model selection", () => {
).toBeNull();
});
});
+
+describe("presentProviderGoal", () => {
+ it("rolls token counts that round to 1000k over to 1m", () => {
+ const usage = (tokensUsed: number) =>
+ 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(
+ presentProviderGoal(
+ {
+ objective: "Ship the feature",
+ status: "paused",
+ tokensUsed: 999_500,
+ tokenBudget: 999_500,
+ },
+ false,
+ ).usage,
+ ).toBe("1m / 1m tokens");
+ });
+});
diff --git a/packages/client-runtime/src/state/threadExecution.ts b/packages/client-runtime/src/state/threadExecution.ts
index 52d07babfbb..951e5d06404 100644
--- a/packages/client-runtime/src/state/threadExecution.ts
+++ b/packages/client-runtime/src/state/threadExecution.ts
@@ -428,7 +428,8 @@ const PROVIDER_GOAL_TITLES: Record<OrchestrationV2ProviderGoal["status"], string
function formatGoalTokens(tokens: number): string {
if (tokens < 1_000) return `${tokens}`;
- if (tokens < 1_000_000) return `${Math.round(tokens / 1_000)}k`;
+ const thousands = Math.round(tokens / 1_000);
+ if (thousands < 1_000) return `${thousands}k`;
return `${(tokens / 1_000_000).toFixed(1).replace(/\.0$/, "")}m`;
}