@@ -598,6 +598,7 @@ export async function runBabysitPiWithOptions(
598598
599599 let latestThreads : BabysitThreadsState | undefined
600600 let latestChecks : BabysitCheckState | undefined
601+ let lastKnownChecksGreen = false
601602 let githubWriteOccurred = false
602603 try {
603604 if ( signal . aborted ) throw new Error ( 'Pi run aborted' )
@@ -617,6 +618,7 @@ export async function runBabysitPiWithOptions(
617618 }
618619 latestThreads = await fetchBabysitThreads ( params , signal )
619620 latestChecks = await fetchBabysitCheckState ( params , pinnedHeadSha , undefined , signal )
621+ lastKnownChecksGreen = latestChecks . checksGreen
620622 const initialRequirements = latestChecks . contextRequirements
621623 if ( latestChecks . startupFailure ) {
622624 const threadsClean =
@@ -726,6 +728,7 @@ export async function runBabysitPiWithOptions(
726728 initialRequirements ,
727729 signal
728730 )
731+ lastKnownChecksGreen = latestChecks . checksGreen
729732 if ( reviewRequest && ! reviewRequest . landed ) {
730733 reviewRequest . landed = await babysitReviewLandedSince (
731734 params ,
@@ -853,6 +856,7 @@ export async function runBabysitPiWithOptions(
853856 githubWriteOccurred = true
854857 progress . changedFiles = finalized . changedFiles
855858 progress . diff = finalized . diff
859+ lastKnownChecksGreen = ! [ ...initialRequirements . values ( ) ] . some ( ( required ) => required )
856860 let convergence : Awaited < ReturnType < typeof waitForHeadConvergence > >
857861 try {
858862 convergence = await waitForHeadConvergence (
@@ -938,6 +942,16 @@ export async function runBabysitPiWithOptions(
938942 laggingHeadSha
939943 )
940944 progress . threadsResolved += writeResult . threadsResolved
945+ const resolvedThreadIds = new Set ( writeResult . resolvedThreadIds ?? [ ] )
946+ if ( resolvedThreadIds . size > 0 ) {
947+ latestThreads = {
948+ ...latestThreads ,
949+ actionable : latestThreads . actionable . filter (
950+ ( thread ) => ! resolvedThreadIds . has ( thread . id )
951+ ) ,
952+ totalUnresolved : Math . max ( 0 , latestThreads . totalUnresolved - resolvedThreadIds . size ) ,
953+ }
954+ }
941955 githubWriteOccurred ||= writeResult . repliesPosted > 0 || writeResult . threadsResolved > 0
942956 if ( writeResult . replyFailures . length ) {
943957 progress . notes . push ( `${ writeResult . replyFailures . length } thread replies failed.` )
@@ -951,7 +965,15 @@ export async function runBabysitPiWithOptions(
951965 )
952966 }
953967 if ( writeResult . stopReason ) {
954- return resultFor ( totals , writeResult . stopReason , progress , threadsClean , false )
968+ const knownThreadsClean =
969+ latestThreads . actionable . length === 0 && latestThreads . skipped . length === 0
970+ return resultFor (
971+ totals ,
972+ writeResult . stopReason ,
973+ progress ,
974+ knownThreadsClean ,
975+ lastKnownChecksGreen
976+ )
955977 }
956978 if ( writeResult . phaseError ) {
957979 progress . notes . push (
@@ -964,15 +986,27 @@ export async function runBabysitPiWithOptions(
964986 totals ,
965987 finalized . commitPushed ? 'pushed_awaiting_confirmation' : 'agent_failure' ,
966988 progress ,
967- threadsClean ,
968- false
989+ latestThreads . actionable . length === 0 && latestThreads . skipped . length === 0 ,
990+ lastKnownChecksGreen
969991 )
970992 }
971993 if ( writeResult . headMoved ) {
972- return resultFor ( totals , 'head_moved' , progress , threadsClean , false )
994+ return resultFor (
995+ totals ,
996+ 'head_moved' ,
997+ progress ,
998+ latestThreads . actionable . length === 0 && latestThreads . skipped . length === 0 ,
999+ lastKnownChecksGreen
1000+ )
9731001 }
9741002 if ( writeResult . awaitingConfirmation ) {
975- return resultFor ( totals , 'pushed_awaiting_confirmation' , progress , threadsClean , false )
1003+ return resultFor (
1004+ totals ,
1005+ 'pushed_awaiting_confirmation' ,
1006+ progress ,
1007+ latestThreads . actionable . length === 0 && latestThreads . skipped . length === 0 ,
1008+ lastKnownChecksGreen
1009+ )
9761010 }
9771011
9781012 if ( finalized . commitPushed && params . reviewMentions . length > 0 ) {
@@ -1016,6 +1050,7 @@ export async function runBabysitPiWithOptions(
10161050 initialRequirements ,
10171051 signal
10181052 )
1053+ lastKnownChecksGreen = latestChecks . checksGreen
10191054 if ( reviewRequest ) {
10201055 reviewRequest . landed = await babysitReviewLandedSince (
10211056 params ,
@@ -1089,7 +1124,7 @@ export async function runBabysitPiWithOptions(
10891124 githubError . reason as BabysitStopReason ,
10901125 progress ,
10911126 threadsClean ,
1092- latestChecks ?. checksGreen ?? false
1127+ lastKnownChecksGreen
10931128 )
10941129 }
10951130 if ( githubWriteOccurred ) {
@@ -1103,8 +1138,10 @@ export async function runBabysitPiWithOptions(
11031138 totals ,
11041139 progress . commitsPushed > 0 ? 'pushed_awaiting_confirmation' : 'agent_failure' ,
11051140 progress ,
1106- false ,
1107- false
1141+ ! ! latestThreads &&
1142+ latestThreads . actionable . length === 0 &&
1143+ latestThreads . skipped . length === 0 ,
1144+ lastKnownChecksGreen
11081145 )
11091146 }
11101147 throw createScrubbedPiError ( error , secrets , 'Babysit failed' )
0 commit comments