Skip to content

Commit 3f7df08

Browse files
authored
perf: make vcs init non-blocking by forking git branch resolution (#22771)
1 parent ef6c26c commit 3f7df08

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

packages/opencode/AGENTS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ See `specs/effect/migration.md` for the compact pattern reference and examples.
3939
- Do the work directly in the `InstanceState.make` closure — `ScopedCache` handles run-once semantics. Don't add fibers, `ensure()` callbacks, or `started` flags on top.
4040
- Use `Effect.addFinalizer` or `Effect.acquireRelease` inside the `InstanceState.make` closure for cleanup (subscriptions, process teardown, etc.).
4141
- Use `Effect.forkScoped` inside the closure for background stream consumers — the fiber is interrupted when the instance is disposed.
42+
- To make a service's `init()` non-blocking, fork `InstanceState.get(state)` at the `init()` call site (e.g. `Effect.forkIn(scope)`), not by forking work inside the `InstanceState.make` closure. Forking inside the closure leaves state incomplete for other methods that read it.
43+
- `src/project/bootstrap.ts` already wraps every service `init()` in `Effect.forkDetach`, so `init()` is fire-and-forget in production. Keep `init()` methods synchronous internally; the caller controls concurrency.
44+
45+
## Effect v4 beta API
46+
47+
- `Effect.fork` and `Effect.forkDaemon` do not exist. Use `Effect.forkIn(scope)` to fork a fiber into a specific scope.
4248

4349
## Preferred Effect services
4450

packages/opencode/src/project/vcs.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Effect, Layer, Context, Stream } from "effect"
1+
import { Effect, Layer, Context, Stream, Scope } from "effect"
22
import { formatPatch, structuredPatch } from "diff"
33
import path from "path"
44
import { Bus } from "@/bus"
@@ -157,6 +157,7 @@ export const layer: Layer.Layer<Service, never, AppFileSystem.Service | Git.Serv
157157
const fs = yield* AppFileSystem.Service
158158
const git = yield* Git.Service
159159
const bus = yield* Bus.Service
160+
const scope = yield* Scope.Scope
160161

161162
const state = yield* InstanceState.make<State>(
162163
Effect.fn("Vcs.state")(function* (ctx) {
@@ -194,7 +195,7 @@ export const layer: Layer.Layer<Service, never, AppFileSystem.Service | Git.Serv
194195

195196
return Service.of({
196197
init: Effect.fn("Vcs.init")(function* () {
197-
yield* InstanceState.get(state)
198+
yield* InstanceState.get(state).pipe(Effect.forkIn(scope))
198199
}),
199200
branch: Effect.fn("Vcs.branch")(function* () {
200201
return yield* InstanceState.use(state, (x) => x.current)

0 commit comments

Comments
 (0)