Repository navigation
fix(usage): read opencode's limits with the OpenCode Console sign-in - #60
Merged
Merged
Conversation
OpenCode 2 connects the account with /connect and stores an OAuth sign-in to the console (entry `opencode`), not a Go API key, so the usage view had nothing to read. Without a Go key the console sign-in now reads the Go meters; a workspace without Go pays from Zen credits and says so (Reason::PayAsYouGo). An expired sign-in is left for opencode to renew: its refresh token is single use.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
OpenCode 2 connects the account with
/connectand stores an OAuth sign-in to the OpenCode Console (credentialtable, integrationopencode), not a Go API key (opencode-go). Leon only looked for the Go key, so for a Go subscriber the usage view said "Limits cannot be read for this agent here".Change
opencode.rs: reads the console sign-in (OAuthaccesswith itsexpires, or a service-account/Zen key) fromOPENCODE_AUTH_CONTENT,auth.jsonand the credential database, read only.network.rs: newCredentials::opencode_console(defaultMissing).opencode_usageuses the Go key first and falls back to the console sign-in. With the console sign-in:zen/go/v1/usage(the endpoint accepts the console token).Reason::PayAsYouGo, planZen("no limit to read; the balance is on the opencode console").SessionExpired. Leon never refreshes it, because the refresh token is single use and spending it would sign opencode out.model.rs:Reason::PayAsYouGo.The Zen balance has no public endpoint for a user token: the console's routes return 404, and
/api/v1/budgets/membersneeds an admin service-account key.Verification
leon --diagnose usage --network opencodeagainst a real Go account signed in through/connect: 5-hour 0%, weekly 0%, monthly 19%, plan Go.cargo test -p leon-usagepasses (195 tests, 6 new).cargo clippy -p leon-usage --all-targets -D warningsis clean.Note:
PayAsYouGois a new serialized reason, so an older peer cannot decode a Zen reading.