Skip to content

feat: show the total number of AI spend unpriced models - #32553

Merged
ssncferreira merged 2 commits into
mainfrom
ssncf/ai-spend-unpriced-models-count
Nov 24, 2026
Merged

ssncferreira merged 2 commits into
mainfrom
ssncf/ai-spend-unpriced-models-count

Conversation

@ssncferreira

@ssncferreira ssncferreira commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Description

The unpriced models endpoint is now paginated (#32170), so models is one page and count is the total. The total spend card used the number of listed models, so it would undercount with more than one page.

Changes

  • Request up to 100 unpriced models, the most the endpoint returns, with UNPRICED_MODELS_COUNT.
  • Pass the whole response down, and label N Models not set up with count.
  • Show and M more under the list for the models it doesn't show, count minus the listed models.
  • Remove the TODO(AIGOV-730).
  • Add a story for more models than listed.

Related to AIGOV-730

Note

Generated by Coder Agents on behalf of @ssncferreira.

@linear-code

linear-code Bot commented Nov 20, 2026

Copy link
Copy Markdown

AIGOV-730

@ssncferreira
ssncferreira force-pushed the ssncf/ai-spend-unpriced-models-count branch 3 times, most recently from a26e049 to 18757ae Compare November 23, 2026 19:04
@ssncferreira
ssncferreira force-pushed the ssncf/ai-spend-unpriced-models-count branch from 18757ae to c465e93 Compare November 24, 2026 10:05
@ssncferreira
ssncferreira marked this pull request as ready for review November 24, 2026 10:09

@mollymaefraser mollymaefraser left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀 few nits but nothing blocking

const endDateSearchParam = "endDate";
// The number of unpriced models the total spend card lists. 100 is the most the
// endpoint returns.
const UNPRICED_MODELS_COUNT = 100;

@mollymaefraser mollymaefraser Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could we export this the way TOP_SPENDERS_COUNT is exported from topSpenders.ts, and use it in AISpendPage.test.tsx instead of the literal 100? Then the tests follow the constant if it changes.

Small question: the list is capped at max-h-48 and "and M more" covers the rest, so do we need 100 rows? You mentioned this query is slow to compute, so a smaller page (10–20?) might be cheaper. Fine to keep 100 if it's intentional.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it to unpricedModels.ts like TOP_SPENDERS_COUNT and used it in the tests.

100 is intentional. It's the endpoint's maximum and the same limit the notification uses. Ideally, admins would fix unpriced models from a dedicated page, but until that exists, we want to show as many as possible here. In practice, a deployment is unlikely to have that many unpriced models. Once that page or workflow exists, we should revisit the limit.

On cost, the query already scans every unpriced model to compute count, so a bigger page mostly adds payload, not query time.

const headingId = useId();
// TODO(AIGOV-730): adjust once the unpriced models endpoint is paginated.
const isSingle = models.length === 1;
const isSingleModel = count === 1;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: count === 1 is right for the wording. The compact single-row layout (p-0, no px-2, no ScrollArea) depends on how many rows we render, though. They're equivalent today because count >= models.length, but splitting them would make the intent clearer:

	const isSingleModel = count === 1;
	const isSingleRow = models.length === 1 && count === 1;

Or just leave a comment saying why count is safe for both. Not blocking.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The popover only renders with at least one model and count is never less than models.length, so count === 1 always means one row. I kept a single flag so the two can't drift.

Comment on lines +50 to +54
{unlistedCount > 0 && (
<li className="p-2 text-sm text-content-secondary">
and {unlistedCount} more
</li>
)}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit (a11y): because "and M more" is an

  • inside the model list, screen readers announce it as one of the models (for example, "list, 11 items"). Moving it out of the
      (a

      right after the list, still inside the ScrollArea) keeps the list count accurate. Not blocking.

  • Copy link
    Copy Markdown
    Collaborator Author

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Good catch, moved it to a <p> after the list so the item count is accurate.

    };

    /** More models have no price than the first page lists. */
    export const MoreModelsThanListed: Story = {

    Copy link
    Copy Markdown
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    nit: this story renders the new "and M more" row, but nothing checks it. Could we add a play that opens the popover (like the meta play) and then checks await expect(screen.getByText("and 5 more")).toBeInTheDocument();? That makes it a regression test for the new behaviour.

    Copy link
    Copy Markdown
    Collaborator Author

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    In our guidelines, stories only capture visual state and their play functions don't assert, so Pixel shows what changed. Assertions belong in Vitest tests, but in this case I think the story is enough: if the "and 5 more" row is removed or changed, it shows up in Pixel.

    @ssncferreira
    ssncferreira merged commit 1932573 into main Nov 24, 2026
    26 checks passed
    @ssncferreira
    ssncferreira deleted the ssncf/ai-spend-unpriced-models-count branch November 24, 2026 12:42
    @github-actions github-actions Bot locked and limited conversation to collaborators Nov 24, 2026

    This branch had an error being deployed

    1 failed deployment
    docs-preview — 16c7eb55 Deployed Nov 24, 2026 by ssncferreira via cleanup #404
    Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

    Labels

    None yet

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    2 participants