Skip to content

fix(opencode): accept the nested usage envelope - #103

Closed
alvorithm wants to merge 1 commit into
bernardopg:mainfrom
alvorithm:fix/opencode-usage-envelope
Closed

alvorithm wants to merge 1 commit into
bernardopg:mainfrom
alvorithm:fix/opencode-usage-envelope

Conversation

@alvorithm

@alvorithm alvorithm commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

/zen/go/v1/usage no longer returns the envelope the adapter validates. A live response today is:

{"usage":{"rolling":{"status":"ok","percent":0,"resetsAt":"2026-11-08T15:24:56.000Z"},
          "weekly":{"status":"ok","percent":19,"resetsAt":"2026-11-09T00:00:00.000Z"},
          "monthly":{"status":"ok","percent":75,"resetsAt":"2026-11-14T14:38:46.000Z"}}}

The adapter requires a top-level rollingUsage/weeklyUsage/monthlyUsage with usagePercent and a relative resetInSec (providers/native/opencode.bash), so validation fails on every response and the provider degrades to the authenticated-only /models check. The card reads "Authenticated, quota endpoint unavailable" and none of the three windows that #22 added is shown.

This PR makes the adapter accept both envelopes, so the provider reads the live windows and an older deployment that still returns the flat shape is unchanged (fix(opencode): accept the nested).

Verifications

tests/test-opencode.sh gains a case that answers with the nested envelope and asserts the source, the three percentages and the absolute reset, and it still covers the flat envelope. tests/test-cov-c2-opencode.sh, the rest of the offline fixture suites, scripts/check-changelog --base origin/main and scripts/check-dco origin/main pass.

Shell lint ran with shellcheck 0.10.0. It reports no new findings on the changed file. The four pre-existing SC2034 findings in providers/get-provider-usage reproduce at this version; that file is untouched here.

Not verified: no live request was made from CI, since the suite stays offline and uses the captured payload above.

Out of scope

  • Reading each window's status field. The adapter accepts a window whenever its percentage is in range, as it did before.
  • The resetAt precision. The nested shape carries an absolute timestamp that is passed through as-is; the flat shape still computes one from resetInSec.

GET /zen/go/v1/usage returns usage.rolling.percent with an absolute resetsAt,
not the flat rollingUsage.usagePercent with a relative resetInSec the adapter
validated. Every response therefore failed validation and the card degraded
to the authenticated-only /models check, hiding all three quota windows.

Both shapes are now accepted, so an older deployment is unchanged.

Signed-off-by: Álvaro Tejero Cantero <[email protected]>
@github-actions github-actions Bot added documentation Improvements or additions to documentation area:providers Provider adapters (providers/) area:ci CI, workflows, tooling labels Nov 8, 2026
@bernardopg
bernardopg marked this pull request as ready for review November 8, 2026 18:18
@bernardopg
bernardopg self-requested a review as a code owner November 8, 2026 18:18
@bernardopg

Copy link
Copy Markdown
Owner

Thank you @alvorithm, this was a precise catch: the live payload in the description made the change easy to confirm, and other clients that read /zen/go/v1/usage report the same shape change.

I carried this forward as #104 rather than waiting on the draft. Your commit is kept as-is, with you as its author, and one follow-up commit sits on top:

  • A nested window with no resetsAt, or an empty one, keeps its percentage with a null reset instead of an invented one.
  • New fixtures cover fractional percentages, a rate-limited window, useBalance in the nested shape and an out-of-range nested percentage (which falls back to auth-only, like the flat shape).
  • docs/providers.md described only the flat rollingUsage / resetInSec shape; it now documents the nested one first.

The CHANGELOG ### Thanks section credits you, and you'll show up in the README contributor grid once it merges. I'll close this PR when #104 lands. Thanks again!

@bernardopg

Copy link
Copy Markdown
Owner

Merged as part of #104 with your commit and authorship intact. Thank you again @alvorithm!

@bernardopg bernardopg closed this Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, workflows, tooling area:providers Provider adapters (providers/) documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants