@@ -992,7 +992,7 @@ interface ActiveAcpTurn {
992992 | undefined ;
993993 contextUsage : ThreadTokenUsageSnapshot | null ;
994994 nativeMetadata : OrchestrationV2ProviderThreadNativeMetadata | null ;
995- readonly tools : Map < string , AcpToolCallState > ;
995+ readonly tools : Map < string , AcpToolCallState & { readonly backgroundCommandTaskId ?: string } > ;
996996 readonly toolUpdatesSkipped : Map < string , number > ;
997997 readonly toolStartedAt : Map < string , DateTime . Utc > ;
998998 readonly subagents : Map < string , ActiveAcpSubagent > ;
@@ -2860,28 +2860,36 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
28602860 const merged = mergeToolCallState ( previous , incoming ) ;
28612861 const normalized = flavor . normalizeToolCall ?.( merged ) ?? merged ;
28622862 const backgroundTaskId = flavor . extractBackgroundTaskId ?.( normalized ) ;
2863+ const backgroundCommandTaskId =
2864+ flavor . isBackgroundCommandTool ?.( normalized ) === true
2865+ ? backgroundTaskId
2866+ : previous ?. backgroundCommandTaskId ;
28632867 if (
2864- backgroundTaskId !== undefined &&
2865- flavor . isBackgroundCommandTool ?.( normalized ) === true &&
2866- ! context . backgroundCommands . has ( backgroundTaskId )
2868+ backgroundCommandTaskId !== undefined &&
2869+ ! context . backgroundCommands . has ( backgroundCommandTaskId )
28672870 ) {
2868- context . backgroundCommands . set ( backgroundTaskId , null ) ;
2871+ context . backgroundCommands . set ( backgroundCommandTaskId , null ) ;
28692872 }
28702873 const completion =
2871- context . promptSettled && backgroundTaskId !== undefined
2872- ? ( context . backgroundCommands . get ( backgroundTaskId ) ?? undefined )
2874+ context . promptSettled && backgroundCommandTaskId !== undefined
2875+ ? ( context . backgroundCommands . get ( backgroundCommandTaskId ) ?? undefined )
28732876 : undefined ;
2874- // Replayed start ACKs must not replace an authoritative terminal result .
2877+ // Preserve hydrated output; only a replayed start ACK needs its output restored .
28752878 const toolCall =
28762879 completion === undefined
28772880 ? normalized
28782881 : {
2879- ...( completion . output === undefined
2882+ ...( backgroundTaskId === undefined || completion . output === undefined
28802883 ? normalized
28812884 : setToolOutputText ( normalized , completion . output ) ) ,
28822885 status : completion . status ,
28832886 } ;
2884- context . tools . set ( toolCall . toolCallId , toolCall ) ;
2887+ context . tools . set (
2888+ toolCall . toolCallId ,
2889+ backgroundCommandTaskId === undefined
2890+ ? toolCall
2891+ : { ...toolCall , backgroundCommandTaskId } ,
2892+ ) ;
28852893 if ( backgroundTaskId !== undefined ) {
28862894 context . toolCallIdsByBackgroundTaskId . set ( backgroundTaskId , toolCall . toolCallId ) ;
28872895 if ( flavor . isPersistentBackgroundTool ?.( toolCall ) === true ) {
0 commit comments