Follow-ups from the review of the per-organization AI spend stack
(#32202, #32203, #32204).
**Behaviour**
- **A $0 AI budget is exceeded, everywhere.** `getSeverity(0, 0)` now
returns `exceeded` and `usageProgressPercentage(0, 0)` returns 100,
because AI Gateway blocks requests once spend reaches the limit. Before,
the user menu and the Agents usage indicator each patched this locally,
and the group budget pages showed a $0 budget with no spend as normal.
The local patches are removed. As a result, the user menu bar for a $0
budget is now full instead of empty under "Limit exceeded".
- **Organization selector:** the trigger now sets `aria-controls` to the
expanded list.
**Tests**
- `getSpendSeverity` unit tests for unlimited and missing spend. The $0
case is covered in `budget.test.ts`.
- Story assertions:
- `AISpendZeroLimit` checks "Limit exceeded", "AI requests are paused
until" and a full bar.
- `MultiOrgAISpend` checks the selector and the shown spend.
- `MultiOrgAISpendExceeded` checks "AI requests in this organization are
paused until".
- `MultiOrgAISpendUnavailable` checks "AI spend unavailable" with the
selector still shown.
- The single-organization AI spend stories seed
`meOrganizationsAISpendKey`, so they no longer send that request to a
server.
- `TestGetUserAISpendByEffectiveGroupsSince` checks the period start
boundary, a requested group with no spend returning 0, and the exclusion
of other users and unrequested groups.
**Backend**
- `userAISpendStatus` builds `AIBudgetLimit` with `aiBudgetLimitToSDK`.
#32203's `organizationMemberAISpendStatus` has the same change in
#32663, which also shares one type between the two organization spend
responses.
<details>
<summary>Review threads addressed</summary>
| PR | Thread | Change |
| --- | --- | --- |
| #32204 | `UserDropdownAISpend.tsx:90`: $0 limit shows a 0% bar |
Shared helpers return 100% / exceeded |
| #32204 | `viewedSpend.ts:44`: menu-only fork of `getSeverity` | Rule
moved into `getSeverity`. `UsageIndicator` and `AIBudgetAmount` now
agree |
| #32204 | `UserDropdownOrgSelect.tsx:49`: no `aria-controls` | Added |
| #32204 | `viewedSpend.test.ts:8`: `getSpendSeverity` untested | Added
|
| #32204 | `UserDropdown.stories.tsx:304`: exceeded step checks nothing
| Assertions added |
| #32204 | `UserDropdown.stories.tsx:379`: multi-org stories have no
assertions | Assertions added |
| #32204 | `UserDropdown.stories.tsx:141`: single-org stories fire a
real request | Seeded. A shared constant is added to each story, because
a story's `queries` replaces the meta's |
| #32202 | `aicostcontrol.sql:294`: querier test for
`GetUserAISpendByEffectiveGroupsSince` | Added |
| #32203 | `aibridge.go:1399`: use `aiBudgetLimitToSDK` | Same fix
applied to `userAISpendStatus` here |
Not in this PR, still open for a decision: the avatar badge reflecting
other organizations (#32204 `UserDropdown.tsx:62`) and `DropdownMenuSub`
(#32204 `UserDropdownOrgSelect.tsx:49`).
</details>
> Generated by Coder Agents on behalf of @SasSwart.