Skip to content

fix(server): register a provider-usage.v1 source so the panel sees ZCode - #9

Merged
dpolishuk merged 1 commit into
mainfrom
fix/usage-panel-source
Nov 9, 2026
Merged

dpolishuk merged 1 commit into
mainfrom
fix/usage-panel-source

Conversation

@dpolishuk

@dpolishuk dpolishuk commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Problem

After PR #8 the bridge reports real quota windows through provider/usage,
but the Provider usage panel still showed nothing for ZCode.

Root cause: the panel never calls provider/usage. It is federated — bb's
builtin provider-usage plugin discovers usage sources server-side via
experimental_discoverRpc of provider-usage.v1.listResources and reads
each with provider-usage.v1.getResource. Only plugins registering that
contract (experimental_discoverable: true) appear; the builtin provider
plugins (codex, claude-code, acp, account-pool) implement it, bb-zcode did
not. maintenance.usage / providers.list({capability:"usage"}) is display
metadata, not a data source.

Verification that isolated this: the production worker artifact was spawned
exactly as the daemon spawns it (bb-provider-bridge-worker.mjs <artifact> zcode <dataDir>) and answered provider/usage with the real account —
status ok, GLM Coding Max, 5-hour/weekly/MCP windows with live reset times.

Change

  • src/usageContract.ts — pins the panel wire (method names, resource and
    window grammar) extracted from the builtin provider-codex implementation.
  • src/usageSource.ts — discoverable provider-usage.v1 source: host-scoped
    resources for the zcode provider on connected non-ephemeral hosts,
    window-grammar mapping by label (five-hour/weekly/custom, stable
    ${i}:${label} ids, model: null, cost passthrough), a 60 s
    observedAt cache with refresh bypass, non-ok pass-through without
    invented windows, and error usage states for disconnected hosts / failed
    collections (no credential or body text leaks into messages).
  • Measurements flow server → system.usageLimits({hostId, providerId, refresh}) → daemon provider/usage → the bridge quota fetch with its own
    cache; server.ts wires the source with real sdk deps; deps are injectable
    for tests.

Verification

  • 4 focused tests in tests/usage-source.test.ts: listing filters to the
    zcode provider on persistent hosts; window mapping parses against the
    contract and the 60 s cache prevents re-collection (refresh bypasses);
    disconnected-host and failed-collection error states (with a canary check
    that internals do not leak); unauthenticated pass-through.
  • npm run typecheck, full suite 268 tests green, format:check clean.
  • Live worker-level verification of the underlying provider/usage answer
    (see above); the panel entry itself needs this PR merged + plugin update to
    observe.

Docs/knowledge: CHANGELOG, knowledge/contracts/quota-usage-protocol.md
(new "panel federation" section), knowledge/log.md.

Summary by CodeRabbit

  • New Features
    • ZCode usage is now available in the Provider usage panel, with quota windows and optional cost information.
    • Usage readings refresh on request; recent results may be reused for up to 60 seconds.
  • Bug Fixes
    • Disconnected providers and failed usage checks now display an error state instead of missing usage information.
  • Documentation
    • Updated the changelog and usage documentation to describe the Provider usage experience.

The Provider usage panel never calls provider/usage: it federates over the
provider-usage.v1 RPC contract that only builtin provider plugins implement,
so the quota windows shipped earlier were unreachable from it (the panel
listed no ZCode entry at all). The production worker was verified first -
spawned exactly as the daemon spawns it, it returned GLM Coding Max with
all three live windows - isolating the gap to the missing federation.

src/usageSource.ts registers a discoverable source: host-scoped resources
for the zcode provider on connected non-ephemeral hosts, window-grammar
mapping by label (five-hour/weekly/custom, stable ids), a 60 s observedAt
cache with refresh bypass, and error usage states for disconnected hosts
and failed collections. Measurements flow through the daemon's
provider/usage path via system.usageLimits, reusing the bridge quota fetch
and its cache. src/usageContract.ts pins the wire; server.ts wires it with
real sdk deps; tests cover listing, mapping, caching, and degradation.

Wire semantics recorded in knowledge/contracts/quota-usage-protocol.md.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T15:01:24.455431Z bb83d18 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

Adds a discoverable ZCode usage source for the Provider usage panel. The source lists eligible host-scoped resources and retrieves usage through system.usageLimits. It validates RPC data, caches successful readings for 60 seconds with refresh bypass, and returns error states for disconnected hosts or failed collections.

Changes: Provider usage source

Layer / File(s) Summary
Define the usage RPC contract
src/usageContract.ts
Adds schemas for usage resources, accounts, windows, statuses, and strict list and read RPC inputs and outputs.
Register and implement usage discovery and reads
src/usageSource.ts, server.ts, tests/usage-source.test.ts, knowledge/contracts/quota-usage-protocol.md, knowledge/log.md, CHANGELOG.md
Registers the source, lists eligible host-scoped ZCode resources, and retrieves usage with caching, refresh bypass, window mapping, and error states. Tests cover listing, mapping, caching, failures, and unauthenticated usage. The documentation describes the source and its relationship to the panel.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Panel as Provider usage panel
  participant Source as provider-usage.v1 source
  participant SDK as SDK host and provider APIs
  participant Limits as system.usageLimits
  Panel->>Source: listResources
  Source->>SDK: list hosts and usage providers
  SDK-->>Source: host-scoped ZCode resources
  Source-->>Panel: resources
  Panel->>Source: getResource with resourceId and refresh
  Source->>Limits: collect usage when cache is unavailable or bypassed
  Limits-->>Source: usage result
  Source-->>Panel: account, observedAt, and usage state
Loading

Possibly related PRs

  • dpolishuk/bb-zcode#8: Adds the provider/usage response windows and cache behavior consumed by this usage source.
Merge Risk: Low · up to bb83d

The new usage source works for the listed ZCode resources. It also accepts resource IDs it never lists, which is low-impact and easy to guard. The panel behavior is not verified until after merge and a plugin update.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@dpolishuk
dpolishuk merged commit 3eef2da into main Nov 9, 2026
2 of 3 checks passed
@dpolishuk
dpolishuk deleted the fix/usage-panel-source branch November 9, 2026 15:04
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