GeezerVison is showing github.com — fix(server): dev servers a Codex agent starts show under its thread (… · pingdotgg/t3code@b7add5a
File treeExpand file treeCollapse file tree Open diff view settings apps/server/src/orchestration-v2/Adapters
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts +61Lines changed: 61 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -71,6 +71,7 @@ import * as ProviderReplayHarness from "../testkit/ProviderReplayHarness.ts"; | 71 | 71 | import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; | 72 | 72 | import type * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests"; | 73 | 73 | import * as ModelManifest from "../../provider/ModelManifest.ts"; | | 74 | +import * as PortScanner from "../../preview/PortScanner.ts"; | 74 | 75 | import { resolveProviderCompatibility } from "../../provider/providerCompatibility.ts"; | 75 | 76 | import * as CodexAdapterV2 from "./CodexAdapterV2.ts"; | 76 | 77 | import { withCodexReplayChildMetadata } from "./CodexAdapterV2.testkit.ts"; | @@ -886,6 +887,66 @@ describe("CodexAdapterV2 process exit", () => { | 886 | 887 | ), | 887 | 888 | ), | 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 | + }); | 889 | 950 | }); | 890 | 951 |
| 891 | 952 | describe("CodexAdapterV2 session initialize", () => { | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1557,13 +1557,16 @@ function isSensitiveCodexProtocolKey(key: string): boolean { | 1557 | 1557 | export const layerAppServerClientFactory: Layer.Layer< | 1558 | 1558 | CodexAppServerClientFactory, | 1559 | 1559 | never, | 1560 | | - ChildProcessSpawner.ChildProcessSpawner | ProviderEventLoggers.ProviderEventLoggers | | 1560 | + | ChildProcessSpawner.ChildProcessSpawner | | 1561 | + | PortScanner.PortDiscovery | | 1562 | + | ProviderEventLoggers.ProviderEventLoggers | 1561 | 1563 | > = Layer.effect( | 1562 | 1564 | CodexAppServerClientFactory, | 1563 | 1565 | Effect.gen(function* () { | 1564 | 1566 | const spawner = yield* ChildProcessSpawner.ChildProcessSpawner; | 1565 | 1567 | const { native: nativeEventLogger } = yield* ProviderEventLoggers.ProviderEventLoggers; | 1566 | 1568 | const agentScope = yield* AgentScope; | | 1569 | + const portDiscovery = yield* PortScanner.PortDiscovery; | 1567 | 1570 |
| 1568 | 1571 | return CodexAppServerClientFactory.of({ | 1569 | 1572 | open: Effect.fn("CodexAdapterV2.open")(function* (input) { | @@ -1591,6 +1594,10 @@ export const layerAppServerClientFactory: Layer.Layer< | 1591 | 1594 | }), | 1592 | 1595 | ), | 1593 | 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 | + ); | 1594 | 1601 | const protocolLogger = makeCodexAppServerProtocolLogger({ | 1595 | 1602 | nativeEventLogger, | 1596 | 1603 | threadId: input.threadId, | |
|