Skip to content

Commit a0d6cc8

Browse files
fix(client-runtime): goal token counts no longer read 1000k (pingdotgg#21594)
Co-authored-by: maria-rcks <[email protected]>
1 parent 1d162e1 commit a0d6cc8

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

‎packages/client-runtime/src/state/threadExecution.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
deriveRunlessWorkStartedAt,
2626
deriveThreadActivityRun,
2727
deriveThreadRuntime,
28+
presentProviderGoal,
2829
presentRunStop,
2930
threadRuntimeHasInterruptibleRun,
3031
} from "./threadExecution.ts";
@@ -462,3 +463,28 @@ describe("provider-reported model selection", () => {
462463
).toBeNull();
463464
});
464465
});
466+
467+
describe("presentProviderGoal", () => {
468+
it("rolls token counts that round to 1000k over to 1m", () => {
469+
const usage = (tokensUsed: number) =>
470+
presentProviderGoal(
471+
{ objective: "Ship the feature", status: "active", tokensUsed, tokenBudget: 2_000_000 },
472+
true,
473+
).usage;
474+
expect(usage(999_499)).toBe("999k / 2m tokens");
475+
expect(usage(999_500)).toBe("1m / 2m tokens");
476+
expect(usage(999_999)).toBe("1m / 2m tokens");
477+
expect(usage(1_000_000)).toBe("1m / 2m tokens");
478+
expect(
479+
presentProviderGoal(
480+
{
481+
objective: "Ship the feature",
482+
status: "paused",
483+
tokensUsed: 999_500,
484+
tokenBudget: 999_500,
485+
},
486+
false,
487+
).usage,
488+
).toBe("1m / 1m tokens");
489+
});
490+
});

‎packages/client-runtime/src/state/threadExecution.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,8 @@ const PROVIDER_GOAL_TITLES: Record<OrchestrationV2ProviderGoal["status"], string
428428

429429
function formatGoalTokens(tokens: number): string {
430430
if (tokens < 1_000) return `${tokens}`;
431-
if (tokens < 1_000_000) return `${Math.round(tokens / 1_000)}k`;
431+
const thousands = Math.round(tokens / 1_000);
432+
if (thousands < 1_000) return `${thousands}k`;
432433
return `${(tokens / 1_000_000).toFixed(1).replace(/\.0$/, "")}m`;
433434
}
434435

0 commit comments

Comments
 (0)