Skip to content

Commit 430bde9

Browse files
HyeokjaeLeethdxr
andauthored
fix(instance): restore InstanceBootstrap init parameter for non-Effec… (#25449)
Co-authored-by: Dax Raad <[email protected]>
1 parent 05b82a6 commit 430bde9

6 files changed

Lines changed: 26 additions & 6 deletions

File tree

packages/opencode/src/cli/bootstrap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { Instance } from "../project/instance"
22
import { InstanceStore } from "../project/instance-store"
3+
import { getBootstrapRunEffect } from "../effect/app-runtime"
34

45
export async function bootstrap<T>(directory: string, cb: () => Promise<T>) {
56
return Instance.provide({
67
directory,
8+
init: await getBootstrapRunEffect(),
79
fn: async () => {
810
try {
911
const result = await cb()

packages/opencode/src/cli/cmd/tui/worker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { GlobalBus } from "@/bus/global"
1010
import { Flag } from "@opencode-ai/core/flag/flag"
1111
import { writeHeapSnapshot } from "node:v8"
1212
import { Heap } from "@/cli/heap"
13-
import { AppRuntime } from "@/effect/app-runtime"
13+
import { AppRuntime, getBootstrapRunEffect } from "@/effect/app-runtime"
1414
import { ensureProcessMetadata } from "@opencode-ai/core/util/opencode-process"
1515

1616
ensureProcessMetadata("worker")
@@ -77,6 +77,7 @@ export const rpc = {
7777
async checkUpgrade(input: { directory: string }) {
7878
await Instance.provide({
7979
directory: input.directory,
80+
init: await getBootstrapRunEffect(),
8081
fn: async () => {
8182
await upgrade().catch(() => {})
8283
},

packages/opencode/src/effect/app-runtime.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Layer, ManagedRuntime } from "effect"
1+
import { Effect, Layer, ManagedRuntime } from "effect"
22
import { attach } from "./run-service"
33
import * as Observability from "@opencode-ai/core/effect/observability"
44

@@ -40,6 +40,7 @@ import { Command } from "@/command"
4040
import { Truncate } from "@/tool/truncate"
4141
import { ToolRegistry } from "@/tool/registry"
4242
import { Format } from "@/format"
43+
import { InstanceBootstrap } from "@/project/bootstrap"
4344
import { InstanceStore } from "@/project/instance-store"
4445
import { Project } from "@/project/project"
4546
import { Vcs } from "@/project/vcs"
@@ -93,6 +94,7 @@ export const AppLayer = Layer.mergeAll(
9394
Truncate.defaultLayer,
9495
ToolRegistry.defaultLayer,
9596
Format.defaultLayer,
97+
InstanceBootstrap.defaultLayer,
9698
InstanceStore.defaultLayer,
9799
Project.defaultLayer,
98100
Vcs.defaultLayer,
@@ -130,3 +132,15 @@ export const AppRuntime: Runtime = {
130132
},
131133
dispose: () => rt.dispose(),
132134
}
135+
136+
let bootstrapRun: Promise<Effect.Effect<void>>
137+
export function getBootstrapRunEffect(): Promise<Effect.Effect<void>> {
138+
if (!bootstrapRun) {
139+
bootstrapRun = AppRuntime.runPromise(
140+
Effect.gen(function* () {
141+
return (yield* InstanceBootstrap.Service).run
142+
}),
143+
)
144+
}
145+
return bootstrapRun
146+
}

packages/opencode/src/server/routes/instance/middleware.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { MiddlewareHandler } from "hono"
22
import { Instance } from "@/project/instance"
3-
import { AppRuntime } from "@/effect/app-runtime"
3+
import { getBootstrapRunEffect } from "@/effect/app-runtime"
44
import { AppFileSystem } from "@opencode-ai/core/filesystem"
55
import { WorkspaceContext } from "@/control-plane/workspace-context"
66
import { WorkspaceID } from "@/control-plane/schema"
@@ -23,6 +23,7 @@ export function InstanceMiddleware(workspaceID?: WorkspaceID): MiddlewareHandler
2323
async fn() {
2424
return Instance.provide({
2525
directory,
26+
init: await getBootstrapRunEffect(),
2627
async fn() {
2728
return next()
2829
},

packages/opencode/src/server/routes/instance/project.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import z from "zod"
88
import { ProjectID } from "@/project/schema"
99
import { errors } from "../../error"
1010
import { lazy } from "@/util/lazy"
11-
import { AppRuntime } from "@/effect/app-runtime"
11+
import { getBootstrapRunEffect } from "@/effect/app-runtime"
1212
import { jsonRequest, runRequest } from "./trace"
1313

1414
export const ProjectRoutes = lazy(() =>
@@ -82,7 +82,7 @@ export const ProjectRoutes = lazy(() =>
8282
Project.Service.use((svc) => svc.initGit({ directory: dir, project: prev })),
8383
)
8484
if (next.id === prev.id && next.vcs === prev.vcs && next.worktree === prev.worktree) return c.json(next)
85-
await InstanceStore.reloadInstance({ directory: dir, worktree: dir, project: next })
85+
await InstanceStore.reloadInstance({ directory: dir, worktree: dir, project: next, init: await getBootstrapRunEffect() })
8686
return c.json(next)
8787
},
8888
)

packages/opencode/src/server/workspace.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import { WorkspaceID } from "@/control-plane/schema"
55
import { WorkspaceContext } from "@/control-plane/workspace-context"
66
import { Workspace } from "@/control-plane/workspace"
77
import { Flag } from "@opencode-ai/core/flag/flag"
8+
import { getBootstrapRunEffect, AppRuntime } from "@/effect/app-runtime"
89
import { Instance } from "@/project/instance"
910
import { Session } from "@/session/session"
1011
import { SessionID } from "@/session/schema"
11-
import { AppRuntime } from "@/effect/app-runtime"
1212
import { Effect } from "effect"
1313
import * as Log from "@opencode-ai/core/util/log"
1414
import { ServerProxy } from "./proxy"
@@ -94,11 +94,13 @@ export function WorkspaceRouterMiddleware(upgrade: UpgradeWebSocket): Middleware
9494
const target = await adapter.target(workspace)
9595

9696
if (target.type === "local") {
97+
const init = await getBootstrapRunEffect()
9798
return WorkspaceContext.provide({
9899
workspaceID: WorkspaceID.make(workspaceID),
99100
fn: () =>
100101
Instance.provide({
101102
directory: target.directory,
103+
init,
102104
async fn() {
103105
return next()
104106
},

0 commit comments

Comments
 (0)