Skip to content

Commit 1ccd9f4

Browse files
Add force-kill timeout to app server spawn
- Set a default `forceKillAfter` when spawning the Codex app server - Rely on child-process lifecycle from the spawned handle instead of an explicit release kill
1 parent 68775bc commit 1ccd9f4

1 file changed

Lines changed: 20 additions & 20 deletions

File tree

  • packages/effect-codex-app-server/src

‎packages/effect-codex-app-server/src/client.ts‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import {
1717
} from "./_internal/shared.ts";
1818
import { makeChildStdio, makeTerminationError } from "./_internal/stdio.ts";
1919

20+
const DEFAULT_APP_SERVER_FORCE_KILL_AFTER = "2 seconds" as const;
21+
2022
export interface CodexAppServerClientOptions {
2123
readonly logIncoming?: boolean;
2224
readonly logOutgoing?: boolean;
@@ -273,26 +275,24 @@ export const layerCommand = (
273275
> =>
274276
Layer.effect(
275277
CodexAppServerClient,
276-
Effect.acquireRelease(
277-
Effect.gen(function* () {
278-
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
279-
const command = ChildProcess.make(options.command, [...(options.args ?? [])], {
280-
...(options.cwd ? { cwd: options.cwd } : {}),
281-
...(options.env ? { env: { ...process.env, ...options.env } } : {}),
282-
shell: process.platform === "win32",
283-
});
284-
return yield* spawner.spawn(command).pipe(
285-
Effect.mapError(
286-
(cause) =>
287-
new CodexError.CodexAppServerSpawnError({
288-
command: [options.command, ...(options.args ?? [])].join(" "),
289-
cause,
290-
}),
291-
),
292-
);
293-
}),
294-
(handle) => handle.kill().pipe(Effect.orDie),
295-
).pipe(
278+
Effect.gen(function* () {
279+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
280+
const command = ChildProcess.make(options.command, [...(options.args ?? [])], {
281+
...(options.cwd ? { cwd: options.cwd } : {}),
282+
...(options.env ? { env: { ...process.env, ...options.env } } : {}),
283+
forceKillAfter: DEFAULT_APP_SERVER_FORCE_KILL_AFTER,
284+
shell: process.platform === "win32",
285+
});
286+
return yield* spawner.spawn(command).pipe(
287+
Effect.mapError(
288+
(cause) =>
289+
new CodexError.CodexAppServerSpawnError({
290+
command: [options.command, ...(options.args ?? [])].join(" "),
291+
cause,
292+
}),
293+
),
294+
);
295+
}).pipe(
296296
Effect.flatMap((handle) =>
297297
make(makeChildStdio(handle), options, makeTerminationError(handle)),
298298
),

0 commit comments

Comments
 (0)