diff --git a/ui/src/components/BudgetIncidentCard.tsx b/ui/src/components/BudgetIncidentCard.tsx
index 8a1146b5dae..f38474ae6c5 100644
--- a/ui/src/components/BudgetIncidentCard.tsx
+++ b/ui/src/components/BudgetIncidentCard.tsx
@@ -1,5 +1,5 @@
import { useState } from "react";
-import type { BudgetIncident } from "@paperclipai/shared";
+import type { BudgetIncident, BudgetPolicySummary } from "@paperclipai/shared";
import { AlertOctagon, AlertTriangle, ArrowUpRight, PauseCircle } from "lucide-react";
import { formatCents } from "../lib/utils";
import { Badge } from "@/components/ui/badge";
@@ -27,22 +27,30 @@ function incidentStateLabel(incident: BudgetIncident) {
export function BudgetIncidentCard({
incident,
+ policy,
onRaiseAndResume,
onKeepPaused,
isMutating,
}: {
incident: BudgetIncident;
+ policy?: BudgetPolicySummary | null;
onRaiseAndResume: (amountCents: number) => void;
onKeepPaused: () => void;
isMutating?: boolean;
}) {
const isWarning = incident.thresholdType === "soft";
+ const effectiveObserved = policy ? policy.observedAmount : incident.amountObserved;
+ const effectiveLimit = policy ? policy.amount : incident.amountLimit;
const isIncompleteAccountingHardStop =
- incident.thresholdType === "hard" && incident.amountObserved < incident.amountLimit;
+ incident.thresholdType === "hard" &&
+ (policy
+ ? policy.unpricedUsagePolicy !== "allow" &&
+ (policy.unpricedEventCount > 0 || (policy.status === "hard_stop" && policy.observedAmount < policy.amount))
+ : incident.amountObserved < incident.amountLimit);
const [draftAmount, setDraftAmount] = useState(
centsInputValue(isWarning
- ? Math.max(incident.amountObserved, incident.amountLimit) + 1000
- : Math.max(incident.amountObserved + 1000, incident.amountLimit)),
+ ? Math.max(effectiveObserved, effectiveLimit) + 1000
+ : Math.max(effectiveObserved + 1000, effectiveLimit)),
);
const parsed = parseDollarInput(draftAmount);
const stateLabel = incidentStateLabel(incident);
@@ -65,8 +73,8 @@ export function BudgetIncidentCard({
The new budget must exceed current observed spend.
diff --git a/ui/src/components/PausedBudgetNotices.test.tsx b/ui/src/components/PausedBudgetNotices.test.tsx index 54af74666a2..56ac56f2004 100644 --- a/ui/src/components/PausedBudgetNotices.test.tsx +++ b/ui/src/components/PausedBudgetNotices.test.tsx @@ -3,7 +3,7 @@ import { act } from "react"; import { createRoot, type Root } from "react-dom/client"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; -import type { Agent, BudgetIncident } from "@paperclipai/shared"; +import type { Agent, BudgetIncident, BudgetPolicySummary } from "@paperclipai/shared"; import { MemoryRouter } from "@/lib/router"; import { IssueAssigneePausedNotice } from "./IssueAssigneePausedNotice"; import { BudgetIncidentCard } from "./BudgetIncidentCard"; @@ -136,4 +136,47 @@ describe("IssueAssigneePausedNotice and BudgetIncidentCard", () => { expect(container.textContent).toContain("Keeping paused dismisses this alert without resuming work."); expect(container.textContent).not.toContain("Raise budget & resume"); }); + + it("restores Raise budget & resume when live policy state shows usage settled above the limit", () => { + const settledPolicy: BudgetPolicySummary = { + policyId: "policy-1", + companyId: "company-1", + scopeType: "agent", + scopeId: "agent-dorian", + scopeName: "Dorian", + metric: "billed_cents", + windowKind: "calendar_month_utc", + amount: 100000, + observedAmount: 120000, + unpricedEventCount: 0, + pendingRunCount: 0, + remainingAmount: 0, + utilizationPercent: 120, + warnPercent: 80, + hardStopEnabled: true, + unpricedUsagePolicy: "block", + notifyEnabled: true, + isActive: true, + status: "hard_stop", + paused: true, + pauseReason: "budget", + windowStart: new Date("2026-12-01T00:00:00Z"), + windowEnd: new Date("2027-01-01T00:00:00Z"), + }; + + act(() => { + root.render( +