Skip to content

fix(core): import credentials from previous channel database - #40920

Closed
kitlangton wants to merge 1 commit into
v2from
next-credential-import
Closed

kitlangton wants to merge 1 commit into
v2from
next-credential-import

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

What

The channel database consolidation (#40723) pointed the next channel at the shared opencode.db and imported legacy credentials from V1 auth.json only. Credentials that existed only in the previous channel database (opencode-next.db) were dropped: the next-database import copies project, session, and session_message rows, and nothing copies the credential table.

Before / After

Before

  1. On the next channel, connect OpenCode Zen through the integration dialog. The credential is stored in opencode-next.db's credential table — it never existed in V1 auth.json.
  2. Update to a build containing feat(core): migrate v1 data to v2 #40723. The service now opens opencode.db; 20260805200742_import_legacy_credentials imports auth.json (Anthropic/OpenAI/Copilot OAuth entries survive), and the next-database import copies sessions only.
  3. Zen is silently disconnected: the integration shows no connections, every paid opencode/* model disappears from the catalog (only the free list remains), and sessions pinned to a paid Zen model fail with ModelUnavailableError.

After

A new migration, 20260806200000_import_next_credentials, copies credential rows from opencode-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 — opens opencode-next.db read-only via bun:sqlite, validates each row's value against Credential.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 matches bun script/migration.ts output (no schema changes).

Scope

  • Overlap priority is unchanged: for a not-yet-migrated database the auth.json import runs first and wins for integrations present in both sources.
  • Fresh database bootstraps mark migrations completed without executing them, so this migration (like the existing auth.json import) only takes effect on existing databases.
  • wellknown:sources kv 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 typecheck
  • Full bun test in packages/core: 1524 pass; the single failure (Config > loads authenticated wellknown config at highest priority) also fails on clean origin/v2.
  • Real-world verification: ran the importer against the actual opencode-next.db from the machine that hit this bug, into a scratch database — it recovered exactly the dropped opencode Zen credential and left everything else alone.

@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant