Skip to content

🙌 OpenHands: AI-Driven Development

fix: OHE-3110 : remove misleading "No budget limit" line from Token Usage panel (#17264)

Tim O'Farrell7beb87f31c46
diff --git a/__tests__/components/features/conversation-panel/budget-display.test.tsx b/__tests__/components/features/conversation-panel/budget-display.test.tsx
new file mode 100644
index 0000000000..487adfdfa9
--- /dev/null
+++ b/__tests__/components/features/conversation-panel/budget-display.test.tsx
@@ -0,0 +1,51 @@
+import React from "react";
+import { describe, expect, it } from "vitest";
+import { screen } from "@testing-library/react";
+import { renderWithProviders } from "test-utils";
+import { BudgetDisplay } from "#/components/features/conversation-panel/budget-display";
+
+describe("BudgetDisplay", () => {
+ it("renders nothing when cost is null", () => {
+ const { container } = renderWithProviders(
+ <BudgetDisplay cost={null} maxBudgetPerTask={5} />,
+ );
+ expect(container).toBeEmptyDOMElement();
+ });
+
+ it("renders nothing when maxBudgetPerTask is null (no budget cap)", () => {
+ // Per OHE-3110: there is no way for a user to set max_budget_per_task, so
+ // the "No budget limit" line must be omitted rather than shown.
+ const { container } = renderWithProviders(
+ <BudgetDisplay cost={1.23} maxBudgetPerTask={null} />,
+ );
+ expect(container).toBeEmptyDOMElement();
+ });
+
+ it("renders nothing when maxBudgetPerTask is zero", () => {
+ const { container } = renderWithProviders(
+ <BudgetDisplay cost={1.23} maxBudgetPerTask={0} />,
+ );
+ expect(container).toBeEmptyDOMElement();
+ });
+
+ it("renders nothing when maxBudgetPerTask is negative", () => {
+ const { container } = renderWithProviders(
+ <BudgetDisplay cost={1.23} maxBudgetPerTask={-1} />,
+ );
+ expect(container).toBeEmptyDOMElement();
+ });
+
+ it("renders the progress bar and usage text when a real cap exists", () => {
+ const { container } = renderWithProviders(
+ <BudgetDisplay cost={1.23} maxBudgetPerTask={5} />,
+ );
+ // Cap-present branch renders two child rows: BudgetProgressBar (whose
+ // fill div carries the transition-all class) and BudgetUsageText (the
+ // usage key renders untranslated in tests). Asserting on both proves we
+ // did not take the cap-absent (null) branch.
+ expect(container.querySelector(".transition-all")).toBeInTheDocument();
+ expect(
+ screen.getByText("CONVERSATION$BUDGET_USAGE_FORMAT"),
+ ).toBeInTheDocument();
+ });
+});
diff --git a/__tests__/components/features/home/home-chat-launcher.test.tsx b/__tests__/components/features/home/home-chat-launcher.test.tsx
index 097c03503f..e58245b353 100644
--- a/__tests__/components/features/home/home-chat-launcher.test.tsx
+++ b/__tests__/components/features/home/home-chat-launcher.test.tsx
@@ -6,6 +6,7 @@ import toast from "react-hot-toast";
import { HomeChatLauncher } from "#/components/features/home/home-chat-launcher";
import AgentServerConversationService from "#/api/conversation-service/agent-server-conversation-service.api";
+import AutomationService from "#/api/automation-service/automation-service.api";
import WorkspacesService from "#/api/workspaces-service/workspaces-service.api";
import {
LAST_LOCAL_WORKSPACE_MODE_STORAGE_KEY,
@@ -330,6 +331,19 @@ describe("HomeChatLauncher", () => {
workspaces: [],
workspaceParents: [],
});
+ // The launcher mounts the pinned/running automation dashboards, whose
+ // queries would otherwise fire real axios XHRs into MSW. If such a
+ // request is still in flight when the file's jsdom environment is torn
+ // down, MSW's XHR interceptor throws `ReferenceError:
+ // XMLHttpRequestUpload is not defined` as an unhandled rejection.
+ // Mocking the underlying service keeps all automation traffic in-process.
+ vi.spyOn(AutomationService, "checkHealth").mockResolvedValue({
+ status: "ok",
+ });
+ vi.spyOn(AutomationService, "getAutomations").mockResolvedValue({
+ automations: [],
+ total: 0,
+ });
});
afterEach(() => {
diff --git a/src/components/features/conversation-panel/budget-display.tsx b/src/components/features/conversation-panel/budget-display.tsx
index e693717ab6..8c5311ddaf 100644
--- a/src/components/features/conversation-panel/budget-display.tsx
+++ b/src/components/features/conversation-panel/budget-display.tsx
@@ -1,6 +1,3 @@
-import React from "react";
-import { useTranslation } from "react-i18next";
-import { I18nKey } from "#/i18n/declaration";
import { BudgetProgressBar } from "./budget-progress-bar";
import { BudgetUsageText } from "./budget-usage-text";
@@ -10,25 +7,18 @@ interface BudgetDisplayProps {
}
export function BudgetDisplay({ cost, maxBudgetPerTask }: BudgetDisplayProps) {
- const { t } = useTranslation("openhands");
-
- // Don't render anything if cost is not available
- if (cost === null) {
+ // Only render the cap/progress UI when a real per-conversation budget cap
+ // exists. There is currently no way for a user to set max_budget_per_task,
+ // so showing a "No budget limit" line is misleading — omit it entirely
+ // and let the surrounding cost/usage rows speak for themselves.
+ if (cost === null || maxBudgetPerTask === null || maxBudgetPerTask <= 0) {
return null;
}
return (
<div>
- {maxBudgetPerTask !== null && maxBudgetPerTask > 0 ? (
- <>
- <BudgetProgressBar currentCost={cost} maxBudget={maxBudgetPerTask} />
- <BudgetUsageText currentCost={cost} maxBudget={maxBudgetPerTask} />
- </>
- ) : (
- <span className="text-xs text-[var(--oh-muted)]">
- {t(I18nKey.CONVERSATION$NO_BUDGET_LIMIT)}
- </span>
- )}
+ <BudgetProgressBar currentCost={cost} maxBudget={maxBudgetPerTask} />
+ <BudgetUsageText currentCost={cost} maxBudget={maxBudgetPerTask} />
</div>
);
}
diff --git a/src/i18n/translation.json b/src/i18n/translation.json
index db383de480..a405d73355 100644
--- a/src/i18n/translation.json
+++ b/src/i18n/translation.json
@@ -19551,23 +19551,6 @@
"uk": "% використано",
"ca": "% utilitzat"
},
- "CONVERSATION$NO_BUDGET_LIMIT": {
- "en": "No budget limit",
- "ja": "予算制限なし",
- "zh-CN": "无预算限制",
- "zh-TW": "無預算限制",
- "ko-KR": "예산 제한 없음",
- "de": "Kein Budgetlimit",
- "no": "Ingen budsjettgrense",
- "it": "Nessun limite di budget",
- "pt": "Sem limite de orçamento",
- "es": "Sin límite de presupuesto",
- "ar": "لا حد للميزانية",
- "fr": "Pas de limite de budget",
- "tr": "Bütçe limiti yok",
- "uk": "Без обмеження бюджету",
- "ca": "Sense límit de pressupost"
- },
"CONVERSATION$INPUT": {
"en": "Input",
"ja": "入力",
diff --git a/vitest.setup.ts b/vitest.setup.ts
index 3079f8cd06..00dd86011c 100644
--- a/vitest.setup.ts
+++ b/vitest.setup.ts
@@ -61,15 +61,17 @@ if (typeof requestAnimationFrame === "undefined") {
}
// MSW's XMLHttpRequest interceptor references the bare `ProgressEvent`
-// global from inside async `respondWith` callbacks (via `createEvent`).
-// Vitest's jsdom environment installs `ProgressEvent` as an own property on
-// `globalThis` and removes it during per-file teardown with
+// global from inside async `respondWith` callbacks (via `createEvent`), and
+// the bare `XMLHttpRequestUpload` global in `trigger` (`target instanceof
+// XMLHttpRequestUpload`). Vitest's jsdom environment installs these as own
+// properties on `globalThis` and removes them during per-file teardown with
// `keys.forEach((key) => delete global[key])`. If an in-flight intercepted
// XHR (e.g. PostHog analytics, or any request that escaped to the real
// network under `onUnhandledRequest: "bypass"` and is still waiting on a
// socket) settles after teardown, its callback evaluates `ProgressEvent`
// against a torn-down global and throws
-// `ReferenceError: ProgressEvent is not defined`. Vitest reports that as an
+// `ReferenceError: ProgressEvent is not defined` (or the
+// `XMLHttpRequestUpload` equivalent). Vitest reports that as an
// unhandled rejection and fails the whole run even though every test passed.
//
// Two earlier attempts at this (an own-property getter, then the `afterAll`
@@ -79,13 +81,13 @@ if (typeof requestAnimationFrame === "undefined") {
// can settle long after 30 macrotask ticks.
//
// `delete` only removes *own* properties, while identifier resolution walks
-// the prototype chain. So the fallback goes on an object inserted into
-// `globalThis`'s prototype chain, where teardown cannot delete it: while the
-// environment is alive jsdom's own property shadows it, and once teardown
-// removes that own property, the bare `ProgressEvent` identifier resolves
-// through the prototype to the class below. Node's `globalThis` does not have
-// `Object.prototype` as its direct prototype, so this adds nothing to plain
-// objects.
+// the prototype chain. So the fallbacks go on an object inserted into
+// `globalThis`'s prototype chain, where teardown cannot delete them: while
+// the environment is alive jsdom's own properties shadow them, and once
+// teardown removes those own properties, the bare identifiers resolve
+// through the prototype to the classes below. Node's `globalThis` does not
+// have `Object.prototype` as its direct prototype, so this adds nothing to
+// plain objects.
class MockProgressEvent extends Event {
readonly lengthComputable: boolean;
@@ -101,28 +103,38 @@ class MockProgressEvent extends Event {
}
}
+// The interceptor only needs `XMLHttpRequestUpload` as an `instanceof`
+// operand. While jsdom is alive its own property shadows this fallback, so
+// behavior is unchanged; after teardown the check just takes the non-upload
+// branch, quietly skipping listener dispatch for callbacks that have already
+// outlived their environment instead of crashing the run.
+class MockXMLHttpRequestUpload extends EventTarget {}
+
// Setup files run once per test file, and a worker process is reused across
// files. Without this marker each file would splice another holder into the
// prototype chain, so the chain would grow with every file in the run.
-const PROGRESS_EVENT_FALLBACK = Symbol.for(
- "agent-canvas.progress-event-fallback",
-);
+const XHR_GLOBALS_FALLBACK = Symbol.for("agent-canvas.xhr-globals-fallback");
-function installProgressEventFallback(fallback: unknown) {
+function installXhrGlobalsFallback(fallbacks: Record<string, unknown>) {
const currentProto = Object.getPrototypeOf(globalThis) as object | null;
- if (currentProto && PROGRESS_EVENT_FALLBACK in currentProto) return;
+ if (currentProto && XHR_GLOBALS_FALLBACK in currentProto) return;
const holder = Object.create(currentProto) as Record<PropertyKey, unknown>;
- Object.defineProperty(holder, PROGRESS_EVENT_FALLBACK, { value: true });
- Object.defineProperty(holder, "ProgressEvent", {
- value: fallback,
- configurable: true,
- writable: true,
- });
+ Object.defineProperty(holder, XHR_GLOBALS_FALLBACK, { value: true });
+ for (const [name, fallback] of Object.entries(fallbacks)) {
+ Object.defineProperty(holder, name, {
+ value: fallback,
+ configurable: true,
+ writable: true,
+ });
+ }
Object.setPrototypeOf(globalThis, holder);
}
-installProgressEventFallback(MockProgressEvent);
+installXhrGlobalsFallback({
+ ProgressEvent: MockProgressEvent,
+ XMLHttpRequestUpload: MockXMLHttpRequestUpload,
+});
// Mock ResizeObserver for test environment
class MockResizeObserver {
@@ -195,7 +207,7 @@ afterAll(async () => {
// against a live jsdom rather than a torn-down one. This is a best-effort
// tidy-up, not the guarantee: a callback can always outlast the drain
// window (a bypassed request stuck on a real socket, for instance), which
- // is what the prototype-chain `ProgressEvent` fallback above is for. We
+ // is what the prototype-chain XHR-globals fallback above is for. We
// restore real timers first so a test that left fake timers active can't
// stall the drain.
vi.useRealTimers();