@@ -68,6 +68,7 @@ import {
6868 SECRET_REQUEST_UNSAVED_NOTE ,
6969} from "@t3tools/contracts" ;
7070import { getProviderOptionCurrentValue , withLegacyUltracodeEffort } from "@t3tools/shared/model" ;
71+ import { backgroundWorkHoldsCompletion } from "@t3tools/shared/orchestrationV2PendingBackgroundWork" ;
7172import { runRanAfter } from "@t3tools/shared/orchestrationV2ThreadError" ;
7273import { formatThreadLink } from "@t3tools/shared/threadLinks" ;
7374import {
@@ -814,6 +815,14 @@ function threadPullRequests(
814815 } ) ) ;
815816}
816817
818+ // Awaited background work keeps a thread live after its turn ends, as auto-settle and the sidebar treat it.
819+ function listedThreadStatus ( shell : OrchestrationV2ThreadShell ) {
820+ if ( shell . activityRunStatus != null ) return shell . activityRunStatus ;
821+ return backgroundWorkHoldsCompletion ( shell . pendingBackgroundTasks ?? [ ] )
822+ ? "waiting"
823+ : shell . status ;
824+ }
825+
817826function listItemFromShell (
818827 scope : McpInvocationScope ,
819828 shell : OrchestrationV2ThreadShell ,
@@ -826,7 +835,7 @@ function listItemFromShell(
826835 link : threadLinkFor ( scope , shell . id , shell . title ) ,
827836 createdBy : shell . createdBy ,
828837 creationSource : shell . creationSource ,
829- status : shell . activityRunStatus ?? shell . status ,
838+ status : listedThreadStatus ( shell ) ,
830839 latestRunId : shell . latestRunId ,
831840 providerInstanceId : shell . modelSelection . instanceId ,
832841 model : shell . modelSelection . model ,
@@ -2978,9 +2987,7 @@ const make = Effect.gen(function* () {
29782987 : new Set ( input . statuses ) ;
29792988 const titleContains = input . titleContains ?. toLocaleLowerCase ( ) ;
29802989 const filtered = projectThreads
2981- . filter (
2982- ( thread ) => statuses === null || statuses . has ( thread . activityRunStatus ?? thread . status ) ,
2983- )
2990+ . filter ( ( thread ) => statuses === null || statuses . has ( listedThreadStatus ( thread ) ) )
29842991 . filter (
29852992 ( thread ) =>
29862993 input . settled === undefined || threadSettlement ( thread ) . settled === input . settled ,
0 commit comments