Skip to content

Provider usage: show a source-reported account error state on that account's row instead of treating it as a failed refresh of the whole group #7421

Done

Description

@seklow

The workflow

I use Provider usage to see which account has a problem. When a usage source reports expired or unauthenticated for an account, that account's row says so. When it reports error with a message, Provider usage treats that as a failed refresh: the whole group gets a generic notice such as "Couldn’t refresh. Showing last update.", the message is dropped, and the row keeps whatever it showed before, even a sign-in hint its source no longer reports. I expected the affected row to show what its source reported, and values kept from an earlier measurement to be marked as old.

This is the Provider usage half of #7417, filed separately because it changes what the panel shows and needs sign-off before a PR.

What happens today

The ok-then-error display was seen once on a live account (#7417; bb 0.49.0, npm bb-app, Debian 13). Below is a synthetic repro on main at 365d7c5237ae270be0555b5b44ea61020252713e: the real server.ts with a fake usage source. It is not verified in a running bb or a browser.

git checkout 365d7c5237ae270be0555b5b44ea61020252713e
pnpm install --frozen-lockfile --prefer-offline
pnpm exec turbo run build build:types --filter=@get-bb/plugin-sdk
# save the script below as plugins/provider-usage/source-error.repro.ts
node_modules/.bin/tsx plugins/provider-usage/source-error.repro.ts

The setup lines are from the #7417 report. I ran all of them, as written, in a fresh clone (Node 24.22.1, pnpm 9.15.0).

source-error.repro.ts
import { createFakePluginHost } from "@get-bb/plugin-sdk/testing";
import plugin from "./server.js";
import { usageListMethod } from "./usage-source-contract.js";

const account = { accountEmail: null, planLabel: "Pro" };
const week = { id: "week", label: "Weekly limit", usedPercent: 42, resetsAt: null, model: null, cost: null };
const states: Record<string, object> = {
  ok: { status: "ok", ...account, windows: [week] },
  expired: { status: "expired", ...account },
  error: { status: "error", ...account, message: "Fake source message." },
};
const resources = [{ id: "a", providerId: "fake", label: "Account A", scope: { kind: "shared" } }];
const request = { force: true, machineIds: null, providerIds: ["fake"], maxAgeMs: 0 };

for (const sequence of [["ok", "error"], ["expired", "error"], ["error"], ["ok", "rpc-throws"]]) {
  let reply = "";
  let observedAt: number | null = null;
  const host = createFakePluginHost({
    pluginId: "provider-usage",
    sdk: {
      system: { config: async () => ({ primaryHostId: null }) },
      hosts: { list: async () => [] },
      providers: { list: async () => [] },
      plugins: {
        experimental_discoverRpc: async () => [
          { pluginId: "fake-source", displayName: "Fake source", method: usageListMethod },
        ],
        callRpc: async ({ method, outputSchema }) => {
          if (method === usageListMethod) return outputSchema.parse({ resources });
          if (reply === "rpc-throws") throw new Error("Fake transport error.");
          if (reply === "ok") observedAt = 1_800_000_000_000;
          return outputSchema.parse({ observedAt, usage: states[reply] });
        },
      },
    },
  });
  plugin(host.bb);
  let result: any;
  for (reply of sequence) result = await host.harness.behavior.callRpc("getUsage", request);
  const { providers, error } = result.machines[0];
  console.log(`source returned ${sequence.join(", then ")}`);
  console.log(`  row usage    ${JSON.stringify(providers[0].usage)}`);
  console.log(`  group error  ${JSON.stringify(error)}`);
}

Each block is the group after the last reply of a sequence. Every call uses force: true, as Reload and Retry do.

source returned ok, then error
  row usage    {"status":"ok","accountEmail":null,"planLabel":"Pro","windows":[{"label":"Weekly limit","usedPercent":42,"resetsAt":null,"cost":null}]}
  group error  "Some usage could not be refreshed."
source returned expired, then error
  row usage    {"status":"expired"}
  group error  "Some usage could not be refreshed."
source returned error
  row usage    null
  group error  "Some usage could not be refreshed."
source returned ok, then rpc-throws
  … the same two lines as in the first block
  • ok, then error: the old values and plan badge stay, unmarked. The source's message and observedAt are not in the result. A thrown RPC gives the same result.
  • expired, then error: the row still says "This account’s session expired. Sign in again…". unauthenticated behaves the same.
  • error, nothing stored: the card shows only "Couldn’t load usage."; next to a healthy row, the row reads "Usage unavailable.".

(Card texts: the production card component rendered to static markup.)

Code at that commit:

  1. fetchResource throws on status: "error" before the only measurements.set (server.ts#L191-L198). readUsage then sets an error on the whole group (L354-L361), shown as the generic notice (app.tsx#L612-L625). The row's own error branch (app.tsx L344-L345) is unreachable.
  2. The source contract says "Per-account authentication and collection failures are usage states. observedAt is the last successful measurement time." (usage-source-contract.ts#L130). The panel's row model has no observedAt or stale field (usage-schema.ts#L16-L48).
  3. Not only the pool: by the code (not run), Codex signed in with an API key always returns error (provider-maintenance.ts#L348-L358), so its row is a permanent failed refresh with Retry.

What you would expect

The affected row shows what its source reported, and no other row carries a warning for it. A row stops showing expired or unauthenticated once its source reports something else. Kept values are marked as old.

Proposed fix and question for maintainers. Keeping the last measurement after a failed refresh is deliberate (#3449, README.md#L14-L16), but the tests cover it only for a thrown RPC. Each option touches only plugins/provider-usage and leaves thrown RPCs and inventory failures as they are. I ran 1–3 as local patches to server.ts; the plugin's 23 tests pass with each. Option 4 is not prototyped.

  1. Keep the throw, but first drop a stored state that isn't ok. Fixes only the stale state message (a sign-in hint or "Not installed on this machine."); that row then looks like "nothing stored". About 3 lines, no new text or schema.
  2. Store error unless an ok measurement is stored. A row with no values to lose shows the source's message, without a group notice. One condition changes. Source-written text becomes visible, including raw exception messages from host sources.
  3. Always store error. The message replaces the values and plan badge, so a temporary source failure blanks the row, against README L14. Removes 2 lines.
  4. Option 2 plus a per-row stale marker. ok then error keeps the values and adds the source's message and the measurement time. Needs new fields in the strict row schema, rendering on both surfaces and an age format.

Option 1 is the smallest fix that is correct on its own: the only visible change is that a stale state message gives way to the existing "nothing stored" display, so it needs no design decision. I'll open a PR once a direction is signed off, and can link a fork prototype here first.

Question: when a source returns error for an account whose last successful measurement is still stored, should that row show (a) the last values with a marker carrying the source's message and the measurement time (option 4), (b) only the source's message (option 3), or (c) the last values unmarked behind the group notice, as today (then option 1 or 2 covers the rest)?

Context and alternatives

Checks

  • I searched open and closed issues for the same request.
  • If an agent wrote this, the body ends with > AGENT GENERATED.

AGENT GENERATED

Activity

  1. added theissue type on Nov 11, 2026
  2. added
    providers
    confirmed-repro
    on Nov 11, 2026
  3. bb-slop-cop commented on Nov 11, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · Priority: Medium · Effort: Medium. Labels: providers, confirmed-repro.
    • Reproduction and root-cause report: REPRODUCED · root-cause confidence: high.
    • Root cause: a valid account-level error reply throws before updating the cache, retaining the previous account state and promoting its failure to a group-wide notice.
    • Verification: two clean trusted-main checkouts reproduce the same failure (expected error, received expired); all 23 existing plugin tests pass. Synthetic source through the real RPC and production component rendering; no live-account claim.
    • No PR: a complete repair needs a product decision about retaining successful measurements; row-local error/age metadata would also change the strict RPC schema, outside the simple-fix safety gate.
  4. seklow commented on Dec 2, 2026

    @seklow
    Author

    #7777 covers this in 0.51.0: a source's error message now shows on that account's row, and a kept reading is labelled "Showing last update". Closing.

    One small case is left, from reading the code. After expired and then error, the row shows the new error and still the old sign-in hint, without marking the hint as old. I can file it separately if it's worth a change.

    AGENT GENERATED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-reproproviders

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions