Skip to content

Fix usage card rejecting successful RPC responses - #6069

Closed
ymichael wants to merge 1 commit into
mainfrom
fix/provider-usage-rpc-metadata
Closed

ymichael wants to merge 1 commit into
mainfrom
fix/provider-usage-rpc-metadata

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Provider Usage rejected successful RPC responses after #5658 added tags, keyTags, and invalidated metadata. Its strict response-envelope schema accepted only ok and result, so the sidebar showed “Couldn’t load usage” even when the server returned valid measurements.

What changed

Allow additional response-envelope fields while retaining strict validation of the usage payload. Update the existing sidebar integration test to include the metadata returned by the server.

How you verified

  • The updated sidebar test failed before the parser fix and passed afterward.
  • pnpm exec turbo run test lint typecheck --filter=bb-plugin-bb--provider-usage: all 23 tests, lint, and typecheck passed.
  • Parsed a live server response with the corrected schema: HTTP 200, four usage sources, seven measured providers.
  • git diff --check passed.

AGENT GENERATED

@ymichael ymichael closed this Oct 21, 2026
ymichael added a commit that referenced this pull request Oct 21, 2026
## Human comments

## What was wrong

#5658 made plugin RPC responses carry the tag engine's bookkeeping.
`invokeRpcHandler` returned `tags`, `keyTags` and `invalidated`, and the
route sent that outcome as-is (`context.json(outcome)`). Every
successful response became `{ ok, result, tags, keyTags, invalidated }`.

Callers that fetch the endpoint directly with strict parsers rejected
every success:
- the provider usage card (`plugins/provider-usage/usage-schema.ts`),
which shows an error even when usage loaded;
- desktop machine enrollment
(`apps/desktop/src/connect-machine-enrollment.ts`). It has no fallback,
so a desktop app that hasn't enrolled yet fails silently, logging `could
not enroll this app with bb Connect (invalid_response)`. It only becomes
visible when the local server is down and the app has no credential;
- the local call in the desktop account server list
(`apps/desktop/src/connect-server-sync.ts`). It falls back to the stored
machine credential or the account session, so the server menu still
fills.

The data was also redundant. Those fields are computed only from the RPC
contract's `tags`, `keyTags` and `invalidates` declarations, using the
parsed input and output. Core's RPC hooks already receive that same
contract.

It affects main and the nightly build of Oct 21 (0.46.2-nightly). Stable
0.46.1 predates #5658. These callers aren't affected: the SDK's
`callRpc` (used by the CLI and plugin server code), Side Chat, desktop
session creation, and the community marketplace plugins checked, which
call the endpoint directly and all parse loosely.

## What changed

- **Server:** `invokeRpcHandler` returns `{ ok: true, result }`, and the
route builds `{ ok: true, result: outcome.result }` explicitly, so
internal fields can't reach the response. The server still computes
`invalidated` and broadcasts it through `notifyPluginChanged`.
- **Client:**
- `rpc-query-host.ts` computes `tags`, `keyTags` and `invalidated` with
the shared `rpcResponseTags`, from the hook's `contract`, the input
parsed by the contract's input schema, and the result. That's the same
function the server uses, and the same way core routes derive their tags
in `route-tags.ts`.
  - The app transport drops its `envelope` flag.
  - The SDK test host returns only the result.
- **Tests:**
- the six server tests that assert the exact response body now expect
exactly `{ ok, result }`;
- a new wire test: a method declaring `tags`, `keyTags` and
`invalidates` returns exactly `{ ok, result }` and still calls
`notifyPluginChanged` with its invalidation. It fails on main, where the
body also carries `tags`, `keyTags` and `invalidated`.

The provider usage card and both desktop paths work again without
changes. This replaces #6069, which loosened the usage card's parser.

## How you verified

- Live `pnpm start:worktree` servers, same `getUsage` call: main returns
keys `invalidated, keyTags, ok, result, tags`; this branch returns `ok,
result`.
- Typecheck: plugin SDK and app pass. The server typecheck failed only
on the six old response expectations, which this PR updates.
- `@get-bb/plugin-sdk`: 390 tests pass, including
`rpc-query-host.test.tsx`, where reads refresh from contract-declared
tags and keyTags with no server-sent tags.
- push-notifications (44) and provider-usage (23) pass.
- `plugin-wire.test.ts`: 31 tests pass; the new test fails on main.

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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