@@ -1920,6 +1920,62 @@ it.effect.each([
19201920 ) ,
19211921) ;
19221922
1923+ // regression: #32891 a restart into a failed provider turn is lost
1924+ it . effect ( "queues a restart sent into a provider turn that failed before its run settled" , ( ) =>
1925+ Effect . scoped (
1926+ Effect . gen ( function * ( ) {
1927+ const { events, started, steered, layer, startFirstTurn } = yield * nextTurnSelectionHarness (
1928+ "restart-after-failed-unsettled" ,
1929+ ) ;
1930+ yield * Effect . gen ( function * ( ) {
1931+ const orchestrator = yield * Orchestrator . OrchestratorV2 ;
1932+ const worker = yield * EffectWorker . OrchestrationEffectWorkerV2 ;
1933+ const threadId = yield * startFirstTurn ;
1934+ const first = started [ 0 ] ! ;
1935+ const turn = ( yield * orchestrator . getThreadProjection ( threadId ) ) . providerTurns [ 0 ] ! ;
1936+ const turnFailed = yield * orchestrator . streamDomainEvents . pipe (
1937+ Stream . filter (
1938+ ( event ) =>
1939+ event . type === "provider-turn.updated" &&
1940+ event . payload . id === turn . id &&
1941+ event . payload . status === "failed" ,
1942+ ) ,
1943+ Stream . take ( 1 ) ,
1944+ Stream . runDrain ,
1945+ Effect . forkScoped ,
1946+ ) ;
1947+ yield * Queue . offer ( events , {
1948+ type : "provider_turn.updated" ,
1949+ driver,
1950+ providerTurn : { ...turn , status : "failed" , completedAt : yield * DateTime . now } ,
1951+ } ) ;
1952+ yield * Fiber . join ( turnFailed ) ;
1953+
1954+ yield * orchestrator . dispatch ( {
1955+ type : "message.dispatch" ,
1956+ commandId : CommandId . make ( "restart" ) ,
1957+ threadId,
1958+ messageId : MessageId . make ( "message:restart" ) ,
1959+ text : "restart" ,
1960+ attachments : [ ] ,
1961+ modelSelection : runSelection ,
1962+ dispatchMode : { type : "restart_active" , targetRunId : first . runId } ,
1963+ createdBy : "user" ,
1964+ creationSource : "web" ,
1965+ } ) ;
1966+ yield * worker . drain ( ) ;
1967+
1968+ assert . deepEqual ( steered , [ ] ) ;
1969+ const projection = yield * orchestrator . getThreadProjection ( threadId ) ;
1970+ assert . equal (
1971+ projection . runs . find ( ( run ) => run . userMessageId === "message:restart" ) ?. status ,
1972+ "queued" ,
1973+ ) ;
1974+ } ) . pipe ( Effect . provide ( layer ) ) ;
1975+ } ) ,
1976+ ) ,
1977+ ) ;
1978+
19231979it . effect ( "queues a plain send behind the stopped queue and releases its hold" , ( ) =>
19241980 Effect . scoped (
19251981 Effect . gen ( function * ( ) {
0 commit comments