The best way to control Claude Code, Codex and more from any computer or phone
fix(server): dev servers a Codex agent starts show under its thread (#29687)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Alex Southwell committed
Nov 3, 2026 at 23:08 UTC
b7add5a06d81061bb49b778d8e5420a89ff05383
2 files changed
+69
-1
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
+61
@@ -71,6 +71,7 @@ import * as ProviderReplayHarness from "../testkit/ProviderReplayHarness.ts";
71
import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
72
import type * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests";
73
import * as ModelManifest from "../../provider/ModelManifest.ts";
74
+import * as PortScanner from "../../preview/PortScanner.ts";
75
import { resolveProviderCompatibility } from "../../provider/providerCompatibility.ts";
76
import * as CodexAdapterV2 from "./CodexAdapterV2.ts";
77
import { withCodexReplayChildMetadata } from "./CodexAdapterV2.testkit.ts";
@@ -886,6 +887,66 @@ describe("CodexAdapterV2 process exit", () => {
887
),
888
),
889
);
890
+
891
+ it.effect("counts the app-server as a running agent until its session closes", () => {
892
+ let runningAgents = 0;
893
+ const factoryLayer = CodexAdapterV2.layerAppServerClientFactory.pipe(
894
+ Layer.provide(
895
+ Layer.mock(PortScanner.PortDiscovery)({
896
+ trackAgent: () => {
897
+ runningAgents += 1;
898
+ return () => {
899
+ runningAgents -= 1;
900
+ };
901
+ },
902
+ }),
903
+ ),
904
+ Layer.provide(
905
+ Layer.succeed(ProviderEventLoggers.ProviderEventLoggers, {
906
+ native: undefined,
907
+ canonical: undefined,
908
+ }),
909
+ ),
910
+ Layer.provide(
911
+ Layer.succeed(
912
+ ChildProcessSpawner.ChildProcessSpawner,
913
+ ChildProcessSpawner.make(() =>
914
+ Effect.succeed(
915
+ ChildProcessSpawner.makeHandle({
916
+ pid: ChildProcessSpawner.ProcessId(999_999_999),
917
+ exitCode: Effect.never,
918
+ isRunning: Effect.succeed(true),
919
+ kill: () => Effect.void,
920
+ unref: Effect.succeed(Effect.void),
921
+ stdin: Sink.drain,
922
+ stdout: Stream.never,
923
+ stderr: Stream.empty,
924
+ all: Stream.empty,
925
+ getInputFd: () => Sink.drain,
926
+ getOutputFd: () => Stream.empty,
927
+ }),
928
+ ),
929
+ ),
930
+ ),
931
+ ),
932
+ );
933
+ return Effect.gen(function* () {
934
+ const factory = yield* CodexAdapterV2.CodexAppServerClientFactory;
935
+ yield* Effect.scoped(
936
+ factory
937
+ .open({
938
+ instanceId: CodexAdapterV2.CODEX_DEFAULT_INSTANCE_ID,
939
+ threadId: ThreadId.make("thread-codex-agent"),
940
+ providerSessionId: ProviderSessionId.make("session-codex-agent"),
941
+ runtimePolicy: CODEX_TEST_RUNTIME_POLICY,
942
+ settings: DEFAULT_CODEX_SETTINGS,
943
+ environment: {},
944
+ })
945
+ .pipe(Effect.tap(() => Effect.sync(() => assert.equal(runningAgents, 1)))),
946
+ );
947
+ assert.equal(runningAgents, 0);
948
+ }).pipe(Effect.provide(factoryLayer));
949
+ });
950
});
951
952
describe("CodexAdapterV2 session initialize", () => {
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+8
-1
@@ -1557,13 +1557,16 @@ function isSensitiveCodexProtocolKey(key: string): boolean {
1557
export const layerAppServerClientFactory: Layer.Layer<
1558
CodexAppServerClientFactory,
1559
never,
1560
- ChildProcessSpawner.ChildProcessSpawner | ProviderEventLoggers.ProviderEventLoggers
1560
+ | ChildProcessSpawner.ChildProcessSpawner
1561
+ | PortScanner.PortDiscovery
1562
+ | ProviderEventLoggers.ProviderEventLoggers
1563
> = Layer.effect(
1564
CodexAppServerClientFactory,
1565
Effect.gen(function* () {
1566
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
1567
const { native: nativeEventLogger } = yield* ProviderEventLoggers.ProviderEventLoggers;
1568
const agentScope = yield* AgentScope;
1569
+ const portDiscovery = yield* PortScanner.PortDiscovery;
1570
1571
return CodexAppServerClientFactory.of({
1572
open: Effect.fn("CodexAdapterV2.open")(function* (input) {
@@ -1591,6 +1594,10 @@ export const layerAppServerClientFactory: Layer.Layer<
1594
}),
1595
),
1596
);
1597
+ // Its shells carry each thread's T3CODE_THREAD_ID, so port discovery reads listeners' threads.
1598
+ yield* Effect.acquireRelease(Effect.sync(portDiscovery.trackAgent), (release) =>
1599
+ Effect.sync(release),
1600
+ );
1601
const protocolLogger = makeCodexAppServerProtocolLogger({
1602
nativeEventLogger,
1603
threadId: input.threadId,