@@ -5,8 +5,8 @@ import OpenClawProtocol
55enum OpenClawConfigFile {
66 private static let logger = Logger ( subsystem: " ai.openclaw " , category: " config " )
77 private static let configAuditFileName = " config-audit.jsonl "
8- private static let configHealthFileName = " config-health.json "
98 private static let fileLock = NSRecursiveLock ( )
9+ private nonisolated ( unsafe) static var configHealthState : [ String : Any ] = [ : ]
1010
1111 private static func withFileLock< T> ( _ body: ( ) throws -> T ) rethrows -> T {
1212 self . fileLock. lock ( )
@@ -477,39 +477,6 @@ enum OpenClawConfigFile {
477477 . appendingPathComponent ( self . configAuditFileName, isDirectory: false )
478478 }
479479
480- private static func configHealthStateURL( ) -> URL {
481- self . stateDirURL ( )
482- . appendingPathComponent ( " logs " , isDirectory: true )
483- . appendingPathComponent ( self . configHealthFileName, isDirectory: false )
484- }
485-
486- private static func readConfigHealthState( ) -> [ String : Any ] {
487- let url = self . configHealthStateURL ( )
488- guard let data = try ? Data ( contentsOf: url) ,
489- let root = try ? JSONSerialization . jsonObject ( with: data) as? [ String : Any ]
490- else {
491- return [ : ]
492- }
493- return root
494- }
495-
496- private static func writeConfigHealthState( _ root: [ String : Any ] ) {
497- guard JSONSerialization . isValidJSONObject ( root) ,
498- let data = try ? JSONSerialization . data ( withJSONObject: root, options: [ . prettyPrinted, . sortedKeys] )
499- else {
500- return
501- }
502- let url = self . configHealthStateURL ( )
503- do {
504- try FileManager ( ) . createDirectory (
505- at: url. deletingLastPathComponent ( ) ,
506- withIntermediateDirectories: true )
507- try data. write ( to: url, options: [ . atomic] )
508- } catch {
509- // best-effort
510- }
511- }
512-
513480 private static func configHealthEntry( state: [ String : Any ] , configPath: String ) -> [ String : Any ] {
514481 let entries = state [ " entries " ] as? [ String : Any ]
515482 return entries ? [ configPath] as? [ String : Any ] ?? [ : ]
@@ -672,7 +639,7 @@ enum OpenClawConfigFile {
672639 private static func observeConfigRead( data: Data , root: [ String : Any ] ? , configURL: URL , valid: Bool ) {
673640 let observedAt = ISO8601DateFormatter ( ) . string ( from: Date ( ) )
674641 let current = self . configFingerprint ( data: data, root: root, configURL: configURL, observedAt: observedAt)
675- var state = self . readConfigHealthState ( )
642+ var state = self . configHealthState
676643 let entry = self . configHealthEntry ( state: state, configPath: configURL. path)
677644 let lastKnownGood = entry [ " lastKnownGood " ] as? [ String : Any ]
678645 let suspicious = self . observeSuspiciousReasons (
@@ -688,7 +655,7 @@ enum OpenClawConfigFile {
688655 ]
689656 if !self . sameFingerprint ( lastKnownGood, current) || entry [ " lastObservedSuspiciousSignature " ] != nil {
690657 state = self . setConfigHealthEntry ( state: state, configPath: configURL. path, entry: nextEntry)
691- self . writeConfigHealthState ( state)
658+ self . configHealthState = state
692659 }
693660 return
694661 }
@@ -750,7 +717,7 @@ enum OpenClawConfigFile {
750717 var nextEntry = entry
751718 nextEntry [ " lastObservedSuspiciousSignature " ] = signature
752719 state = self . setConfigHealthEntry ( state: state, configPath: configURL. path, entry: nextEntry)
753- self . writeConfigHealthState ( state)
720+ self . configHealthState = state
754721 }
755722
756723 private static func appendConfigWriteAudit( _ fields: [ String : Any ] ) {
0 commit comments