Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(runtimes): trim the Codex credit balance to two decimals (#10816)

Jiayuan Zhangfe0059cb2131
diff --git a/packages/views/runtimes/components/rate-limit-section.test.tsx b/packages/views/runtimes/components/rate-limit-section.test.tsx
index ad286bfdfe..a152ee09e9 100644
--- a/packages/views/runtimes/components/rate-limit-section.test.tsx
+++ b/packages/views/runtimes/components/rate-limit-section.test.tsx
@@ -104,6 +104,20 @@ describe("RateLimitSection", () => {
expect(meters.map((m) => m.getAttribute("aria-valuenow"))).toEqual(["72", "41"]);
});
+ it.each([
+ ["62500.0000000000", "62,500 left"],
+ ["12.3456", "12.35 left"],
+ ])("trims the reported credit balance %s", async (balance, shown) => {
+ getRuntimeRateLimits.mockResolvedValue({
+ rate_limits: {
+ ...SNAPSHOT.rate_limits!,
+ credits: { has_credits: true, unlimited: false, balance },
+ },
+ });
+ render(<RateLimitSection runtime={RUNTIME} />, { wrapper: Wrapper });
+ expect(await screen.findByText(shown)).toBeInTheDocument();
+ });
+
it("explains an empty runtime instead of showing zeros", async () => {
getRuntimeRateLimits.mockResolvedValue({ rate_limits: null });
render(<RateLimitSection runtime={RUNTIME} />, { wrapper: Wrapper });
diff --git a/packages/views/runtimes/components/rate-limit-section.tsx b/packages/views/runtimes/components/rate-limit-section.tsx
index 7e7987ace4..45bac2d756 100644
--- a/packages/views/runtimes/components/rate-limit-section.tsx
+++ b/packages/views/runtimes/components/rate-limit-section.tsx
@@ -71,6 +71,16 @@ function useRateLimitText() {
});
return (date: Date) => `${weekday.format(date)} ${time.format(date)}`;
}, [locale, tz]);
+ const creditFormat = useMemo(
+ () => new Intl.NumberFormat(locale, { maximumFractionDigits: 2 }),
+ [locale],
+ );
+
+ // Codex reports the balance as a fixed-point string ("62500.0000000000").
+ const creditBalance = (balance: string) => {
+ const n = Number(balance);
+ return balance.trim() !== "" && Number.isFinite(n) ? creditFormat.format(n) : balance;
+ };
const duration = (minutes: number) => {
if (minutes < 60) {
@@ -155,7 +165,7 @@ function useRateLimitText() {
return null;
};
- return { t, windowLabel, shortLabel, reset, usage, verdict };
+ return { t, windowLabel, shortLabel, reset, usage, verdict, creditBalance };
}
function useWindowViews(rateLimits: RuntimeRateLimits | null | undefined, now: number) {
@@ -283,7 +293,9 @@ export function RateLimitSection({ runtime }: { runtime: AgentRuntime }) {
{credits.unlimited
? text.t(($) => $.rate_limits.credits_unlimited)
: credits.has_credits && credits.balance
- ? text.t(($) => $.rate_limits.credits_balance, { balance: credits.balance })
+ ? text.t(($) => $.rate_limits.credits_balance, {
+ balance: text.creditBalance(credits.balance),
+ })
: text.t(($) => $.rate_limits.credits_none)}
</span>
</div>