@@ -1309,9 +1309,13 @@ layer("ProviderEventIngestorV2", (it) => {
13091309 } ) ,
13101310 ) ;
13111311
1312- it . effect (
1313- "preserves an answer committed after terminal normalization reads a pending question" ,
1314- ( ) =>
1312+ it . effect . each ( [
1313+ { kind : "user_input" , source : "terminal" } ,
1314+ { kind : "user_input" , source : "callback" } ,
1315+ { kind : "command" , source : "callback" } ,
1316+ ] as const ) (
1317+ "preserves a $kind response committed before a $source cancellation" ,
1318+ ( { kind, source } ) =>
13151319 Effect . scoped (
13161320 Effect . gen ( function * ( ) {
13171321 const eventSink = yield * EventSink . EventSinkV2 ;
@@ -1339,7 +1343,7 @@ layer("ProviderEventIngestorV2", (it) => {
13391343 nodeId,
13401344 providerTurnId,
13411345 nativeRequestRef : null ,
1342- kind : "user_input" ,
1346+ kind,
13431347 status : "pending" ,
13441348 responseCapability : { type : "live" , providerSessionId } ,
13451349 createdAt : now ,
@@ -1351,7 +1355,7 @@ layer("ProviderEventIngestorV2", (it) => {
13511355 runId : null ,
13521356 parentNodeId : null ,
13531357 rootNodeId : nodeId ,
1354- kind : "user_input_request" ,
1358+ kind : kind === "command" ? "approval_request" : "user_input_request" ,
13551359 status : "waiting" ,
13561360 countsForRun : false ,
13571361 providerThreadId,
@@ -1377,9 +1381,9 @@ layer("ProviderEventIngestorV2", (it) => {
13771381 startedAt : now ,
13781382 completedAt : null ,
13791383 updatedAt : now ,
1380- type : "user_input_request" ,
1381- requestId : request . id ,
1382- questions : [ ] ,
1384+ ... ( kind === "command"
1385+ ? { type : "approval_request" , requestId : request . id , requestKind : "command" }
1386+ : { type : "user_input_request" , requestId : request . id , questions : [ ] } ) ,
13831387 } ;
13841388 const seedEvents : Array < OrchestrationV2DomainEvent > = [ threadEvent ] ;
13851389 for ( const payload of [
@@ -1408,35 +1412,71 @@ layer("ProviderEventIngestorV2", (it) => {
14081412 Effect . provide ( Layer . fresh ( ProviderEventIngestor . layer ) ) ,
14091413 Effect . provideService ( EventSink . EventSinkV2 , gatedSink ) ,
14101414 ) ;
1411- const terminal = yield * ingestor
1412- . ingestNormalized ( {
1413- providerSessionId,
1414- providerInstanceId : modelSelection . instanceId ,
1415- threadId,
1416- event : {
1417- type : "provider_turn.updated" ,
1418- driver : CODEX_DRIVER ,
1419- providerTurn : {
1420- id : providerTurnId ,
1421- providerThreadId,
1422- nodeId,
1423- runAttemptId : null ,
1424- nativeTurnRef : null ,
1425- ordinal : 1 ,
1426- status : "completed" ,
1427- startedAt : now ,
1428- completedAt : now ,
1429- } ,
1430- } ,
1431- } )
1432- . pipe ( Effect . forkScoped ) ;
1415+ const terminal = yield * (
1416+ source === "terminal"
1417+ ? ingestor . ingestNormalized ( {
1418+ providerSessionId,
1419+ providerInstanceId : modelSelection . instanceId ,
1420+ threadId,
1421+ event : {
1422+ type : "provider_turn.updated" ,
1423+ driver : CODEX_DRIVER ,
1424+ providerTurn : {
1425+ id : providerTurnId ,
1426+ providerThreadId,
1427+ nodeId,
1428+ runAttemptId : null ,
1429+ nativeTurnRef : null ,
1430+ ordinal : 1 ,
1431+ status : "completed" ,
1432+ startedAt : now ,
1433+ completedAt : now ,
1434+ } ,
1435+ } ,
1436+ } )
1437+ : Effect . forEach (
1438+ [
1439+ {
1440+ type : "runtime_request.updated" as const ,
1441+ driver : CODEX_DRIVER ,
1442+ runtimeRequest : { ...request , status : "cancelled" as const , resolvedAt : now } ,
1443+ } ,
1444+ {
1445+ type : "node.updated" as const ,
1446+ driver : CODEX_DRIVER ,
1447+ node : { ...node , status : "cancelled" as const , completedAt : now } ,
1448+ } ,
1449+ {
1450+ type : "turn_item.updated" as const ,
1451+ driver : CODEX_DRIVER ,
1452+ turnItem : {
1453+ ...item ,
1454+ status : "cancelled" as const ,
1455+ completedAt : now ,
1456+ updatedAt : now ,
1457+ } ,
1458+ } ,
1459+ ] ,
1460+ ( event ) =>
1461+ ingestor . ingestNormalized ( {
1462+ providerSessionId,
1463+ providerInstanceId : modelSelection . instanceId ,
1464+ threadId,
1465+ event,
1466+ } ) ,
1467+ { concurrency : 1 } ,
1468+ ) . pipe ( Effect . map ( ( batches ) => batches . flat ( ) ) )
1469+ ) . pipe ( Effect . forkScoped ) ;
14331470 yield * Deferred . await ( normalized ) ;
1434- const answers = { decision : "Use the existing workspace" } ;
1471+ const response =
1472+ kind === "command"
1473+ ? { decision : "accept" as const }
1474+ : { answers : { decision : "Use the existing workspace" } } ;
14351475 const responseEvents : Array < OrchestrationV2DomainEvent > = [ ] ;
14361476 for ( const payload of [
14371477 {
14381478 type : "runtime-request.updated" as const ,
1439- payload : { ...request , status : "resolved" as const , answers , resolvedAt : now } ,
1479+ payload : { ...request , status : "resolved" as const , ... response , resolvedAt : now } ,
14401480 } ,
14411481 {
14421482 type : "node.updated" as const ,
@@ -1458,12 +1498,13 @@ layer("ProviderEventIngestorV2", (it) => {
14581498 const committedTerminal = yield * Fiber . join ( terminal ) ;
14591499 assert . deepEqual (
14601500 committedTerminal . map ( ( stored ) => stored . event . type ) ,
1461- [ "provider-turn.updated" ] ,
1501+ source === "terminal" ? [ "provider-turn.updated" ] : [ ] ,
14621502 ) ;
14631503 const projection = yield * projections . getThreadProjection ( threadId ) ;
14641504 const answered = projection . runtimeRequests . find ( ( entry ) => entry . id === request . id ) ! ;
14651505 assert . equal ( answered . status , "resolved" ) ;
1466- assert . deepEqual ( answered . answers , answers ) ;
1506+ assert . deepEqual ( answered . answers , "answers" in response ? response . answers : undefined ) ;
1507+ assert . equal ( answered . decision , "decision" in response ? response . decision : undefined ) ;
14671508 assert . equal ( projection . nodes . find ( ( entry ) => entry . id === nodeId ) ! . status , "completed" ) ;
14681509 assert . equal (
14691510 projection . turnItems . find ( ( entry ) => entry . id === item . id ) ! . status ,
0 commit comments