@@ -2218,6 +2218,67 @@ describe("subagent registry seam flow", () => {
22182218 expect ( run ?. cleanupCompletedAt ) . toBeTypeOf ( "number" ) ;
22192219 } ) ;
22202220
2221+ it ( "completes stale active runs as ok when child session has readable output" , async ( ) => {
2222+ mocks . callGateway . mockImplementation ( async ( request : { method ?: string } ) => {
2223+ if ( request . method === "agent.wait" ) {
2224+ return { status : "pending" } ;
2225+ }
2226+ if ( request . method === "chat.history" ) {
2227+ return {
2228+ messages : [
2229+ {
2230+ role : "assistant" ,
2231+ content : [ { type : "text" , text : "# ARCHITECTURE.md\nrelease readiness design" } ] ,
2232+ } ,
2233+ ] ,
2234+ } ;
2235+ }
2236+ return { } ;
2237+ } ) ;
2238+ mocks . loadSessionStore . mockReturnValue ( {
2239+ "agent:main:subagent:child" : {
2240+ sessionId : "sess-child" ,
2241+ updatedAt : 1 ,
2242+ status : "running" ,
2243+ } ,
2244+ } ) ;
2245+
2246+ const createdAt = Date . parse ( "2026-03-24T11:00:00Z" ) ;
2247+ vi . setSystemTime ( createdAt ) ;
2248+ mod . registerSubagentRun ( {
2249+ runId : "run-lost-context-with-output" ,
2250+ childSessionKey : "agent:main:subagent:child" ,
2251+ requesterSessionKey : "agent:main:main" ,
2252+ requesterDisplayKey : "main" ,
2253+ task : "deliver architecture doc" ,
2254+ cleanup : "keep" ,
2255+ expectsCompletionMessage : true ,
2256+ } ) ;
2257+
2258+ vi . setSystemTime ( createdAt + 65_000 ) ;
2259+ await mod . testing . sweepOnceForTests ( ) ;
2260+
2261+ await waitForFast ( ( ) => {
2262+ const announceParams = findRecordCallArg (
2263+ mocks . runSubagentAnnounceFlow ,
2264+ 0 ,
2265+ "lost context recovered announce" ,
2266+ ( record ) => record . childRunId === "run-lost-context-with-output" ,
2267+ ) ;
2268+ expectRecordFields (
2269+ announceParams . outcome ,
2270+ { status : "ok" } ,
2271+ "lost context recovered announce outcome" ,
2272+ ) ;
2273+ } ) ;
2274+
2275+ const run = mod
2276+ . listSubagentRunsForRequester ( "agent:main:main" )
2277+ . find ( ( entry ) => entry . runId === "run-lost-context-with-output" ) ;
2278+ expectRecordFields ( run ?. outcome , { status : "ok" } , "lost context recovered run outcome" ) ;
2279+ expect ( run ?. outcome ?. error ) . toBeUndefined ( ) ;
2280+ } ) ;
2281+
22212282 it ( "uses session-store start time when sweeping stale explicit-timeout runs" , async ( ) => {
22222283 mocks . callGateway . mockImplementation ( async ( request : { method ?: string } ) => {
22232284 if ( request . method === "agent.wait" ) {
0 commit comments