GeezerVison is showing github.com — fix(core): ask to reconnect ChatGPT when its refresh token is rejected by hearnadam · Pull Request #65289 · anomalyco/opencode
Conversation
hearnadam
commented
Nov 21, 2026
•
edited by opencodejr
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Issue for this PR
Closes #60133
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
When a ChatGPT sign-in's refresh token has been revoked or has expired, OpenAI's token endpoint answers 400 with {"error":"invalid_grant"}. request() dropped the body, so every prompt failed with "Request failed: 400" and nothing told the user to reconnect.
refresh() now turns that response into "This ChatGPT sign-in has expired or was revoked. Connect again." Only invalid_grant on the refresh grant is matched. Other failures, and the authorization-code exchange, keep their current errors.
This does not add a "needs sign in" status for the connection. The refresh runs in core rather than in the plugin, so where that status would be set needs a decision and is left out of this PR.
How did you verify your code works?
- Added a test in
provider-chatgpt.test.ts that runs refresh() against a local server. invalid_grant gives the new message; a 400 with a different error and a 500 still give "Request failed: ". The test fails without the fix.
bun run test test/plugin/provider-chatgpt.test.ts and bun typecheck in packages/core, and bun run check at the root.
- Confirmed the response shape by posting an invalid refresh token to the real token endpoint, which returned 400
{"error":"invalid_grant"}. I have not tested against a real sign-in whose token was revoked.
Screenshots / recordings
Not a UI change.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
Added by the opencode bot (AI-generated).
Related: #55211
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change looks sound to me. When OpenAI rejects a refresh with invalid_grant, the new message replaces the bare 400. It reaches users unchanged through Integration.AuthorizationError. I couldn't run it end to end, because that needs a real ChatGPT sign-in whose token has been revoked. Instead I ran refresh() against a local server. Without the fix, the invalid_grant case fails with "Request failed: 400". With the fix, the new message appears, and other 400s and 500s keep their current error. The package's tests and tsc -b pass.
The export with a default URL follows the pattern revoke already uses. The invalid_grant check matches the existing handling in opencode.ts. The test is small and uses a local server, not the real network.
Public API: unchanged. refresh is a newly exported function inside core only.
No blocking concerns.
Related: #55211
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The reconnect-message branch incorrectly handles non-400 responses containing invalid_grant, masking server errors as expired sign-ins instead of preserving the existing HTTP error.
1 open issue
What changed in this PR
Improves ChatGPT OAuth refresh errors in core so users are told to reconnect when their refresh token is rejected, addressing the unclear prompt failures reported in #60133. Authorization-code exchange behavior and connection status remain unchanged.
Changes:
- Recognizes
invalid_grant responses during refresh and supplies an actionable reconnect message.
- Adds local-server tests for rejected refresh tokens and other HTTP failures.
| File |
Description |
packages/core/test/plugin/provider-chatgpt.test.ts |
Tests reconnect messaging and fallback HTTP errors. |
packages/core/src/plugin/provider/chatgpt.ts |
Decodes refresh rejection responses and provides the reconnect message. |
Review effort: Balanced
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
if (!response.ok) throw new Error(`Request failed: ${response.status}`)
|
|
|
return response.json() as Promise<A>
|
|
|
if (response.ok) return response.json() as Promise<A>
|
|
|
if (rejected && Option.isSome(decodeInvalidGrant(await response.text()))) throw new Error(rejected)
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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.
|