@@ -1837,3 +1837,168 @@ it.layer(layerTest)("delegated tasks across a server restart", (it) => {
18371837 } ) ,
18381838 ) ;
18391839} ) ;
1840+
1841+ it . layer ( layerTest ) ( "delegated follow-ups promoted to Steer" , ( it ) => {
1842+ it . effect ( "settles a promoted follow-up with the turn it steered, not as cancelled" , ( ) =>
1843+ Effect . gen ( function * ( ) {
1844+ const orchestrator = yield * Orchestrator . OrchestratorV2 ;
1845+ const eventSink = yield * EventSink . EventSinkV2 ;
1846+ const now = yield * DateTime . now ;
1847+ const threadId = ThreadId . make ( "thread:steer-parent" ) ;
1848+ const projectId = ProjectId . make ( "project:steer-parent" ) ;
1849+ const runId = RunId . make ( "run:steer-parent" ) ;
1850+ const rootNodeId = NodeId . make ( "node:steer-parent-root" ) ;
1851+ yield * seedParentWithTerminalTask ( {
1852+ threadId,
1853+ projectId,
1854+ runId,
1855+ rootNodeId,
1856+ taskId : NodeId . make ( "node:steer-parent-settled" ) ,
1857+ deliveryState : "delivered" ,
1858+ now,
1859+ } ) ;
1860+ const child = yield * seedRestartCancelledChild ( {
1861+ parentThreadId : threadId ,
1862+ projectId,
1863+ parentRunId : runId ,
1864+ rootNodeId,
1865+ name : "steer-child" ,
1866+ completionWake : "always" ,
1867+ continuationPending : false ,
1868+ runStatus : "completed" ,
1869+ now,
1870+ } ) ;
1871+ const steeredRunId = RunId . make ( "run:steer-child:2" ) ;
1872+ const followUpTaskId = NodeId . make ( "node:steer-child-follow-up" ) ;
1873+ const followUpMessageId = MessageId . make ( "message:steer-child-follow-up" ) ;
1874+ const followUpRun = runEvent ( {
1875+ threadId : child . childThreadId ,
1876+ runId : RunId . make ( "run:steer-child:3" ) ,
1877+ ordinal : 3 ,
1878+ status : "cancelled" ,
1879+ userMessageId : followUpMessageId ,
1880+ now,
1881+ } ) ;
1882+ // The follow-up was queued as its own task, then promoted into the running turn.
1883+ yield * eventSink . write ( {
1884+ commandId : CommandId . make ( "command:steer-child:promoted" ) ,
1885+ events : [
1886+ runEvent ( {
1887+ threadId : child . childThreadId ,
1888+ runId : steeredRunId ,
1889+ ordinal : 2 ,
1890+ status : "running" ,
1891+ now,
1892+ } ) ,
1893+ {
1894+ ...followUpRun ,
1895+ payload : { ...followUpRun . payload , startedAt : null , delegatedTaskId : followUpTaskId } ,
1896+ } ,
1897+ {
1898+ id : EventId . make ( "event:steer-child:follow-up-message" ) ,
1899+ type : "message.updated" ,
1900+ threadId : child . childThreadId ,
1901+ runId : steeredRunId ,
1902+ occurredAt : now ,
1903+ payload : {
1904+ id : followUpMessageId ,
1905+ threadId : child . childThreadId ,
1906+ runId : steeredRunId ,
1907+ nodeId : null ,
1908+ role : "user" ,
1909+ text : "Also merge the fixture branch." ,
1910+ attachments : [ ] ,
1911+ streaming : false ,
1912+ createdBy : "agent" ,
1913+ creationSource : "mcp" ,
1914+ createdAt : now ,
1915+ updatedAt : now ,
1916+ } ,
1917+ } ,
1918+ {
1919+ id : EventId . make ( "event:steer-child:follow-up-task" ) ,
1920+ type : "subagent.updated" ,
1921+ threadId,
1922+ runId,
1923+ nodeId : followUpTaskId ,
1924+ driver,
1925+ providerInstanceId : modelSelection . instanceId ,
1926+ occurredAt : now ,
1927+ payload : {
1928+ id : followUpTaskId ,
1929+ threadId,
1930+ runId,
1931+ parentNodeId : rootNodeId ,
1932+ origin : "app_owned" ,
1933+ createdBy : "agent" ,
1934+ driver,
1935+ providerInstanceId : modelSelection . instanceId ,
1936+ providerThreadId : null ,
1937+ childThreadId : child . childThreadId ,
1938+ nativeTaskRef : null ,
1939+ prompt : "Also merge the fixture branch." ,
1940+ title : null ,
1941+ model : null ,
1942+ completionWake : "always" ,
1943+ status : "pending" ,
1944+ result : null ,
1945+ startedAt : now ,
1946+ completedAt : null ,
1947+ updatedAt : now ,
1948+ } ,
1949+ } ,
1950+ ] ,
1951+ } ) ;
1952+
1953+ yield * orchestrator . recoverDelegatedTask ( child . childThreadId , followUpRun . payload . id ) ;
1954+
1955+ const steering = yield * orchestrator . getThreadProjection ( threadId ) ;
1956+ assert . equal ( steering . subagents . find ( ( row ) => row . id === followUpTaskId ) ?. status , "pending" ) ;
1957+ assert . isTrue (
1958+ yield * orchestrator . delegatedTaskResultPending ( child . childThreadId , followUpTaskId ) ,
1959+ ) ;
1960+
1961+ yield * eventSink . write ( {
1962+ commandId : CommandId . make ( "command:steer-child:completed" ) ,
1963+ events : [
1964+ {
1965+ id : EventId . make ( "event:steer-child:result" ) ,
1966+ type : "message.updated" ,
1967+ threadId : child . childThreadId ,
1968+ runId : steeredRunId ,
1969+ occurredAt : now ,
1970+ payload : {
1971+ id : MessageId . make ( "message:steer-child:result" ) ,
1972+ threadId : child . childThreadId ,
1973+ runId : steeredRunId ,
1974+ nodeId : null ,
1975+ role : "assistant" ,
1976+ text : "Merged both branches." ,
1977+ attachments : [ ] ,
1978+ streaming : false ,
1979+ createdBy : "agent" ,
1980+ creationSource : "server" ,
1981+ createdAt : now ,
1982+ updatedAt : now ,
1983+ } ,
1984+ } ,
1985+ runEvent ( {
1986+ threadId : child . childThreadId ,
1987+ runId : steeredRunId ,
1988+ ordinal : 2 ,
1989+ status : "completed" ,
1990+ now,
1991+ } ) ,
1992+ ] ,
1993+ } ) ;
1994+ yield * orchestrator . recoverDelegatedTask ( child . childThreadId , steeredRunId ) ;
1995+
1996+ const settled = yield * orchestrator . getThreadProjection ( threadId ) ;
1997+ const original = settled . subagents . find ( ( row ) => row . id === child . taskId ) ;
1998+ const followUp = settled . subagents . find ( ( row ) => row . id === followUpTaskId ) ;
1999+ assert . equal ( original ?. result , "Merged both branches." ) ;
2000+ assert . equal ( followUp ?. status , "completed" ) ;
2001+ assert . equal ( followUp ?. result , "Merged both branches." ) ;
2002+ } ) ,
2003+ ) ;
2004+ } ) ;
0 commit comments