Add command code support#857
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7fbb353304
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| return CommandCodeCookieOverride( | ||
| name: self.supportedSessionCookieNames[0], |
There was a problem hiding this comment.
Use the secure cookie name for bare tokens
When a bare session token is provided, this now picks supportedSessionCookieNames[0], which is __Host-better-auth.session_token; the added CommandCodeUsageFetcherTests.cookie header accepts bare token and uses secure name expects __Secure-better-auth.session_token, so the new test suite fails and bare-token manual setup will send the wrong cookie name for the documented production variant. Choose the intended production cookie name explicitly instead of depending on the array order.
Useful? React with 👍 / 👎.
7fbb353 to
b435292
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b435292bb6
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } else { | ||
| let names = httpCookies.map(\.name).joined(separator: ", ") | ||
| log("No known session name in \(label); sending all domain cookies (\(names))") | ||
| } | ||
| sessions.append(session) |
There was a problem hiding this comment.
Skip cookie sets without a Command Code session token
This loop appends every domain cookie bundle even when session.sessionCookie is missing, and importSession() later returns sessions.first, so a non-authenticated profile can be chosen ahead of a valid one. In multi-profile or multi-browser setups, auto mode can consistently send a cookie header that lacks better-auth.session_token, producing invalidCredentials even though another discovered session is valid.
Useful? React with 👍 / 👎.
| async let creditsResult = self.fetchCredits(cookieHeader: cookieHeader, session: session) | ||
| async let subscriptionResult = self.fetchSubscription(cookieHeader: cookieHeader, session: session) | ||
|
|
||
| let credits = try await creditsResult | ||
| let subscription = try await subscriptionResult |
There was a problem hiding this comment.
Don’t fail usage fetch when subscriptions call errors
The subscription request is treated as a hard dependency via try await subscriptionResult, so any transient failure on /internal/billing/subscriptions aborts the whole provider fetch, even if credits were fetched successfully. Because credits are enough to show remaining balance (and parseSubscription already models missing subscription data as optional), this turns partial backend outages into full Command Code outages for users.
Useful? React with 👍 / 👎.
steipete
left a comment
There was a problem hiding this comment.
Thanks @sixhobbits. I rebased this onto current main, kept the newer Crof/Venice provider entries, fixed the Command Code bare-token cookie default, updated provider-order coverage, and verified local/CI checks.
Might be slop because I'm not a macos dev and I don't have XCode so my agent had to do a bunch of workarounds to build this locally and test it
But it works for me