@devries-cameron20 / t3code Mirror · read-only / commits / 9786b82b09
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 21:00 UTC

fix(provider-acp): wait_for_exit answers when a background child holds the output pipes (#34825)

Julius Marminge committed Nov 11, 2026 at 23:20 UTC 9786b82b0952c663fccaa0069377edce335c4963
2 files changed +43
packages/provider-acp/src/server/clientTerminals.test.ts
+40
@@ -200,6 +200,46 @@ describe("AcpClientTerminals", () => {
200 ),
201 );
202
203 + it.effect("answers wait_for_exit when a background child keeps the output pipes open", () =>
204 + Effect.gen(function* () {
205 + // Models `sh -c "setsid server & echo done"`: sh exits, the orphan inherits stdout/stderr.
206 + const orphanExited = yield* Deferred.make<void>();
207 + const heldOpen = Stream.fromEffectDrain(Deferred.await(orphanExited));
208 + const child = ChildProcessSpawner.makeHandle({
209 + pid: ChildProcessSpawner.ProcessId(1),
210 + exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(0)),
211 + isRunning: Effect.succeed(false),
212 + kill: () => Effect.void,
213 + stdin: Sink.drain,
214 + stdout: Stream.make(new TextEncoder().encode("done\n")).pipe(Stream.concat(heldOpen)),
215 + stderr: heldOpen,
216 + all: Stream.empty,
217 + getInputFd: () => Sink.drain,
218 + getOutputFd: () => Stream.empty,
219 + unref: Effect.succeed(Effect.void),
220 + });
221 + const terminals = yield* makeAcpClientTerminals({ defaultCwd: process.cwd() }).pipe(
222 + Effect.provideService(
223 + ChildProcessSpawner.ChildProcessSpawner,
224 + ChildProcessSpawner.make(() => Effect.succeed(child)),
225 + ),
226 + );
227 + yield* Effect.addFinalizer(() =>
228 + Deferred.succeed(orphanExited, undefined).pipe(Effect.andThen(terminals.disposeAll)),
229 + );
230 + const terminal = yield* terminals.create({ sessionId: "session", command: "fixture" });
231 + const request = { sessionId: "session", ...terminal };
232 + const waiting = yield* terminals.waitForExit(request).pipe(Effect.forkChild);
233 +
234 + yield* TestClock.adjust("5 seconds");
235 + expect(waiting.pollUnsafe()).toBeDefined();
236 + expect(yield* Fiber.join(waiting)).toEqual({ exitCode: 0, signal: null });
237 + const output = yield* terminals.output(request);
238 + expect(output.output).toBe("done\n");
239 + expect(output.exitStatus).toEqual({ exitCode: 0, signal: null });
240 + }).pipe(Effect.scoped),
241 + );
242 +
243 it.effect.each([
244 { deadline: "default", forceKillAfter: undefined, deadlineMillis: 5000 },
245 { deadline: "configured", forceKillAfter: "250 millis" as const, deadlineMillis: 250 },
packages/provider-acp/src/server/clientTerminals.ts
+3
@@ -19,6 +19,7 @@ const MAX_RETAINED_TERMINALS = 32;
19 const MAX_RETAINED_OUTPUT_BYTES = 16 * 1024 * 1024;
20 const DEFAULT_OUTPUT_BYTE_LIMIT = 4 * 1024 * 1024;
21 const MAX_OUTPUT_BYTE_LIMIT = 8 * 1024 * 1024;
22 +const OUTPUT_DRAIN_GRACE = "1 second";
23
24 const terminalRequestError = (message: string, cause?: unknown) =>
25 EffectAcpErrors.AcpRequestError.internalError(
@@ -301,6 +302,8 @@ export const makeAcpClientTerminals = Effect.fn("makeAcpClientTerminals")(functi
302 Effect.all([Fiber.join(stdoutPump), Fiber.join(stderrPump)], {
303 discard: true,
304 }).pipe(
305 + // A background child can inherit the pipes and hold them open indefinitely.
306 + Effect.timeoutOption(OUTPUT_DRAIN_GRACE),
307 Effect.andThen(
308 Effect.sync(() => {
309 record.exitStatus = status;