fix(opencode): own effect sqlite lifecycle in layers

This commit is contained in:
Kit Langton
2026-04-28 11:03:23 -04:00
parent 8e2c15214e
commit aaa42cca07
6 changed files with 129 additions and 80 deletions
@@ -10,6 +10,7 @@ import { Vcs } from "@/project/vcs"
import { Snapshot } from "@/snapshot"
import { Bus } from "@/bus"
import { Config } from "@/config/config"
import { lazy } from "@/util/lazy"
import * as Observability from "@opencode-ai/core/effect/observability"
import { memoMap } from "@opencode-ai/core/effect/memo-map"
@@ -26,4 +27,20 @@ export const BootstrapLayer = Layer.mergeAll(
Bus.defaultLayer,
).pipe(Layer.provide(Observability.layer))
export const BootstrapRuntime = ManagedRuntime.make(BootstrapLayer, { memoMap })
const rt = lazy(() => ManagedRuntime.make(BootstrapLayer, { memoMap }))
type Runtime = Pick<ReturnType<typeof rt>, "runPromise" | "dispose">
export const BootstrapRuntime: Runtime = {
runPromise(effect, options) {
return rt().runPromise(effect, options)
},
async dispose() {
const current = rt.peek()
if (!current) return
try {
await current.dispose()
} finally {
if (rt.peek() === current) rt.reset()
}
},
}