Files
PaperClipAI/packages/shared
DottaandPaperclip ee05db9e16 fix(budgets): add Anthropic rate cards with family-max fallback and surface paused-agent budget notices (#23658)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Cost accounting prices Anthropic token receipts against rate cards
so budget policies can track spend and enforce hard stops
> - `anthropic-pricing.ts` only had rate cards for `claude-sonnet-5` and
`claude-opus-5-5`, so newer shipped models such as `claude-fable-5-2`
settled as `unpriced`
> - Because budget policies default to `unpriced_usage_policy =
"block"`, creating a spend cap on an agent that ran an unpriced model
immediately triggered a budget hard stop even when observed spend was
far below the limit
> - Meanwhile, the chat thread notice for a budget-paused agent had no
action link and did not state that messages sent while paused will not
receive a reply, and the budget incident card did not clearly explain
unpriced-usage stops or what "Keep paused" does
> - This pull request adds rate cards for shipped Anthropic models with
a conservative family-maximum fallback for uncataloged models, clarifies
the paused-agent chat notice and unpriced budget incident card, and adds
Storybook coverage
> - The benefit is that budget caps track current and future Anthropic
models accurately without false unpriced-usage lockouts, and operators
immediately see why an agent is not replying and where to resolve it

## Linked Issues or Issue Description

**What happened?**

When an agent ran a shipped Anthropic model missing from `RATE_CARDS`
(such as `claude-fable-5-2`), its usage receipts settled with
`costStatus: "unpriced"`. Creating a budget policy (which defaults to
`unpriced_usage_policy: "block"`) immediately fired a hard-stop incident
and paused the agent even when known spend was well below the limit. In
the task chat thread, the paused-agent banner gave no link to the
agent's budget page and did not clearly warn that new messages would not
trigger replies; on the budget incident card, the unpriced-usage stop
looked like a regular spend-limit alert and dismissing it via "Keep
paused" left the agent paused with no clear explanation.

**Expected behavior**

Shipped Anthropic models should have explicit rate cards, and
uncataloged models in a known Claude family (`fable`, `mythos`, `opus`,
`sonnet`, `haiku`) should fall back conservatively to the most expensive
rate card in that family rather than settling as unpriced. When an agent
is paused in chat, the notice should clearly state that messages will
not get a reply until the agent is resumed and provide a direct "Review
budget" link for budget pauses. Unpriced-usage budget stops should
clearly explain why work stopped and that "Keep paused" dismisses the
alert without resuming work.

**Steps to reproduce**

1. Run an agent on `claude-fable-5-2` using direct Anthropic API billing
so usage receipts settle as `unpriced`.
2. Add a monthly budget policy (e.g. $1,000) on that agent.
3. Observe an immediate hard-stop budget incident pausing the agent
despite low observed spend.
4. Return to the agent's chat thread and observe the paused banner lacks
a budget link and does not clearly state that new messages will not get
a reply.

## What Changed

- `server/src/services/anthropic-pricing.ts`: Added explicit standard
API rate cards for shipped Anthropic models (`claude-fable-5-2`, `5-1`,
`5`; `claude-mythos-5-2`, `5-1`, `5`; `claude-opus-5-5`, `5`, `4-8`,
`4-7`, `4-6`, `4-5`; `claude-sonnet-5-5`, `5`, `4-6`, `4-5`;
`claude-haiku-5-5`, `4-5`), normalized optional `[1m]` suffixes, and
added a dynamic family-maximum fallback (`FAMILY_MAX_RATE_CARDS`) so any
uncataloged model in a known Claude family conservatively uses the
highest rate in that group with explicit provenance.
- `server/src/services/anthropic-pricing.test.ts`: Added unit tests
covering `claude-fable-5-2` (including `[1m]`), `claude-sonnet-5-5`,
`claude-haiku-4-5`, family-maximum fallbacks across all five Claude
families, and preserving unknown/non-Anthropic models as unpriced.
- `ui/src/components/IssueChatThread.tsx`: Updated
`IssueAssigneePausedNotice` to state clearly that messages sent while
paused will not get a reply, distinguish budget pauses in the title, and
render a direct "Review budget" link to `${agentUrl(agent)}/budgets`.
- `ui/src/components/BudgetIncidentCard.tsx`: Clarified unpriced-usage
hard stops (`unpriced usage stop`, known spend vs. limit, and why
unpriced usage blocked work) and added a muted note beside "Keep paused"
explaining that dismissing the alert keeps the scope paused.
- `ui/src/components/PausedBudgetNotices.test.tsx`: Added focused jsdom
unit tests for `IssueAssigneePausedNotice` (budget pause link and manual
resume action) and `BudgetIncidentCard` (unpriced-usage hard-stop copy).
-
`ui/storybook/stories/budgets-costs/paused-agent-chat-notice.stories.tsx`:
Added production-component Storybook stories (`BudgetPausedInChat`,
`BudgetPausedWithUnpricedIncident`, `ManuallyPausedInChat`) with
interaction tests.

## Verification

- `pnpm vitest run server/src/services/anthropic-pricing.test.ts
ui/src/components/PausedBudgetNotices.test.tsx`: 2 test files, 30 tests
passed.
- `pnpm --filter @paperclipai/server typecheck`: passed.
- `pnpm --filter @paperclipai/ui typecheck` (including `node
../scripts/storybook-catalog.mjs`): passed.
- Verified all three new Storybook stories interactively in a browser
against local Storybook (`http://localhost:6006`) with zero runtime
errors and passing Storybook play assertions.
- `pnpm verify` exited 2 due to pre-existing untracked local files;
relying on required CI for full-repo coverage.

## Risks

- Low risk. Existing rate cards for `claude-sonnet-5` and
`claude-opus-5-5` keep their exact rates and versions. Family-maximum
fallbacks are intentionally conservative upper bounds and are labeled in
`pricingProvenance.evidence` as estimates rather than invoices.
- Existing already-settled `unpriced` cost events in databases are not
retroactively rewritten; this prevents new runs on shipped or future
Claude-family models from settling as unpriced.

## Model Used

- Google Gemini (Gemini 4 Neon Medium via Antigravity), with file
editing, terminal execution, browser verification, and web search tools.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-12-04 15:50:56 -06:00
..
2026-03-12 13:09:22 -05:00