Skip to content

fix: read OpenCode Go usage from the console API - #21462

Merged
nwparker merged 2 commits into
stablyai:mainfrom
innocarpe:fix/opencode-go-console-usage
Sep 21, 2026
Merged

nwparker merged 2 commits into
stablyai:mainfrom
innocarpe:fix/opencode-go-console-usage

Conversation

@innocarpe

Copy link
Copy Markdown
Contributor

Description

OpenCode Go usage is read from GET /console/api/go/status instead of scraping the old workspace HTML page, which now redirects to login.

Focused fix

Preserves

  • Cookie allowlist stays closed: auth, __Host-auth, __Host-console_session only.
  • /_server workspace discovery still uses auth.

Evidence

  • Test: 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)
  • Changed-code quality against upstream/main passed.

User-regression-tradeoffs

  • Users must paste a Cookie header that includes __Host-console_session for Go status. The old HTML scrape cannot work after the console move.

Fixes #21420

@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

📝 Walkthrough

Walkthrough

The fetcher now calls https://opencode.ai/console/api/go/status with x-org-id and parses JSON meters into session, weekly, and optional monthly windows. The parser validates payloads, handles numeric and string micro-cent values, parses reset timestamps, and clamps percentages. Cookie handling now preserves __Host-console_session. The legacy HTML scraper was removed, and tests now cover the API flow and failure cases.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 9b1bc

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning 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, Wh… 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…
Docstring Coverage ⚠️ Warning 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… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: reading OpenCode Go usage from the console API.
Linked Issues check ✅ Passed The changes satisfy the coding requirements in #21420. The fetcher uses GET /console/api/go/status with x-org-id and Accept: application/json. The parser maps fiveHour, week, and month to …
Out of Scope Changes check ✅ Passed The changes stay within #21420. They replace the obsolete OpenCode Go HTML scraper, add console API parsing and request coverage, update the related cookie handling and settings guidance, and remove o…
Full details: Description check

Explanation

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 Coverage

Explanation

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.)

  • Fix all pre-merge checks with AI

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

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts is deleted; the fetcher now GETs https://opencode.ai/console/api/go/status with x-org-id, Origin, and a console Referer, and reads the body as JSON.
  • New payload parser — opencode-go-status-parsing.ts maps access.meters.{fiveHour,week,month} micro-cent meters to session/weekly/monthly windows (used/limit*100, clamped; absolute resetsAt; month optional), capped at 1 MB.
  • Cookie allowlist widened — __Host-console_session is added to AUTH_COOKIE_NAMES and to the normalizeCookieInput prefix regex; /_server workspace discovery still uses auth.
  • 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 only auth/__Host-auth, so it now diverges from AUTH_COOKIE_NAMES. Not reachable today — a plaintext __Host-console_session value 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 as auth=<token> by normalizeCookieInput, which will then fail; worth covering in the same hint update.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@innocarpe
innocarpe force-pushed the fix/opencode-go-console-usage branch from 74b1395 to 9b1bc63 Compare September 18, 2026 15:04
@innocarpe

Copy link
Copy Markdown
Contributor Author

The status API is authed only by __Host-console_session, but Accounts still told people to paste Fe26.2**… / auth= alone — following that copy is exactly the #21420 401.

Settings now asks for the full Cookie header, including __Host-console_session (e.g. auth=…; __Host-console_session=…). auth still covers /_server workspace discovery; it is not enough for usage. A 401 from /console/api/go/status now says the same thing.

Preserves: cookie allowlist, workspace lookup, and wrapping a bare token as auth=.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/renderer/src/components/settings/accounts-pane-provider-setting-sections.tsx (1)

148-148: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Wrap 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.37b4b4a3f7 uses 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.ts
  • src/main/rate-limits/opencode-go-usage-fetcher.ts
  • src/renderer/src/components/settings/AccountsPane.test.tsx
  • src/renderer/src/components/settings/accounts-pane-provider-setting-sections.tsx
  • src/renderer/src/components/settings/accounts-search.test.ts
  • src/renderer/src/components/settings/accounts-search.ts
  • src/renderer/src/i18n/locales/en.json

Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 that auth still covers workspace discovery; the console keyword is added.
  • Search entry mirrors the hint — getAccountsOpencodeSearchEntries gets the same description and console keyword, so search copy matches the pane.
  • 401 gets an actionable message — a 401 from /console/api/go/status now returns Usage 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).

Pullfrog  | View workflow run | Using 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.
@nwparker
nwparker force-pushed the fix/opencode-go-console-usage branch from 9b1bc63 to 4c9621a Compare September 21, 2026 03:11
@nwparker
nwparker merged commit 7a6d100 into stablyai:main Sep 21, 2026
1 check failed
Jinwoo-H added a commit that referenced this pull request Sep 21, 2026
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
Jinwoo-H added a commit that referenced this pull request Sep 21, 2026
…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
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.

[Bug]: OpenCode Go usage stuck on "Refresh failed" — opencode.ai moved it to the console and the fetcher still scrapes the old page

2 participants