@@ -1231,6 +1231,136 @@ it.layer(layerTest)("OrchestrationV2LayerLive", (it) => {
12311231 } ) ,
12321232 ) ;
12331233
1234+ it . effect ( "reports an answer that never reaches its provider without reopening it" , ( ) =>
1235+ Effect . gen ( function * ( ) {
1236+ const orchestrator = yield * Orchestrator . OrchestratorV2 ;
1237+ const eventSink = yield * EventSink . EventSinkV2 ;
1238+ const outbox = yield * EffectOutbox . EffectOutboxV2 ;
1239+ const worker = yield * EffectWorker . OrchestrationEffectWorkerV2 ;
1240+ const now = yield * DateTime . now ;
1241+ const threadId = ThreadId . make ( "runtime-lost-answer" ) ;
1242+ // Projected as attached, but no live session holds it, so every delivery fails.
1243+ const providerSessionId = ProviderSessionId . make ( "runtime-lost-answer-session" ) ;
1244+ const requestId = RuntimeRequestId . make ( "runtime-lost-answer-request" ) ;
1245+ const nodeId = NodeId . make ( "runtime-lost-answer-node" ) ;
1246+ yield * orchestrator . dispatch ( {
1247+ type : "thread.create" ,
1248+ commandId : CommandId . make ( "runtime-lost-answer-create" ) ,
1249+ createdBy : "user" ,
1250+ creationSource : "web" ,
1251+ threadId,
1252+ projectId : ProjectId . make ( "runtime-lost-answer-project" ) ,
1253+ title : "Lost answer" ,
1254+ modelSelection,
1255+ runtimeMode : "full-access" ,
1256+ interactionMode : "default" ,
1257+ branch : null ,
1258+ worktreePath : process . cwd ( ) ,
1259+ } ) ;
1260+ yield * eventSink . write ( {
1261+ commandId : CommandId . make ( "runtime-lost-answer-seed" ) ,
1262+ events : [
1263+ {
1264+ id : EventId . make ( "runtime-lost-answer-session-event" ) ,
1265+ type : "provider-session.attached" ,
1266+ threadId,
1267+ driver,
1268+ occurredAt : now ,
1269+ payload : {
1270+ id : providerSessionId ,
1271+ driver,
1272+ providerInstanceId : modelSelection . instanceId ,
1273+ status : "running" ,
1274+ cwd : process . cwd ( ) ,
1275+ model : modelSelection . model ,
1276+ capabilities : CodexProviderCapabilitiesV2 ,
1277+ createdAt : now ,
1278+ updatedAt : now ,
1279+ lastError : null ,
1280+ } ,
1281+ } ,
1282+ {
1283+ id : EventId . make ( "runtime-lost-answer-node-event" ) ,
1284+ type : "node.updated" ,
1285+ threadId,
1286+ nodeId,
1287+ occurredAt : now ,
1288+ payload : {
1289+ id : nodeId ,
1290+ threadId,
1291+ runId : null ,
1292+ parentNodeId : null ,
1293+ rootNodeId : nodeId ,
1294+ kind : "user_input_request" ,
1295+ status : "waiting" ,
1296+ countsForRun : false ,
1297+ providerThreadId : null ,
1298+ providerTurnId : null ,
1299+ nativeItemRef : null ,
1300+ runtimeRequestId : requestId ,
1301+ checkpointScopeId : null ,
1302+ startedAt : now ,
1303+ completedAt : null ,
1304+ } ,
1305+ } ,
1306+ {
1307+ id : EventId . make ( "runtime-lost-answer-request-event" ) ,
1308+ type : "runtime-request.updated" ,
1309+ threadId,
1310+ nodeId,
1311+ occurredAt : now ,
1312+ payload : {
1313+ id : requestId ,
1314+ nodeId,
1315+ providerTurnId : null ,
1316+ nativeRequestRef : null ,
1317+ kind : "user_input" ,
1318+ status : "pending" ,
1319+ responseCapability : { type : "live" , providerSessionId } ,
1320+ createdAt : now ,
1321+ resolvedAt : null ,
1322+ } ,
1323+ } ,
1324+ ] ,
1325+ } ) ;
1326+ const commandId = CommandId . make ( "runtime-lost-answer-answer" ) ;
1327+ const answers = { color : "Blue" } ;
1328+ yield * orchestrator . dispatch ( {
1329+ type : "runtime-request.respond" ,
1330+ commandId,
1331+ threadId,
1332+ requestId,
1333+ answers,
1334+ } ) ;
1335+ const errors = orchestrator
1336+ . getThreadProjection ( threadId )
1337+ . pipe (
1338+ Effect . map ( ( projection ) => projection . turnItems . filter ( ( item ) => item . type === "error" ) ) ,
1339+ ) ;
1340+
1341+ // A delivery that can still be retried reports nothing.
1342+ yield * worker . drain ( ) ;
1343+ assert . deepEqual ( yield * errors , [ ] ) ;
1344+ for ( let attempt = 1 ; attempt < 5 ; attempt ++ ) {
1345+ yield * TestClock . adjust ( "30 seconds" ) ;
1346+ yield * worker . drain ( ) ;
1347+ }
1348+
1349+ const [ deliveryEffect ] = yield * outbox . listByCommandId ( commandId ) ;
1350+ assert . equal ( deliveryEffect ?. request . type , "runtime-request.respond" ) ;
1351+ assert . equal ( deliveryEffect ?. status , "failed" ) ;
1352+ const failed = yield * orchestrator . getThreadProjection ( threadId ) ;
1353+ const reported = failed . turnItems . filter ( ( item ) => item . type === "error" ) ;
1354+ assert . equal ( reported . length , 1 ) ;
1355+ assert . equal ( reported [ 0 ] ?. status , "failed" ) ;
1356+ assert . equal ( reported [ 0 ] ?. nodeId , nodeId ) ;
1357+ // The answer stays recorded; the user is not asked again.
1358+ const request = failed . runtimeRequests . find ( ( row ) => row . id === requestId ) ;
1359+ assert . equal ( request ?. status , "resolved" ) ;
1360+ assert . deepEqual ( request ?. answers , answers ) ;
1361+ } ) ,
1362+ ) ;
1363+
12341364 it . effect ( "dismisses message-capable questions directly and while settling" , ( ) =>
12351365 Effect . gen ( function * ( ) {
12361366 const orchestrator = yield * Orchestrator . OrchestratorV2 ;
0 commit comments