@@ -1453,6 +1453,13 @@ const make = Effect.gen(function* () {
14531453 null ) ;
14541454 const resultTransfer = taskResultTransfer ( parentProjection , childProjection , task ) ?? null ;
14551455 const terminalStatus = terminalRun === undefined ? null : taskStatusForRun ( terminalRun ) ;
1456+ const latestTerminalSummary = canExposeTaskRunResult ( terminalRun )
1457+ ? terminalRun . id === childRun ?. id
1458+ ? derivedResult
1459+ : subagentResultForRun ( childProjection , terminalRun ) . text
1460+ : null ;
1461+ const resultContextTransferId = resultTransfer ?. id ?? null ;
1462+ const latestTerminalResultContextTransferId = resultTransferForRun ( terminalRun ) ?. id ?? null ;
14561463 const response = {
14571464 taskId : task . id ,
14581465 childThreadId : task . childThreadId ,
@@ -1464,16 +1471,15 @@ const make = Effect.gen(function* () {
14641471 providerInstanceId : task . providerInstanceId ,
14651472 model : task . model ,
14661473 summary : derivedResult ,
1467- resultContextTransferId : resultTransfer ?. id ?? null ,
1474+ resultContextTransferId,
14681475 latestTerminalRunId : terminalRun ?. id ?? null ,
14691476 latestTerminalStatus :
14701477 terminalStatus !== null && isTerminalTaskStatus ( terminalStatus ) ? terminalStatus : null ,
1471- latestTerminalSummary : canExposeTaskRunResult ( terminalRun )
1472- ? terminalRun . id === childRun ?. id
1473- ? derivedResult
1474- : subagentResultForRun ( childProjection , terminalRun ) . text
1475- : null ,
1476- latestTerminalResultContextTransferId : resultTransferForRun ( terminalRun ) ?. id ?? null ,
1478+ latestTerminalSummary : latestTerminalSummary === derivedResult ? null : latestTerminalSummary ,
1479+ latestTerminalResultContextTransferId :
1480+ latestTerminalResultContextTransferId === resultContextTransferId
1481+ ? null
1482+ : latestTerminalResultContextTransferId ,
14771483 hasPendingQuestion :
14781484 ! isTerminalTaskStatus ( status ) &&
14791485 childControls . runtimeRequests . some (
@@ -1507,124 +1513,11 @@ const make = Effect.gen(function* () {
15071513 ? observingRun . id
15081514 : null ,
15091515 } )
1510- . pipe ( Effect . mapError ( threadManagementFailure ) ) ;
1511- const childProjection = {
1512- ...childControls ,
1513- messages : [ ...childControls . messages , ...resultRecords . messages ] ,
1514- turnItems : resultRecords . turnItems ,
1515- } ;
1516- const heldForRestart =
1517- task . result === null &&
1518- taskWorkState === "result_available" &&
1519- ( yield * threadManagement
1520- . delegatedTaskResultPending ( task . childThreadId , childRun ?. delegatedTaskId )
1521- . pipe ( Effect . mapError ( threadManagementFailure ) ) ) ;
1522- const workState =
1523- task . result !== null ? "result_available" : heldForRestart ? "working" : taskWorkState ;
1524- const status =
1525- task . result !== null
1526- ? taskStatusForRun (
1527- task . status === "completed" ||
1528- task . status === "failed" ||
1529- task . status === "cancelled" ||
1530- task . status === "interrupted"
1531- ? { status : task . status }
1532- : childRun ,
1533- )
1534- : workState === "result_available"
1535- ? taskStatusForRun ( taskResultRun ?? childRun )
1536- : taskStatusForRun ( taskResultRun ?? childRun ) === "queued"
1537- ? "queued"
1538- : "running" ;
1539- const derivedResult =
1540- task . result !== null
1541- ? task . result
1542- : taskResultRun !== undefined && isTerminalTaskStatus ( status )
1543- ? subagentResultForRun ( childProjection , taskResultRun ) . text
1544- : null ;
1545- const resultTransfers = parentProjection . contextTransfers . filter (
1546- ( transfer ) =>
1547- transfer . type === "subagent_result" &&
1548- transfer . sourceThreadId === task . childThreadId &&
1549- transfer . targetThreadId === scope . thread . threadId ,
1550- ) ;
1551- const resultTransferForRun = ( run : OrchestrationV2Run | undefined ) =>
1552- ! canExposeTaskRunResult ( run )
1553- ? null
1554- : ( resultTransfers . find ( ( transfer ) => transfer . sourcePoint . runId === run . id ) ??
1555- ( run . id === childRun ?. id
1556- ? resultTransfers . find ( ( transfer ) => transfer . sourcePoint . runId === undefined )
1557- : undefined ) ??
1558- null ) ;
1559- const resultTransfer = taskResultTransfer ( parentProjection , childProjection , task ) ?? null ;
1560- const terminalStatus = terminalRun === undefined ? null : taskStatusForRun ( terminalRun ) ;
1561- const latestTerminalSummary = canExposeTaskRunResult ( terminalRun )
1562- ? terminalRun . id === childRun ?. id
1563- ? derivedResult
1564- : subagentResultForRun ( childProjection , terminalRun ) . text
1565- : null ;
1566- const resultContextTransferId = resultTransfer ?. id ?? null ;
1567- const latestTerminalResultContextTransferId = resultTransferForRun ( terminalRun ) ?. id ?? null ;
1568- const response = {
1569- taskId : task . id ,
1570- childThreadId : task . childThreadId ,
1571- childRunId : childRun ?. id ?? null ,
1572- childNodeId : task . id ,
1573- status,
1574- workState,
1575- hasPendingChildRuns : hasPendingChildRuns ( childProjection , childRun ) ,
1576- providerInstanceId : task . providerInstanceId ,
1577- model : task . model ,
1578- summary : derivedResult ,
1579- resultContextTransferId,
1580- latestTerminalRunId : terminalRun ?. id ?? null ,
1581- latestTerminalStatus :
1582- terminalStatus !== null && isTerminalTaskStatus ( terminalStatus ) ? terminalStatus : null ,
1583- latestTerminalSummary :
1584- latestTerminalSummary === derivedResult ? null : latestTerminalSummary ,
1585- latestTerminalResultContextTransferId :
1586- latestTerminalResultContextTransferId === resultContextTransferId
1587- ? null
1588- : latestTerminalResultContextTransferId ,
1589- hasPendingQuestion :
1590- ! isTerminalTaskStatus ( status ) &&
1591- childControls . runtimeRequests . some (
1592- ( request ) =>
1593- request . kind === "user_input" &&
1594- request . status === "pending" &&
1595- request . responseCapability . type === "live" ,
1596- ) ,
1597- waitTimedOut,
1598- } satisfies OrchestratorMcpDelegateTaskResult ;
1599- if (
1600- acknowledgeTerminal &&
1601- isTerminalTaskStatus ( status ) &&
1602- task . completionDelivery ?. state !== "acknowledged" &&
1603- task . completionDelivery ?. state !== "disposed"
1604- ) {
1605- const observingRun = ThreadManagementService . latestActiveRun ( parentProjection ) ;
1606- const acknowledgementRequestKey = yield * requestKey ( undefined ) ;
1607- yield * threadManagement
1608- . dispatch ( {
1609- type : "delegated_task.completion-delivery.acknowledge" ,
1610- commandId : stableCommandId ( {
1611- scope,
1612- requestKey : acknowledgementRequestKey ,
1613- operation : acknowledgementOperation ,
1614- } ) ,
1615- parentThreadId : scope . thread . threadId ,
1616- taskId,
1617- observedByRunId :
1618- observingRun ?. providerInstanceId === scope . thread . providerInstanceId
1619- ? observingRun . id
1620- : null ,
1621- } )
1622- . pipe (
1623- Effect . mapError ( ( error ) =>
1624- failure (
1625- "orchestration_error" ,
1626- `Unable to acknowledge delegated task ${ taskId } : ${ errorMessage ( error ) } ` ,
1627- ) ,
1516+ . pipe (
1517+ Effect . mapError ( ( error ) =>
1518+ failure (
1519+ "orchestration_error" ,
1520+ `Unable to acknowledge delegated task ${ taskId } : ${ errorMessage ( error ) } ` ,
16281521 ) ,
16291522 ) ,
16301523 ) ;
0 commit comments