Repository navigation
fix: read OpenCode Go usage from the console API - #21462
Conversation
📝 WalkthroughWalkthroughThe fetcher now calls Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to The migration’s endpoint, meter parsing, cookie handling, and updated guidance are covered by the changed implementation and tests. The remaining localization cleanup is non-blocking. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the main implementation, scope, trade-offs, testing command, and linked issue. However, it does not follow the repository template and omits required sections such as ELI5, What Changed, Why, Visual Proof or an explicit N/A, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist details. Resolution Update the description to include all template sections. Add an ELI5 summary, structured What Changed and Why sections, visual proof or explicitly state N/A with a reason, testing checklist details and platforms tested, AI Disclosure status, Review, Agent skill upstream boundary, Notes covering security and compatibility, and the required Checklist items. Full details: Docstring CoverageExplanation Docstring coverage is 7.69% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 8 files. (1 skipped: 1 unsupported.)
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. Comment |
There was a problem hiding this comment.
Important
The status endpoint is authed only by __Host-console_session, but the Accounts settings copy still tells users to paste an auth-only cookie — so the in-app flow in #21420's repro still ends in a 401.
Reviewed changes
- Console JSON fetch replaces the HTML scrape —
opencode-go-page-scraper.tsis deleted; the fetcher now GETshttps://opencode.ai/console/api/go/statuswithx-org-id,Origin, and a consoleReferer, and reads the body as JSON. - New payload parser —
opencode-go-status-parsing.tsmapsaccess.meters.{fiveHour,week,month}micro-cent meters to session/weekly/monthly windows (used/limit*100, clamped; absoluteresetsAt; month optional), capped at 1 MB. - Cookie allowlist widened —
__Host-console_sessionis added toAUTH_COOKIE_NAMESand to thenormalizeCookieInputprefix regex;/_serverworkspace discovery still usesauth. - Tests rewritten — JSON fixtures replace the React Flight pages, including a pin that the legacy HTML page is no longer accepted. I ran both suites: 38 passed.
⚠️ Settings hint still tells users to paste an auth-only cookie
src/renderer/src/components/settings/accounts-pane-provider-setting-sections.tsx still instructs users to paste Fe26.2**… or auth=Fe26.2**…, but the new endpoint accepts only __Host-console_session. Anyone following the in-app instructions — exactly the repro in #21420 — will keep failing with Usage fetch failed (401), so the fix is only reachable for users who already know to include the console cookie. #21420 explicitly called for updating this hint alongside the allowlist change.
Technical details
# Update the OpenCode Go cookie hint for the console session cookie
## Affected sites
- `src/renderer/src/components/settings/accounts-pane-provider-setting-sections.tsx:103-106` — description: "Paste your opencode.ai session cookie for rate limit fetching."
- `src/renderer/src/components/settings/accounts-pane-provider-setting-sections.tsx:122-125` — placeholder: `Fe26.2**… token or auth=Fe26.2**… header`
- `src/renderer/src/components/settings/accounts-pane-provider-setting-sections.tsx:143-161` — help text naming only `Fe26.2**…` / `auth=Fe26.2**…`
- `src/renderer/src/components/settings/accounts-search.ts:136-139` — search description, same wording
- `src/main/rate-limits/opencode-go-usage-fetcher.ts:237` — the 401 surfaces as `Usage fetch failed (401)` with no pointer to the missing cookie
## Required outcome
- The hint tells users to paste the full Cookie header including `__Host-console_session` (e.g. `auth=…; __Host-console_session=…`), and notes that `auth` alone still covers workspace discovery.
- A 401 from the status endpoint should steer toward the console-session cookie rather than a bare status code.
## Suggested approach
- Update the description/placeholder/help strings (and the matching `accounts-search.ts` description); the i18n auto keys regenerate from the source strings.
- Optionally special-case `statusRes.status === 401` in `opencode-go-usage-fetcher.ts` to a message like "Console session cookie missing — paste the full Cookie header from opencode.ai".
- Note the bare-token path: a console-session value pasted without its `__Host-console_session=` name is wrapped as `auth=<token>` by `normalizeCookieInput`, so the hint should steer to the full header.
## Open questions for the human
- Is the hint intentionally deferred to a follow-up, or should it land with this fix?ℹ️ Nitpicks
isLegacyOpenCodeSessionCookie(src/main/persistence/leasing-ssh-ptys/secret-validation.ts:5) still recognizes onlyauth/__Host-auth, so it now diverges fromAUTH_COOKIE_NAMES. Not reachable today — a plaintext__Host-console_sessionvalue cannot exist from a pre-encryption install — so non-blocking; extend it only if you want the two lists to stay in lockstep.- A bare console-session token (pasted without
__Host-console_session=) is silently wrapped asauth=<token>bynormalizeCookieInput, which will then fail; worth covering in the same hint update.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
74b1395 to
9b1bc63
Compare
|
The status API is authed only by Settings now asks for the full Cookie header, including Preserves: cookie allowlist, workspace lookup, and wrapping a bare token as |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/components/settings/accounts-pane-provider-setting-sections.tsx (1)
148-148: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueWrap the cookie-format example in
translate()for i18n consistency.This user-facing code example bypasses localization, unlike the adjacent Workspace ID example. The existing key
auto.components.settings.AccountsPane.37b4b4a3f7uses this exact literal and is suitable for reuse.♻️ Proposed fix
- <code className="text-xs">auth=…; __Host-console_session=…</code> + <code className="text-xs"> + {translate( + 'auto.components.settings.AccountsPane.37b4b4a3f7', + 'auth=…; __Host-console_session=…' + )} + </code>
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: bf46b56d-60b4-48a8-a3a7-01d90b9bb99c
📥 Commits
Reviewing files that changed from the base of the PR and between 74b1395a28385034e96565745ceff0d64f46e5d4 and 9b1bc632a9936a51b68933008e1a748de24ffa31.
📒 Files selected for processing (7)
src/main/rate-limits/opencode-go-usage-fetcher.test.tssrc/main/rate-limits/opencode-go-usage-fetcher.tssrc/renderer/src/components/settings/AccountsPane.test.tsxsrc/renderer/src/components/settings/accounts-pane-provider-setting-sections.tsxsrc/renderer/src/components/settings/accounts-search.test.tssrc/renderer/src/components/settings/accounts-search.tssrc/renderer/src/i18n/locales/en.json
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run re-reviewed the commit landed since the prior pullfrog review (9b1bc63), which updates the OpenCode Go cookie guidance and turns a bare 401 into an actionable message. The prior review's settings-hint concern is fully addressed.
- Settings hint now names
__Host-console_session— the Accounts pane description, input placeholder (auth=…; __Host-console_session=…), and help text all tell users to paste the full Cookie header, and note thatauthstill covers workspace discovery; theconsolekeyword is added. - Search entry mirrors the hint —
getAccountsOpencodeSearchEntriesgets the same description andconsolekeyword, so search copy matches the pane. - 401 gets an actionable message — a 401 from
/console/api/go/statusnow returnsUsage fetch failed (401) — paste the full Cookie header including __Host-console_session (auth alone is not enough)instead of a bare status code. - Coverage added — renderer tests pin the new hint and search entry (including that the old
Fe26.2**…copy is gone); a fetcher test pins the exact 401 message.
I ran the touched suites (opencode-go-usage-fetcher, opencode-go-status-parsing, accounts-search, AccountsPane): 52 tests pass. verify:localization-extraction exits 0 (the superseded English keys are report-only orphans).
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
The workspace HTML page now 302s to console login. Fetch /console/api/go/status with x-org-id, map JSON meters into the existing windows, and keep __Host-console_session on the closed cookie allowlist. Fixes stablyai#21420
The Go status API is authed by __Host-console_session. Settings still told people to paste auth only, which 401s. Ask for the full Cookie header; auth remains enough for workspace discovery.
9b1bc63 to
4c9621a
Compare
The same commit (#21462) left one `<code>` example as raw JSX text, so `verify:localization-coverage` fails on main once the runtime catalog passes. The text already has a key (its placeholder twin uses `auto.components.settings.AccountsPane.37b4b4a3f7`); reuse it. Control: with this edit reverted the check names exactly this site, with it restored the check passes. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
…mple from #21462 (#21889) * fix(i18n): regenerate the runtime-required English catalog for the AccountsPane strings #21462 (7a6d100) added eight en.json entries without re-running the generator, so `verify:localization-runtime-catalog` fails on main and on every PR's merge ref. Generated with `--fix`; no hand edits. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb * fix(i18n): localize the cookie-header example in the OpenCode Go setting The same commit (#21462) left one `<code>` example as raw JSX text, so `verify:localization-coverage` fails on main once the runtime catalog passes. The text already has a key (its placeholder twin uses `auto.components.settings.AccountsPane.37b4b4a3f7`); reuse it. Control: with this edit reverted the check names exactly this site, with it restored the check passes. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb

Description
OpenCode Go usage is read from
GET /console/api/go/statusinstead of scraping the old workspace HTML page, which now redirects to login.Focused fix
x-org-id, meter mapping, and allowing__Host-console_sessionon the closed cookie allowlist.net::ERR_FAILED(OpenCode Go usage refresh fails with net::ERR_FAILED on Windows despite valid cookie #7104), and accepting arbitrary cookies.Preserves
auth,__Host-auth,__Host-console_sessiononly./_serverworkspace discovery still usesauth.Evidence
pnpm exec vitest run --config config/vitest.config.ts src/main/rate-limits/opencode-go-usage-fetcher.test.ts src/main/rate-limits/opencode-go-status-parsing.test.ts(38 tests)upstream/mainpassed.User-regression-tradeoffs
__Host-console_sessionfor Go status. The old HTML scrape cannot work after the console move.Fixes #21420