@@ -1422,66 +1422,89 @@ it.effect("retries a failed workspace preparation on the same run", () => {
14221422 } ) . pipe ( Effect . provide ( harness . layer ) ) ;
14231423} ) ;
14241424
1425- it . effect ( "holds a message queued during setup when the workspace preparation fails" , ( ) =>
1426- Effect . gen ( function * ( ) {
1427- const allowFetch = yield * Deferred . make < void > ( ) ;
1428- const harness = makeHarness ( {
1429- fetchRemote : ( ) =>
1430- Deferred . await ( allowFetch ) . pipe (
1431- Effect . andThen (
1432- Effect . fail (
1433- new GitCommandError ( {
1434- operation : "GitVcsDriver.fetchRemote" ,
1435- command : "git" ,
1436- cwd : project . workspaceRoot ,
1437- detail : "Git could not reach the remote." ,
1438- exitCode : 128 ,
1439- } ) ,
1440- ) ,
1441- ) ,
1442- ) ,
1443- } ) ;
1444- yield * Effect . gen ( function * ( ) {
1445- const launches = yield * ThreadLaunch . ThreadLaunchService ;
1446- const threads = yield * ThreadManagement . ThreadManagementService ;
1447- const launched = yield * launches . launch (
1448- launchInput ( {
1449- command : "command:launch:queued-failed-setup" ,
1450- thread : "thread:launch:queued-failed-setup" ,
1451- message : "First message" ,
1452- workspace : { type : "worktree" , baseRef : "main" , startFromOrigin : true } ,
1453- } ) ,
1454- ) ;
1455- const queued = yield * threads . sendToThread ( {
1456- projectId,
1457- commandId : CommandId . make ( "command:launch:queued-failed-setup:follow-up" ) ,
1458- threadId : launched . threadId ,
1459- messageId : MessageId . make ( "message:launch:queued-failed-setup:follow-up" ) ,
1460- text : "Sent during setup" ,
1461- attachments : [ ] ,
1462- mode : "queue" ,
1463- createdBy : "user" ,
1464- creationSource : "web" ,
1425+ it . effect . each ( [ "fails" , "is interrupted" ] as const ) (
1426+ "holds a message queued during setup when the workspace preparation %s" ,
1427+ ( ending ) =>
1428+ Effect . gen ( function * ( ) {
1429+ const allowFetch = yield * Deferred . make < void > ( ) ;
1430+ let fetchFailures = 1 ;
1431+ const harness = makeHarness ( {
1432+ fetchRemote : ( ) =>
1433+ fetchFailures -- <= 0
1434+ ? Effect . void
1435+ : Deferred . await ( allowFetch ) . pipe (
1436+ Effect . andThen (
1437+ Effect . fail (
1438+ new GitCommandError ( {
1439+ operation : "GitVcsDriver.fetchRemote" ,
1440+ command : "git" ,
1441+ cwd : project . workspaceRoot ,
1442+ detail : "Git could not reach the remote." ,
1443+ exitCode : 128 ,
1444+ } ) ,
1445+ ) ,
1446+ ) ,
1447+ ) ,
14651448 } ) ;
1466- assert . equal ( queued . delivery , "queued" ) ;
1467- yield * Deferred . succeed ( allowFetch , undefined ) ;
1449+ yield * Effect . gen ( function * ( ) {
1450+ const launches = yield * ThreadLaunch . ThreadLaunchService ;
1451+ const threads = yield * ThreadManagement . ThreadManagementService ;
1452+ const launched = yield * launches . launch (
1453+ launchInput ( {
1454+ command : `command:launch:queued-setup-${ ending } ` ,
1455+ thread : `thread:launch:queued-setup-${ ending } ` ,
1456+ message : "First message" ,
1457+ workspace : { type : "worktree" , baseRef : "main" , startFromOrigin : true } ,
1458+ } ) ,
1459+ ) ;
1460+ const queued = yield * threads . sendToThread ( {
1461+ projectId,
1462+ commandId : CommandId . make ( `command:launch:queued-setup-${ ending } :follow-up` ) ,
1463+ threadId : launched . threadId ,
1464+ messageId : MessageId . make ( `message:launch:queued-setup-${ ending } :follow-up` ) ,
1465+ text : "Sent during setup" ,
1466+ attachments : [ ] ,
1467+ mode : "queue" ,
1468+ createdBy : "user" ,
1469+ creationSource : "web" ,
1470+ } ) ;
1471+ assert . equal ( queued . delivery , "queued" ) ;
1472+ if ( ending === "fails" ) {
1473+ yield * Deferred . succeed ( allowFetch , undefined ) ;
1474+ } else {
1475+ // An agent stop does not ask to hold the queue.
1476+ yield * threads . dispatch ( {
1477+ type : "run.interrupt" ,
1478+ commandId : CommandId . make ( "command:launch:queued-setup-interrupt" ) ,
1479+ threadId : launched . threadId ,
1480+ runId : launched . projection . runs [ 0 ] ! . id ,
1481+ } ) ;
1482+ }
14681483
1469- // Without its worktree the follow-up would start in the project checkout.
1470- yield * threads . streamStoredEventsFrom ( { threadId : launched . threadId } ) . pipe (
1471- Stream . filter (
1472- ( stored ) =>
1473- stored . event . type === "run.updated" && stored . event . payload . queueHeld === true ,
1474- ) ,
1475- Stream . runHead ,
1476- ) ;
1477- const projection = yield * threads . getThreadProjection ( launched . threadId ) ;
1478- assert . deepEqual (
1479- projection . runs . map ( ( run ) => run . status ) ,
1480- [ "failed" , "queued" ] ,
1481- ) ;
1482- assert . equal ( projection . thread . worktreePath , null ) ;
1483- } ) . pipe ( Effect . provide ( harness . layer ) ) ;
1484- } ) ,
1484+ // Without its worktree the follow-up would start in the project checkout.
1485+ yield * threads . streamStoredEventsFrom ( { threadId : launched . threadId } ) . pipe (
1486+ Stream . filter (
1487+ ( stored ) =>
1488+ stored . event . type === "run.updated" && stored . event . payload . queueHeld === true ,
1489+ ) ,
1490+ Stream . runHead ,
1491+ ) ;
1492+ const projection = yield * threads . getThreadProjection ( launched . threadId ) ;
1493+ assert . equal ( projection . runs . at ( - 1 ) ?. status , "queued" ) ;
1494+ assert . equal ( projection . thread . worktreePath , null ) ;
1495+
1496+ if ( ending === "fails" ) {
1497+ // A successful retry lets the held message follow the first turn again.
1498+ yield * launches . retryPreparation ( {
1499+ commandId : CommandId . make ( "command:launch:queued-setup-retry" ) ,
1500+ threadId : launched . threadId ,
1501+ runId : launched . projection . runs [ 0 ] ! . id ,
1502+ } ) ;
1503+ const retried = yield * threads . getThreadProjection ( launched . threadId ) ;
1504+ assert . equal ( retried . runs . at ( - 1 ) ?. queueHeld , false ) ;
1505+ }
1506+ } ) . pipe ( Effect . provide ( harness . layer ) ) ;
1507+ } ) ,
14851508) ;
14861509
14871510it . effect ( "a retry reuses a recorded worktree without undoing its branch rename" , ( ) => {
0 commit comments