From dec13c5cc7543be7e6fe52a18590849e10294077 Mon Sep 17 00:00:00 2001 From: ScriptedAlchemy Date: Thu, 19 Nov 2026 01:00:25 -0800 Subject: [PATCH 1/2] fix(server): settle Codex turns when the app-server exits --- .../Adapters/CodexAdapterV2.test.ts | 16 +-- .../Adapters/CodexAdapterV2.ts | 1 + .../RunExecutionService.test.ts | 126 +++++++++++------- .../orchestration-v2/RunExecutionService.ts | 76 +++++------ .../src/_internal/stdio.test.ts | 15 ++- .../src/_internal/stdio.ts | 43 +++--- .../src/server/ProviderAdapter.ts | 2 + packages/provider-core/src/server/failure.ts | 5 +- 8 files changed, 160 insertions(+), 124 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts index be4c7e621ac35..e4de8a77d8c5b 100644 --- a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts @@ -954,9 +954,9 @@ function withReplayRequestId( describe("CodexAdapterV2 process exit", () => { it.effect.each([ { exit: "numeric", active: false }, - { exit: "SIGKILL", active: false }, + { exit: "unknown exit status", active: false }, { exit: "numeric", active: true }, - { exit: "SIGKILL", active: true }, + { exit: "unknown exit status", active: true }, ] as const)("retires the shared session after $exit (active turn: $active)", ({ exit, active }) => Effect.gen(function* () { const scenario = `process-exit-${exit}-${active}`; @@ -982,7 +982,7 @@ describe("CodexAdapterV2 process exit", () => { _tag: "Unknown", module: "ChildProcess", method: "exitCode", - cause: new Error("Process terminated by SIGKILL"), + cause: new Error("Exit status unavailable"), }), }); const client = yield* CodexClient.make( @@ -1089,11 +1089,11 @@ describe("CodexAdapterV2 process exit", () => { // Without the fix the stream never ends, so this waits until the project timeout. const readerExit = yield* Fiber.await(eventReader); // A failure, not a clean end, carries the Codex error into the session's lastError. - assert.isTrue( - Exit.isFailure(readerExit) && - isProviderAdapterEventStreamError(Cause.squash(readerExit.cause)), - "the session manager must receive process death so it can retire the shared process", - ); + if (Exit.isSuccess(readerExit)) assert.fail("Expected the session event stream to fail"); + const failure = Cause.squash(readerExit.cause); + if (!isProviderAdapterEventStreamError(failure)) + assert.fail("Expected a provider stream error"); + assert.equal(failure.processExited, exit === "numeric"); }).pipe( Effect.scoped, Effect.provide( diff --git a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts index 51f90c096bbeb..3d434becbd94b 100644 --- a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts @@ -2251,6 +2251,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* ( new ProviderAdapter.ProviderAdapterEventStreamError({ driver: CODEX_PROVIDER, providerSessionId: input.providerSessionId, + processExited: cause._tag === "CodexAppServerProcessExitedError", cause, }), ), diff --git a/apps/server/src/orchestration-v2/RunExecutionService.test.ts b/apps/server/src/orchestration-v2/RunExecutionService.test.ts index 9991a42c11b45..d408a3301926f 100644 --- a/apps/server/src/orchestration-v2/RunExecutionService.test.ts +++ b/apps/server/src/orchestration-v2/RunExecutionService.test.ts @@ -43,7 +43,10 @@ import * as Queue from "effect/Queue"; import * as Ref from "effect/Ref"; import * as Stream from "effect/Stream"; import * as TestClock from "effect/testing/TestClock"; -import { CodexAppServerRequestError } from "effect-codex-app-server/errors"; +import { + CodexAppServerProcessExitedError, + CodexAppServerRequestError, +} from "effect-codex-app-server/errors"; import { SqlError, classifySqliteError } from "effect/sql/SqlError"; import { toPersistenceSqlError } from "../persistence/Errors.ts"; @@ -3618,59 +3621,80 @@ it.effect("does not interrupt an ended provider when its terminal write fails", }), ); -it.effect("ends a running root command when the provider stream fails mid-turn", () => - Effect.gen(function* () { - const now = yield* DateTime.now; - const { written, observed } = yield* captureRootRunTermination({ - key: "stream-error-running-command", - shouldFinalizeRun: () => Effect.succeed(true), - events: (ids) => - Stream.make( - { - type: "provider_turn.updated" as const, - driver, - providerTurn: { - id: ids.rootProviderTurnId, - providerThreadId: ids.providerThreadId, - nodeId: ids.rootNodeId, - runAttemptId: ids.attemptId, - nativeTurnRef: null, - ordinal: 1, - status: "running" as const, - startedAt: now, - completedAt: null, +it.effect.each([true, false])( + "ends a running root command after stream failure (confirmed exit: %s)", + (processExited) => + Effect.gen(function* () { + const now = yield* DateTime.now; + const interrupts = yield* Ref.make(0); + const { written, observed, finalEvents } = yield* captureRootRunTermination({ + key: "stream-error-running-command", + shouldFinalizeRun: () => Effect.succeed(true), + events: (ids) => + Stream.make( + { + type: "provider_turn.updated" as const, + driver, + providerTurn: { + id: ids.rootProviderTurnId, + providerThreadId: ids.providerThreadId, + nodeId: ids.rootNodeId, + runAttemptId: ids.attemptId, + nativeTurnRef: null, + ordinal: 1, + status: "running" as const, + startedAt: now, + completedAt: null, + }, }, - }, - backgroundTurnItemEvent(ids, "command_execution", "running", 1), - ).pipe( - Stream.concat( - Stream.fail( - new ProviderAdapter.ProviderAdapterEventStreamError({ - driver, - providerSessionId: ProviderSessionId.make("session:stream-error-running-command"), - cause: "provider process exited", - }), + backgroundTurnItemEvent(ids, "command_execution", "running", 1), + ).pipe( + Stream.concat( + Stream.fail( + new ProviderAdapter.ProviderAdapterEventStreamError({ + driver, + providerSessionId: ProviderSessionId.make("session:stream-error-running-command"), + processExited, + cause: processExited + ? new CodexAppServerProcessExitedError({ code: 0, stderr: "private stderr" }) + : "provider stream failed", + }), + ), ), ), - ), - // The dead process cannot take the interrupt either. - interruptTurn: (input) => - Effect.fail( - new ProviderAdapter.ProviderAdapterInterruptError({ - driver, - providerThreadId: input.providerThread.id, - providerTurnId: input.providerTurnId, - cause: "provider already exited", - }), - ), - }); - assert.deepEqual(observed, ["run:failed", "pull-requests-refreshed"]); - const ids = backgroundScenarioIds("stream-error-running-command"); - const endedCommand = written.find( - (item) => item.id === ids.itemId && item.status !== "running", - ); - assert.isDefined(endedCommand); - }), + interruptTurn: (input) => + Ref.update(interrupts, (count) => count + 1).pipe( + Effect.andThen( + Effect.fail( + new ProviderAdapter.ProviderAdapterInterruptError({ + driver, + providerThreadId: input.providerThread.id, + providerTurnId: input.providerTurnId, + cause: "interrupt unavailable", + }), + ), + ), + ), + }); + assert.deepEqual(observed, ["run:failed", "pull-requests-refreshed"]); + const ids = backgroundScenarioIds("stream-error-running-command"); + const endedCommand = written.find( + (item) => item.id === ids.itemId && item.status !== "running", + ); + assert.isDefined(endedCommand); + assert.equal(yield* Ref.get(interrupts), processExited ? 0 : 1); + const turn = finalEvents.find((event) => event.type === "provider-turn.updated"); + if (!processExited) { + assert.isUndefined(turn); + return; + } + assert.equal(turn?.payload.id, ids.rootProviderTurnId); + assert.equal(turn?.payload.status, "interrupted"); + assert.deepEqual(turn?.payload.completedAt, now); + const error = written.find((item) => item.type === "error"); + assert.include(error?.failure.message ?? "", "Codex app-server exited with code 0"); + assert.notInclude(error?.failure.message ?? "", "private stderr"); + }), ); it.effect("keeps a running root command open when a write fails under a live provider", () => diff --git a/apps/server/src/orchestration-v2/RunExecutionService.ts b/apps/server/src/orchestration-v2/RunExecutionService.ts index 5c00cc89d5873..8c2c7757cb578 100644 --- a/apps/server/src/orchestration-v2/RunExecutionService.ts +++ b/apps/server/src/orchestration-v2/RunExecutionService.ts @@ -2088,12 +2088,16 @@ export const layer: Layer.Layer< const routing = yield* Ref.get(eventRouting); const rootProviderTurn = yield* Ref.get(latestRootProviderTurn); const squashed = Cause.squash(cause); + const streamError = + isRunExecutionIngestError(squashed) && + isProviderEventStreamError(squashed.cause) + ? squashed.cause + : undefined; // An exclusive session closes when its thread detaches, and no terminal // follows. The process is gone, so a handoff settles here with no interrupt. if ( - isRunExecutionIngestError(squashed) && - isProviderEventStreamError(squashed.cause) && - squashed.cause.detachedThreadId === input.run.threadId && + streamError !== undefined && + streamError.detachedThreadId === input.run.threadId && (yield* workspaceHandedOff) ) { const handedOff = yield* finalizeRootRun( @@ -2139,50 +2143,42 @@ export const layer: Layer.Layer< // An adapter fails its stream when its runtime is gone. A failed write, or a session T3 // released or saw end, leaves work that can still report or that the releaser settles. const runtimeLost = - !detached && - isRunExecutionIngestError(squashed) && - isProviderEventStreamError(squashed.cause) && - squashed.cause.raisedByT3 !== true; + !detached && streamError !== undefined && streamError.raisedByT3 !== true; if (yield* Ref.get(rootRunFinalized)) { if (runtimeLost) yield* endWorkLostAfterRootRun(completedAt); return; } const providerThread = yield* Ref.get(latestProviderThread); // Stop background work too; the failed consumer cannot persist terminal events. + const turnStopped = + routing.rootProviderTurnId !== null && + !routing.rootTurnEnded && + ((runtimeLost && streamError.processExited === true) || + (yield* input.session + .interruptTurn({ + providerThread, + providerTurnId: routing.rootProviderTurnId, + requestRuntimeRestart: true, + }) + .pipe( + Effect.as(true), + Effect.catchCauseIf( + (interruptCause) => !Cause.hasInterruptsOnly(interruptCause), + (interruptCause) => + Effect.logWarning( + "orchestration V2 failed to interrupt turn after ingestion failure", + { runId: input.run.id, cause: interruptCause }, + ).pipe(Effect.as(false)), + ), + ))); + // A failed interrupt leaves the turn open for recovery. Preserve a terminal + // snapshot if its original write failed. const abandonedProviderTurn = - routing.rootProviderTurnId !== null && !routing.rootTurnEnded - ? yield* input.session - .interruptTurn({ - providerThread, - providerTurnId: routing.rootProviderTurnId, - requestRuntimeRestart: true, - }) - .pipe( - Effect.as(true), - Effect.catchCauseIf( - (interruptCause) => !Cause.hasInterruptsOnly(interruptCause), - (interruptCause) => - Effect.logWarning( - "orchestration V2 failed to interrupt turn after ingestion failure", - { runId: input.run.id, cause: interruptCause }, - ).pipe(Effect.as(false)), - ), - // A failed interrupt leaves the stored turn running so the next start - // retries it. The snapshot is cached before it is published, so it may - // not be stored: replay a terminal one as-is. - Effect.map((interrupted) => - !interrupted || rootProviderTurn === null - ? null - : isTerminalProviderTurnStatus(rootProviderTurn.status) - ? rootProviderTurn - : { - ...rootProviderTurn, - status: "interrupted" as const, - completedAt, - }, - ), - ) - : null; + !turnStopped || rootProviderTurn === null + ? null + : isTerminalProviderTurnStatus(rootProviderTurn.status) + ? rootProviderTurn + : { ...rootProviderTurn, status: "interrupted" as const, completedAt }; const latestItemOrdinal = yield* Ref.get(latestTurnItemOrdinal); const openSubagents = yield* Ref.get(openRunOwnedSubagents); const lostToolCalls = runtimeLost diff --git a/packages/effect-codex-app-server/src/_internal/stdio.test.ts b/packages/effect-codex-app-server/src/_internal/stdio.test.ts index dcb00247b36ac..2ee53c409b819 100644 --- a/packages/effect-codex-app-server/src/_internal/stdio.test.ts +++ b/packages/effect-codex-app-server/src/_internal/stdio.test.ts @@ -35,6 +35,7 @@ describe("Codex App Server child process termination", () => { terminationError: makeTerminationError( { pid: ChildProcessSpawner.ProcessId(55), + isRunning: Effect.succeed(false), exitCode: Deferred.await(exited), }, tail.read, @@ -62,7 +63,7 @@ describe("Codex App Server child process termination", () => { }), ); - it.effect("retains the process identifier and exact exit-status cause", () => + it.effect.each([true, false])("retains exit-status diagnostics when isRunning is %s", (running) => Effect.gen(function* () { const rootCause = new Error("private process diagnostics"); const cause = PlatformError.systemError({ @@ -74,17 +75,23 @@ describe("Codex App Server child process termination", () => { const error = yield* makeTerminationError( { pid: ChildProcessSpawner.ProcessId(52), + isRunning: Effect.succeed(running), exitCode: Effect.fail(cause), }, Effect.succeed(""), ); - assert.instanceOf(error, CodexError.CodexAppServerTransportError); + assert.equal( + error._tag, + running ? "CodexAppServerTransportError" : "CodexAppServerProcessExitedError", + ); assert.equal(error.pid, 52); assert.strictEqual(error.cause, cause); assert.equal( error.message, - "Codex App Server transport operation 'read-process-exit-status' failed.", + running + ? "Codex App Server transport operation 'read-process-exit-status' failed." + : "Codex App Server process exited", ); assert.notInclude(error.message, rootCause.message); }), @@ -95,6 +102,7 @@ describe("Codex App Server child process termination", () => { const error = yield* makeTerminationError( { pid: ChildProcessSpawner.ProcessId(53), + isRunning: Effect.succeed(false), exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(1)), }, Effect.succeed("Error: Missing optional dependency @openai/codex-darwin-arm64.\n"), @@ -114,6 +122,7 @@ describe("Codex App Server child process termination", () => { const error = yield* makeTerminationError( { pid: ChildProcessSpawner.ProcessId(54), + isRunning: Effect.succeed(false), exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(1)), }, Effect.succeed(" \n\n"), diff --git a/packages/effect-codex-app-server/src/_internal/stdio.ts b/packages/effect-codex-app-server/src/_internal/stdio.ts index a047d1aa804d4..1435043a95517 100644 --- a/packages/effect-codex-app-server/src/_internal/stdio.ts +++ b/packages/effect-codex-app-server/src/_internal/stdio.ts @@ -5,6 +5,7 @@ import * as Fiber from "effect/Fiber"; import * as Effect from "effect/Effect"; import * as Queue from "effect/Queue"; import * as Ref from "effect/Ref"; +import * as Result from "effect/Result"; import * as Sink from "effect/Sink"; import * as Stdio from "effect/Stdio"; import * as Stream from "effect/Stream"; @@ -108,29 +109,29 @@ export const makeStderrTail = Effect.fn("makeStderrTail")(function* ( type ChildProcessTerminationHandle = Pick< ChildProcessSpawner.ChildProcessHandle, - "exitCode" | "pid" + "exitCode" | "isRunning" | "pid" >; -export const makeTerminationError = ( +export const makeTerminationError = Effect.fn("CodexAppServer.makeTerminationError")(function* ( handle: ChildProcessTerminationHandle, stderrTail: Effect.Effect, -): Effect.Effect => - Effect.matchEffect(handle.exitCode, { - onFailure: (cause) => - Effect.succeed( - new CodexError.CodexAppServerTransportError({ - operation: "read-process-exit-status", - pid: handle.pid, - cause, - }), - ), - onSuccess: (code) => - Effect.map(stderrTail, (tail) => { - const stderr = stderrExcerpt(tail); - return new CodexError.CodexAppServerProcessExitedError({ - code, - pid: handle.pid, - ...(stderr ? { stderr } : {}), - }); - }), +) { + const status = yield* Effect.result(handle.exitCode); + // A signal exit and a failed stdin write can both fail the exit-code read. + if ( + Result.isFailure(status) && + (yield* handle.isRunning.pipe(Effect.orElseSucceed(() => true))) + ) { + return new CodexError.CodexAppServerTransportError({ + operation: "read-process-exit-status", + pid: handle.pid, + cause: status.failure, + }); + } + const stderr = stderrExcerpt(yield* stderrTail); + return new CodexError.CodexAppServerProcessExitedError({ + ...(Result.isSuccess(status) ? { code: status.success } : { cause: status.failure }), + pid: handle.pid, + ...(stderr ? { stderr } : {}), }); +}); diff --git a/packages/provider-core/src/server/ProviderAdapter.ts b/packages/provider-core/src/server/ProviderAdapter.ts index 5325c19dc62f7..9d26c7ff0cafd 100644 --- a/packages/provider-core/src/server/ProviderAdapter.ts +++ b/packages/provider-core/src/server/ProviderAdapter.ts @@ -454,6 +454,8 @@ export class ProviderAdapterEventStreamError extends Schema.TaggedError Date: Thu, 19 Nov 2026 10:07:01 -0800 Subject: [PATCH 2/2] fix(codex): finish transport when the owned process exits Observe process exit independently of stdout EOF and allow a bounded final drain. A descendant retaining the pipe no longer strands active requests or turn termination. Cover final replies, unterminated notifications, and signal exits. --- .../src/_internal/stdio.test.ts | 71 ++++++++++++++----- .../src/_internal/stdio.ts | 13 +++- 2 files changed, 65 insertions(+), 19 deletions(-) diff --git a/packages/effect-codex-app-server/src/_internal/stdio.test.ts b/packages/effect-codex-app-server/src/_internal/stdio.test.ts index 2ee53c409b819..7ee95979529fe 100644 --- a/packages/effect-codex-app-server/src/_internal/stdio.test.ts +++ b/packages/effect-codex-app-server/src/_internal/stdio.test.ts @@ -3,6 +3,7 @@ import * as Effect from "effect/Effect"; import * as Deferred from "effect/Deferred"; import * as Fiber from "effect/Fiber"; import * as Queue from "effect/Queue"; +import * as Ref from "effect/Ref"; import * as Stream from "effect/Stream"; import * as TestClock from "effect/testing/TestClock"; import * as PlatformError from "effect/PlatformError"; @@ -20,26 +21,44 @@ import { } from "./stdio.ts"; describe("Codex App Server child process termination", () => { - it.effect("retains exit diagnostics when stderr stays open after stdout ends", () => + it.effect.each([ + { name: "stdout closes", stdoutEnds: true, signal: false }, + { name: "stdout remains open", stdoutEnds: false, signal: false }, + { name: "stdout remains open after a signal", stdoutEnds: false, signal: true }, + ])("drains final output when $name", ({ stdoutEnds, signal }) => Effect.gen(function* () { const { stdio, input, output } = yield* makeInMemoryStdio(); const captured = yield* Deferred.make(); + const terminated = yield* Deferred.make(); + const finalReply = yield* Deferred.make(); + const notifications = yield* Ref.make>([]); const stderr = Stream.make(new TextEncoder().encode("Error: invalid config\n")).pipe( Stream.concat(Stream.fromEffect(Deferred.succeed(captured, undefined)).pipe(Stream.drain)), Stream.concat(Stream.never), ); const tail = yield* makeStderrTail(stderr); - const exited = yield* Deferred.make(); + const exited = yield* Deferred.make< + ChildProcessSpawner.ExitCode, + PlatformError.PlatformError + >(); + const exitFailure = PlatformError.systemError({ + _tag: "Unknown", + module: "ChildProcess", + method: "exitCode", + cause: new Error("Process interrupted due to receipt of signal: 'SIGKILL'"), + }); + const handle = { + stdout: stdio.stdin, + stdin: stdio.stdout(), + pid: ChildProcessSpawner.ProcessId(55), + isRunning: Effect.succeed(false), + exitCode: Deferred.await(exited), + }; const transport = yield* CodexProtocol.makeCodexAppServerPatchedProtocol({ - stdio: makeChildStdio({ stdout: stdio.stdin, stdin: stdio.stdout() }, tail.awaitDrained), - terminationError: makeTerminationError( - { - pid: ChildProcessSpawner.ProcessId(55), - isRunning: Effect.succeed(false), - exitCode: Deferred.await(exited), - }, - tail.read, - ), + stdio: makeChildStdio(handle, tail.awaitDrained), + terminationError: makeTerminationError(handle, tail.read), + onTermination: (error) => Deferred.succeed(terminated, error).pipe(Effect.asVoid), + onNotification: ({ method }) => Ref.update(notifications, (all) => [...all, method]), }); const pending = yield* transport.request("thread/read", {}).pipe( Effect.match({ @@ -49,17 +68,37 @@ describe("Codex App Server child process termination", () => { Effect.forkScoped, ); yield* Queue.take(output); + yield* transport.request("thread/list", {}).pipe( + Effect.flatMap((reply) => Deferred.succeed(finalReply, reply)), + Effect.forkScoped, + ); + const lastRequest = JSON.parse(yield* Queue.take(output)); + const finalOutput = new TextEncoder().encode( + `${JSON.stringify({ id: lastRequest.id, result: "final response" })}\n{"method":"turn/completed"}`, + ); yield* Deferred.await(captured); - yield* Queue.end(input); - yield* TestClock.adjust("100 millis"); - yield* Deferred.succeed(exited, ChildProcessSpawner.ExitCode(1)); - yield* TestClock.adjust("250 millis"); + if (stdoutEnds) { + yield* Queue.offer(input, finalOutput); + yield* Queue.end(input); + yield* TestClock.adjust("100 millis"); + } + if (signal) yield* Deferred.fail(exited, exitFailure); + else yield* Deferred.succeed(exited, ChildProcessSpawner.ExitCode(1)); + if (!stdoutEnds) yield* Queue.offer(input, finalOutput); + yield* TestClock.adjust("500 millis"); + assert.isTrue(yield* Deferred.isDone(terminated)); + assert.isTrue(yield* Deferred.isDone(finalReply)); + assert.equal(yield* Deferred.await(finalReply), "final response"); + assert.deepEqual(yield* Ref.get(notifications), ["turn/completed"]); const error = yield* Fiber.join(pending); assert.instanceOf(error, CodexError.CodexAppServerProcessExitedError); assert.equal( error.message, - "Codex App Server process exited with code 1: Error: invalid config", + signal + ? "Codex App Server process exited: Error: invalid config" + : "Codex App Server process exited with code 1: Error: invalid config", ); + if (signal) assert.strictEqual(error.cause, exitFailure); }), ); diff --git a/packages/effect-codex-app-server/src/_internal/stdio.ts b/packages/effect-codex-app-server/src/_internal/stdio.ts index 1435043a95517..3a208298e5cd5 100644 --- a/packages/effect-codex-app-server/src/_internal/stdio.ts +++ b/packages/effect-codex-app-server/src/_internal/stdio.ts @@ -14,15 +14,22 @@ import { ChildProcessSpawner } from "effect/process"; import * as CodexError from "../errors.ts"; const encoder = new TextEncoder(); +const PROCESS_EXIT_DRAIN_GRACE = "250 millis"; export const makeChildStdio = ( - handle: Pick, + handle: Pick, stderrDrained: Effect.Effect, ) => Stdio.make({ args: Effect.succeed([]), - // Finish stderr separately from the protocol's exit-status deadline. - stdin: handle.stdout.pipe(Stream.onEnd(stderrDrained)), + stdin: handle.stdout.pipe( + // Descendants can retain stdout after the owner exits; drain its final frames for a bounded time. + Stream.interruptWhen( + handle.exitCode.pipe(Effect.ignore, Effect.andThen(Effect.sleep(PROCESS_EXIT_DRAIN_GRACE))), + ), + // Finish stderr separately from the protocol's exit-status deadline. + Stream.onEnd(stderrDrained), + ), stdout: () => Sink.mapInput(handle.stdin, (chunk: string | Uint8Array) => typeof chunk === "string" ? encoder.encode(chunk) : chunk,