@@ -1959,6 +1959,77 @@ it.effect("shared intake preserves durable attachment bytes after a lost launch
19591959 } ) . pipe ( Effect . provide ( Layer . mergeAll ( harness . layer , files ) ) ) ;
19601960} ) ;
19611961
1962+ it . effect ( "fails preparation completed while archived and accepts a new send after unarchive" , ( ) =>
1963+ Effect . gen ( function * ( ) {
1964+ const setupEntered = yield * Deferred . make < void > ( ) ;
1965+ const allowSetup = yield * Deferred . make < void > ( ) ;
1966+ const harness = makeHarness ( {
1967+ runSetup : ( ) =>
1968+ Deferred . succeed ( setupEntered , undefined ) . pipe (
1969+ Effect . andThen ( Deferred . await ( allowSetup ) ) ,
1970+ Effect . as ( { status : "no-script" as const } ) ,
1971+ ) ,
1972+ } ) ;
1973+ yield * Effect . gen ( function * ( ) {
1974+ const launches = yield * ThreadLaunch . ThreadLaunchService ;
1975+ const threads = yield * ThreadManagement . ThreadManagementService ;
1976+ const outbox = yield * EffectOutbox . EffectOutboxV2 ;
1977+ const input = launchInput ( {
1978+ command : "launch:archive-during-setup" ,
1979+ thread : "thread:archive-during-setup" ,
1980+ message : "Start" ,
1981+ } ) ;
1982+ const launched = yield * launches . launch ( input ) ;
1983+ yield * Deferred . await ( setupEntered ) ;
1984+ yield * threads . dispatch ( {
1985+ type : "thread.archive" ,
1986+ commandId : CommandId . make ( "archive:during-setup" ) ,
1987+ threadId : launched . threadId ,
1988+ } ) ;
1989+ yield * Deferred . succeed ( allowSetup , undefined ) ;
1990+ yield * threads . streamStoredEventsFrom ( { threadId : launched . threadId } ) . pipe (
1991+ Stream . filter (
1992+ ( stored ) =>
1993+ ( stored . commandId === CommandId . make ( `${ input . commandId } :fail` ) ||
1994+ stored . commandId === CommandId . make ( `${ input . commandId } :release` ) ) &&
1995+ stored . event . type === "run.updated" ,
1996+ ) ,
1997+ Stream . runHead ,
1998+ ) ;
1999+ const failed = yield * threads . getThreadProjection ( launched . threadId ) ;
2000+ assert . equal ( failed . runs [ 0 ] ?. status , "failed" ) ;
2001+ assert . isEmpty ( failed . providerTurns ) ;
2002+ assert . isEmpty ( failed . checkpointScopes ) ;
2003+ assert . isEmpty ( yield * outbox . listByCommandId ( CommandId . make ( `${ input . commandId } :release` ) ) ) ;
2004+
2005+ yield * threads . dispatch ( {
2006+ type : "thread.unarchive" ,
2007+ commandId : CommandId . make ( "unarchive:after-setup" ) ,
2008+ threadId : launched . threadId ,
2009+ } ) ;
2010+ const next = yield * threads . sendToThread ( {
2011+ projectId,
2012+ commandId : CommandId . make ( "send:after-unarchive" ) ,
2013+ threadId : launched . threadId ,
2014+ messageId : MessageId . make ( "message:after-unarchive" ) ,
2015+ text : "Try again" ,
2016+ attachments : [ ] ,
2017+ mode : "auto" ,
2018+ createdBy : "user" ,
2019+ creationSource : "web" ,
2020+ } ) ;
2021+ assert . equal ( next . delivery , "started" ) ;
2022+ assert . equal ( next . run . status , "starting" ) ;
2023+ assert . notEqual ( next . run . id , failed . runs [ 0 ] ?. id ) ;
2024+ assert . isTrue (
2025+ ( yield * outbox . listByCommandId ( CommandId . make ( "send:after-unarchive" ) ) ) . some (
2026+ ( entry ) => entry . request . type === "provider-turn.start" ,
2027+ ) ,
2028+ ) ;
2029+ } ) . pipe ( Effect . provide ( harness . layer ) ) ;
2030+ } ) ,
2031+ ) ;
2032+
19622033it . effect ( "cancels tracked setup before provider work is released" , ( ) =>
19632034 Effect . gen ( function * ( ) {
19642035 const entered = yield * Deferred . make < void > ( ) ;
0 commit comments