fix(budgets): address review feedback on pricing rates, incomplete accounting card, and paused notice extraction

- Fix claude-sonnet-4-5 to standard API rates (/) and add legacy claude-opus-4/4-1 (/)
- Keep [1m] suffixes unstripped so long-context variants fall back conservatively to the family maximum
- Freeze ANTHROPIC_FAMILY_MAX_RATE_CARDS as immutable reviewed constants with a regression test
- Update budget-live-usage.test.ts for Claude family-max live projection
- Broaden below-limit BudgetIncidentCard copy to cover all incomplete-accounting causes (unpriced or unaccounted usage) and omit the guaranteed-422 Raise budget & resume form on incomplete-accounting stops
- Extract IssueAssigneePausedNotice into its own component file and align the Storybook story with real server recovery behavior

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-12-03 15:31:35 -06:00
1 parent 17b0c281a8
commit 244439ebd7
8 files changed
+257 -203

No files matched your search

+47 -5
View File
@@ -1,6 +1,12 @@
import { describe, expect, it } from "vitest";
import { usdToUnits } from "@paperclipai/shared";
import type { AdapterUsageCheckpoint } from "@paperclipai/adapter-utils";
import { priceAnthropicReceipt } from "./anthropic-pricing.js";
import {
ANTHROPIC_FAMILY_MAX_RATE_CARDS,
ANTHROPIC_RATE_CARDS,
anthropicModelFamily,
priceAnthropicReceipt,
} from "./anthropic-pricing.js";
const receipt: AdapterUsageCheckpoint = { complete: true, usageBasis: "per_run", provider: "anthropic", biller: "anthropic",
billingType: "metered_api", model: "claude-sonnet-5", costUsd: null, costStatus: "unpriced",
@@ -26,7 +32,7 @@ describe("complete Anthropic receipt pricing", () => {
expect(priced.pricingProvenance).toMatchObject({ source: "rate_card" });
expect(priced.pricingProvenance?.evidence).toMatch(/one-hour upper rate used; not an invoice; observed usage is a lower bound$/);
});
it("prices Fable 5.2 (including [1m] suffix) and other shipped Anthropic models", () => {
it("prices Fable 5.2, Sonnet 4.5 standard rates, legacy Opus 4.1, and other shipped Anthropic models", () => {
const fable52 = priceAnthropicReceipt({ ...receipt, model: "claude-fable-5-2" });
expect(fable52.costStatus).toBe("estimated");
expect(fable52.pricingProvenance).toMatchObject({
@@ -38,9 +44,35 @@ describe("complete Anthropic receipt pricing", () => {
outputCentsPerMillion: "4000",
});
// Long-context [1m] variants are not silently discounted to the base card;
// they conservatively fall back to the family maximum.
const fable52Long = priceAnthropicReceipt({ ...receipt, model: "claude-fable-5-2[1m]" });
expect(fable52Long.costUsdExact).toBe(fable52.costUsdExact);
expect(fable52Long.pricingProvenance?.version).toBe("anthropic-standard-2026-12-03");
expect(fable52Long.pricingProvenance).toMatchObject({
source: "rate_card",
version: "anthropic-fable-family-max-2026-12-03",
inputCentsPerMillion: "1000",
cachedInputCentsPerMillion: "100",
cacheWriteCentsPerMillion: "2000",
outputCentsPerMillion: "5000",
});
const sonnet45 = priceAnthropicReceipt({ ...receipt, model: "claude-sonnet-4-5" });
expect(sonnet45.costStatus).toBe("estimated");
expect(sonnet45.pricingProvenance).toMatchObject({
inputCentsPerMillion: "300",
cachedInputCentsPerMillion: "30",
cacheWriteCentsPerMillion: "600",
outputCentsPerMillion: "1500",
});
const opus41 = priceAnthropicReceipt({ ...receipt, model: "claude-opus-4-1" });
expect(opus41.costStatus).toBe("estimated");
expect(opus41.pricingProvenance).toMatchObject({
inputCentsPerMillion: "1500",
cachedInputCentsPerMillion: "150",
cacheWriteCentsPerMillion: "3000",
outputCentsPerMillion: "7500",
});
const sonnet55 = priceAnthropicReceipt({ ...receipt, model: "claude-sonnet-5-5" });
expect(sonnet55.costStatus).toBe("estimated");
@@ -60,10 +92,20 @@ describe("complete Anthropic receipt pricing", () => {
outputCentsPerMillion: "500",
});
});
it("keeps every immutable family-max fallback >= every explicit card in its family", () => {
for (const [modelId, card] of Object.entries(ANTHROPIC_RATE_CARDS)) {
const family = anthropicModelFamily(modelId);
expect(family).not.toBeNull();
const maxCard = ANTHROPIC_FAMILY_MAX_RATE_CARDS[family!];
for (let i = 0; i < 4; i++) {
expect(usdToUnits(maxCard.rates[i])).toBeGreaterThanOrEqual(usdToUnits(card.rates[i]));
}
}
});
it.each([
{ model: "claude-fable-5-9", family: "fable", input: "1000", cached: "100", cacheWrite: "2000", output: "5000" },
{ model: "claude-mythos-6", family: "mythos", input: "1000", cached: "100", cacheWrite: "2000", output: "5000" },
{ model: "claude-opus-6", family: "opus", input: "500", cached: "50", cacheWrite: "1000", output: "2500" },
{ model: "claude-opus-6", family: "opus", input: "1500", cached: "150", cacheWrite: "3000", output: "7500" },
{ model: "claude-sonnet-latest", family: "sonnet", input: "300", cached: "30", cacheWrite: "600", output: "1500" },
{ model: "claude-haiku-6", family: "haiku", input: "100", cached: "10", cacheWrite: "200", output: "500" },
])("defaults uncataloged $model to the most expensive rate in the $family group", ({ model, family, input, cached, cacheWrite, output }) => {
+28 -38
View File
@@ -10,7 +10,9 @@ type RateCard = {
type AnthropicModelFamily = "fable" | "mythos" | "opus" | "sonnet" | "haiku";
const RATE_CARDS: Record<string, RateCard> = {
// Standard direct Anthropic API list prices (USD per 1M tokens: input, cache read, 1h cache write, output).
// Source: https://platform.claude.com/docs/en/about-claude/pricing
export const ANTHROPIC_RATE_CARDS: Readonly<Record<string, RateCard>> = Object.freeze({
// Fable / Mythos
"claude-fable-5-2": { rates: ["8", "0.2", "16", "40"], version: "anthropic-standard-2026-12-03" },
"claude-fable-5-1": { rates: ["10", "0.25", "20", "50"], version: "anthropic-standard-2026-12-03" },
@@ -18,71 +20,59 @@ const RATE_CARDS: Record<string, RateCard> = {
"claude-mythos-5-2": { rates: ["8", "0.2", "16", "40"], version: "anthropic-standard-2026-12-03" },
"claude-mythos-5-1": { rates: ["10", "0.25", "20", "50"], version: "anthropic-standard-2026-12-03" },
"claude-mythos-5": { rates: ["10", "1", "20", "50"], version: "anthropic-standard-2026-12-03" },
// Opus
// Opus (including legacy Opus 4 / 4.1 at $15/$75)
"claude-opus-5-5": { rates: ["4", "0.2", "8", "20"], version: "anthropic-standard-2026-10-12" },
"claude-opus-5": { rates: ["5", "0.5", "10", "25"], version: "anthropic-standard-2026-12-03" },
"claude-opus-4-8": { rates: ["5", "0.5", "10", "25"], version: "anthropic-standard-2026-12-03" },
"claude-opus-4-7": { rates: ["5", "0.5", "10", "25"], version: "anthropic-standard-2026-12-03" },
"claude-opus-4-6": { rates: ["5", "0.5", "10", "25"], version: "anthropic-standard-2026-12-03" },
"claude-opus-4-5": { rates: ["5", "0.5", "10", "25"], version: "anthropic-standard-2026-12-03" },
// Sonnet
"claude-opus-4-1": { rates: ["15", "1.5", "30", "75"], version: "anthropic-standard-2026-12-03" },
"claude-opus-4": { rates: ["15", "1.5", "30", "75"], version: "anthropic-standard-2026-12-03" },
// Sonnet (standard API rates, never Batch API rates)
"claude-sonnet-5-5": { rates: ["2", "0.1", "4", "10"], version: "anthropic-standard-2026-12-03" },
"claude-sonnet-5": { rates: ["2", "0.2", "4", "10"], version: "anthropic-standard-2026-10-07" },
"claude-sonnet-4-6": { rates: ["3", "0.3", "6", "15"], version: "anthropic-standard-2026-12-03" },
"claude-sonnet-4-5": { rates: ["1.5", "0.15", "3", "7.5"], version: "anthropic-standard-2026-12-03" },
"claude-sonnet-4-5": { rates: ["3", "0.3", "6", "15"], version: "anthropic-standard-2026-12-03" },
// Haiku
"claude-haiku-5-5": { rates: ["0.5", "0.05", "1", "2.5"], version: "anthropic-standard-2026-12-03" },
"claude-haiku-4-5": { rates: ["1", "0.1", "2", "5"], version: "anthropic-standard-2026-12-03" },
};
});
// Reviewed, immutable per-family conservative maximums (must be >= every card in that family).
// Bump the version date whenever a family maximum changes so stored provenance stays reproducible.
export const ANTHROPIC_FAMILY_MAX_RATE_CARDS: Readonly<Record<AnthropicModelFamily, RateCard>> = Object.freeze({
fable: { rates: ["10", "1", "20", "50"], version: "anthropic-fable-family-max-2026-12-03" },
mythos: { rates: ["10", "1", "20", "50"], version: "anthropic-mythos-family-max-2026-12-03" },
opus: { rates: ["15", "1.5", "30", "75"], version: "anthropic-opus-family-max-2026-12-03" },
sonnet: { rates: ["3", "0.3", "6", "15"], version: "anthropic-sonnet-family-max-2026-12-03" },
haiku: { rates: ["1", "0.1", "2", "5"], version: "anthropic-haiku-family-max-2026-12-03" },
});
const ANTHROPIC_FAMILY_RE = /^claude-(fable|mythos|opus|sonnet|haiku)(?:[-@].*)?$/;
function normalizeAnthropicModelId(model: string): string {
return model.trim().toLowerCase().replace(/\[1m\]$/, "");
// Preserve variant suffixes such as `[1m]` so long-context variants do not
// silently fall down to a cheaper standard card; they fall back to the
// conservative family maximum instead.
return model.trim().toLowerCase();
}
function anthropicModelFamily(normalizedModel: string): AnthropicModelFamily | null {
export function anthropicModelFamily(normalizedModel: string): AnthropicModelFamily | null {
const match = ANTHROPIC_FAMILY_RE.exec(normalizedModel);
return (match?.[1] as AnthropicModelFamily | undefined) ?? null;
}
function maxRateString(a: string, b: string): string {
return usdToUnits(b) > usdToUnits(a) ? b : a;
}
const FAMILY_MAX_RATE_CARDS: Record<AnthropicModelFamily, RateCard> = (() => {
const result = {} as Record<AnthropicModelFamily, RateCard>;
for (const [modelId, card] of Object.entries(RATE_CARDS)) {
const family = anthropicModelFamily(modelId);
if (!family) continue;
const existing = result[family];
if (!existing) {
result[family] = {
rates: [card.rates[0], card.rates[1], card.rates[2], card.rates[3]],
version: `anthropic-${family}-family-max-2026-12-03`,
};
} else {
existing.rates = [
maxRateString(existing.rates[0], card.rates[0]),
maxRateString(existing.rates[1], card.rates[1]),
maxRateString(existing.rates[2], card.rates[2]),
maxRateString(existing.rates[3], card.rates[3]),
];
}
}
return result;
})();
function resolveAnthropicRateCard(model: string | null | undefined): { card: RateCard; fallbackFamily: AnthropicModelFamily | null } | null {
if (!model) return null;
const normalized = normalizeAnthropicModelId(model);
if (!normalized) return null;
if (Object.hasOwn(RATE_CARDS, normalized)) {
return { card: RATE_CARDS[normalized], fallbackFamily: null };
if (Object.hasOwn(ANTHROPIC_RATE_CARDS, normalized)) {
return { card: ANTHROPIC_RATE_CARDS[normalized], fallbackFamily: null };
}
const family = anthropicModelFamily(normalized);
if (family && Object.hasOwn(FAMILY_MAX_RATE_CARDS, family)) {
return { card: FAMILY_MAX_RATE_CARDS[family], fallbackFamily: family };
if (family && Object.hasOwn(ANTHROPIC_FAMILY_MAX_RATE_CARDS, family)) {
return { card: ANTHROPIC_FAMILY_MAX_RATE_CARDS[family], fallbackFamily: family };
}
return null;
}
@@ -48,8 +48,12 @@ describe("live run budget pricing", () => {
expect(liveRunUsageCostCents({ ...openai, ...override })).toBeNull();
});
it("projects uncataloged Claude family models at the conservative family maximum", () => {
expect(liveRunUsageCostCents({ ...anthropic, model: "claude-sonnet-latest" })).toBe("23.3951400");
});
it.each([
{ biller: "aws_bedrock" }, { model: "claude-sonnet-latest" }, { pricingContext: { serviceTier: "priority" } },
{ biller: "aws_bedrock" }, { model: "claude-unknown-1" }, { pricingContext: { serviceTier: "priority" } },
{ usage: { inputTokens: 1, outputTokens: 1 } },
{ usage: { inputTokens: 1, cacheWriteTokens: 2, cachedInputTokens: 0, outputTokens: 1 } },
] as Partial<AdapterUsageCheckpoint>[])("retains Anthropic rate-card restrictions: %j", override => {
+40 -34
View File
@@ -37,7 +37,7 @@ export function BudgetIncidentCard({
isMutating?: boolean;
}) {
const isWarning = incident.thresholdType === "soft";
const isUnpricedHardStop =
const isIncompleteAccountingHardStop =
incident.thresholdType === "hard" && incident.amountObserved < incident.amountLimit;
const [draftAmount, setDraftAmount] = useState(
centsInputValue(isWarning
@@ -56,7 +56,7 @@ export function BudgetIncidentCard({
<div className={isWarning
? "text-(length:--text-micro) uppercase tracking-(--tracking-caps) text-amber-700 dark:text-amber-200"
: "text-(length:--text-micro) uppercase tracking-(--tracking-caps) text-red-700/90 dark:text-red-200/80"}>
{incident.scopeType} {isWarning ? "budget warning" : isUnpricedHardStop ? "unpriced usage stop" : "hard stop"}
{incident.scopeType} {isWarning ? "budget warning" : isIncompleteAccountingHardStop ? "incomplete accounting stop" : "hard stop"}
</div>
<Badge variant={incident.status === "resolved" ? "outline" : "secondary"}>
{stateLabel}
@@ -64,8 +64,8 @@ export function BudgetIncidentCard({
</div>
<CardTitle className={isWarning ? "mt-1 text-base" : "mt-1 text-base text-red-950 dark:text-red-50"}>{incident.scopeName}</CardTitle>
<CardDescription className={isWarning ? "mt-1" : "mt-1 text-red-900/75 dark:text-red-100/70"}>
{isUnpricedHardStop
? `Known spend is ${formatCents(incident.amountObserved)} of ${formatCents(incident.amountLimit)}, but recent runs have unpriced model usage and this policy blocks unpriced usage.`
{isIncompleteAccountingHardStop
? `Known spend is ${formatCents(incident.amountObserved)} of ${formatCents(incident.amountLimit)}, but accounting is incomplete (unpriced or unaccounted usage) and this policy blocks incomplete accounting.`
: `Spending reached ${formatCents(incident.amountObserved)} against a limit of ${formatCents(incident.amountLimit)}.`}
</CardDescription>
</div>
@@ -92,10 +92,10 @@ export function BudgetIncidentCard({
<div className="flex items-start gap-2 rounded-xl border border-red-400/20 bg-red-500/10 px-3 py-2 text-sm text-red-950/90 dark:text-red-50/90">
<PauseCircle className="mt-0.5 h-4 w-4 shrink-0" />
<div>
{isUnpricedHardStop
{isIncompleteAccountingHardStop
? incident.scopeType === "project"
? "Project execution is paused because unpriced usage is blocked. Allow unpriced usage in this policy or wait for pricing, then resume."
: "This scope is paused because unpriced usage is blocked. Messages and new runs won’t start until unpriced usage is allowed or priced and this scope is resumed."
? "Project execution is paused because this policy blocks unpriced or unaccounted usage. Update the policy to allow unpriced usage or wait for accounting to finish, then resume."
: "This scope is paused because this policy blocks unpriced or unaccounted usage. Messages and new runs won’t start until unpriced usage is allowed in the policy (or accounting finishes) and this scope is resumed."
: incident.scopeType === "project"
? "Project execution is paused. New work in this project will not start until you raise the budget and resume."
: "This scope is paused. Messages and new runs won’t start until you raise the budget and resume."}
@@ -103,34 +103,40 @@ export function BudgetIncidentCard({
</div>
)}
<div className="rounded-xl border border-border/60 bg-background/60 p-3">
<label className="text-(length:--text-micro) uppercase tracking-(--tracking-caps) text-muted-foreground">
New budget (USD)
</label>
<div className="mt-2 flex flex-col gap-3 sm:flex-row">
<Input
value={draftAmount}
onChange={(event) => setDraftAmount(event.target.value)}
inputMode="decimal"
placeholder="0.00"
/>
<Button
className="gap-2"
disabled={isMutating || parsed === null || parsed <= incident.amountObserved}
onClick={() => {
if (typeof parsed === "number") onRaiseAndResume(parsed);
}}
>
<ArrowUpRight className="h-4 w-4" />
{isMutating ? "Applying..." : isWarning ? "Raise budget" : "Raise budget & resume"}
</Button>
{isIncompleteAccountingHardStop ? (
<div className="rounded-xl border border-border/60 bg-background/60 p-3 text-sm text-muted-foreground">
Raising the dollar limit will not clear this stop while unpriced or unaccounted usage is blocked. Review this scope’s budget policy to allow unpriced usage or wait for pending accounting to settle, then resume.
</div>
{parsed !== null && parsed <= incident.amountObserved ? (
<p className="mt-2 text-xs text-red-700 dark:text-red-200/80">
The new budget must exceed current observed spend.
</p>
) : null}
</div>
) : (
<div className="rounded-xl border border-border/60 bg-background/60 p-3">
<label className="text-(length:--text-micro) uppercase tracking-(--tracking-caps) text-muted-foreground">
New budget (USD)
</label>
<div className="mt-2 flex flex-col gap-3 sm:flex-row">
<Input
value={draftAmount}
onChange={(event) => setDraftAmount(event.target.value)}
inputMode="decimal"
placeholder="0.00"
/>
<Button
className="gap-2"
disabled={isMutating || parsed === null || parsed <= incident.amountObserved}
onClick={() => {
if (typeof parsed === "number") onRaiseAndResume(parsed);
}}
>
<ArrowUpRight className="h-4 w-4" />
{isMutating ? "Applying..." : isWarning ? "Raise budget" : "Raise budget & resume"}
</Button>
</div>
{parsed !== null && parsed <= incident.amountObserved ? (
<p className="mt-2 text-xs text-red-700 dark:text-red-200/80">
The new budget must exceed current observed spend.
</p>
) : null}
</div>
)}
<div className="flex flex-wrap items-center justify-between gap-2">
{!isWarning ? (
@@ -0,0 +1,125 @@
import type { Agent } from "@paperclipai/shared";
import { PauseCircle } from "lucide-react";
import { Link } from "@/lib/router";
import { agentUrl } from "@/lib/utils";
import { InlineBanner } from "./InlineBanner";
import { Button } from "@/components/ui/button";
function isTerminalIssueDisposition(issueStatus: string | undefined): boolean {
return issueStatus === "done" || issueStatus === "cancelled";
}
export function IssueAssigneePausedNotice({
agent,
issueStatus,
onResume,
resuming,
}: {
agent: Agent | null;
issueStatus: string | undefined;
onResume?: () => Promise<void> | void;
resuming?: boolean;
}) {
if (!agent || agent.status !== "paused" || isTerminalIssueDisposition(issueStatus)) return null;
// Lifecycle setup is shown by the queued turn and its inline connection card.
// Resume changes operator holds; it cannot complete verification.
if (!agent.pauseReason && ["preparing", "verifying", "resuming"].includes(agent.lifecycleState ?? "")) return null;
// A freshly created agent is stored as paused with pauseReason "setup" until
// its setup finishes. That is not an operator pause, so say what is actually
// happening and point at the real recovery path instead of "Resume agent".
if (agent.pauseReason === "setup") {
// Only computer preparation advances on its own (matches NewAgentSetup).
// A "verifying" or parked draft waits for the user to finish the wizard.
const stillPreparing = ["preparing", "pausing"].includes(agent.lifecycleState ?? "");
return (
<div data-testid="issue-assignee-paused-notice" className="mb-3">
<InlineBanner
tone="info"
compact
title={
<>
<span className="font-medium">{agent.name}</span> is still being set up.
</>
}
actions={
stillPreparing ? undefined : (
<Button size="sm" variant="outline" asChild>
<Link to={agentUrl(agent)} data-testid="issue-assignee-finish-setup">
Finish setup
</Link>
</Button>
)
}
>
{stillPreparing
? "Its computer is being prepared. Runs start automatically when setup finishes."
: "Its setup isn't finished yet. Finish setup to let it start runs."}
</InlineBanner>
</div>
);
}
const isBudgetPause = agent.pauseReason === "budget";
const pauseDetail =
agent.pauseReason === "import"
? "It arrived paused from an organization import — imported agents stay parked until you resume them."
: agent.pauseReason === "system"
? "It was paused by the system."
: agent.pauseReason === "manual"
? "It was paused manually."
: "";
// Budget pauses clear when the budget stop is resolved and archive pauses
// clear when the company is restored; resuming directly from chat would fight
// either, so budget pauses link to the agent's budget page instead.
const canResume = Boolean(onResume) && !isBudgetPause && agent.pauseReason !== "company_archived";
const title = isBudgetPause ? (
<>
<span className="font-medium">{agent.name}</span> is paused by a budget stop.
</>
) : (
<>
<span className="font-medium">{agent.name}</span> is paused.
</>
);
const body = isBudgetPause
? `Messages you send won’t get a reply until the budget stop is resolved and ${agent.name} is resumed.`
: agent.pauseReason === "company_archived"
? "Messages you send won’t get a reply while this company is archived."
: `Messages you send won’t get a reply until ${agent.name} is resumed.${pauseDetail ? ` ${pauseDetail}` : ""}`;
const actions = isBudgetPause ? (
<Button size="sm" variant="outline" asChild>
<Link to={`${agentUrl(agent)}/budgets`} data-testid="issue-assignee-paused-budget">
Review budget
</Link>
</Button>
) : canResume ? (
<Button
size="sm"
variant="outline"
onClick={onResume}
disabled={resuming}
data-testid="issue-assignee-paused-resume"
>
{resuming ? "Resuming…" : "Resume agent"}
</Button>
) : undefined;
return (
<div data-testid="issue-assignee-paused-notice" className="mb-3">
<InlineBanner
tone="warning"
icon={PauseCircle}
compact
title={title}
actions={actions}
>
{body}
</InlineBanner>
</div>
);
}
+2 -115
View File
@@ -12,6 +12,8 @@ import type { ComposerRunSettings } from "./task-chat/composer-run-settings";
import { ComposerRunSettingsPicker } from "./task-chat/ComposerRunSettingsPicker";
import { ComposerAddMenu, ComposerModeChip } from "./task-chat/ComposerAddMenu";
import { TaskChatPausedTakeover, type TaskComposerPause } from "./task-chat/TaskChatPausedTakeover";
import { IssueAssigneePausedNotice } from "./IssueAssigneePausedNotice";
export { IssueAssigneePausedNotice };
import { useEmailComment } from "./EmailMessageCard";
import { AssistantRuntimeProvider } from "@assistant-ui/react";
import type {
@@ -826,121 +828,6 @@ class IssueChatErrorBoundary extends Component<
}
}
export function IssueAssigneePausedNotice({
agent,
issueStatus,
onResume,
resuming,
}: {
agent: Agent | null;
issueStatus: string | undefined;
onResume?: () => Promise<void> | void;
resuming?: boolean;
}) {
if (!agent || agent.status !== "paused" || issueStatusIsTerminalDisposition(issueStatus)) return null;
// Lifecycle setup is shown by the queued turn and its inline connection card.
// Resume changes operator holds; it cannot complete verification.
if (!agent.pauseReason && ["preparing", "verifying", "resuming"].includes(agent.lifecycleState ?? "")) return null;
// A freshly created agent is stored as paused with pauseReason "setup" until
// its setup finishes. That is not an operator pause, so say what is actually
// happening and point at the real recovery path instead of "Resume agent".
if (agent.pauseReason === "setup") {
// Only computer preparation advances on its own (matches NewAgentSetup).
// A "verifying" or parked draft waits for the user to finish the wizard.
const stillPreparing = ["preparing", "pausing"].includes(agent.lifecycleState ?? "");
return (
<div data-testid="issue-assignee-paused-notice" className="mb-3">
<InlineBanner
tone="info"
compact
title={
<>
<span className="font-medium">{agent.name}</span> is still being set up.
</>
}
actions={
stillPreparing ? undefined : (
<Button size="sm" variant="outline" asChild>
<Link to={agentUrl(agent)} data-testid="issue-assignee-finish-setup">
Finish setup
</Link>
</Button>
)
}
>
{stillPreparing
? "Its computer is being prepared. Runs start automatically when setup finishes."
: "Its setup isn't finished yet. Finish setup to let it start runs."}
</InlineBanner>
</div>
);
}
const isBudgetPause = agent.pauseReason === "budget";
const pauseDetail =
agent.pauseReason === "import"
? "It arrived paused from an organization import — imported agents stay parked until you resume them."
: agent.pauseReason === "system"
? "It was paused by the system."
: agent.pauseReason === "manual"
? "It was paused manually."
: "";
// Budget pauses clear when the budget stop is resolved and archive pauses
// clear when the company is restored; resuming directly from chat would fight
// either, so budget pauses link to the agent's budget page instead.
const canResume = Boolean(onResume) && !isBudgetPause && agent.pauseReason !== "company_archived";
const title = isBudgetPause ? (
<>
<span className="font-medium">{agent.name}</span> is paused by a budget stop.
</>
) : (
<>
<span className="font-medium">{agent.name}</span> is paused.
</>
);
const body = isBudgetPause
? `Messages you send won’t get a reply until the budget stop is resolved and ${agent.name} is resumed.`
: agent.pauseReason === "company_archived"
? "Messages you send won’t get a reply while this company is archived."
: `Messages you send won’t get a reply until ${agent.name} is resumed.${pauseDetail ? ` ${pauseDetail}` : ""}`;
const actions = isBudgetPause ? (
<Button size="sm" variant="outline" asChild>
<Link to={`${agentUrl(agent)}/budgets`} data-testid="issue-assignee-paused-budget">
Review budget
</Link>
</Button>
) : canResume ? (
<Button
size="sm"
variant="outline"
onClick={onResume}
disabled={resuming}
data-testid="issue-assignee-paused-resume"
>
{resuming ? "Resuming…" : "Resume agent"}
</Button>
) : undefined;
return (
<div data-testid="issue-assignee-paused-notice" className="mb-3">
<InlineBanner
tone="warning"
icon={PauseCircle}
compact
title={title}
actions={actions}
>
{body}
</InlineBanner>
</div>
);
}
function fallbackAuthorLabel(message: ThreadMessage) {
const custom = message.metadata?.custom as
Record<string, unknown> | undefined;
@@ -5,7 +5,7 @@ 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 { MemoryRouter } from "@/lib/router";
import { IssueAssigneePausedNotice } from "./IssueChatThread";
import { IssueAssigneePausedNotice } from "./IssueAssigneePausedNotice";
import { BudgetIncidentCard } from "./BudgetIncidentCard";
vi.mock("@/context/CompanyContext", () => ({
@@ -118,7 +118,7 @@ describe("IssueAssigneePausedNotice and BudgetIncidentCard", () => {
expect(onResume).toHaveBeenCalledTimes(1);
});
it("distinguishes unpriced-usage budget stops from spend-limit stops on BudgetIncidentCard", () => {
it("distinguishes incomplete-accounting stops from spend-limit stops and omits the invalid raise-budget action", () => {
act(() => {
root.render(
<BudgetIncidentCard
@@ -129,9 +129,11 @@ describe("IssueAssigneePausedNotice and BudgetIncidentCard", () => {
);
});
expect(container.textContent).toContain("unpriced usage stop");
expect(container.textContent).toContain("incomplete accounting stop");
expect(container.textContent).toContain("$1.67 of $1,000.00");
expect(container.textContent).toContain("unpriced model usage");
expect(container.textContent).toContain("unpriced or unaccounted usage");
expect(container.textContent).toContain("Raising the dollar limit will not clear this stop");
expect(container.textContent).toContain("Keeping paused dismisses this alert without resuming work.");
expect(container.textContent).not.toContain("Raise budget & resume");
});
});
@@ -2,7 +2,7 @@ import { useState } from "react";
import type { Meta, StoryObj } from "@storybook/react-vite";
import type { Agent, BudgetIncident } from "@paperclipai/shared";
import { expect, userEvent, within } from "storybook/test";
import { IssueAssigneePausedNotice } from "@/components/IssueChatThread";
import { IssueAssigneePausedNotice } from "@/components/IssueAssigneePausedNotice";
import { BudgetIncidentCard } from "@/components/BudgetIncidentCard";
import { TaskChatBubble } from "@/components/task-chat/TaskChatBubble";
@@ -92,10 +92,7 @@ function PausedAgentChatSurface({
<div className="pt-2">
<BudgetIncidentCard
incident={{ ...unpricedIncident, status: incidentStatus }}
onRaiseAndResume={() => {
setIncidentStatus("resolved");
setResumed(true);
}}
onRaiseAndResume={() => undefined}
onKeepPaused={() => setIncidentStatus("dismissed")}
/>
</div>
@@ -138,8 +135,9 @@ export const BudgetPausedWithUnpricedIncident: Story = {
args: { pauseReason: "budget", showIncidentCard: true },
play: async ({ canvasElement }) => {
const c = within(canvasElement);
await expect(c.getByText(/unpriced usage stop/i)).toBeInTheDocument();
await expect(c.getByText(/incomplete accounting stop/i)).toBeInTheDocument();
await expect(c.getByText(/\$1\.67 of \$1,000\.00/)).toBeInTheDocument();
await expect(c.queryByRole("button", { name: "Raise budget & resume" })).not.toBeInTheDocument();
await expect(
c.getByText(/Keeping paused dismisses this alert without resuming work\./),
).toBeInTheDocument();