|
4 | 4 | ChatAttachmentId, |
5 | 5 | ChatFileAttachment, |
6 | 6 | CommandId, |
| 7 | + EnvironmentId, |
7 | 8 | EventId, |
8 | 9 | MessageId, |
9 | 10 | NodeId, |
@@ -36,7 +37,12 @@ import * as Layer from "effect/Layer"; |
36 | 37 | import * as Option from "effect/Option"; |
37 | 38 | import * as Ref from "effect/Ref"; |
38 | 39 | import * as Stream from "effect/Stream"; |
| 40 | +import { HttpServer } from "effect/http"; |
| 41 | +import * as NetAddress from "effect/net/NetAddress"; |
| 42 | +import * as TestClock from "effect/testing/TestClock"; |
| 43 | +import * as NodeServices from "@effect/platform-node/NodeServices"; |
39 | 44 |
|
| 45 | +import * as ServerEnvironment from "../environment/ServerEnvironment.ts"; |
40 | 46 | import * as McpSessionRegistry from "../mcp/McpSessionRegistry.ts"; |
41 | 47 | import * as ServerSettings from "../serverSettings.ts"; |
42 | 48 | import * as CheckpointService from "./CheckpointService.ts"; |
@@ -1030,6 +1036,109 @@ it.effect("refreshes MCP credential liveness before calling the provider", () => |
1030 | 1036 | }).pipe(Effect.provide(layerRunExecutionTest)), |
1031 | 1037 | ); |
1032 | 1038 |
|
| 1039 | +const layerMcpSessionRegistryTest = McpSessionRegistry.layer.pipe( |
| 1040 | + Layer.provide( |
| 1041 | + Layer.mergeAll( |
| 1042 | + NodeServices.layer, |
| 1043 | + Layer.succeed( |
| 1044 | + HttpServer.HttpServer, |
| 1045 | + HttpServer.HttpServer.of({ |
| 1046 | + address: NetAddress.inetAddressFromIpStringUnsafe("127.0.0.1", 43123), |
| 1047 | + serve: (() => Effect.void) as HttpServer.HttpServer["Service"]["serve"], |
| 1048 | + }), |
| 1049 | + ), |
| 1050 | + Layer.succeed( |
| 1051 | + ServerEnvironment.ServerEnvironment, |
| 1052 | + ServerEnvironment.ServerEnvironment.of({ |
| 1053 | + getEnvironmentId: Effect.succeed(EnvironmentId.make("environment:mcp-heartbeat")), |
| 1054 | + getDescriptor: Effect.die("unused"), |
| 1055 | + }), |
| 1056 | + ), |
| 1057 | + ), |
| 1058 | + ), |
| 1059 | +); |
| 1060 | + |
| 1061 | +it.effect.each([ |
| 1062 | + ["keeps the MCP credential alive while the turn waits on the user", Stream.never, true], |
| 1063 | + [ |
| 1064 | + "lets the MCP credential expire once the provider event stream ends", |
| 1065 | + // The provider exits two hours into the turn. |
| 1066 | + Stream.fromEffect(Effect.sleep("2 hours")).pipe(Stream.drain), |
| 1067 | + false, |
| 1068 | + ], |
| 1069 | +] as const)("%s", ([, events, tokenSurvives]) => |
| 1070 | + Effect.gen(function* () { |
| 1071 | + const runExecution = yield* RunExecutionService.RunExecutionServiceV2; |
| 1072 | + const registry = yield* McpSessionRegistry.McpSessionRegistry; |
| 1073 | + const threadId = ThreadId.make("thread:run-execution-mcp-heartbeat"); |
| 1074 | + const issued = yield* registry.issue({ |
| 1075 | + threadId, |
| 1076 | + providerInstanceId: ProviderInstanceId.make("codex"), |
| 1077 | + capabilities: new Set(), |
| 1078 | + }); |
| 1079 | + const token = issued.config.authorizationHeader.replace(/^Bearer\s+/, ""); |
| 1080 | + |
| 1081 | + yield* runExecution.startRootRun({ |
| 1082 | + commandId: CommandId.make("command:run-execution-mcp-heartbeat"), |
| 1083 | + appThread: { id: threadId } as OrchestrationV2AppThread, |
| 1084 | + providerSessionId: ProviderSessionId.make(issued.config.providerSessionId), |
| 1085 | + session: { |
| 1086 | + events, |
| 1087 | + startTurn: () => Effect.void, |
| 1088 | + } as unknown as ProviderAdapter.ProviderAdapterV2SessionRuntime, |
| 1089 | + run: { |
| 1090 | + id: RunId.make("run:run-execution-mcp-heartbeat"), |
| 1091 | + threadId, |
| 1092 | + ordinal: 1, |
| 1093 | + providerInstanceId: ProviderInstanceId.make("codex"), |
| 1094 | + } as OrchestrationV2Run, |
| 1095 | + rootNode: { |
| 1096 | + id: NodeId.make("node:run-execution-mcp-heartbeat"), |
| 1097 | + } as OrchestrationV2ExecutionNode, |
| 1098 | + checkpointScope: { |
| 1099 | + id: CheckpointScopeId.make("checkpoint-scope:run-execution-mcp-heartbeat"), |
| 1100 | + } as OrchestrationV2CheckpointScope, |
| 1101 | + providerThread: { |
| 1102 | + id: ProviderThreadId.make("provider-thread:run-execution-mcp-heartbeat"), |
| 1103 | + driver, |
| 1104 | + } as OrchestrationV2ProviderThread, |
| 1105 | + attempt: { |
| 1106 | + id: RunAttemptId.make("attempt:run-execution-mcp-heartbeat"), |
| 1107 | + providerTurnId: null, |
| 1108 | + } as OrchestrationV2RunAttempt, |
| 1109 | + attemptId: RunAttemptId.make("attempt:run-execution-mcp-heartbeat"), |
| 1110 | + providerTurnOrdinal: 1, |
| 1111 | + message: { |
| 1112 | + messageId: MessageId.make("message:run-execution-mcp-heartbeat"), |
| 1113 | + text: "Ask me something and wait.", |
| 1114 | + attachments: [], |
| 1115 | + createdBy: "user", |
| 1116 | + creationSource: "web", |
| 1117 | + }, |
| 1118 | + modelSelection: { |
| 1119 | + instanceId: ProviderInstanceId.make("codex"), |
| 1120 | + model: "gpt-5.4", |
| 1121 | + }, |
| 1122 | + runtimePolicy: { |
| 1123 | + runtimeMode: "full-access", |
| 1124 | + interactionMode: "default", |
| 1125 | + cwd: process.cwd(), |
| 1126 | + approvalPolicy: "never", |
| 1127 | + sandboxPolicy: { |
| 1128 | + type: "readOnly", |
| 1129 | + access: { type: "fullAccess" }, |
| 1130 | + networkAccess: false, |
| 1131 | + }, |
| 1132 | + }, |
| 1133 | + }); |
| 1134 | + // The report in #14076 answered a question 44 hours into the turn. |
| 1135 | + yield* TestClock.adjust("44 hours"); |
| 1136 | + |
| 1137 | + const resolved = yield* registry.resolve(token); |
| 1138 | + assert.equal(resolved?.thread.threadId === threadId, tokenSurvives); |
| 1139 | + }).pipe(Effect.provide(Layer.merge(layerRunExecutionTest, layerMcpSessionRegistryTest))), |
| 1140 | +); |
| 1141 | + |
1033 | 1142 | it.effect("starts the provider when checkpoint baseline capture fails", () => |
1034 | 1143 | Effect.gen(function* () { |
1035 | 1144 | const threadId = ThreadId.make("thread:run-execution-baseline-failure"); |
|
0 commit comments