Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

CodexSessionRuntime.test.ts

853 lines24.9 KB

1import * as NodeAssert from "node:assert/strict";
2​
3import { it } from "@effect/vitest";
4import * as Effect from "effect/Effect";
5import * as Schema from "effect/Schema";
6import { describe } from "vite-plus/test";
7import { DEFAULT_MODEL, ThreadId } from "@t3tools/contracts";
8import * as CodexErrors from "effect-codex-app-server/errors";
9import * as CodexRpc from "effect-codex-app-server/rpc";
10import * as EffectCodexSchema from "effect-codex-app-server/schema";
11​
12import {
13 buildCodexDeveloperInstructions,
14 codexDefaultModeDeveloperInstructions,
15 codexPlanModeDeveloperInstructions,
16} from "../CodexDeveloperInstructions.ts";
17import { codexSessionAppServerArgs } from "./codexLaunchArgs.ts";
18import {
19 buildTurnStartParams,
20 describeMcpElicitation,
21 hasConfiguredMcpServer,
22 isRecoverableThreadResumeError,
23 makeMemoryConsolidationNotificationFilter,
24 openCodexThread,
25 toMcpElicitationResponse,
26} from "./CodexSessionRuntime.ts";
27const isCodexAppServerRequestError = Schema.is(CodexErrors.CodexAppServerRequestError);
28​
29describe("CodexSessionRuntimeIdentifierGenerationError", () => {
30 it("retains identifier purpose and the random source failure", () => {
31 const cause = new Error("random source unavailable");
32 const error = new CodexErrors.CodexAppServerIdentifierGenerationError({
33 purpose: "provider-event",
34 cause,
35 });
36​
37 NodeAssert.equal(error.purpose, "provider-event");
38 NodeAssert.strictEqual(error.cause, cause);
39 NodeAssert.equal(
40 error.message,
41 "Failed to generate Codex App Server identifier for provider-event.",
42 );
43 });
44});
45​
46function makeThreadOpenResponse(
47 threadId: string,
48): CodexRpc.ClientRequestResponsesByMethod["thread/start"] {
49 return {
50 cwd: "/tmp/project",
51 model: "gpt-5.3-codex",
52 modelProvider: "openai",
53 approvalPolicy: "never",
54 approvalsReviewer: "user",
55 sandbox: { type: "danger-full-access" },
56 thread: {
57 id: threadId,
58 createdAt: "2026-04-18T00:00:00.000Z",
59 source: { session: "cli" },
60 turns: [],
61 status: {
62 state: "idle",
63 activeFlags: [],
64 },
65 },
66 } as unknown as CodexRpc.ClientRequestResponsesByMethod["thread/start"];
68​
69describe("buildTurnStartParams", () => {
70 it("keeps invalid turn values only in the schema cause", () => {
71 const secret = "codex-turn-input-secret-sentinel";
72 const error = Effect.runSync(
73 buildTurnStartParams({
74 threadId: "provider-thread-1",
75 runtimeMode: "full-access",
76 attachments: [
77 {
78 type: "image",
79 url: { secret } as unknown as string,
80 },
81 ],
82 }).pipe(Effect.flip),
83 );
84 const { cause, ...directDiagnostics } = error;
85​
86 NodeAssert.equal(error.operation, "decode-request-payload");
87 NodeAssert.equal(error.method, "turn/start");
88 NodeAssert.ok((error.issueCount ?? 0) > 0);
89 NodeAssert.ok(error.issueKinds?.includes("Pointer"));
90 NodeAssert.ok((error.maximumPathDepth ?? 0) > 0);
91 NodeAssert.ok(Schema.isSchemaError(cause));
92 NodeAssert.doesNotMatch(error.message, new RegExp(secret));
93 NodeAssert.doesNotMatch(JSON.stringify(directDiagnostics), new RegExp(secret));
94 });
95​
96 it("includes plan collaboration mode when requested", () => {
97 const params = Effect.runSync(
98 buildTurnStartParams({
99 threadId: "provider-thread-1",
100 runtimeMode: "full-access",
101 prompt: "Make a plan",
102 model: "gpt-5.3-codex",
103 effort: "medium",
104 interactionMode: "plan",
105 }),
106 );
107​
108 NodeAssert.deepStrictEqual(params, {
109 threadId: "provider-thread-1",
110 approvalPolicy: "never",
111 approvalsReviewer: "user",
112 sandboxPolicy: {
113 type: "dangerFullAccess",
114 },
115 input: [
116 {
117 type: "text",
118 text: "Make a plan",
119 },
120 ],
121 model: "gpt-5.3-codex",
122 effort: "medium",
123 collaborationMode: {
124 mode: "plan",
125 settings: {
126 model: "gpt-5.3-codex",
127 reasoning_effort: "medium",
128 developer_instructions: buildCodexDeveloperInstructions("plan", {
129 model: "gpt-5.3-codex",
130 reasoningEffort: "medium",
131 }),
132 },
133 },
134 });
135 });
136​
137 it("includes default collaboration mode and image attachments", () => {
138 const params = Effect.runSync(
139 buildTurnStartParams({
140 threadId: "provider-thread-1",
141 runtimeMode: "auto-accept-edits",
142 prompt: "Implement it",
143 model: "gpt-5.3-codex",
144 interactionMode: "default",
145 attachments: [
146 {
147 type: "image",
148 url: "data:image/png;base64,abc",
149 },
150 ],
151 }),
152 );
153​
154 NodeAssert.deepStrictEqual(params, {
155 threadId: "provider-thread-1",
156 approvalPolicy: "on-request",
157 approvalsReviewer: "user",
158 sandboxPolicy: {
159 type: "workspaceWrite",
160 },
161 input: [
162 {
163 type: "text",
164 text: "Implement it",
165 },
166 {
167 type: "image",
168 url: "data:image/png;base64,abc",
169 },
170 ],
171 model: "gpt-5.3-codex",
172 collaborationMode: {
173 mode: "default",
174 settings: {
175 model: "gpt-5.3-codex",
176 reasoning_effort: "medium",
177 developer_instructions: buildCodexDeveloperInstructions("default", {
178 model: "gpt-5.3-codex",
179 reasoningEffort: "medium",
180 }),
181 },
182 },
183 });
184 });
185​
186 it("reports the same fallback model and effort in settings and instructions", () => {
187 const params = Effect.runSync(
188 buildTurnStartParams({
189 threadId: "provider-thread-1",
190 runtimeMode: "full-access",
191 prompt: "Go",
192 interactionMode: "default",
193 }),
194 );
195​
196 const settings = params.collaborationMode?.settings;
197 NodeAssert.equal(settings?.model, DEFAULT_MODEL);
198 NodeAssert.equal(settings?.reasoning_effort, "medium");
199 NodeAssert.ok(settings?.developer_instructions?.includes(`as ${DEFAULT_MODEL} with medium`));
200 });
201​
202 it.effect("routes approvals to the auto reviewer in auto mode", () =>
203 Effect.gen(function* () {
204 const params = yield* buildTurnStartParams({
205 threadId: "provider-thread-1",
206 runtimeMode: "auto",
207 prompt: "Ship it",
208 });
209​
210 NodeAssert.deepStrictEqual(params, {
211 threadId: "provider-thread-1",
212 approvalPolicy: "on-request",
213 approvalsReviewer: "auto_review",
214 sandboxPolicy: {
215 type: "workspaceWrite",
216 },
217 input: [
218 {
219 type: "text",
220 text: "Ship it",
221 },
222 ],
223 });
224 }),
225 );
226​
227 it("omits collaboration mode when interaction mode is absent", () => {
228 const params = Effect.runSync(
229 buildTurnStartParams({
230 threadId: "provider-thread-1",
231 runtimeMode: "approval-required",
232 prompt: "Review",
233 }),
234 );
235​
236 NodeAssert.deepStrictEqual(params, {
237 threadId: "provider-thread-1",
238 approvalPolicy: "untrusted",
239 approvalsReviewer: "user",
240 sandboxPolicy: {
241 type: "readOnly",
242 },
243 input: [
244 {
245 type: "text",
246 text: "Review",
247 },
248 ],
249 });
250 });
251});
252​
253describe("Codex MCP elicitation approvals", () => {
254 const request = {
255 mode: "form",
256 message: "Allow ChatGPT to use Safari?",
257 serverName: "computer-use",
258 threadId: "provider-thread-1",
259 turnId: "turn-1",
260 _meta: {
261 app_name: "Safari",
262 persist: ["session", "always"],
263 },
264 requestedSchema: {
265 type: "object",
266 properties: {
267 approval: {
268 type: "string",
269 oneOf: [
270 { const: "once", title: "Allow once" },
271 { const: "session", title: "Allow for this session" },
272 { const: "always", title: "Always allow Safari" },
273 ],
274 },
275 },
276 required: ["approval"],
277 },
278 } satisfies EffectCodexSchema.McpServerElicitationRequestParams;
279​
280 it("preserves the app name and advertised persistence choices", () => {
281 NodeAssert.deepStrictEqual(describeMcpElicitation(request), {
282 appName: "Safari",
283 options: [
284 { decision: "cancel", label: "Cancel" },
285 { decision: "decline", label: "Decline" },
286 { decision: "acceptForSession", label: "Allow for this session" },
287 { decision: "acceptAlways", label: "Always allow Safari" },
288 { decision: "accept", label: "Approve" },
289 ],
290 });
291 });
292​
293 it("extracts the app name from a Computer Use request without metadata", () => {
294 const { _meta, ...requestWithoutMetadata } = request;
295​
296 NodeAssert.equal(describeMcpElicitation(requestWithoutMetadata).appName, "Safari");
297 });
298​
299 it("returns the accepted form option to Codex", () => {
300 NodeAssert.deepStrictEqual(toMcpElicitationResponse(request, "accept"), {
301 action: "accept",
302 content: { approval: "once" },
303 });
304 });
305​
306 it("returns session-scoped approval in the MCP response", () => {
307 NodeAssert.deepStrictEqual(toMcpElicitationResponse(request, "acceptForSession"), {
308 action: "accept",
309 _meta: { persist: "session" },
310 content: { approval: "session" },
311 });
312 });
313​
314 it("returns persistent approval in the MCP response", () => {
315 NodeAssert.deepStrictEqual(toMcpElicitationResponse(request, "acceptAlways"), {
316 action: "accept",
317 _meta: { persist: "always" },
318 content: { approval: "always" },
319 });
320 });
321​
322 it("returns rejection without form content", () => {
323 NodeAssert.deepStrictEqual(toMcpElicitationResponse(request, "decline"), {
324 action: "decline",
325 });
326 });
327​
328 it("returns cancellation without form content", () => {
329 NodeAssert.deepStrictEqual(toMcpElicitationResponse(request, "cancel"), {
330 action: "cancel",
331 });
332 });
333​
334 it("supports boolean permanent-approval fields", () => {
335 const booleanRequest = {
336 ...request,
337 _meta: { app_name: "Safari" },
338 requestedSchema: {
339 type: "object",
340 properties: {
341 always: { type: "boolean", title: "Always allow Safari" },
342 },
343 },
344 } satisfies EffectCodexSchema.McpServerElicitationRequestParams;
345​
346 NodeAssert.ok(
347 describeMcpElicitation(booleanRequest).options.some(
348 (option) => option.decision === "acceptAlways",
349 ),
350 );
351 NodeAssert.deepStrictEqual(toMcpElicitationResponse(booleanRequest, "acceptAlways"), {
352 action: "accept",
353 _meta: { persist: "always" },
354 content: { always: true },
355 });
356 });
357​
358 it("preserves valid nullable MCP form fields and persistence choices", () => {
359 const nullableRequest = {
360 ...request,
361 _meta: {
362 app_name: null,
363 appName: "Safari",
364 connector_name: null,
365 persist: null,
366 target: null,
367 tool_params: null,
368 },
369 requestedSchema: {
370 type: "object",
371 properties: {
372 approval: {
373 type: "string",
374 title: null,
375 description: null,
376 default: null,
377 enum: ["once", "always"],
378 enumNames: null,
379 },
380 },
381 required: ["approval"],
382 },
383 } satisfies EffectCodexSchema.McpServerElicitationRequestParams;
384​
385 NodeAssert.equal(describeMcpElicitation(nullableRequest).appName, "Safari");
386 NodeAssert.ok(
387 describeMcpElicitation(nullableRequest).options.some(
388 (option) => option.decision === "acceptAlways",
389 ),
390 );
391 NodeAssert.deepStrictEqual(toMcpElicitationResponse(nullableRequest, "acceptAlways"), {
392 action: "accept",
393 _meta: { persist: "always" },
394 content: { approval: "always" },
395 });
396 });
397​
398 it("declines required form fields that an approval prompt cannot collect", () => {
399 const inputRequest = {
400 ...request,
401 requestedSchema: {
402 type: "object",
403 properties: {
404 email: { type: "string", format: "email" },
405 },
406 required: ["email"],
407 },
408 } satisfies EffectCodexSchema.McpServerElicitationRequestParams;
409​
410 NodeAssert.deepStrictEqual(toMcpElicitationResponse(inputRequest, "accept"), {
411 action: "decline",
412 });
413 });
414​
415 it("does not approve URL elicitations without opening their requested URL", () => {
416 const urlRequest = {
417 mode: "url",
418 message: "Finish signing in to continue.",
419 serverName: "computer-use",
420 threadId: "provider-thread-1",
421 turnId: "turn-1",
422 elicitationId: "sign-in-1",
423 url: "https://example.com/authorize",
424 } satisfies EffectCodexSchema.McpServerElicitationRequestParams;
425​
426 NodeAssert.deepStrictEqual(toMcpElicitationResponse(urlRequest, "accept"), {
427 action: "decline",
428 });
429 });
430​
431 it("omits persistence choices that cannot satisfy required form fields", () => {
432 const onceOnlyRequest = {
433 ...request,
434 _meta: { app_name: "Safari", persist: ["session", "always"] },
435 requestedSchema: {
436 type: "object",
437 properties: {
438 approval: {
439 type: "string",
440 enum: ["once"],
441 },
442 },
443 required: ["approval"],
444 },
445 } satisfies EffectCodexSchema.McpServerElicitationRequestParams;
446​
447 NodeAssert.deepStrictEqual(describeMcpElicitation(onceOnlyRequest).options, [
448 { decision: "cancel", label: "Cancel" },
449 { decision: "decline", label: "Decline" },
450 { decision: "accept", label: "Approve" },
451 ]);
452 });
453});
454​
455describe("buildCodexDeveloperInstructions", () => {
456 it("appends runtime info after the mode instructions", () => {
457 const instructions = buildCodexDeveloperInstructions("default", {
458 model: "gpt-5.3-codex",
459 reasoningEffort: "high",
460 });
461​
462 NodeAssert.ok(instructions.startsWith(codexDefaultModeDeveloperInstructions(true)));
463 NodeAssert.match(instructions, /T3 Code/);
464 NodeAssert.match(instructions, /Codex harness/);
465 NodeAssert.match(instructions, /as gpt-5\.3-codex with high reasoning effort/);
466 });
467​
468 it("includes runtime info alongside plan mode instructions", () => {
469 const instructions = buildCodexDeveloperInstructions("plan", {
470 model: "gpt-5.3-codex",
471 reasoningEffort: "medium",
472 });
473​
474 NodeAssert.ok(instructions.startsWith(codexPlanModeDeveloperInstructions(true)));
475 NodeAssert.match(instructions, /as gpt-5\.3-codex with medium reasoning effort/);
476 });
477​
478 it("varies with the model and effort of each turn", () => {
479 const first = buildCodexDeveloperInstructions("default", {
480 model: "gpt-5.3-codex",
481 reasoningEffort: "medium",
482 });
483 const second = buildCodexDeveloperInstructions("default", {
484 model: "gpt-5.4",
485 reasoningEffort: "high",
486 });
487​
488 NodeAssert.notEqual(first, second);
489 });
490​
491 it("flattens multiline metadata into single-line runtime info", () => {
492 const instructions = buildCodexDeveloperInstructions("default", {
493 model: "gpt\n5.3\ncodex",
494 reasoningEffort: " high\neffort ",
495 });
496​
497 NodeAssert.match(instructions, /as gpt 5\.3 codex with high effort reasoning effort/);
498 NodeAssert.doesNotMatch(instructions, /<runtime_info>[^<]*\n/);
499 });
500});
501​
502describe("T3 browser developer instructions", () => {
503 it("prefers the product-native preview tools in both collaboration modes", () => {
504 for (const instructions of [
505 codexDefaultModeDeveloperInstructions(true),
506 codexPlanModeDeveloperInstructions(true),
507 ]) {
508 NodeAssert.match(instructions, /t3-code/);
509 NodeAssert.match(instructions, /preview_status/);
510 NodeAssert.match(instructions, /preview_open/);
511 NodeAssert.match(instructions, /Do not switch to global browser skills/);
512 }
513 });
514​
515 it("omits the browser block entirely when the preview tools are not attached", () => {
516 for (const instructions of [
517 codexDefaultModeDeveloperInstructions(false),
518 codexPlanModeDeveloperInstructions(false),
519 ]) {
520 NodeAssert.doesNotMatch(instructions, /preview_status/);
521 NodeAssert.doesNotMatch(instructions, /preview_open/);
522 NodeAssert.doesNotMatch(instructions, /T3 Code collaborative browser/);
523 // Steering away from other browser automation must go with the tools;
524 // keeping it would leave the model talked out of its only option.
525 NodeAssert.doesNotMatch(instructions, /Do not switch to global browser skills/);
526 // The rest of the collaboration mode is untouched.
527 NodeAssert.match(instructions, /<collaboration_mode>/);
528 NodeAssert.match(instructions, /<\/collaboration_mode>/);
529 }
530 });
531​
532 it("tracks the turn's MCP configuration rather than defaulting to on", () => {
533 const runtime = { model: "gpt-5.3-codex", reasoningEffort: "high" };
534 NodeAssert.match(buildCodexDeveloperInstructions("default", runtime, true), /preview_open/);
535 NodeAssert.doesNotMatch(
536 buildCodexDeveloperInstructions("default", runtime, false),
537 /preview_open/,
538 );
539 });
540});
541​
542describe("hasConfiguredMcpServer", () => {
543 it("detects inline Codex MCP configuration arguments", () => {
544 NodeAssert.equal(hasConfiguredMcpServer(undefined), false);
545 NodeAssert.equal(hasConfiguredMcpServer(["--model", "gpt-5.4"]), false);
546 NodeAssert.equal(
547 hasConfiguredMcpServer(["-c", 'mcp_servers.t3-code.url="http://127.0.0.1/mcp"']),
548 true,
549 );
550 });
551});
552​
553function makeThreadStartedNotification(
554 threadId: string,
555 source: EffectCodexSchema.V2ThreadStartedNotification["thread"]["source"],
556 threadSource?: string,
557) {
558 return {
559 method: "thread/started" as const,
560 params: {
561 thread: {
562 cliVersion: "0.0.0",
563 createdAt: 0,
564 cwd: "/tmp/project",
565 ephemeral: true,
566 id: threadId,
567 modelProvider: "openai",
568 preview: "",
569 sessionId: threadId,
570 source,
571 status: { type: "idle" as const },
572 ...(threadSource ? { threadSource } : {}),
573 turns: [],
574 updatedAt: 0,
575 },
576 },
577 };
579​
580describe("makeMemoryConsolidationNotificationFilter", () => {
581 it("suppresses memory consolidation without hiding other Codex subagents", () => {
582 const shouldSuppress = makeMemoryConsolidationNotificationFilter();
583​
584 NodeAssert.equal(
585 shouldSuppress(
586 makeThreadStartedNotification("memory-thread", "unknown", "memory_consolidation"),
587 ),
588 true,
589 );
590 NodeAssert.equal(
591 shouldSuppress({
592 method: "item/agentMessage/delta",
593 params: {
594 delta: "internal memory update",
595 itemId: "memory-message",
596 threadId: "memory-thread",
597 turnId: "memory-turn",
598 },
599 }),
600 true,
601 );
602 NodeAssert.equal(
603 shouldSuppress({
604 method: "serverRequest/resolved",
605 params: {
606 requestId: "memory-approval",
607 threadId: "memory-thread",
608 },
609 }),
610 false,
611 );
612 NodeAssert.equal(
613 shouldSuppress({
614 method: "warning",
615 params: {
616 message: "internal warning",
617 threadId: "memory-thread",
618 },
619 }),
620 true,
621 );
622 NodeAssert.equal(
623 shouldSuppress({
624 method: "item/agentMessage/delta",
625 params: {
626 delta: "normal reply",
627 itemId: "root-message",
628 threadId: "root-thread",
629 turnId: "root-turn",
630 },
631 }),
632 false,
633 );
634​
635 NodeAssert.equal(
636 shouldSuppress(
637 makeThreadStartedNotification("legacy-memory-thread", {
638 subAgent: "memory_consolidation",
639 }),
640 ),
641 true,
642 );
643​
644 for (const source of [
645 { subAgent: "review" as const },
646 { subAgent: "compact" as const },
647 {
648 subAgent: {
649 thread_spawn: {
650 depth: 1,
651 parent_thread_id: "root-thread",
652 },
653 },
654 },
655 ]) {
656 NodeAssert.equal(
657 shouldSuppress(makeThreadStartedNotification("visible-subagent", source)),
658 false,
659 );
660 }
661 });
662​
663 it("forgets memory consolidation threads after they close", () => {
664 const shouldSuppress = makeMemoryConsolidationNotificationFilter();
665 shouldSuppress(
666 makeThreadStartedNotification("memory-thread", "unknown", "memory_consolidation"),
667 );
668​
669 NodeAssert.equal(
670 shouldSuppress({
671 method: "thread/closed",
672 params: { threadId: "memory-thread" },
673 }),
674 true,
675 );
676 NodeAssert.equal(
677 shouldSuppress({
678 method: "item/agentMessage/delta",
679 params: {
680 delta: "later message",
681 itemId: "later-message",
682 threadId: "memory-thread",
683 turnId: "later-turn",
684 },
685 }),
686 false,
687 );
688 });
689});
690​
691describe("codexSessionAppServerArgs", () => {
692 it("keeps the app-server subcommand when explicit args are provided", () => {
693 NodeAssert.deepStrictEqual(codexSessionAppServerArgs(["-c", "model=gpt-5"], undefined), [
694 "app-server",
695 "-c",
696 "model=gpt-5",
697 ]);
698 });
699​
700 it("keeps launch args when explicit app-server args are provided", () => {
701 NodeAssert.deepStrictEqual(
702 codexSessionAppServerArgs(
703 ["-c", "mcp_servers.t3-code.url=http://127.0.0.1/mcp"],
704 "--strict-config --enable foo",
705 ),
706 [
707 "app-server",
708 "--strict-config",
709 "--enable",
710 "foo",
711 "-c",
712 "mcp_servers.t3-code.url=http://127.0.0.1/mcp",
713 ],
714 );
715 });
716});
717​
718describe("isRecoverableThreadResumeError", () => {
719 it("matches missing thread errors", () => {
720 NodeAssert.equal(
721 isRecoverableThreadResumeError(
722 new CodexErrors.CodexAppServerRequestError({
723 code: -32603,
724 errorMessage: "Thread does not exist",
725 }),
726 ),
727 true,
728 );
729 });
730​
731 it("matches a missing rollout for a known thread id", () => {
732 NodeAssert.equal(
733 isRecoverableThreadResumeError(
734 new CodexErrors.CodexAppServerRequestError({
735 code: -32603,
736 errorMessage: "no rollout found for thread id 019fdf74-aaa9-7950-b252-7cc7a8650470",
737 }),
738 ),
739 true,
740 );
741 });
742​
743 it("ignores non-recoverable resume errors", () => {
744 NodeAssert.equal(
745 isRecoverableThreadResumeError(
746 new CodexErrors.CodexAppServerRequestError({
747 code: -32603,
748 errorMessage: "Permission denied",
749 }),
750 ),
751 false,
752 );
753 });
754​
755 it("ignores unrelated missing-resource errors that do not mention threads", () => {
756 NodeAssert.equal(
757 isRecoverableThreadResumeError(
758 new CodexErrors.CodexAppServerRequestError({
759 code: -32603,
760 errorMessage: "Config file not found",
761 }),
762 ),
763 false,
764 );
765 NodeAssert.equal(
766 isRecoverableThreadResumeError(
767 new CodexErrors.CodexAppServerRequestError({
768 code: -32603,
769 errorMessage: "Model does not exist",
770 }),
771 ),
772 false,
773 );
774 });
775});
776​
777describe("openCodexThread", () => {
778 it.effect("falls back to thread/start when resume fails recoverably", () =>
779 Effect.gen(function* () {
780 const calls: Array<{ method: "thread/start" | "thread/resume"; payload: unknown }> = [];
781 const started = makeThreadOpenResponse("fresh-thread");
782 const client = {
783 request: <M extends "thread/start" | "thread/resume">(
784 method: M,
785 payload: CodexRpc.ClientRequestParamsByMethod[M],
786 ) => {
787 calls.push({ method, payload });
788 if (method === "thread/resume") {
789 return Effect.fail(
790 new CodexErrors.CodexAppServerRequestError({
791 code: -32603,
792 errorMessage: "thread not found",
793 }),
794 );
795 }
796 return Effect.succeed(started as CodexRpc.ClientRequestResponsesByMethod[M]);
797 },
798 };
799​
800 const opened = yield* openCodexThread({
801 client,
802 threadId: ThreadId.make("thread-1"),
803 runtimeMode: "full-access",
804 cwd: "/tmp/project",
805 requestedModel: "gpt-5.3-codex",
806 serviceTier: undefined,
807 resumeThreadId: "stale-thread",
808 });
809​
810 NodeAssert.equal(opened.thread.id, "fresh-thread");
811 NodeAssert.deepStrictEqual(
812 calls.map((call) => call.method),
813 ["thread/resume", "thread/start"],
814 );
815 }),
816 );
817​
818 it.effect("propagates non-recoverable resume failures", () =>
819 Effect.gen(function* () {
820 const client = {
821 request: <M extends "thread/start" | "thread/resume">(
822 method: M,
823 _payload: CodexRpc.ClientRequestParamsByMethod[M],
824 ) => {
825 if (method === "thread/resume") {
826 return Effect.fail(
827 new CodexErrors.CodexAppServerRequestError({
828 code: -32603,
829 errorMessage: "timed out waiting for server",
830 }),
831 );
832 }
833 return Effect.succeed(
834 makeThreadOpenResponse("fresh-thread") as CodexRpc.ClientRequestResponsesByMethod[M],
835 );
836 },
837 };
838​
839 const error = yield* openCodexThread({
840 client,
841 threadId: ThreadId.make("thread-1"),
842 runtimeMode: "full-access",
843 cwd: "/tmp/project",
844 requestedModel: "gpt-5.3-codex",
845 serviceTier: undefined,
846 resumeThreadId: "stale-thread",
847 }).pipe(Effect.flip);
848​
849 NodeAssert.ok(isCodexAppServerRequestError(error));
850 NodeAssert.equal(error.errorMessage, "timed out waiting for server");
851 }),
852 );
853});