revert unrelated event and worktree changes

This commit is contained in:
Dax Raad
2026-05-12 21:08:38 -04:00
parent e9a5186c76
commit 273ffc30ea
3 changed files with 24 additions and 54 deletions
@@ -18,7 +18,6 @@ export interface Interface {
readonly load: (input: LoadInput) => Effect.Effect<InstanceContext>
readonly reload: (input: LoadInput) => Effect.Effect<InstanceContext>
readonly dispose: (ctx: InstanceContext) => Effect.Effect<void>
readonly disposeDirectory: (directory: string) => Effect.Effect<void>
readonly disposeAll: () => Effect.Effect<void>
readonly provide: <A, E, R>(input: LoadInput, effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
}
@@ -149,16 +148,6 @@ export const layer: Layer.Layer<Service, never, Project.Service | InstanceBootst
yield* disposeEntry(ctx.directory, entry, ctx).pipe(Effect.asVoid)
})
const disposeDirectory = Effect.fn("InstanceStore.disposeDirectory")(function* (directory: string) {
const key = AppFileSystem.resolve(directory)
const entry = cache.get(key)
if (!entry) return
const exit = yield* Deferred.await(entry.deferred).pipe(Effect.exit)
if (Exit.isFailure(exit)) return yield* removeEntry(key, entry).pipe(Effect.asVoid)
yield* disposeEntry(key, entry, exit.value).pipe(Effect.asVoid)
})
const disposeAllOnce = Effect.fnUntraced(function* () {
yield* Effect.logInfo("disposing all instances")
yield* Effect.forEach(
@@ -193,7 +182,6 @@ export const layer: Layer.Layer<Service, never, Project.Service | InstanceBootst
load,
reload,
dispose,
disposeDirectory,
disposeAll,
provide,
})
@@ -1,6 +1,6 @@
import { Bus } from "@/bus"
import * as Log from "@opencode-ai/core/util/log"
import { Effect, Queue, Schema } from "effect"
import { Effect, Schema } from "effect"
import * as Stream from "effect/Stream"
import { HttpServerResponse } from "effect/unstable/http"
import { HttpApi, HttpApiBuilder, HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/unstable/httpapi"
@@ -9,12 +9,6 @@ import { WorkspaceRoutingQuery } from "./middleware/workspace-routing"
const log = Log.create({ service: "server" })
type EventPayload = {
id: string
type: string
properties: Record<string, unknown>
}
export const EventPaths = {
event: "/event",
} as const
@@ -46,39 +40,30 @@ function eventData(data: unknown): Sse.Event {
}
function eventResponse(bus: Bus.Interface) {
return Effect.gen(function* () {
const queue = yield* Queue.unbounded<EventPayload>()
const unsubscribe = yield* bus.subscribeAllCallback((event) => Queue.offerUnsafe(queue, event))
const events = Stream.fromQueue(queue).pipe(Stream.takeUntil((event) => event.type === Bus.InstanceDisposed.type))
const heartbeat = Stream.tick("10 seconds").pipe(
Stream.drop(1),
Stream.map(() => ({ id: Bus.createID(), type: "server.heartbeat", properties: {} })),
)
const events = bus.subscribeAll().pipe(Stream.takeUntil((event) => event.type === Bus.InstanceDisposed.type))
const heartbeat = Stream.tick("10 seconds").pipe(
Stream.drop(1),
Stream.map(() => ({ id: Bus.createID(), type: "server.heartbeat", properties: {} })),
)
log.info("event connected")
return HttpServerResponse.stream(
Stream.make({ id: Bus.createID(), type: "server.connected", properties: {} }).pipe(
Stream.concat(events.pipe(Stream.merge(heartbeat, { haltStrategy: "left" }))),
Stream.map(eventData),
Stream.pipeThroughChannel(Sse.encode()),
Stream.encodeText,
Stream.ensuring(
Effect.sync(unsubscribe).pipe(
Effect.andThen(Queue.shutdown(queue)),
Effect.andThen(Effect.sync(() => log.info("event disconnected"))),
),
),
),
{
contentType: "text/event-stream",
headers: {
"Cache-Control": "no-cache, no-transform",
"X-Accel-Buffering": "no",
"X-Content-Type-Options": "nosniff",
},
log.info("event connected")
return HttpServerResponse.stream(
Stream.make({ id: Bus.createID(), type: "server.connected", properties: {} }).pipe(
Stream.concat(events.pipe(Stream.merge(heartbeat, { haltStrategy: "left" }))),
Stream.map(eventData),
Stream.pipeThroughChannel(Sse.encode()),
Stream.encodeText,
Stream.ensuring(Effect.sync(() => log.info("event disconnected"))),
),
{
contentType: "text/event-stream",
headers: {
"Cache-Control": "no-cache, no-transform",
"X-Accel-Buffering": "no",
"X-Content-Type-Options": "nosniff",
},
)
})
},
)
}
export const eventHandlers = HttpApiBuilder.group(EventApi, "event", (handlers) =>
@@ -87,7 +72,7 @@ export const eventHandlers = HttpApiBuilder.group(EventApi, "event", (handlers)
return handlers.handleRaw(
"subscribe",
Effect.fn("EventHttpApi.subscribe")(function* () {
return yield* eventResponse(bus)
return eventResponse(bus)
}),
)
}),
-3
View File
@@ -380,7 +380,6 @@ export const layer: Layer.Layer<
throw new NotGitError({ message: "Worktrees are only supported for git projects" })
}
yield* store.disposeDirectory(input.directory).pipe(Effect.ignore)
const directory = yield* canonical(input.directory)
const list = yield* git(["worktree", "list", "--porcelain"], { cwd: ctx.worktree })
@@ -394,14 +393,12 @@ export const layer: Layer.Layer<
if (!entry?.path) {
const directoryExists = yield* fs.exists(directory).pipe(Effect.orDie)
if (directoryExists) {
yield* store.disposeDirectory(directory).pipe(Effect.ignore)
yield* stopFsmonitor(directory)
yield* cleanDirectory(directory)
}
return true
}
yield* store.disposeDirectory(entry.path).pipe(Effect.ignore)
yield* stopFsmonitor(entry.path)
const removed = yield* git(["worktree", "remove", "--force", entry.path], { cwd: ctx.worktree })
if (removed.code !== 0) {