@@ -3500,6 +3500,9 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
35003500 // instead of waiting in the wake buffer for a continuation run.
35013501 const settledTurnByNativeThread = new Map < string , ActiveClaudeTurnContext > ( ) ;
35023502 const subagentStopOutcomes = new Map < string , Deferred . Deferred < void > > ( ) ;
3503+ // An idle outcome stays buffered for the parent's wake, but must not
3504+ // settle the child again after that child resumes.
3505+ const appliedSubagentOutcomes = new WeakSet < SDKMessage > ( ) ;
35033506 // Subagent frames can precede the task_started that registers their
35043507 // subagent (the same race rememberPendingClaudeSubagentLaunch covers).
35053508 // They wait here and replay once task_started registers the owner.
@@ -4864,7 +4867,10 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
48644867 "running" | "completed" | "failed" | "cancelled"
48654868 > ;
48664869 readonly reopen ?: boolean ;
4867- readonly nativeOutcome ?: boolean ;
4870+ readonly nativeOutcome ?: Extract <
4871+ SDKMessage ,
4872+ { readonly type : "system" ; readonly subtype : "task_notification" }
4873+ > ;
48684874 readonly onlyIfRunningInRun ?: RunId | null ;
48694875 } ) {
48704876 // The session registry lets a wake-replay turn (fresh context maps)
@@ -5032,7 +5038,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
50325038 const subagent = {
50335039 task,
50345040 confirmedOutcome :
5035- input . nativeOutcome === true
5041+ input . nativeOutcome !== undefined
50365042 ? confirmedSubagentOutcome ( task )
50375043 : isReopen
50385044 ? undefined
@@ -5081,6 +5087,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
50815087 return [ true , new Map ( current ) . set ( input . taskId , subagent ) ] as const ;
50825088 } ) ;
50835089 if ( ! accepted ) return ;
5090+ if ( input . nativeOutcome !== undefined ) appliedSubagentOutcomes . add ( input . nativeOutcome ) ;
50845091 // A call the subagent left open never returns once it ends. It ends
50855092 // first, while the run that owns the child thread still takes its
50865093 // events.
@@ -5254,7 +5261,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
52545261 } ,
52555262 } ) ;
52565263
5257- if ( input . nativeOutcome === true && subagent . confirmedOutcome !== undefined ) {
5264+ if ( input . nativeOutcome !== undefined && subagent . confirmedOutcome !== undefined ) {
52585265 const outcome = subagentStopOutcomes . get ( input . taskId ) ;
52595266 if ( outcome !== undefined ) yield * Deferred . succeed ( outcome , undefined ) ;
52605267 }
@@ -6778,7 +6785,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
67786785 taskId : message . task_id ,
67796786 ...( message . tool_use_id === undefined ? { } : { toolUseId : message . tool_use_id } ) ,
67806787 workflowFrame : message ,
6781- nativeOutcome : true ,
6788+ nativeOutcome : message ,
67826789 result : message . summary ,
67836790 status : claudeTaskOutcome ( message . status ) ,
67846791 onlyIfRunningInRun : registered . task . runId ,
@@ -7273,7 +7280,10 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
72737280 if ( message . type === "system" && message . subtype === "task_notification" ) {
72747281 // A live outcome supersedes earlier idle starts. During replay only
72757282 // remove frames before this notification, preserving a later resume.
7276- if ( ( yield * Ref . get ( sessionSubagentsByTaskId ) ) . has ( message . task_id ) ) {
7283+ if (
7284+ ! appliedSubagentOutcomes . has ( message ) &&
7285+ ( yield * Ref . get ( sessionSubagentsByTaskId ) ) . has ( message . task_id )
7286+ ) {
72777287 yield * discardBufferedSubagentStarts (
72787288 liveQuery . nativeThreadId ,
72797289 message . task_id ,
@@ -7322,14 +7332,18 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
73227332 message,
73237333 activeContext : context ,
73247334 } ) ;
7325- if ( ! wasBackgroundTask && ! context . ignoredTaskIds . has ( message . task_id ) ) {
7335+ if (
7336+ ! wasBackgroundTask &&
7337+ ! context . ignoredTaskIds . has ( message . task_id ) &&
7338+ ! appliedSubagentOutcomes . has ( message )
7339+ ) {
73267340 yield * updateClaudeSubagentNode ( {
73277341 context,
73287342 taskId : message . task_id ,
73297343 ...( message . tool_use_id === undefined ? { } : { toolUseId : message . tool_use_id } ) ,
73307344 // Terminal usage totals arrive here, after the last snapshot.
73317345 workflowFrame : message ,
7332- nativeOutcome : true ,
7346+ nativeOutcome : message ,
73337347 result : message . summary ,
73347348 status :
73357349 message . status === "completed"
0 commit comments