fix: recover from expired enterprise auth on remote config load#31661
Merged
Conversation
`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.
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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.
Issue for this PR
Closes #31649
Type of change
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>inheritedeffectCmd's defaultinstance: true, so it bootstraps the project instance before running the loginhandler. Bootstrap eagerly calls
Config.get(), which loads the enterprise remoteconfig 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.
filterStatusOkaccepts the 200,schemaBodyJsonthen fails toparse HTML, and that error is
Effect.die'd, so startup aborts withfailed 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:
opencode auth login <url>crashed during bootstrap with the decode defect, andnormal startup printed
Decode error (200)plus a stack trace.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 returns200 application/jsonfrom the config endpoint.Added a unit test (extends the existing well-known harness in
config.test.ts): a remote config endpoint that returns200 text/htmlnow producesConfigRemoteAuthErrorinstead 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