@@ -171,6 +171,8 @@ class MasterOrchestrator extends EventEmitter {
171171 this . _state = OrchestratorState . INITIALIZED ;
172172 this . _previousState = null ;
173173 this . _inFullPipeline = false ; // Flag for gate evaluation during full pipeline
174+ this . _persistenceAvailable = true ;
175+ this . _persistenceError = null ;
174176
175177 // Execution state
176178 this . executionState = {
@@ -1084,6 +1086,10 @@ class MasterOrchestrator extends EventEmitter {
10841086 async saveState ( ) {
10851087 try {
10861088 await fs . ensureDir ( path . dirname ( this . statePath ) ) ;
1089+ const persistedHealth = {
1090+ available : true ,
1091+ lastError : null ,
1092+ } ;
10871093
10881094 // Build comprehensive state object (AC2, AC6, AC7)
10891095 const stateToSave = {
@@ -1128,17 +1134,22 @@ class MasterOrchestrator extends EventEmitter {
11281134 // Errors and insights
11291135 errors : this . executionState . errors ,
11301136 insights : this . executionState . insights ,
1137+ persistence : persistedHealth ,
11311138
11321139 // Session insights
11331140 sessionInsights : this . _collectSessionInsights ( ) ,
11341141 } ;
11351142
11361143 await fs . writeJson ( this . statePath , stateToSave , { spaces : 2 } ) ;
1144+ this . _persistenceAvailable = persistedHealth . available ;
1145+ this . _persistenceError = persistedHealth . lastError ;
11371146 this . _log ( 'State saved successfully' , { path : this . statePath } ) ;
11381147
11391148 return true ;
11401149 } catch ( error ) {
1141- this . _log ( `Failed to save state: ${ error . message } ` , { level : 'warn' } ) ;
1150+ this . _persistenceAvailable = false ;
1151+ this . _persistenceError = error && error . message ? error . message : String ( error ) ;
1152+ this . _log ( `Failed to save state: ${ this . _persistenceError } ` , { level : 'warn' } ) ;
11421153 return false ;
11431154 }
11441155 }
@@ -1434,6 +1445,10 @@ class MasterOrchestrator extends EventEmitter {
14341445 } ,
14351446 errors : this . executionState . errors ,
14361447 insights : this . executionState . insights ,
1448+ persistence : {
1449+ available : this . _persistenceAvailable ,
1450+ error : this . _persistenceError ,
1451+ } ,
14371452 state : this . executionState ,
14381453 } ;
14391454 }
@@ -1475,9 +1490,31 @@ class MasterOrchestrator extends EventEmitter {
14751490 ] ) ,
14761491 ) ,
14771492 errors : this . executionState . errors . length ,
1493+ persistence : {
1494+ available : this . _persistenceAvailable ,
1495+ error : this . _persistenceError ,
1496+ } ,
14781497 } ;
14791498 }
14801499
1500+ /**
1501+ * Whether the last state persistence operation succeeded.
1502+ *
1503+ * @returns {boolean } True when persistence is available.
1504+ */
1505+ isPersistenceAvailable ( ) {
1506+ return this . _persistenceAvailable ;
1507+ }
1508+
1509+ /**
1510+ * Return the last state persistence error message, if any.
1511+ *
1512+ * @returns {string|null } Last persistence error message.
1513+ */
1514+ getPersistenceError ( ) {
1515+ return this . _persistenceError ;
1516+ }
1517+
14811518 // ═══════════════════════════════════════════════════════════════════════════════════
14821519 // LOGGING & CALLBACKS
14831520 // ═══════════════════════════════════════════════════════════════════════════════════
0 commit comments