@@ -1111,8 +1111,8 @@ layer("ProviderEventIngestorV2", (it) => {
11111111 } ) ,
11121112 ) ;
11131113
1114- it . effect . each ( [ "interrupted" , "control" ] as const ) (
1115- "dismisses only native questions when a provider turn ends with %s " ,
1114+ it . effect . each ( [ "interrupted" , "failed" , "completed" , "cancelled" , " control"] as const ) (
1115+ "withdraws approvals only when explicitly abandoned (%s) " ,
11161116 ( terminal ) =>
11171117 Effect . gen ( function * ( ) {
11181118 const now = yield * DateTime . now ;
@@ -1227,6 +1227,7 @@ layer("ProviderEventIngestorV2", (it) => {
12271227 providerSessionId,
12281228 providerInstanceId : modelSelection . instanceId ,
12291229 threadId,
1230+ withdrawApprovals : terminal === "control" ,
12301231 event :
12311232 terminal === "control"
12321233 ? {
@@ -1258,7 +1259,10 @@ layer("ProviderEventIngestorV2", (it) => {
12581259 const stored = yield * ingestor . ingestNormalized ( input ) ;
12591260 const projection = yield * projectionStore . getThreadProjection ( threadId ) ;
12601261 for ( const fixture of fixtures ) {
1261- const closed = fixture . key === "native" || fixture . key === "unavailable" ;
1262+ const closed =
1263+ fixture . key === "native" ||
1264+ fixture . key === "unavailable" ||
1265+ ( fixture . key === "approval" && terminal === "control" ) ;
12621266 const request = projection . runtimeRequests . find (
12631267 ( item ) => item . id === fixture . request . id ,
12641268 ) ! ;
@@ -1279,10 +1283,10 @@ layer("ProviderEventIngestorV2", (it) => {
12791283 }
12801284 assert . equal (
12811285 stored . filter ( ( entry ) => entry . event . type === "runtime-request.updated" ) . length ,
1282- 2 ,
1286+ terminal === "control" ? 3 : 2 ,
12831287 ) ;
12841288 assert . isEmpty (
1285- ( yield * projectionStore . getPendingNativeUserInputs ( threadId , providerTurnId ) )
1289+ ( yield * projectionStore . getPendingNativeRuntimeRequests ( threadId , providerTurnId ) )
12861290 . runtimeRequests ,
12871291 ) ;
12881292 const replayed = yield * eventStore . read ( { threadId } ) . pipe ( Stream . runCollect ) ;
@@ -1292,16 +1296,16 @@ layer("ProviderEventIngestorV2", (it) => {
12921296 entry . event . type === "runtime-request.updated" &&
12931297 entry . event . payload . status === "cancelled" ,
12941298 ) . length ,
1295- 2 ,
1299+ terminal === "control" ? 3 : 2 ,
12961300 ) ;
12971301 const repeated = yield * ingestor . ingestNormalized ( input ) ;
12981302 assert . isFalse ( repeated . some ( ( entry ) => entry . event . type === "runtime-request.updated" ) ) ;
12991303 } ) ,
13001304 ) ;
13011305
1302- it . effect (
1303- "preserves an answer committed after terminal normalization reads a pending question " ,
1304- ( ) =>
1306+ it . effect . each ( [ "question" , "approval" ] as const ) (
1307+ "preserves an answer committed after terminal normalization reads a pending %s " ,
1308+ ( kind ) =>
13051309 Effect . scoped (
13061310 Effect . gen ( function * ( ) {
13071311 const eventSink = yield * EventSink . EventSinkV2 ;
@@ -1329,7 +1333,7 @@ layer("ProviderEventIngestorV2", (it) => {
13291333 nodeId,
13301334 providerTurnId,
13311335 nativeRequestRef : null ,
1332- kind : "user_input" ,
1336+ kind : kind === "approval" ? "command" : "user_input" ,
13331337 status : "pending" ,
13341338 responseCapability : { type : "live" , providerSessionId } ,
13351339 createdAt : now ,
@@ -1341,7 +1345,7 @@ layer("ProviderEventIngestorV2", (it) => {
13411345 runId : null ,
13421346 parentNodeId : null ,
13431347 rootNodeId : nodeId ,
1344- kind : "user_input_request" ,
1348+ kind : kind === "approval" ? "approval_request" : "user_input_request" ,
13451349 status : "waiting" ,
13461350 countsForRun : false ,
13471351 providerThreadId,
@@ -1367,9 +1371,9 @@ layer("ProviderEventIngestorV2", (it) => {
13671371 startedAt : now ,
13681372 completedAt : null ,
13691373 updatedAt : now ,
1370- type : "user_input_request" ,
1371- requestId : request . id ,
1372- questions : [ ] ,
1374+ ... ( kind === "approval"
1375+ ? { type : "approval_request" , requestId : request . id , requestKind : "command" }
1376+ : { type : "user_input_request" , requestId : request . id , questions : [ ] } ) ,
13731377 } ;
13741378 const seedEvents : Array < OrchestrationV2DomainEvent > = [ threadEvent ] ;
13751379 for ( const payload of [
@@ -1400,6 +1404,7 @@ layer("ProviderEventIngestorV2", (it) => {
14001404 ) ;
14011405 const terminal = yield * ingestor
14021406 . ingestNormalized ( {
1407+ withdrawApprovals : kind === "approval" ,
14031408 providerSessionId,
14041409 providerInstanceId : modelSelection . instanceId ,
14051410 threadId,
@@ -1422,11 +1427,12 @@ layer("ProviderEventIngestorV2", (it) => {
14221427 . pipe ( Effect . forkScoped ) ;
14231428 yield * Deferred . await ( normalized ) ;
14241429 const answers = { decision : "Use the existing workspace" } ;
1430+ const response = kind === "approval" ? { decision : "accept" as const } : { answers } ;
14251431 const responseEvents : Array < OrchestrationV2DomainEvent > = [ ] ;
14261432 for ( const payload of [
14271433 {
14281434 type : "runtime-request.updated" as const ,
1429- payload : { ...request , status : "resolved" as const , answers , resolvedAt : now } ,
1435+ payload : { ...request , status : "resolved" as const , ... response , resolvedAt : now } ,
14301436 } ,
14311437 {
14321438 type : "node.updated" as const ,
@@ -1453,7 +1459,8 @@ layer("ProviderEventIngestorV2", (it) => {
14531459 const projection = yield * projections . getThreadProjection ( threadId ) ;
14541460 const answered = projection . runtimeRequests . find ( ( entry ) => entry . id === request . id ) ! ;
14551461 assert . equal ( answered . status , "resolved" ) ;
1456- assert . deepEqual ( answered . answers , answers ) ;
1462+ if ( kind === "approval" ) assert . equal ( answered . decision , "accept" ) ;
1463+ else assert . deepEqual ( answered . answers , answers ) ;
14571464 assert . equal ( projection . nodes . find ( ( entry ) => entry . id === nodeId ) ! . status , "completed" ) ;
14581465 assert . equal (
14591466 projection . turnItems . find ( ( entry ) => entry . id === item . id ) ! . status ,
0 commit comments