Skip to content

feat(site): show AI spend per organization - #32204

Draft
SasSwart wants to merge 2 commits into
aigov-766/org-member-ai-spendfrom
aigov-766/user-dropdown-org-spend
Draft

SasSwart wants to merge 2 commits into
aigov-766/org-member-ai-spendfrom
aigov-766/user-dropdown-org-spend

Conversation

@SasSwart

@SasSwart SasSwart commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Users in more than one organization can now pick an organization in the avatar menu and see their AI spend and budget there. Before, the menu showed one figure from a site-wide effective group, so these users had no way to see their spend in their other organizations.

  • Organization selector: appears only when the response lists more than one organization. It is a menu item that expands a DropdownMenuRadioGroup inside the existing menu, so the menu stays open while the user switches. Each organization in the list shows a warning or exceeded badge with a screen reader label, in API order, and typeahead matches the organization name. The selection lives in local component state. It starts on the entry that matches organization_id, or the first entry if none matches. If a refetch drops the selected organization, it falls back the same way.
  • Avatar badge: the badge on the avatar, and its screen reader label, follow the selected organization.
  • Exceeded state: any user at or over their limit, single-organization users included, sees an "AI spend" header with a red "Limit exceeded" label. A $0 budget counts as exceeded even with no spend, because AI Gateway blocks requests once spend reaches the limit. The shared getSeverity helper is unchanged, so other views still show $0 of $0 as normal. Below the bar, the line "AI requests are paused until {period end}" appears. The normal and warning states look the same as before.
  • Older servers: single-organization users, and servers that do not send organizations, see the top-level fields as before.
  • Invalid values: if the shown organization reports a negative spend or limit, the selector stays and the menu shows "AI spend unavailable", so the user can still switch. A single-organization user with invalid values sees no spend section, as before.
  • Failed polls: meAISpend refetches every 60 seconds. When a refetch fails, the menu now keeps the last spend and adds "Couldn't refresh AI spend:" followed by the server's error message. Before, it hid the section, which would close an open selector while the user was choosing. UsageIndicator still hides spend on error.

The rule for which spend to show lives in a pure helper, getViewedSpend in viewedSpend.ts. The severity map moved into severityIndicators.tsx, next to a shared SeverityBadge. The cost controls page now describes the selector and the exceeded state.

Open questions

A $0 budget blocks every AI Gateway request, but the shared getSeverity helper in site/src/utils/budget.ts still shows $0 of $0 as normal. This PR only changes the user menu. Two other screens use the shared helper:

  • The AI usage indicator on the Agents page (UsageIndicator) shows users their own spend. Should a $0 budget show as exceeded there too, to match the menu?
  • The group budget amounts (AIBudgetAmount) show admins each group's budget. Should a group with a $0 budget, where AI is deliberately off, show as exceeded or stay neutral?

Out of scope, tracked in AIGOV-738: organization search, the count badge on the collapsed row, sorting organizations by severity, the workspace quota row, and a shared app-wide current organization.

UserDropdown.test.tsx checks the exceeded text because the ticket asks for it. A Pixel story also covers that state. The failed-poll state has a Vitest test but no story. The Storybook query client cannot hold cached data and an error at once without a test-only hook.

Screenshots

Multiple organizations

image

Organization picker with severity badges

image

Selected organization over its limit

image

AI spend unavailable for the selected organization

image

🤖 Generated with Claude Code

SasSwart and others added 2 commits November 14, 2026 12:45
Users in more than one organization can pick an organization in the
avatar menu to see their AI spend and budget there. The avatar badge
follows the selected organization, and users over their limit see a
"Limit exceeded" header with the date AI requests resume.

Refs AIGOV-766

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…indings

- Show a $0 budget as exceeded in the user menu, since AI Gateway blocks
  requests once spend reaches the limit.
- Give the organization items a typeahead value, so the avatar initials
  no longer prefix the text Radix matches against.
- Cover picking an organization with the keyboard, including focus
  returning to the organization button.
- Make the organization_id fallback fixture match what the server
  returns.

Refs AIGOV-766

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@linear-code

linear-code Bot commented Nov 14, 2026

Copy link
Copy Markdown

AIGOV-766

@SasSwart
SasSwart added this pull request to stack #32205 November 14, 2026 12:50
@SasSwart
SasSwart temporarily deployed to docs-preview November 14, 2026 12:51 — with GitHub Actions Inactive
@github-actions

Copy link
Copy Markdown
Contributor

Docs preview

Links open this pull request's preview at https://pr-32204.docs.cdr-preview.dev, which updates with each push.

Check off each page once it's been reviewed. If a page changes in a later push, its checkbox clears automatically so it gets a fresh look. Pages not yet wired into the docs navigation aren't listed here.

Preview sites for each built commit (1)

Every built commit keeps its own preview, newest first. Previews aren't indexed by search engines and are deleted when this pull request is merged or closed.

This branch was previously deployed

1 inactive deployment
docs-preview — f496666b Deployed Nov 14, 2026 by SasSwart via deploy #191
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant