@@ -370,50 +370,6 @@ describe("gateway agent handler", () => {
370370 } ) ;
371371 } ) ;
372372
373- it ( "adopts a sessions_yield-paused run when a plugin follow-up targets its session" , async ( ) => {
374- await withTempDir ( { prefix : "openclaw-gateway-plugin-subagent-adopt-" } , async ( root ) => {
375- useTestStateDir ( root ) ;
376- resetSubagentRegistryForTests ( { persist : false } ) ;
377- const childSessionKey = "agent:work:subagent:plugin-yield-followup" ;
378- const originalRequester = "agent:main:telegram:direct:777" ;
379- addSubagentRunForTests ( {
380- runId : "plugin-subagent-paused" ,
381- childSessionKey,
382- requesterSessionKey : originalRequester ,
383- requesterDisplayKey : originalRequester ,
384- task : "wait for the remote job" ,
385- endedAt : 2_000 ,
386- pauseReason : "sessions_yield" ,
387- expectsCompletionMessage : true ,
388- } ) ;
389-
390- await registerPluginSubagentRunFromGateway ( {
391- cfg : {
392- session : { mainKey : "main" , scope : "per-sender" } ,
393- agents : { list : [ { id : "main" , default : true } , { id : "work" } ] } ,
394- } ,
395- runId : "plugin-subagent-followup" ,
396- childSessionKey,
397- task : "the remote job finished" ,
398- pluginId : "memory-core" ,
399- } ) ;
400-
401- const run = requireValue (
402- getSubagentRunByChildSessionKey ( childSessionKey ) ,
403- "expected adopted plugin subagent run" ,
404- ) ;
405- // A follow-up without requester context would otherwise register a sibling
406- // row owned by the child's own agent session, stranding the requester that
407- // is still parked behind its yield.
408- expectRecordFields ( run , {
409- runId : "plugin-subagent-followup" ,
410- requesterSessionKey : originalRequester ,
411- task : "the remote job finished" ,
412- pauseReason : undefined ,
413- } ) ;
414- } ) ;
415- } ) ;
416-
417373 it ( "registers normally when a follow-up to a paused session names its own requester" , async ( ) => {
418374 await withTempDir (
419375 { prefix : "openclaw-gateway-plugin-subagent-own-requester-" } ,
@@ -525,7 +481,7 @@ describe("gateway agent handler", () => {
525481 ) ;
526482 } ) ;
527483
528- it ( "rejects plugin SDK subagent runs and releases admission when registry persistence fails" , async ( ) => {
484+ it ( "rejects plugin SDK subagent registration and adoption when persistence fails" , async ( ) => {
529485 await withTempDir (
530486 { prefix : "openclaw-gateway-plugin-subagent-registry-fail-" } ,
531487 async ( root ) => {
@@ -602,6 +558,54 @@ describe("gateway agent handler", () => {
602558 expect . stringContaining ( "rejecting untracked dispatch" ) ,
603559 ) ;
604560
561+ resetSubagentRegistryForTests ( { persist : false } ) ;
562+ const pausedRunId = "plugin-subagent-paused-before-persistence-failure" ;
563+ addSubagentRunForTests ( {
564+ runId : pausedRunId ,
565+ childSessionKey,
566+ requesterSessionKey : "agent:main:telegram:direct:777" ,
567+ requesterDisplayKey : "agent:main:telegram:direct:777" ,
568+ task : "wait for the remote job" ,
569+ endedAt : 2_000 ,
570+ pauseReason : "sessions_yield" ,
571+ expectsCompletionMessage : true ,
572+ } ) ;
573+ persistSubagentRunsToDiskOrThrow . mockImplementationOnce ( ( ) => {
574+ throw new Error ( "disk full during paused-run adoption" ) ;
575+ } ) ;
576+ const adoptionRunId = "plugin-subagent-adoption-registry-fail" ;
577+ const adoptionRespond = vi . fn ( ) ;
578+ await invokeAgent (
579+ {
580+ message : "the remote job finished" ,
581+ sessionKey : childSessionKey ,
582+ idempotencyKey : adoptionRunId ,
583+ } ,
584+ {
585+ context,
586+ reqId : adoptionRunId ,
587+ respond : adoptionRespond ,
588+ client : {
589+ connect : baseClient . connect ,
590+ internal : {
591+ ...baseClient . internal ,
592+ agentRunTracking : "plugin_subagent" ,
593+ pluginRuntimeOwnerId : "memory-core" ,
594+ } ,
595+ } ,
596+ } ,
597+ ) ;
598+
599+ expect ( mocks . agentCommand ) . toHaveBeenCalledTimes ( commandCallCount ) ;
600+ expect ( getSubagentRunByChildSessionKey ( childSessionKey ) ) . toMatchObject ( {
601+ runId : pausedRunId ,
602+ pauseReason : "sessions_yield" ,
603+ } ) ;
604+ expect ( getSubagentRunByChildSessionKey ( childSessionKey ) ?. runId ) . not . toBe ( adoptionRunId ) ;
605+ const adoptionError = expectRespondError ( adoptionRespond , { code : ErrorCodes . UNAVAILABLE } ) ;
606+ expectStringFieldContains ( adoptionError , "message" , "run was not started" ) ;
607+
608+ resetSubagentRegistryForTests ( { persist : false } ) ;
605609 const retryRunId = "plugin-subagent-registry-retry" ;
606610 await invokeAgent (
607611 {
0 commit comments