Repository navigation
Description
Description
Actual: With a valid legacy auth.json already present, fresh V2 database bootstrap does not import its OpenAI OAuth credential. A native regression test reads undefined for the credential row. Restarting does not import it either.
Expected: The credential is imported during first initialization and appears among saved accounts. The synthetic test credentials are not expected to authenticate.
Cause: Fresh bootstrap runs schema.up(tx) and records all migration IDs without calling their up functions. Thus the existing legacy credential importer is skipped and then marked complete. A minimal fix is to run that importer's up(tx) immediately after schema.up(tx) in the fresh-bootstrap transaction, before recording migration IDs. The attached candidate patch additionally makes malformed, non-object legacy files non-fatal and includes regression coverage.
On native source commit c1c9a139934a707636e59278e18ef3ec4ac763b9, the tests-only patch reproduced the failure (missing row, exit 1); the full candidate passed all 20 migration tests and bun typecheck in packages/core. The fix was also checked against pinned 2.0.6 source (b084acc55ea2cdb50e9c2ec49a8d9ab3608d43ad): 21 focused migration tests and packages/core typecheck passed. These are local database tests, not a verified live OAuth login, provider request, or token refresh.
This fix helps only databases initialized after the legacy file is in place. Already-initialized databases need a separate safe recovery path; resetting an existing database risks user data. Related discussion: #40920 (closed, unmerged).
Plugins
No plugins
OpenCode version
2.0.16
Steps to reproduce
-
Use a clean upstream source checkout with Bun and the candidate patch attached to this issue. Set
PATCHto the downloaded patch's absolute path (if GitHub will not accept.patch, attach a.txtcopy; its contents remain the same). These commands create a disposable worktree; they do not reset an existing database. No Docker, sandbox, account, or provider access is needed. -
Run the regression test with only the test file applied. It creates a temporary legacy
auth.jsoncontaining synthetic OpenAI OAuth fields, bootstraps an in-memory database, and queries itscredentialrow. The core test runner isolates HOME/XDG paths.PATCH=/absolute/path/to/opencode-v2-sbx-auth.patch tmp=$(mktemp -d) git worktree add --detach "$tmp/opencode" c1c9a139934a707636e59278e18ef3ec4ac763b9 cd "$tmp/opencode" bun install --frozen-lockfile git apply --include='packages/core/test/database-migration.test.ts' "$PATCH" cd packages/core bun run test test/database-migration.test.ts --test-name-pattern 'imports legacy credentials during fresh schema bootstrap' # Expected RED: query returns undefined instead of the OpenAI row (exit 1).
-
Apply the production fix and remaining test changes to the same disposable worktree; rerun the migration tests and typecheck:
cd ../.. git apply --exclude='packages/core/test/database-migration.test.ts' "$PATCH" cd packages/core bun run test test/database-migration.test.ts bun typecheck # Expected GREEN: 20 migration tests and typecheck pass at this source commit.
The adjusted pre-existing importer test creates its fixture after bootstrap to preserve its original migration-only assertion. The new regression also checks repeated bootstrap and malformed legacy input. Do not use real OAuth credentials in the fixture.
opencode-v2-sbx-auth.patch
test-sbx-auth.sh
Screenshot and/or share link
No screenshot or share link: this is a headless native database regression. The attached patch contains the reproducible test
Operating System
macOS 26.5.1 (Apple silicon, arm64)
Terminal
Not terminal-specific but using Warp
Activity
Starefossen commentedon Oct 8, 2026
Also on 2.0.24 (macOS arm64). If you delete the
20260805200742_import_legacy_credentialsrow frommigrationand restart, the credentials import, so only the fresh-bootstrap path (migration.ts:31-47) skips it. Workaround:opencode auth importwith theauth exportformat.opencodejr commentedon Oct 28, 2026
Thanks for the detailed report. I reproduced this on 2.0.16, and it still happens on the latest
dev(9adc42b).What I did, with isolated HOME/XDG directories:
auth.json(an OpenAI OAuth entry and an Anthropic API key) in$XDG_DATA_HOME/opencode/before any database existed.opencode auth list --standalonetwice.Both runs printed
No authenticated integrations. The new database has nocredentialrows, but20260805200742_import_legacy_credentialsis already recorded as completed in themigrationtable, so later starts never retry the import. The cause is the one you describe: on an empty database,apply()inpackages/core/src/database/migration.tscreates the schema and records every migration ID without running any migration'sup.The script below reproduces it against the installed
opencode, or against a source checkout viaOC_DEV. Related: #40920 (closed, unmerged), which notes the same fresh-bootstrap behaviour for a different credential import.Reproduction script (repro.sh)
Run it:
bash repro.sh