@@ -5138,6 +5138,73 @@ describe("CodexAdapterV2 post-settle continuation", () => {
51385138 ) ,
51395139 ) ;
51405140
5141+ const MCP_APP_DEFERRED_RESULT = {
5142+ content : [ { type : "text" , text : "An interactive form is being shown to the user." } ] ,
5143+ structuredContent : { status : "awaiting_user_submission" } ,
5144+ } ;
5145+ const mcpAppDeferredTranscript = makeCodexReplayTranscript ( {
5146+ scenario : MCP_APP_SCENARIO ,
5147+ entries : mcpAppTranscript . entries . map ( ( entry ) =>
5148+ entry . type === "emit_inbound" && entry . label === "item/completed/app-tool"
5149+ ? {
5150+ ...entry ,
5151+ frame : {
5152+ method : "item/completed" ,
5153+ params : {
5154+ item : {
5155+ ...mcpAppToolItem ( "inProgress" ) ,
5156+ status : "failed" ,
5157+ result : MCP_APP_DEFERRED_RESULT ,
5158+ } ,
5159+ threadId : MCP_APP_NATIVE_THREAD ,
5160+ turnId : MCP_APP_NATIVE_TURN ,
5161+ completedAtMs : 1782622441500 ,
5162+ } ,
5163+ } ,
5164+ }
5165+ : entry ,
5166+ ) ,
5167+ } ) ;
5168+
5169+ it . effect ( "captures the app of a tool call that defers to its form" , ( ) =>
5170+ Effect . scoped (
5171+ Effect . gen ( function * ( ) {
5172+ const appCaptured = yield * Deferred . make < OrchestrationV2TurnItem > ( ) ;
5173+ const harness = yield * makeCodexReplayHarness ( mcpAppDeferredTranscript , ( event ) =>
5174+ event . type === "turn_item.updated" &&
5175+ event . turnItem . type === "dynamic_tool" &&
5176+ event . turnItem . status === "failed"
5177+ ? Deferred . succeed ( appCaptured , event . turnItem )
5178+ : Effect . void ,
5179+ ) ;
5180+ const now = yield * DateTime . now ;
5181+
5182+ yield * harness . runtime . startTurn (
5183+ makeCodexTestTurnInput ( {
5184+ threadId : harness . threadId ,
5185+ providerThread : harness . providerThread ,
5186+ now,
5187+ attemptId : RunAttemptId . make ( "attempt-codex-mcp-app-deferred" ) ,
5188+ text : MCP_APP_PROMPT ,
5189+ } ) ,
5190+ ) ;
5191+ const item = yield * Deferred . await ( appCaptured ) ;
5192+
5193+ const output = item . type === "dynamic_tool" ? ( item . output as Record < string , unknown > ) : { } ;
5194+ assert . equal (
5195+ readMcpAppReference ( output [ MCP_APP_OUTPUT_KEY ] ) ?. resourceUri ,
5196+ MCP_APP_RESOURCE ,
5197+ ) ;
5198+ assert . deepEqual ( output . result , { ...MCP_APP_DEFERRED_RESULT , isError : true } ) ;
5199+ assert . isFalse ( yield * harness . hasPendingBackgroundWork ) ;
5200+ } ) . pipe (
5201+ Effect . provide (
5202+ Layer . mergeAll ( IdAllocator . layer , McpProviderSessions . layer , NodeServices . layer ) ,
5203+ ) ,
5204+ ) ,
5205+ ) ,
5206+ ) ;
5207+
51415208 const ORPHAN_WAIT_SCENARIO = "codex-orphaned-dynamic-tool" ;
51425209 const ORPHAN_WAIT_NATIVE_THREAD = "native-codex-orphan-wait-thread" ;
51435210 const ORPHAN_WAIT_NATIVE_TURN = "native-codex-orphan-wait-turn" ;
0 commit comments