@@ -1484,69 +1484,71 @@ it.effect("starts a restart sent into a run that Stop reached once the stop sett
14841484) ;
14851485
14861486// regression: #32891 a restart that arrives after the turn ended is lost
1487- it . effect ( "starts a restart that missed the turn as a new turn" , ( ) =>
1488- Effect . scoped (
1489- Effect . gen ( function * ( ) {
1490- const { events, started, steered, layer, startFirstTurn } = yield * nextTurnSelectionHarness (
1491- "restart-after-completion" ,
1492- ) ;
1493- yield * Effect . gen ( function * ( ) {
1494- const orchestrator = yield * Orchestrator . OrchestratorV2 ;
1495- const worker = yield * EffectWorker . OrchestrationEffectWorkerV2 ;
1496- const threadId = yield * startFirstTurn ;
1497- const first = started [ 0 ] ! ;
1498- const settled = yield * orchestrator . streamDomainEvents . pipe (
1499- Stream . filter (
1500- ( event ) =>
1501- event . type === "run.updated" &&
1502- event . payload . id === first . runId &&
1503- event . payload . status === "waiting" ,
1504- ) ,
1505- Stream . take ( 1 ) ,
1506- Stream . runDrain ,
1507- Effect . forkScoped ,
1487+ it . effect . each ( [ "completed" , "interrupted" ] as const ) (
1488+ "starts a restart that missed the turn (%s) as a new turn" ,
1489+ ( status ) =>
1490+ Effect . scoped (
1491+ Effect . gen ( function * ( ) {
1492+ const { events, started, steered, layer, startFirstTurn } = yield * nextTurnSelectionHarness (
1493+ `restart-after-${ status } ` ,
15081494 ) ;
1509- const turn = ( yield * orchestrator . getThreadProjection ( threadId ) ) . providerTurns [ 0 ] ! ;
1510- yield * Queue . offer ( events , {
1511- type : "provider_turn.updated" ,
1512- driver,
1513- providerTurn : { ...turn , status : "completed" , completedAt : yield * DateTime . now } ,
1514- } ) ;
1515- yield * Queue . offer ( events , {
1516- type : "turn.terminal" ,
1517- driver,
1518- providerThreadId : turn . providerThreadId ,
1519- providerTurnId : turn . id ,
1520- runOrdinal : first . runOrdinal ,
1521- status : "completed" ,
1522- failure : null ,
1523- threadDisposition : "reusable" ,
1524- } ) ;
1525- yield * Fiber . join ( settled ) ;
1526- yield * worker . drain ( ) ;
1495+ yield * Effect . gen ( function * ( ) {
1496+ const orchestrator = yield * Orchestrator . OrchestratorV2 ;
1497+ const worker = yield * EffectWorker . OrchestrationEffectWorkerV2 ;
1498+ const threadId = yield * startFirstTurn ;
1499+ const first = started [ 0 ] ! ;
1500+ const settled = yield * orchestrator . streamDomainEvents . pipe (
1501+ Stream . filter (
1502+ ( event ) =>
1503+ event . type === "run.updated" &&
1504+ event . payload . id === first . runId &&
1505+ event . payload . status === ( status === "completed" ? "waiting" : "interrupted" ) ,
1506+ ) ,
1507+ Stream . take ( 1 ) ,
1508+ Stream . runDrain ,
1509+ Effect . forkScoped ,
1510+ ) ;
1511+ const turn = ( yield * orchestrator . getThreadProjection ( threadId ) ) . providerTurns [ 0 ] ! ;
1512+ yield * Queue . offer ( events , {
1513+ type : "provider_turn.updated" ,
1514+ driver,
1515+ providerTurn : { ...turn , status, completedAt : yield * DateTime . now } ,
1516+ } ) ;
1517+ yield * Queue . offer ( events , {
1518+ type : "turn.terminal" ,
1519+ driver,
1520+ providerThreadId : turn . providerThreadId ,
1521+ providerTurnId : turn . id ,
1522+ runOrdinal : first . runOrdinal ,
1523+ status,
1524+ failure : null ,
1525+ threadDisposition : "reusable" ,
1526+ } ) ;
1527+ yield * Fiber . join ( settled ) ;
1528+ yield * worker . drain ( ) ;
15271529
1528- yield * orchestrator . dispatch ( {
1529- type : "message.dispatch" ,
1530- commandId : CommandId . make ( "restart" ) ,
1531- threadId,
1532- messageId : MessageId . make ( "message:restart" ) ,
1533- text : "restart" ,
1534- attachments : [ ] ,
1535- modelSelection : runSelection ,
1536- dispatchMode : { type : "restart_active" , targetRunId : first . runId } ,
1537- createdBy : "user" ,
1538- creationSource : "web" ,
1539- } ) ;
1540- yield * worker . drain ( ) ;
1530+ yield * orchestrator . dispatch ( {
1531+ type : "message.dispatch" ,
1532+ commandId : CommandId . make ( "restart" ) ,
1533+ threadId,
1534+ messageId : MessageId . make ( "message:restart" ) ,
1535+ text : "restart" ,
1536+ attachments : [ ] ,
1537+ modelSelection : runSelection ,
1538+ dispatchMode : { type : "restart_active" , targetRunId : first . runId } ,
1539+ createdBy : "user" ,
1540+ creationSource : "web" ,
1541+ } ) ;
1542+ yield * worker . drain ( ) ;
15411543
1542- assert . deepEqual ( steered , [ ] ) ;
1543- assert . deepEqual (
1544- started . map ( ( turn ) => turn . message . text ) ,
1545- [ "first" , "restart" ] ,
1546- ) ;
1547- } ) . pipe ( Effect . provide ( layer ) ) ;
1548- } ) ,
1549- ) ,
1544+ assert . deepEqual ( steered , [ ] ) ;
1545+ assert . deepEqual (
1546+ started . map ( ( turn ) => turn . message . text ) ,
1547+ [ "first" , "restart" ] ,
1548+ ) ;
1549+ } ) . pipe ( Effect . provide ( layer ) ) ;
1550+ } ) ,
1551+ ) ,
15501552) ;
15511553
15521554it . effect ( "queues a plain send behind the stopped queue and releases its hold" , ( ) =>
0 commit comments