Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import * as Stream from "effect/Stream";
import * as Scope from "effect/Scope";
import * as TestClock from "effect/testing/TestClock";
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
import * as ChildProcess from "effect/process/ChildProcess";
import * as EffectAcpErrors from "effect-acp/errors";
import type * as EffectAcpProtocol from "effect-acp/protocol";
import type * as EffectAcpSchema from "effect-acp/compat";
Expand Down Expand Up @@ -571,6 +572,36 @@ function makeMockRuntime(input: {
});
}

it.effect("detaches owned ACP processes on POSIX hosts but not on Windows", () =>
Effect.gen(function* () {
for (const [platform, expected] of [
["win32", false],
["linux", true],
] as const) {
let detached: boolean | undefined;
yield* AcpSessionRuntime.make({
spawn: { command: "acp-agent", args: [] },
cwd: process.cwd(),
clientInfo: { name: "test", version: "1" },
ownDetachedProcessGroup: true,
processGroupPlatform: platform,
}).pipe(
Effect.provideService(HostProcess.Platform, platform),
Effect.provideService(
ChildProcessSpawner.ChildProcessSpawner,
ChildProcessSpawner.make((command) => {
if (ChildProcess.isStandardCommand(command)) detached = command.options.detached;
return Effect.die("spawn stopped by test");
}),
),
Effect.scoped,
Effect.exit,
);
assert.equal(detached, expected, platform);
}
}).pipe(Effect.provide(layerTest)),
);

const isProviderAdapterProtocolError = Schema.is(ProviderAdapter.ProviderAdapterProtocolError);

const makePromptInactivityHarness = Effect.fnUntraced(function* (input: {
Expand Down
6 changes: 4 additions & 2 deletions packages/provider-acp/src/server/AcpSessionRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,7 @@ export const make = Effect.fn("AcpSessionRuntime.make")(function* (
> {
const random = yield* SecureRandom.SecureRandom;
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
const hostPlatform = yield* HostProcess.Platform;
const runtimeScope = yield* Scope.fork(yield* Scope.Scope);
const eventQueue = yield* Queue.unbounded<AcpSessionRuntimeEvent>();
const modeStateRef = yield* Ref.make<AcpSessionModeState | undefined>(undefined);
Expand Down Expand Up @@ -1464,9 +1465,11 @@ export const make = Effect.fn("AcpSessionRuntime.make")(function* (
...(options.spawn.cwd ? { cwd: options.spawn.cwd } : {}),
...(spawnEnvironment ? { env: spawnEnvironment } : {}),
extendEnv: options.spawn.extendEnv ?? true,
// Windows `detached` gives the child its own console, which breaks stdio pipes through
// `.cmd` shims; taskkill /T cleans up the tree there without it.
...(options.ownDetachedProcessGroup === undefined
? {}
: { detached: options.ownDetachedProcessGroup }),
: { detached: options.ownDetachedProcessGroup && hostPlatform !== "win32" }),
shell: containedSpawnCommand.shell,
}),
)
Expand Down Expand Up @@ -1628,7 +1631,6 @@ export const make = Effect.fn("AcpSessionRuntime.make")(function* (
Effect.uninterruptible(terminateOwnedProcessGroupImpl),
);
if (options.ownDetachedProcessGroup === true) {
const hostPlatform = yield* HostProcess.Platform;
const forceTerminateOwnedProcessGroup =
hostPlatform === "win32"
? terminateWindowsProcessTreeWithTaskkill(Number(child.pid)).pipe(
Expand Down
Loading