fix(core): import credentials from previous channel database - #40920
Open
kitlangton wants to merge 1 commit into
Open
fix(core): import credentials from previous channel database#40920kitlangton wants to merge 1 commit into
kitlangton wants to merge 1 commit into
Conversation
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.
What
The channel database consolidation (#40723) pointed the
nextchannel at the sharedopencode.dband imported legacy credentials from V1auth.jsononly. Credentials that existed only in the previous channel database (opencode-next.db) were dropped: the next-database import copiesproject,session, andsession_messagerows, and nothing copies thecredentialtable.Before / After
Before
opencode-next.db'scredentialtable — it never existed in V1auth.json.opencode.db;20260805200742_import_legacy_credentialsimportsauth.json(Anthropic/OpenAI/Copilot OAuth entries survive), and the next-database import copies sessions only.opencode/*model disappears from the catalog (only the free list remains), and sessions pinned to a paid Zen model fail withModelUnavailableError.After
A new migration,
20260806200000_import_next_credentials, copies credential rows fromopencode-next.db(opened read-only) into the consolidated database. Existing credentials win: an integration that already has a credential row is left untouched, so users who already reconnected are unaffected, and reruns are no-ops.How
packages/core/src/database/migration/20260806200000_import_next_credentials.ts— opensopencode-next.dbread-only viabun:sqlite, validates each row's value againstCredential.Value, skips integrations that already have a credential in the target, and preserves original ids, labels, method ids, and timestamps. An unreadable or incompatible source logs a warning and skips instead of failing startup. The source database is never modified.packages/core/src/database/migration.gen.ts— registry line matchesbun script/migration.tsoutput (no schema changes).Scope
auth.jsonimport runs first and wins for integrations present in both sources.auth.jsonimport) only takes effect on existing databases.wellknown:sourceskv entries from the previous channel database are not merged.Testing
cd packages/core && bun test test/database-migration.test.ts— new test covers import, skip-if-integration-exists, invalid-value rows, idempotent rerun, and missing source file (9 pass).cd packages/core && bun typecheckbun testinpackages/core: 1524 pass; the single failure (Config > loads authenticated wellknown config at highest priority) also fails on cleanorigin/v2.opencode-next.dbfrom the machine that hit this bug, into a scratch database — it recovered exactly the droppedopencodeZen credential and left everything else alone.