GeezerVison is showing github.com — fix: recover from expired enterprise auth on remote config load by Ayushlm10 · Pull Request #31661 · anomalyco/opencode
Conversation
Ayushlm10
commented
Jun 10, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Issue for this PR
Closes #31649
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
Our opencode enterprise config sits behind Cloudflare Access. Once the stored auth token expires, two things break, and together they make it impossible to recover without manually deleting auth.json.
-
opencode auth login <url> inherited effectCmd's default
instance: true, so it bootstraps the project instance before running the login
handler. Bootstrap eagerly calls Config.get(), which loads the enterprise remote
config with the expired token and dies — so it crashes before it ever runs the auth command.
-
The failure is cryptic. Access answers an unauthenticated request with its HTML login
page and HTTP 200. filterStatusOk accepts the 200, schemaBodyJson then fails to
parse HTML, and that error is Effect.die'd, so startup aborts with
failed to decode remote config ... Decode error (200) and a raw stack trace.
How did you verify your code works?
Tested against our real Access-protected endpoint with an expired/invalid token:
- Before:
opencode auth login <url> crashed during bootstrap with the decode defect, and
normal startup printed Decode error (200) plus a stack trace.
- After:
auth login <url> runs the auth command and stores a fresh token. config-loading commands print the clear re-auth message and exit cleanly. Confirmed the freshly stored token returns 200 application/json from the config endpoint.
Added a unit test (extends the existing well-known harness in config.test.ts): a remote config endpoint that returns 200 text/html now produces ConfigRemoteAuthError instead of a generic decode error, and the error carries the login origin.
Screenshots / recordings
Not a UI change — CLI behavior before/after is described above.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
`opencode auth login <url>` inherited effectCmd's default `instance: true`, so it
bootstrapped the project instance and loaded enterprise remote config with the
stored token before the login handler ran. When that token was expired or invalid,
config loading aborted the command, making it impossible to re-authenticate without
first deleting auth.json.
Gate the command with `instance: (args) => !args.url` (mirrors run.ts's --attach
handling) so URL-based login skips instance/config bootstrap. The interactive path
still loads the instance for provider and config selection.
…gin page
Identity-aware proxies (e.g. an SSO gateway) answer unauthenticated requests to a
protected remote config endpoint with their HTML login page and HTTP 200.
filterStatusOk accepted the 200 and schemaBodyJson then failed with a cryptic
"Decode error (200)" defect that aborted startup with a raw stack trace.
Detect the login page in fetchRemoteJson (content-type plus an HTML body sniff) and
raise a tagged ConfigRemoteAuthError carrying the login origin. FormatError renders a
clear, fail-closed message telling the user to run `opencode auth login <origin>`.
The origin is interpolated from the auth entry, so nothing is vendor-specific.
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
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.
|