@@ -1794,3 +1794,91 @@ it.effect("background failures stay reported when another automated run starts",
17941794 assert . deepStrictEqual ( ( yield * projections . getThreadShell ( threadId ) ) ! . background , reported ) ;
17951795 } ) . pipe ( Effect . provide ( layerTest ) ) ,
17961796) ;
1797+
1798+ it . effect (
1799+ "acknowledged background failures stay quiet after delegated delivery metadata changes" ,
1800+ ( ) =>
1801+ Effect . gen ( function * ( ) {
1802+ const orchestrator = yield * Orchestrator . OrchestratorV2 ;
1803+ const projections = yield * ProjectionStore . ProjectionStoreV2 ;
1804+ const events = yield * EventSink . EventSinkV2 ;
1805+ const { threadId } = yield * completeAndSnoozeThread ( "background-metadata" , 30 ) ;
1806+ yield * orchestrator . dispatch ( {
1807+ type : "message.dispatch" ,
1808+ commandId : CommandId . make ( "background-metadata:start" ) ,
1809+ threadId,
1810+ messageId : MessageId . make ( "background-metadata:start" ) ,
1811+ text : "Delegate a check" ,
1812+ attachments : [ ] ,
1813+ dispatchMode : { type : "start_immediately" } ,
1814+ createdBy : "user" ,
1815+ creationSource : "web" ,
1816+ } ) ;
1817+ const run = ( yield * projections . getThreadProjection ( threadId ) ) . runs . at ( - 1 ) ! ;
1818+ yield * orchestrator . dispatch ( {
1819+ type : "delegated_task.request" ,
1820+ commandId : CommandId . make ( "background-metadata:delegate" ) ,
1821+ parentThreadId : threadId ,
1822+ parentRunId : run . id ,
1823+ parentNodeId : run . rootNodeId ! ,
1824+ task : "Check" ,
1825+ modelSelection,
1826+ runtimeMode : "full-access" ,
1827+ interactionMode : "default" ,
1828+ createdBy : "agent" ,
1829+ creationSource : "mcp" ,
1830+ } ) ;
1831+ const task = ( yield * projections . getThreadProjection ( threadId ) ) . subagents [ 0 ] ! ;
1832+ const now = yield * DateTime . now ;
1833+ yield * events . write ( {
1834+ events : [
1835+ {
1836+ id : EventId . make ( "background-metadata:failed" ) ,
1837+ type : "run.updated" ,
1838+ threadId,
1839+ runId : run . id ,
1840+ occurredAt : now ,
1841+ payload : {
1842+ ...run ,
1843+ status : "failed" ,
1844+ completedAt : now ,
1845+ delegatedCompletion : {
1846+ disposition : "open" ,
1847+ nextGeneration : 2 ,
1848+ delivery : {
1849+ generation : 1 ,
1850+ messageId : MessageId . make ( "missing-delivery" ) ,
1851+ taskIds : [ task . id ] ,
1852+ } ,
1853+ } ,
1854+ } ,
1855+ } ,
1856+ ] ,
1857+ } ) ;
1858+ yield * orchestrator . dispatch ( {
1859+ type : "thread.metadata.update" ,
1860+ commandId : CommandId . make ( "background-metadata:background" ) ,
1861+ threadId,
1862+ background : true ,
1863+ } ) ;
1864+ yield * orchestrator . dispatch ( {
1865+ type : "thread.mark-unread" ,
1866+ commandId : CommandId . make ( "background-metadata:report" ) ,
1867+ threadId,
1868+ } ) ;
1869+ yield * orchestrator . dispatch ( {
1870+ type : "thread.metadata.update" ,
1871+ commandId : CommandId . make ( "background-metadata:ack" ) ,
1872+ threadId,
1873+ acknowledgeBackground : true ,
1874+ } ) ;
1875+ const result = yield * orchestrator . dispatch ( {
1876+ type : "delegated_task.completion-delivery.dispose" ,
1877+ commandId : CommandId . make ( "background-metadata:dispose" ) ,
1878+ parentThreadId : threadId ,
1879+ taskId : task . id ,
1880+ } ) ;
1881+ assert . isTrue ( result . storedEvents . some ( ( stored ) => stored . event . type === "run.updated" ) ) ;
1882+ assert . isNull ( ( yield * projections . getThreadShell ( threadId ) ) ! . background ! . reportedAt ) ;
1883+ } ) . pipe ( Effect . provide ( layerTest ) ) ,
1884+ ) ;
0 commit comments