@@ -374,6 +374,41 @@ describe("Task resume api-history persistence on real files", () => {
374374 expect ( await findRecoveryCopyName ( taskDir ) ) . toBeUndefined ( )
375375 } )
376376
377+ it ( "keeps a standalone aborted task active and retains the recovery copy after the commit lands" , async ( ) => {
378+ // A standalone record has no parent transition, so the committed
379+ // active status stands. The restore must still run so its
380+ // committed_elsewhere gate retains the recovery copy, and the task
381+ // loop must not start on the aborted runner.
382+ const standaloneRecord = makeChildRecord ( { parentTaskId : undefined , rootTaskId : undefined } )
383+ await provider . taskHistoryStore . upsert ( standaloneRecord )
384+ const taskDir = await seedTaskFiles ( storagePath , childId , authoritativeApiHistory )
385+
386+ const { task, loop, resumeActivation } = prepareResumedTask ( standaloneRecord )
387+ const reinterrupt = vi . spyOn ( provider , "reinterruptAbandonedChild" )
388+ // A cancel racing the commit flips the abort flag while the
389+ // activation is in flight.
390+ resumeActivation . mockImplementation ( async ( taskId : string , parentTaskId ?: string ) => {
391+ await ClineProvider . prototype . resumeInterruptedTask . call ( provider , taskId , parentTaskId )
392+ task . abort = true
393+ } )
394+
395+ await task [ "resumeTaskFromHistory" ] ( )
396+
397+ expect ( reinterrupt ) . not . toHaveBeenCalled ( )
398+ expect ( loop ) . not . toHaveBeenCalled ( )
399+ const persisted = await readPersistedApiHistory ( storagePath , childId )
400+ expect ( persisted ) . toEqual ( preparedApiHistory )
401+ const persistedRecord = await readPersistedRecord ( storagePath , childId )
402+ expect ( persistedRecord . status ) . toBe ( "active" )
403+ expect ( provider . taskHistoryStore . get ( childId ) ?. status ) . toBe ( "active" )
404+ // The record is active, so no restore write ran. The recovery copy
405+ // stays on disk with the pre-resume history for recovery.
406+ const recoveryCopyName = await findRecoveryCopyName ( taskDir )
407+ expect ( recoveryCopyName ) . toBeDefined ( )
408+ const recoveryCopy = JSON . parse ( await fs . readFile ( path . join ( taskDir , recoveryCopyName as string ) , "utf8" ) )
409+ expect ( recoveryCopy ) . toEqual ( authoritativeApiHistory )
410+ } )
411+
377412 it ( "stops before activation and keeps the persisted api history when the preparation write fails" , async ( ) => {
378413 await provider . taskHistoryStore . upsert ( makeChildRecord ( { parentTaskId : undefined , rootTaskId : undefined } ) )
379414 const taskDir = await seedTaskFiles ( storagePath , childId , authoritativeApiHistory )
0 commit comments