fix(core): map legacy auth success callback results to Credential.Value#32099
Open
bertrandgressier wants to merge 9 commits into
Open
fix(core): map legacy auth success callback results to Credential.Value#32099bertrandgressier wants to merge 9 commits into
bertrandgressier wants to merge 9 commits into
Conversation
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
…callback decoding
… credential store
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 #32101
Type of change
What does this PR do?
This PR resolves a schema validation failure and a synchronization gap that occur when dynamic/external plugins (using the legacy dynamic plugin contract) complete their OAuth authorization callback and write credentials.
There were two distinct issues causing the
/connectfailure and subsequent401 Unauthorizederrors in OpenCode1.17.4:The
/connectCallback Sync Gap (Root Cause for TUI):When completing
/connectin the TUI, OpenCode invokes the legacyProviderAuth.callbackendpoint, which delegates writes toAuth.set(packages/opencode/src/auth/index.ts). However, whileAuth.setwrote correctly toauth.jsonon disk, it did not synchronize the credentials to the new SQLitecredentialtable in real-time. Since the model execution layer in1.17.4reads credentials strictly from SQLite, the system continued to use old/expired tokens from SQLite, resulting in a401.Auth.setandAuth.remove(packages/opencode/src/auth/index.ts) to automatically synchronize all legacy auth writes and deletions directly to the SQLitecredentialstore in real-time.Schema Mismatch on Completed Callbacks (Root Cause for Connectors):
The public
@opencode-ai/pluginAPI types enforce that completed callbacks return{ type: "success", access, refresh, expires, metadata }. However, the backend's connector callback completion endpoint (connector.connect.oauth.completecallingcompleteinpackages/core/src/integration.ts) executes this callback directly and pipes the result intocredentials.create(...), which strictly expects aCredential.Value(only accepting"oauth"or"key"astype). This caused schema validation failures and "Authentication failed" errors in the TUI.@effect/schemabridge mapper insidepackages/core/src/integration.ts'ssettle()function. When the completed callback results in a legacy{ type: "success" }payload, it is dynamically mapped to the correct, modernCredential.Valueshape (eitherCredential.OAuthorCredential.Key) before validating and writing to SQLite.This restores seamless, green-status backward compatibility for all dynamic plugins (such as custom enterprise LLM gateways) connecting via Client Credentials / OAuth prompts!
How did you verify your code works?
packages/opencode/test/auth/auth.test.tsverifying real-time synchronization between legacyAuth.set/Auth.removeand SQLiteCredential.Service.packages/core/test/integration.test.tsverifying that legacy success callbacks returning{ type: "success" }are parsed, normalized, and saved type-safely.authplugins no longer cause validation failures upon/connectcompletion.Screenshots / recordings
N/A (strictly a backend API adapter fix)
Checklist