GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(core): import legacy auth.json on fresh-database bootstrap · neumark/opencode@eedb493

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • FORK.md
  • packages/core
    • src/database
      • migration.ts
    • test
      • database-migration.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎FORK.md‎

Copy file name to clipboardExpand all lines: FORK.md
+5-1Lines changed: 5 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ v1: `45dfb2b` + `318f171` (hardened). `util/fence-breaker.ts` ported nearly verb
5454

5555
v1 served on the trusted tailnet with no auth; stock v2 always enforces a password (random when unset — rotating per boot, pairing screen per browser). The server layer already supports an open mode (`ServerAuth.required` is false for an empty password) but nothing could reach it: the CLI always generated one, and the pre-API `dispatch` layer enforced credentials independently of `required()`. `OPENCODE_SERVER_UNSECURED=1` (cli `server-process.ts`, read directly like the fork's other knobs — Effect Config treats an empty env value as unset, so the empty-`OPENCODE_SERVER_PASSWORD` spelling can't work) serves with an empty password; `ServerProcess.start`'s guard and `dispatch` now let the empty password through, and the middleware no-ops. Guests set it in the serve unit; `fc-sessions`/`fc-transcript-archive` detect the open mode (and verify journal passwords before trusting them — stale lines linger across mode switches).
5656

57+
### 9. Legacy auth.json import on fresh-database bootstrap (fix, v2-only)
58+
59+
v2's `20260805200742_import_legacy_credentials` migration imports a v1 `~/.local/share/opencode/auth.json`, but only on the upgrade path: a FRESH database takes `DatabaseMigration.apply`'s bootstrap branch, which creates the full schema and records every migration id WITHOUT running any `up()` — so a fresh install over a pre-staged `auth.json` (exactly the fc-opencode guest model: secrets disk stages `auth.json` into every new VM) silently loses all provider credentials. The fork runs `importLegacyCredentials` inside the bootstrap transaction (idempotent — per-integration existence checks — and tolerant of a missing file), so a seeded `auth.json` lands in `credential` on first boot. The stop-side round trip (guest DB credentials exported back to the slot's `auth.json` at VM stop) lives in fc-opencode.
60+
5761
## The overlayfs plugin (rewrite)
5862

5963
v1: `~/.config/opencode/plugins/overlay-workspace.js` against `experimental_workspace`. v2 rewrite against the promise plugin API (`@opencode/plugin`, `Plugin.define`):
@@ -70,7 +74,7 @@ v1: `~/.config/opencode/plugins/overlay-workspace.js` against `experimental_work
7074
- `fc-transcript-archive`: continuous capture until v2 grows an archive API — the plugin exports after every run reaches a terminal state and an hourly timer sweeps `--all` (same design as the deployment's claude-code hook in `docs/.claude/hooks/archive-transcript.sh`); deletion costs at most the in-flight run. Replaced by an archive-API hook when upstream ships one.
7175
- `fc-sessions` / `fc-transcript-archive`: dual-version (v1 unauthenticated `/session`, v2 `/api/session` under basic auth with the password pulled from the guest's serve journal); v2 links are `/server/<base64url(origin)>/session/<id>`.
7276
- Release resolver: unchanged — verified against `v2.0.27-neumark.3` (asset name `opencode-linux-x64.tar.gz`, `find`-based install, serve smoke test all match).
73-
- Secrets channel: v2 imports legacy `~/.local/share/opencode/auth.json` credentials at migration — keep shipping `auth.json` through `secrets/vm$SLOT`.
77+
- Secrets channel: v2 imports legacy `~/.local/share/opencode/auth.json` credentials — on the upgrade path at migration, and (fork feature 9) on fresh-database bootstrap. Keep shipping `auth.json` through `secrets/vm$SLOT`; fc-opencode's stop path exports guest DB credentials back into it.
7478

7579
## Phases
7680

Collapse file

‎packages/core/src/database/migration.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/database/migration.ts
+12-1Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
export * as DatabaseMigration from "./migration.js"
22

33
import { sql } from "drizzle-orm"
4+
import path from "node:path"
45
import { Effect } from "effect"
56
import { supportsForeignKeyToggle } from "#sqlite"
67
import type { EffectDrizzleSqlite } from "./drizzle.js"
78
import { migrations } from "./migration.gen.js"
89
import schema from "./schema.gen.js"
910
import { Global } from "@opencode/util/global"
11+
import { importLegacyCredentials } from "./migration/20260805200742_import_legacy_credentials.js"
1012

1113
type Database = EffectDrizzleSqlite.EffectSQLiteDatabase
1214
type Transaction = Parameters<Parameters<Database["transaction"]>[0]>[0]
@@ -19,7 +21,7 @@ export type Migration = {
1921

2022
// Not serialized here: the Database layer holds a lock scoped to the database
2123
// it is bootstrapping, since two instances over one file must not race.
22-
export function apply(db: Database) {
24+
export function apply(db: Database): Effect.Effect<void, unknown, Global.Service> {
2325
return Effect.gen(function* () {
2426
// OpenCode owns the unprefixed table namespace. Embedders sharing this
2527
// database may own underscore-prefixed tables, which bootstrap ignores.
@@ -42,6 +44,15 @@ export function apply(db: Database) {
4244
sql`INSERT INTO ${sql.identifier("migration")} (id, time_completed) VALUES (${migration.id}, ${Date.now()})`,
4345
),
4446
)
47+
// (fork, v1 parity) fresh installs must still import a seeded legacy
48+
// auth.json: bootstrap records every migration id without running its
49+
// up(), so the v1->v2 credential import never executes on a fresh
50+
// database — deployments that stage auth.json into a new machine
51+
// (fc-opencode guests) silently lose every provider credential. Run
52+
// the same import the upgrade path would have run; it is idempotent
53+
// (per-integration existence check) and tolerates a missing file.
54+
const global = yield* Global.Service
55+
yield* importLegacyCredentials(tx, path.join(global.data, "auth.json"))
4556
}),
4657
)
4758
yield* Effect.logInfo("database schema bootstrap completed", {
Collapse file

‎packages/core/test/database-migration.test.ts‎

Copy file name to clipboardExpand all lines: packages/core/test/database-migration.test.ts
+49-3Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,44 @@ describe("DatabaseMigration", () => {
193193
)
194194
})
195195

196+
test("fresh bootstrap imports a seeded legacy auth.json", async () => {
197+
await using tmp = await tmpdir()
198+
await Bun.write(
199+
path.join(tmp.path, "auth.json"),
200+
JSON.stringify({ "fireworks-ai": { type: "api", key: "fw-seeded" } }),
201+
)
202+
203+
await run(
204+
Effect.gen(function* () {
205+
const db = yield* makeDb
206+
yield* DatabaseMigration.apply(db)
207+
208+
expect(yield* db.all(sql`SELECT integration_id, label, value FROM credential`)).toEqual([
209+
{
210+
integration_id: "fireworks-ai",
211+
label: "API key",
212+
value: JSON.stringify({ type: "key", key: "fw-seeded" }),
213+
},
214+
])
215+
}),
216+
Global.make({ data: tmp.path }),
217+
)
218+
})
219+
220+
test("fresh bootstrap without auth.json imports no credentials", async () => {
221+
await using tmp = await tmpdir()
222+
223+
await run(
224+
Effect.gen(function* () {
225+
const db = yield* makeDb
226+
yield* DatabaseMigration.apply(db)
227+
228+
expect(yield* db.get(sql`SELECT count(*) AS count FROM credential`)).toEqual({ count: 0 })
229+
}),
230+
Global.make({ data: tmp.path }),
231+
)
232+
})
233+
196234
test("adds nullable attention state to existing sessions", async () => {
197235
await run(
198236
Effect.gen(function* () {
@@ -448,13 +486,16 @@ describe("DatabaseMigration", () => {
448486
await run(
449487
Effect.gen(function* () {
450488
const db = yield* makeDb
489+
// bootstrap imports the seeded auth.json wholesale (fork: v1 parity)
451490
yield* DatabaseMigration.apply(db)
452491
const now = Date.now()
453492
yield* db.run(sql`
454493
INSERT INTO credential (id, integration_id, label, value, time_created, time_updated)
455-
VALUES ('existing', 'anthropic', 'Existing', ${JSON.stringify({ type: "key", key: "current-key" })}, ${now}, ${now})
494+
VALUES ('existing', 'existing-integration', 'Existing', ${JSON.stringify({ type: "key", key: "current-key" })}, ${now}, ${now})
456495
`)
457496

497+
// re-running the legacy import changes nothing: per-integration
498+
// existence checks skip everything bootstrap already imported
458499
yield* db.run(sql`DELETE FROM migration WHERE id = ${legacyCredentialsMigration.id}`)
459500
yield* DatabaseMigration.applyOnly(db, [legacyCredentialsMigration])
460501
yield* DatabaseMigration.applyOnly(db, [legacyCredentialsMigration])
@@ -463,14 +504,19 @@ describe("DatabaseMigration", () => {
463504
[
464505
{
465506
integration_id: "anthropic",
466-
label: "Existing",
467-
value: JSON.stringify({ type: "key", key: "current-key" }),
507+
label: "API key",
508+
value: JSON.stringify({ type: "key", key: "legacy-key", metadata: { region: "us" } }),
468509
},
469510
{
470511
integration_id: "custom-provider",
471512
label: "API key",
472513
value: JSON.stringify({ type: "key", key: "custom-key" }),
473514
},
515+
{
516+
integration_id: "existing-integration",
517+
label: "Existing",
518+
value: JSON.stringify({ type: "key", key: "current-key" }),
519+
},
474520
{
475521
integration_id: "github-copilot",
476522
label: "OAuth",

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.