@@ -162,6 +162,9 @@ export class AutoresearchService {
162162 researchFindings : [ ] ,
163163 iterations : [ ] ,
164164 startedAt : Date . now ( ) ,
165+ pausedAt : null ,
166+ pausedDurationMs : 0 ,
167+ pauseIntervals : [ ] ,
165168 endedAt : null ,
166169 endReason : null ,
167170 interruptedReason : null ,
@@ -213,6 +216,7 @@ export class AutoresearchService {
213216 this . clearPendingReaction ( runId ) ;
214217 this . clearRecoveryTimer ( runId ) ;
215218 this . remindersSent . delete ( runId ) ;
219+ this . pauseClock ( runId ) ;
216220 autoresearchStoreActions . setRunStatus ( runId , "paused" ) ;
217221 this . persist ( runId ) ;
218222 this . restoreOriginalStage ( run ) ;
@@ -231,6 +235,7 @@ export class AutoresearchService {
231235 return ;
232236 }
233237
238+ this . settlePausedClock ( runId ) ;
234239 this . clearRecoveryTimer ( runId ) ;
235240 const session = getSessionForTask (
236241 sessionStore . getState ( ) ,
@@ -257,6 +262,7 @@ export class AutoresearchService {
257262 autoresearchStoreActions . setRunStatus ( runId , "interrupted" , {
258263 interruptedReason : run . interruptedReason ?? "session-error" ,
259264 } ) ;
265+ this . pauseClock ( runId ) ;
260266 this . persist ( runId ) ;
261267 void this . attemptRecovery ( runId ) ;
262268 return ;
@@ -765,6 +771,7 @@ export class AutoresearchService {
765771 if ( run ?. status === "running" ) {
766772 this . clearPendingReaction ( runId ) ;
767773 this . remindersSent . delete ( runId ) ;
774+ this . pauseClock ( runId ) ;
768775 autoresearchStoreActions . setRunStatus ( runId , "paused" ) ;
769776 this . persist ( runId ) ;
770777 this . restoreOriginalStage ( run ) ;
@@ -806,6 +813,7 @@ export class AutoresearchService {
806813 this . clearPendingReaction ( runId ) ;
807814 // A fresh interruption gets its own reminder budget on resume.
808815 this . remindersSent . delete ( runId ) ;
816+ this . pauseClock ( runId ) ;
809817 autoresearchStoreActions . setRunStatus ( runId , "interrupted" , {
810818 interruptedReason : reason ,
811819 lastError,
@@ -885,6 +893,7 @@ export class AutoresearchService {
885893 return ;
886894 }
887895
896+ this . settlePausedClock ( runId ) ;
888897 this . clearRecoveryTimer ( runId ) ;
889898 const session = getSessionForTask (
890899 sessionStore . getState ( ) ,
@@ -915,6 +924,7 @@ export class AutoresearchService {
915924 status : "completed" | "stopped" | "failed" ,
916925 options : { endReason : AutoresearchEndReason ; lastError ?: string } ,
917926 ) : void {
927+ this . settlePausedClock ( runId ) ;
918928 const run = autoresearchStore . getState ( ) . runs [ runId ] ;
919929 autoresearchStoreActions . setRunStatus ( runId , status , options ) ;
920930 this . persist ( runId ) ;
@@ -928,6 +938,29 @@ export class AutoresearchService {
928938 if ( run ) this . restoreOriginalStage ( run ) ;
929939 }
930940
941+ private pauseClock ( runId : string ) : void {
942+ const run = autoresearchStore . getState ( ) . runs [ runId ] ;
943+ if ( ! run || run . pausedAt != null ) return ;
944+ autoresearchStoreActions . setPauseTiming (
945+ runId ,
946+ Date . now ( ) ,
947+ run . pausedDurationMs ?? 0 ,
948+ run . pauseIntervals ?? [ ] ,
949+ ) ;
950+ }
951+
952+ private settlePausedClock ( runId : string ) : void {
953+ const run = autoresearchStore . getState ( ) . runs [ runId ] ;
954+ if ( ! run || run . pausedAt == null ) return ;
955+ const endedAt = Date . now ( ) ;
956+ autoresearchStoreActions . setPauseTiming (
957+ runId ,
958+ null ,
959+ ( run . pausedDurationMs ?? 0 ) + Math . max ( 0 , endedAt - run . pausedAt ) ,
960+ [ ...( run . pauseIntervals ?? [ ] ) , { startedAt : run . pausedAt , endedAt } ] ,
961+ ) ;
962+ }
963+
931964 private clearPendingReaction ( runId : string ) : void {
932965 const timer = this . pendingReactions . get ( runId ) ;
933966 if ( timer ) clearTimeout ( timer ) ;
0 commit comments