From 6933e2e2629bfa0a5b310eefe02b0470a1037442 Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Wed, 19 Aug 2026 23:49:34 -0400 Subject: [PATCH] refactor(core): use Latch for shell output gate --- packages/core/src/shell.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/core/src/shell.ts b/packages/core/src/shell.ts index 51598e7b3388..c8c23b9502b3 100644 --- a/packages/core/src/shell.ts +++ b/packages/core/src/shell.ts @@ -1,7 +1,7 @@ export * as Shell from "./shell.js" import path from "path" -import { Context, Deferred, Duration, Effect, Fiber, Layer, Schema, Schedule, Stream } from "effect" +import { Context, Deferred, Duration, Effect, Fiber, Latch, Layer, Schema, Schedule, Stream } from "effect" import { ChildProcess } from "effect/unstable/process" import { produce } from "immer" import { Shell } from "@opencode-ai/schema/shell" @@ -286,7 +286,7 @@ const layer = () => sessions.set(id, session) const stream = createWriteStream(file) - const outputDone = Deferred.makeUnsafe() + const outputDone = Latch.makeUnsafe() const pump = handle.all.pipe( Stream.runForEach((chunk: Uint8Array) => Effect.sync(() => { @@ -304,8 +304,8 @@ const layer = () => stream.end(() => resolve()) }), ) - yield* Deferred.succeed(outputDone, undefined) - }).pipe(Effect.catch(() => Deferred.succeed(outputDone, undefined))), + yield* outputDone.open + }).pipe(Effect.catch(() => outputDone.open)), ) yield* Effect.promise( () => @@ -324,7 +324,7 @@ const layer = () => draft.time.completed = Date.now() }) yield* beforeWait - yield* Deferred.await(outputDone) + yield* outputDone.await // Resolve waiters with the terminal Info before any retention eviction, so an evicted // session still reports success rather than the removal NotFoundError. This runs before // the timeout-fiber interrupt below, which on the timeout path would otherwise cancel