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, 16:00 UTC
fix(server): stopping an agent's server no longer wakes Codex as if it crashed (#36501)
Julius Marminge committed
Nov 13, 2026 at 21:04 UTC
be78ee494019ac6bed347f7d622132eadf2bae12
7 files changed
+280
-4
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
+89
@@ -1382,6 +1382,7 @@ describe("CodexAdapterV2 post-settle continuation", () => {
1382
const changes = yield* makeChangeSignal;
1383
const continuationRequests: Array<ProviderContinuationRequests.ProviderContinuationRequest> =
1384
[];
1385
+ const commandStopWatchers: Array<PortScanner.AgentCommandStopWatcher> = [];
1386
const driver = yield* CodexReplay.makeReplayDriver(
1387
withConfigReads(transcript),
1388
beforeEmitInbound === undefined ? {} : { beforeEmitInbound },
@@ -1445,6 +1446,10 @@ describe("CodexAdapterV2 post-settle continuation", () => {
1446
continuationRequests.push(request);
1447
}).pipe(Effect.andThen(changes.notify)),
1448
},
1449
+ watchCommandStops: (watcher) =>
1450
+ Effect.sync(() => {
1451
+ commandStopWatchers.push(watcher);
1452
+ }),
1453
});
1454
const threadId = ThreadId.make(`thread-${transcript.scenario}`);
1455
const runtime = yield* adapter.openSession({
@@ -1504,6 +1509,7 @@ describe("CodexAdapterV2 post-settle continuation", () => {
1509
serverConfig,
1510
events,
1511
continuationRequests,
1512
+ commandStopWatchers,
1513
terminalEvents,
1514
subagentUpdates,
1515
hasPendingBackgroundWork,
@@ -5287,6 +5293,89 @@ describe("CodexAdapterV2 post-settle continuation", () => {
5293
),
5294
);
5295
5296
+ it.effect.each([
5297
+ { stop: "onStop", woken: ["CODEX_BG_OTHER_DONE"] },
5298
+ { stop: "onStopAbandoned", woken: ["CODEX_BG_OTHER_DONE", "CODEX_BG_WAKE_DONE"] },
5299
+ ] as const)("wakes for every command but the one the user stopped ($stop)", ({ stop, woken }) =>
5300
+ Effect.gen(function* () {
5301
+ // Same command and start as the stopped one, and it finishes first.
5302
+ const other = (status: "inProgress" | "completed") => ({
5303
+ ...backgroundCommandItem(status),
5304
+ id: "call-codex-bg-other",
5305
+ processId: "4243",
5306
+ aggregatedOutput: status === "completed" ? "CODEX_BG_OTHER_DONE\n" : null,
5307
+ });
5308
+ const [started, ...settle] = backgroundExecTranscript.entries.slice(-4, -1);
5309
+ const inbound = (label: string, method: string, item: Record<string, unknown>) => ({
5310
+ type: "emit_inbound" as const,
5311
+ label,
5312
+ frame: {
5313
+ method,
5314
+ params: { item, threadId: BG_NATIVE_THREAD, turnId: BG_NATIVE_TURN },
5315
+ },
5316
+ });
5317
+ const released = yield* Deferred.make<void>();
5318
+ const harness = yield* makeCodexReplayHarness(
5319
+ makeCodexReplayTranscript({
5320
+ scenario: `codex-bg-user-stop-${stop}`,
5321
+ entries: [
5322
+ ...backgroundExecTranscript.entries.slice(0, -4),
5323
+ started!,
5324
+ inbound("item/started/other", "item/started", other("inProgress")),
5325
+ ...settle,
5326
+ inbound("item/completed/other", "item/completed", other("completed")),
5327
+ inbound("item/completed/stopped", "item/completed", backgroundCommandItem("completed")),
5328
+ ],
5329
+ }),
5330
+ undefined,
5331
+ undefined,
5332
+ undefined,
5333
+ (entry) =>
5334
+ entry.label === "item/completed/other" ? Deferred.await(released) : Effect.void,
5335
+ );
5336
+ yield* harness.runtime.startTurn(
5337
+ makeCodexTestTurnInput({
5338
+ threadId: harness.threadId,
5339
+ providerThread: harness.providerThread,
5340
+ now: yield* DateTime.now,
5341
+ attemptId: RunAttemptId.make("attempt-command-user-stop"),
5342
+ text: BG_PROMPT,
5343
+ }),
5344
+ );
5345
+ yield* harness.firstTerminal;
5346
+ const [watcher] = harness.commandStopWatchers;
5347
+ assert.equal(watcher?.variable, "CODEX_TOOL_CALL_ID");
5348
+ yield* watcher!.onStop("not-a-command-of-this-session");
5349
+ yield* watcher!.onStop(BG_COMMAND_ITEM);
5350
+ if (stop === "onStopAbandoned") yield* watcher!.onStopAbandoned(BG_COMMAND_ITEM);
5351
+ yield* Deferred.succeed(released, undefined);
5352
+ yield* harness.until(
5353
+ () =>
5354
+ harness.events.filter(
5355
+ (event) =>
5356
+ event.type === "turn_item.updated" &&
5357
+ event.turnItem.type === "command_execution" &&
5358
+ event.turnItem.status === "completed",
5359
+ ).length === 2 && harness.continuationRequests.length === woken.length,
5360
+ );
5361
+ assert.isFalse(yield* harness.hasPendingBackgroundWork);
5362
+ assert.deepEqual(
5363
+ harness.continuationRequests.map((request) => request.detail?.trim().split("\n").at(-1)),
5364
+ [...woken],
5365
+ );
5366
+ }).pipe(
5367
+ Effect.scoped,
5368
+ Effect.provide(
5369
+ Layer.mergeAll(
5370
+ IdAllocator.layer,
5371
+ McpProviderSessions.layer,
5372
+ NodeServices.layer,
5373
+ NodeCrypto.layer,
5374
+ ),
5375
+ ),
5376
+ ),
5377
+ );
5378
+
5379
it.effect("wakes with well-formed text when the cuts split an emoji", () =>
5380
Effect.gen(function* () {
5381
const harness = yield* makeCodexReplayHarness(
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.testkit.ts
+2
@@ -13,6 +13,7 @@ import * as ServerConfig from "../../config.ts";
13
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
14
import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
15
import { ProviderAdapterDriverCreateError } from "@t3tools/provider-core/server/adapterDriver";
16
+import * as PortScanner from "../../preview/PortScanner.ts";
17
import * as ProviderAdapterRegistry from "../ProviderAdapterRegistry.ts";
18
import {
19
makeReplayServerConfig,
@@ -142,6 +143,7 @@ export function layer(input: {
143
NodeServices.layer,
144
NodeCrypto.layer,
145
IdAllocator.layer,
146
+ PortScanner.layerTest,
147
),
148
),
149
);
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+32
@@ -1556,6 +1556,8 @@ function readCodexProtocolPath(value: unknown, ...path: ReadonlyArray<string>):
1556
return current;
1557
}
1558
1559
+/** Codex sets this on every command it starts, to that command's item id. */
1560
+const CODEX_COMMAND_ITEM_ENV = "CODEX_TOOL_CALL_ID";
1561
const CODEX_THREAD_ENV_CONFIG_KEY = `shell_environment_policy.set.${PortScanner.AGENT_THREAD_ENV}`;
1562
1563
/**
@@ -1766,6 +1768,7 @@ export type CodexAdapterV2DriverEnv =
1768
| IdAllocator.IdAllocatorV2
1769
| McpProviderSessions.McpProviderSessions
1770
| Path.Path
1771
+ | PortScanner.PortDiscovery
1772
| ServerConfig;
1773
1774
export const createCodexAdapterV2 = Effect.fn("CodexAdapterV2.createCodexAdapterV2")(function* (
@@ -1781,6 +1784,7 @@ export const createCodexAdapterV2 = Effect.fn("CodexAdapterV2.createCodexAdapter
1784
const fileSystem = yield* FileSystem.FileSystem;
1785
const hostEnvironment = yield* HostProcess.Environment;
1786
const idAllocator = yield* IdAllocator.IdAllocatorV2;
1787
+ const portDiscovery = yield* PortScanner.PortDiscovery;
1788
const serverConfig = yield* ServerConfig;
1789
const homeLayout = yield* resolveCodexHomeLayout(config);
1790
@@ -1813,6 +1817,7 @@ export const createCodexAdapterV2 = Effect.fn("CodexAdapterV2.createCodexAdapter
1817
idAllocator,
1818
serverConfig,
1819
continuationRequests,
1820
+ watchCommandStops: portDiscovery.watchAgentCommandStops,
1821
...hooks,
1822
});
1823
});
@@ -1839,6 +1844,8 @@ export interface CodexAdapterV2Options {
1844
request: ProviderContinuationRequests.ProviderContinuationRequest,
1845
) => Effect.Effect<void>;
1846
};
1847
+ /** Omitting this reports a command the user stopped as one that finished by itself. */
1848
+ readonly watchCommandStops?: PortScanner.PortDiscovery["Service"]["watchAgentCommandStops"];
1849
}
1850
1851
export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
@@ -2095,6 +2102,26 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
2102
new Map<string, Map<string, CodexDynamicToolItem>>(),
2103
);
2104
const interruptingNativeTurns = yield* Ref.make(new Set<string>());
2105
+ // Running commands the user is stopping outside a turn interrupt; their exit wakes nobody.
2106
+ const userStoppedCommandItemIds = yield* Ref.make(new Set<string>());
2107
+ if (adapterOptions.watchCommandStops !== undefined) {
2108
+ yield* adapterOptions.watchCommandStops({
2109
+ variable: CODEX_COMMAND_ITEM_ENV,
2110
+ onStop: Effect.fn("CodexAdapterV2.onCommandStop")(function* (itemId) {
2111
+ const running = yield* Ref.get(runningCommandItemsByTurn);
2112
+ if (![...running.values()].some((items) => items.has(itemId))) return;
2113
+ yield* Ref.update(userStoppedCommandItemIds, (current) =>
2114
+ new Set(current).add(itemId),
2115
+ );
2116
+ }),
2117
+ onStopAbandoned: (itemId) =>
2118
+ Ref.update(userStoppedCommandItemIds, (current) => {
2119
+ const updated = new Set(current);
2120
+ updated.delete(itemId);
2121
+ return updated;
2122
+ }),
2123
+ });
2124
+ }
2125
const terminalizedNonCompletedNativeTurns = yield* Ref.make(new Set<string>());
2126
// Keep the stream open until descendants settle to avoid stranding child projections.
2127
const deferredRootTerminals = yield* Ref.make(new Map<string, DeferredCodexRootTerminal>());
@@ -5417,6 +5444,10 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
5444
// Other tools can retain the context after thread closure.
5445
if (context.closedCommandItemIds?.has(payload.item.id)) return;
5446
const turnDrained = yield* clearRunningCommandItem(payload.turnId, payload.item.id);
5447
+ const userStopped = yield* Ref.modify(userStoppedCommandItemIds, (current) => {
5448
+ const updated = new Set(current);
5449
+ return [updated.delete(payload.item.id), updated] as const;
5450
+ });
5451
const artifacts = yield* buildCommandExecutionArtifacts(context, payload.item);
5452
yield* emitProviderEvent({
5453
type: "node.updated",
@@ -5432,6 +5463,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
5463
if (
5464
context.subagent === null &&
5465
continuationRequests !== undefined &&
5466
+ !userStopped &&
5467
!(yield* Ref.get(interruptingNativeTurns)).has(payload.turnId)
5468
) {
5469
const alreadyOffered = yield* Ref.modify(
apps/server/src/preview/PortScanner.test.ts
+27
-1
@@ -936,6 +936,17 @@ effectIt.effect("stops only a job's own process group", () =>
936
for (const pid of [20, 210, 500, 999]) {
937
expect(PortScanner.stoppableProcessGroup(table, pid, serverPid)).toBeNull();
938
}
939
+ // The tool shell is the command; its `npm run dev &` job only inherited the name.
940
+ const variables = new Map([
941
+ [200, new Map<string, string>()],
942
+ [300, new Map([["COMMAND", "a"]])],
943
+ [400, new Map([["COMMAND", "a"]])],
944
+ ]);
945
+ expect([...PortScanner.agentCommandsInGroup(variables, table.get(300)!)]).toEqual([
946
+ ["COMMAND", "a"],
947
+ ]);
948
+ expect(PortScanner.agentCommandsInGroup(variables, table.get(400)!).size).toBe(0);
949
+ expect(PortScanner.agentCommandsInGroup(variables, table.get(600)!).size).toBe(0);
950
}),
951
);
952
@@ -949,6 +960,8 @@ server.listen(0, "127.0.0.1", () => {
960
});
961
`;
962
963
+const AGENT_COMMAND_ENV = "T3CODE_TEST_AGENT_COMMAND";
964
+
965
/**
966
* A real HTML server with an agent's environment, started the way an agent's tool shell starts a
967
* job: under a detached shell with job control, in a group of its own. Release kills only the pids
@@ -966,7 +979,12 @@ const agentServer = () =>
979
// dash ignores `set -m` without a terminal; bash, like agent tool shells, honors it.
980
const child = NodeChildProcess.spawn(
981
"bash",
969
- ["-c", 'set -m; "$0" -e "$1" & wait', process.execPath, AGENT_SERVER_SCRIPT],
982
+ [
983
+ "-c",
984
+ `set -m; ${AGENT_COMMAND_ENV}=command-live "$0" -e "$1" & wait`,
985
+ process.execPath,
986
+ AGENT_SERVER_SCRIPT,
987
+ ],
988
{ detached: true, env, stdio: ["ignore", "pipe", "ignore"] },
989
);
990
const exited = new Promise<void>((resolve) => child.once("exit", () => resolve()));
@@ -1004,6 +1022,12 @@ effectIt.live.skipIf(HostProcess.Platform.defaultValue() === "win32")(
1022
Effect.sync(release),
1023
);
1024
const job = yield* agentServer();
1025
+ const stops: Array<readonly [string, boolean]> = [];
1026
+ yield* scanner.watchAgentCommandStops({
1027
+ variable: AGENT_COMMAND_ENV,
1028
+ onStop: (command) => Effect.sync(() => stops.push([command, isRunning(job.pid)])),
1029
+ onStopAbandoned: () => Effect.die("the signal reached the job"),
1030
+ });
1031
1032
expect(yield* scanner.scan()).toEqual(
1033
expect.arrayContaining([
@@ -1017,8 +1041,10 @@ effectIt.live.skipIf(HostProcess.Platform.defaultValue() === "win32")(
1041
1042
const unlisted = yield* Effect.flip(scanner.stopServer({ pid: process.pid, port: job.port }));
1043
expect(unlisted.reason).toBe("not-found");
1044
+ expect(stops).toEqual([]);
1045
1046
yield* scanner.stopServer({ pid: job.pid, port: job.port });
1047
+ expect(stops).toEqual([["command-live", true]]);
1048
// The shell waits on its job, so it exits once the job has.
1049
yield* Effect.promise(() => job.exited);
1050
expect(isRunning(job.pid)).toBe(false);
apps/server/src/preview/PortScanner.ts
+126
-2
@@ -56,6 +56,13 @@ export class PortDiscovery extends Context.Service<
56
* outside Effect.
57
*/
58
readonly trackAgent: () => () => void;
59
+ /**
60
+ * Tells an agent CLI's adapter which of its commands a user stop is about to signal, so the
61
+ * exit is not reported to the agent as the command finishing by itself.
62
+ */
63
+ readonly watchAgentCommandStops: (
64
+ watcher: AgentCommandStopWatcher,
65
+ ) => Effect.Effect<void, never, Scope.Scope>;
66
/** Stops a listed server's process group, never this server, an agent CLI, or a shell. */
67
readonly stopServer: (
68
input: PreviewStopLocalServerInput,
@@ -69,6 +76,14 @@ export class PortDiscovery extends Context.Service<
76
*/
77
export const AGENT_THREAD_ENV = "T3CODE_THREAD_ID";
78
79
+export interface AgentCommandStopWatcher {
80
+ /** The variable the CLI sets on each command it starts, naming that command. */
81
+ readonly variable: string;
82
+ readonly onStop: (command: string) => Effect.Effect<void>;
83
+ /** The signal never reached the command, so it is still running or ended by itself. */
84
+ readonly onStopAbandoned: (command: string) => Effect.Effect<void>;
85
+}
86
+
87
/** `0` turns off listener discovery; configured preview URLs are still probed. */
88
const PORT_DISCOVERY_ENV = "T3CODE_PORT_DISCOVERY";
89
@@ -382,6 +397,42 @@ const parsePsEnvironmentThreads = (raw: string): ReadonlyMap<number, ThreadId |
397
return threads;
398
};
399
400
+/** Splits `/proc/<pid>/environ` on NUL, or the environment macOS `ps -E` appends on spaces. */
401
+const parseEnvironmentVariables = (
402
+ raw: string,
403
+ separator: "\0" | RegExp,
404
+ names: ReadonlyArray<string>,
405
+): ReadonlyMap<string, string> => {
406
+ const variables = new Map<string, string>();
407
+ for (const entry of raw.split(separator)) {
408
+ const name = names.find((candidate) => entry.startsWith(`${candidate}=`));
409
+ if (name !== undefined && !variables.has(name)) {
410
+ variables.set(name, entry.slice(name.length + 1));
411
+ }
412
+ }
413
+ return variables;
414
+};
415
+
416
+/**
417
+ * The agent commands that signaling a group stops, by the variable naming each. A CLI starts a
418
+ * command as a group leader and names it in the command's environment, which the CLI itself does
419
+ * not carry. A job the command moved to its own group inherits the name from its parent, and
420
+ * stopping that job does not end the command.
421
+ */
422
+export const agentCommandsInGroup = (
423
+ variables: ReadonlyMap<number, ReadonlyMap<string, string>>,
424
+ leader: ProcessTableRow,
425
+): ReadonlyMap<string, string> => {
426
+ const commands = new Map<string, string>();
427
+ const parent = variables.get(leader.ppid);
428
+ // An unreadable parent cannot rule out an inherited name.
429
+ if (parent === undefined) return commands;
430
+ for (const [name, command] of variables.get(leader.pid) ?? []) {
431
+ if (command !== "" && parent.get(name) !== command) commands.set(name, command);
432
+ }
433
+ return commands;
434
+};
435
+
436
const parseProcessTable = (raw: string): ReadonlyMap<number, ProcessTableRow> => {
437
const rows = new Map<number, ProcessTableRow>();
438
for (const line of raw.split("\n")) {
@@ -476,6 +527,7 @@ export const make = Effect.gen(function* PortDiscoveryMake() {
527
// environment, so a pid is read once while it listens. Cleared while no client retains the
528
// scanner, since unscanned pids can be reused.
529
const agentThreadsRef = yield* Ref.make<ReadonlyMap<number, ThreadId | null>>(new Map());
530
+ const agentCommandStopWatchers = new Set<AgentCommandStopWatcher>();
531
let runningAgents = 0;
532
// An agent that exited, or a cache cleared with a marked listener, owes one listener read: the
533
// servers it left may still run. So does startup, for agents that ran before a restart.
@@ -1016,6 +1068,62 @@ export const make = Effect.gen(function* PortDiscoveryMake() {
1068
};
1069
};
1070
1071
+ const watchAgentCommandStops: PortDiscovery["Service"]["watchAgentCommandStops"] = (watcher) =>
1072
+ Effect.acquireRelease(
1073
+ Effect.sync(() => {
1074
+ agentCommandStopWatchers.add(watcher);
1075
+ }),
1076
+ () => Effect.sync(() => agentCommandStopWatchers.delete(watcher)),
1077
+ );
1078
+
1079
+ /** Each process's launch values for `names`; a process that cannot be read is left out. */
1080
+ const readEnvironmentVariables = Effect.fn("PortDiscovery.readEnvironmentVariables")(function* (
1081
+ pids: ReadonlyArray<number>,
1082
+ names: ReadonlyArray<string>,
1083
+ ) {
1084
+ if (hostPlatform === "linux") {
1085
+ const read = yield* Effect.forEach(pids, (pid) =>
1086
+ fileSystem.readFileString(`/proc/${pid}/environ`).pipe(
1087
+ Effect.map((raw) => [pid, parseEnvironmentVariables(raw, "\0", names)] as const),
1088
+ Effect.option,
1089
+ ),
1090
+ );
1091
+ return new Map(read.flatMap(Option.toArray));
1092
+ }
1093
+ const result = yield* processRunner
1094
+ .run({
1095
+ command: "ps",
1096
+ args: ["-E", "-ww", "-o", "pid=,command=", "-p", pids.join(",")],
1097
+ timeout: Duration.millis(PS_TIMEOUT_MS),
1098
+ maxOutputBytes: PS_MAX_OUTPUT_BYTES,
1099
+ })
1100
+ .pipe(Effect.option);
1101
+ const variables = new Map<number, ReadonlyMap<string, string>>();
1102
+ for (const line of Option.isSome(result) ? result.value.stdout.split("\n") : []) {
1103
+ const match = /^\s*(\d+)\s(.*)$/.exec(line);
1104
+ if (match) {
1105
+ variables.set(Number(match[1]), parseEnvironmentVariables(match[2]!, /\s+/, names));
1106
+ }
1107
+ }
1108
+ return variables;
1109
+ });
1110
+
1111
+ const agentCommandStops = Effect.fn("PortDiscovery.agentCommandStops")(function* (
1112
+ leader: ProcessTableRow | undefined,
1113
+ ) {
1114
+ const watchers = [...agentCommandStopWatchers];
1115
+ if (leader === undefined || watchers.length === 0) return [];
1116
+ const names = [...new Set(watchers.map((watcher) => watcher.variable))];
1117
+ const commands = agentCommandsInGroup(
1118
+ yield* readEnvironmentVariables([leader.pid, leader.ppid], names),
1119
+ leader,
1120
+ );
1121
+ return watchers.flatMap((watcher) => {
1122
+ const command = commands.get(watcher.variable);
1123
+ return command === undefined ? [] : [{ watcher, command }];
1124
+ });
1125
+ });
1126
+
1127
// Fails when `ps` does, so an empty table never reads as every process having exited.
1128
const readProcessTable = Effect.suspend(() =>
1129
processRunner.run({
@@ -1076,7 +1184,19 @@ export const make = Effect.gen(function* PortDiscoveryMake() {
1184
: Effect.fail(new PreviewStopLocalServerError({ reason: "signal-failed", cause }));
1185
}
1186
});
1079
- if (!(yield* signalGroup("SIGTERM"))) return;
1187
+ // Told before the signal, since the CLI can report the exit before a later step runs.
1188
+ const commandStops = yield* agentCommandStops(table.get(group));
1189
+ yield* Effect.forEach(commandStops, ({ watcher, command }) => watcher.onStop(command), {
1190
+ discard: true,
1191
+ });
1192
+ const abandonCommandStops = Effect.forEach(
1193
+ commandStops,
1194
+ ({ watcher, command }) => watcher.onStopAbandoned(command),
1195
+ { discard: true },
1196
+ );
1197
+ if (!(yield* signalGroup("SIGTERM").pipe(Effect.tapError(() => abandonCommandStops)))) {
1198
+ return yield* abandonCommandStops;
1199
+ }
1200
// While one of the group's original members is still in it, the group has not been reused,
1201
// so SIGKILL goes only to the job that ignored SIGTERM.
1202
const members = [...table.values()].filter((row) => row.pgid === group).map((row) => row.pid);
@@ -1103,6 +1223,7 @@ export const make = Effect.gen(function* PortDiscoveryMake() {
1223
registerTerminalProcesses,
1224
unregisterTerminal,
1225
trackAgent,
1226
+ watchAgentCommandStops,
1227
stopServer,
1228
});
1229
}).pipe(Effect.withSpan("PortDiscovery.make"));
@@ -1110,4 +1231,7 @@ export const make = Effect.gen(function* PortDiscoveryMake() {
1231
export const layer = Layer.effect(PortDiscovery, make);
1232
1233
/** A scanner that tracks nothing, for tests that build provider runners without a host. */
1113
-export const layerTest = Layer.mock(PortDiscovery)({ trackAgent: () => () => undefined });
1234
+export const layerTest = Layer.mock(PortDiscovery)({
1235
+ trackAgent: () => () => undefined,
1236
+ watchAgentCommandStops: () => Effect.void,
1237
+});
apps/server/src/provider/Drivers/CodexDriver.test.ts
+2
@@ -42,6 +42,7 @@ import { CodexDriver } from "./CodexDriver.ts";
42
import * as CodexAdapterV2 from "../../orchestration-v2/Adapters/CodexAdapterV2.ts";
43
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
44
import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
45
+import * as PortScanner from "../../preview/PortScanner.ts";
46
import * as ProviderCredentialStore from "../ProviderCredentialStore.ts";
47
import * as ProviderHostLive from "../ProviderHostLive.ts";
48
@@ -51,6 +52,7 @@ const layerDeps = ServerConfig.layerTest(process.cwd(), {
52
Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
53
Layer.provideMerge(IdAllocator.layer),
54
Layer.provideMerge(McpProviderSessions.layer),
55
+ Layer.provideMerge(PortScanner.layerTest),
56
Layer.provideMerge(
57
Layer.mock(CodexAdapterV2.CodexAppServerClientFactory)({
58
open: () => Effect.die("Maintenance resolution must not open a Codex session"),
apps/server/src/provider/ProviderInstanceRegistry.test.ts
+2
-1
@@ -212,7 +212,8 @@ describe("ProviderInstanceRegistry — multi-instance codex slice", () => {
212
);
213
const layerBase = ProviderHostLive.layer.pipe(Layer.provideMerge(layerBaseDeps));
214
const layerTest = ProviderOrchestrationAdapterInfrastructure.layer.pipe(
215
- Layer.provide(Layer.merge(PortScanner.layerTest, SqlitePersistence.layerMemory)),
215
+ Layer.provide(SqlitePersistence.layerMemory),
216
+ Layer.provideMerge(PortScanner.layerTest),
217
Layer.provideMerge(layerBase),
218
);
219