Skip to content

Instantly share code, notes, and snippets.

@jimicze
Created November 6, 2026 12:30
Show Gist options
  • Select an option

  • Save jimicze/43a523fa38e850604b4699472e6ea67c to your computer and use it in GitHub Desktop.

Select an option

Save jimicze/43a523fa38e850604b4699472e6ea67c to your computer and use it in GitHub Desktop.
Follow-up for anomalyco/opencode#58846: timeout marker + path/collapse tests (base 2373d05757)
diff --git a/packages/core/src/database/v1-migration.bun.ts b/packages/core/src/database/v1-migration.bun.ts
index 760aa98b17..d5faf088bd 100644
--- a/packages/core/src/database/v1-migration.bun.ts
+++ b/packages/core/src/database/v1-migration.bun.ts
@@ -762,12 +762,6 @@ export function run(
set: { value: { phase: "completed" }, time_updated: Date.now() },
})
.run()
- // This import already attributed global sessions to their folders' projects.
- yield* tx
- .insert(KVTable)
- .values({ key: REPAIR_STATE_KEY, value: { phase: "completed" } })
- .onConflictDoNothing()
- .run()
}),
)
.pipe(Effect.orDie)
@@ -792,12 +786,13 @@ function repairGlobalSessions(db: Database.Interface["db"]) {
for (const [index, folder] of folders.entries()) {
updateProgress({ label: "Repairing V1 sessions", numerator: index, denominator: folders.length })
const resolved = yield* resolveDirectory(folder.directory)
- // One hung folder (e.g. a dead network mount) usually means more; leave the rest under global.
+ // One hung folder (e.g. a dead network mount) usually means more; leave the rest under global
+ // and retry on the next start instead of marking the repair complete.
if (Option.isNone(resolved)) {
yield* Effect.logWarning("Stopped repairing V1 global sessions after a timeout", {
directory: folder.directory,
})
- break
+ return
}
const owner = resolved.value
if (!owner || owner.project.id === Project.ID.global) continue
diff --git a/packages/core/test/v1-migration.test.ts b/packages/core/test/v1-migration.test.ts
index af05eb16e1..423e8831b6 100644
--- a/packages/core/test/v1-migration.test.ts
+++ b/packages/core/test/v1-migration.test.ts
@@ -1263,6 +1263,8 @@ describe("V1Migration database workflow", () => {
await fs.mkdir(plain, { recursive: true })
await fs.mkdir(path.join(repo, "pkg", "a"), { recursive: true })
await initRepo(repo)
+ const linked = path.join(tmp.path, "plain-link")
+ await fs.symlink(plain, linked, process.platform === "win32" ? "junction" : undefined)
await database(
Effect.gen(function* () {
const { db } = yield* Database.Service
@@ -1274,21 +1276,22 @@ describe("V1Migration database workflow", () => {
sql`INSERT INTO kv (key, value, time_created, time_updated) VALUES ('migration.v1-v2', '{"phase":"completed"}', 1, 1)`,
)
const sessions = [
- { id: "ses_plain", directory: plain, v1: true },
- { id: "ses_repo", directory: path.join(repo, "pkg", "a"), v1: true },
- { id: "ses_missing", directory: missing, v1: true },
- { id: "ses_native", directory: plain, v1: false },
+ { id: "ses_plain", directory: plain, path: "legacy/plain", v1: true },
+ { id: "ses_linked", directory: linked, path: "legacy/linked", v1: true },
+ { id: "ses_repo", directory: path.join(repo, "pkg", "a"), path: "legacy/repo", v1: true },
+ { id: "ses_missing", directory: missing, path: "legacy/missing", v1: true },
+ { id: "ses_native", directory: plain, path: null, v1: false },
]
yield* Effect.forEach(sessions, (input) =>
Effect.gen(function* () {
if (input.v1)
yield* db.run(sql`
- INSERT INTO session (id, project_id, slug, directory, title, version, time_created, time_updated)
- VALUES (${input.id}, 'global', ${input.id}, ${input.directory}, 'Test', '1', 1, 2)
+ INSERT INTO session (id, project_id, slug, directory, path, title, version, time_created, time_updated)
+ VALUES (${input.id}, 'global', ${input.id}, ${input.directory}, ${input.path}, 'Test', '1', 1, 2)
`)
yield* db.run(sql`
- INSERT INTO session_v2 (id, project_id, slug, directory, title, version, time_created, time_updated)
- VALUES (${input.id}, 'global', ${input.id}, ${input.directory}, 'Test', '1', 1, 2)
+ INSERT INTO session_v2 (id, project_id, slug, directory, path, title, version, time_created, time_updated)
+ VALUES (${input.id}, 'global', ${input.id}, ${input.directory}, ${input.path}, 'Test', '1', 1, 2)
`)
}),
)
@@ -1298,12 +1301,16 @@ describe("V1Migration database workflow", () => {
plain: yield* projects.resolve(AbsolutePath.make(plain)),
repo: yield* projects.resolve(AbsolutePath.make(repo)),
}
- expect(yield* db.all(sql`SELECT id, project_id, path, time_updated FROM session_v2 ORDER BY id`)).toEqual([
- { id: "ses_missing", project_id: "global", path: null, time_updated: 2 },
+ const repaired = [
+ { id: "ses_linked", project_id: owners.plain.id, path: "", time_updated: 2 },
+ { id: "ses_missing", project_id: "global", path: "legacy/missing", time_updated: 2 },
{ id: "ses_native", project_id: "global", path: null, time_updated: 2 },
{ id: "ses_plain", project_id: owners.plain.id, path: "", time_updated: 2 },
{ id: "ses_repo", project_id: owners.repo.id, path: "pkg/a", time_updated: 2 },
- ])
+ ]
+ expect(yield* db.all(sql`SELECT id, project_id, path, time_updated FROM session_v2 ORDER BY id`)).toEqual(repaired)
+ expect(yield* V1Migration.run()).toEqual({ status: "completed" })
+ expect(yield* db.all(sql`SELECT id, project_id, path, time_updated FROM session_v2 ORDER BY id`)).toEqual(repaired)
expect(yield* db.get(sql`SELECT value FROM kv WHERE key = 'migration.v1-v2.global-sessions'`)).toEqual({
value: '{"phase":"completed"}',
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment