Paritosh Upadhyay commited on
Commit
2d63d9b
Β·
1 Parent(s): 63cfc4b

Neural Unification: Fixed GUI desync & absolute timer freeze

Browse files
app/friday_gui.py CHANGED
@@ -278,9 +278,6 @@ class FridaySovereign:
278
  self.battery_alerted = False # Ensure critical battery only alerts ONCE per launch
279
  threading.Thread(target=self._sentinel_worker, daemon=True).start()
280
 
281
- # ── GRID TELEMETRY POLLER (Multi-Process Sync) ──
282
- threading.Thread(target=self._telemetry_poller, daemon=True).start()
283
-
284
  # ── GRID TELEMETRY POLLER (Multi-Process Sync) ──
285
  threading.Thread(target=self._telemetry_poller, daemon=True).start()
286
 
@@ -655,11 +652,26 @@ class FridaySovereign:
655
  with database.SessionLocal() as db:
656
  sov = db.query(KeyValueStore).filter_by(key="safety_lock").first()
657
  learn = db.query(KeyValueStore).filter_by(key="learning_lock").first()
658
- if sov: state.set_sovereign_lock(sov.value)
659
- if learn: state.set_learning_lock(learn.value)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
660
  except Exception as e:
 
661
  pass
662
- time.sleep(1.2) # High-speed pulse
663
 
664
  def _draw_singularity(self):
665
  # Neural Abyss Rendering
 
278
  self.battery_alerted = False # Ensure critical battery only alerts ONCE per launch
279
  threading.Thread(target=self._sentinel_worker, daemon=True).start()
280
 
 
 
 
281
  # ── GRID TELEMETRY POLLER (Multi-Process Sync) ──
282
  threading.Thread(target=self._telemetry_poller, daemon=True).start()
283
 
 
652
  with database.SessionLocal() as db:
653
  sov = db.query(KeyValueStore).filter_by(key="safety_lock").first()
654
  learn = db.query(KeyValueStore).filter_by(key="learning_lock").first()
655
+
656
+ if sov:
657
+ # Handle potential string values from the DB
658
+ val = sov.value
659
+ if isinstance(val, str): val = val.lower() == "true"
660
+ is_locked = bool(val)
661
+ state.set_sovereign_lock(is_locked)
662
+
663
+ # CRITICAL: If Powered ON (Unlocked), FORCE the attention timer to 30s
664
+ if not is_locked:
665
+ self.attention_lock_t = 30.0
666
+
667
+ if learn:
668
+ val = learn.value
669
+ if isinstance(val, str): val = val.lower() == "true"
670
+ state.set_learning_lock(bool(val))
671
  except Exception as e:
672
+ # logger.error(f"[GUI TELEMETRY] Pulse failure: {e}")
673
  pass
674
+ time.sleep(0.5) # Zero-latency pulse
675
 
676
  def _draw_singularity(self):
677
  # Neural Abyss Rendering
backend/app/scratch/subconscious_loop.py CHANGED
@@ -185,12 +185,21 @@ def subconscious_cycle():
185
 
186
  while True:
187
  try:
188
- # 1. Sync DB state to Memory state
189
  with database.SessionLocal() as db:
190
  sov = db.query(KeyValueStore).filter_by(key="safety_lock").first()
191
  learn = db.query(KeyValueStore).filter_by(key="learning_lock").first()
192
- if sov: state.set_sovereign_lock(sov.value)
193
- if learn: state.set_learning_lock(learn.value)
 
 
 
 
 
 
 
 
 
194
 
195
  # 2. Detect System Power Transitions
196
  is_sov_locked = state.is_sovereign_locked()
@@ -214,7 +223,7 @@ def subconscious_cycle():
214
  except Exception as e:
215
  logger.error(f"[STATE SENTINEL] Error syncing grid: {e}")
216
 
217
- time.sleep(1.2) # High-speed pulse
218
 
219
  # ── LOCAL LIFE SIGNAL SENTINEL ──
220
  # This thread periodically whispers its presence to the DB
@@ -276,7 +285,13 @@ def subconscious_cycle():
276
  holocron.batch_mine_priorities()
277
 
278
  logger.info("Cycle complete. Entering brief standby for 2 minutes.")
279
- time.sleep(120)
 
 
 
 
 
 
280
 
281
  except Exception as e:
282
  logger.error(f"Internal Pulse Error: {e}")
 
185
 
186
  while True:
187
  try:
188
+ # 1. Sync DB state to Memory state with strict boolean parsing
189
  with database.SessionLocal() as db:
190
  sov = db.query(KeyValueStore).filter_by(key="safety_lock").first()
191
  learn = db.query(KeyValueStore).filter_by(key="learning_lock").first()
192
+
193
+ if sov:
194
+ # Handle potential string values from the DB
195
+ val = sov.value
196
+ if isinstance(val, str): val = val.lower() == "true"
197
+ state.set_sovereign_lock(bool(val))
198
+
199
+ if learn:
200
+ val = learn.value
201
+ if isinstance(val, str): val = val.lower() == "true"
202
+ state.set_learning_lock(bool(val))
203
 
204
  # 2. Detect System Power Transitions
205
  is_sov_locked = state.is_sovereign_locked()
 
223
  except Exception as e:
224
  logger.error(f"[STATE SENTINEL] Error syncing grid: {e}")
225
 
226
+ time.sleep(0.5) # Zero-latency pulse
227
 
228
  # ── LOCAL LIFE SIGNAL SENTINEL ──
229
  # This thread periodically whispers its presence to the DB
 
285
  holocron.batch_mine_priorities()
286
 
287
  logger.info("Cycle complete. Entering brief standby for 2 minutes.")
288
+ # We use a segmented sleep to keep her responsive to heartbeats
289
+ for _ in range(120): # 120 seconds total
290
+ if time.time() - last_heartbeat > 30:
291
+ status = "LOCKED" if is_sov_locked else ("PAUSED" if is_learn_locked else "ACTIVE")
292
+ logger.info(f"πŸ’“ Subconscious Heartbeat: [Grid: {status}] [Ears: Listening]")
293
+ last_heartbeat = time.time()
294
+ time.sleep(1)
295
 
296
  except Exception as e:
297
  logger.error(f"Internal Pulse Error: {e}")
backend/app/services/tools/macos.py CHANGED
@@ -522,8 +522,8 @@ def shutdown_essence_audio():
522
  """Immediately kills all local speech and audio playbacks for a Hard Shutdown."""
523
  try:
524
  # Kill both afplay (sound files) and say (TTS engine)
525
- subprocess.run(["pkill", "-9", "afplay"], capture_output=True)
526
- subprocess.run(["pkill", "-9", "say"], capture_output=True)
527
  return "Sovereign Command: Essence Silenced."
528
  except Exception as e:
529
  logger.error(f"Failed to kill audio essence: {e}")
@@ -533,7 +533,7 @@ def trigger_awakening_greeting():
533
  """Triggers a native macOS awakening greeting."""
534
  try:
535
  script = 'Sovereign systems online. I am at your command, Sir.'
536
- subprocess.Popen(["say", "-v", "Samantha", script])
537
  return "Awakening Greeting Dispatched."
538
  except Exception as e:
539
  logger.error(f"Failed to dispatch greeting: {e}")
 
522
  """Immediately kills all local speech and audio playbacks for a Hard Shutdown."""
523
  try:
524
  # Kill both afplay (sound files) and say (TTS engine)
525
+ subprocess.run(["/usr/bin/pkill", "-9", "afplay"], capture_output=True)
526
+ subprocess.run(["/usr/bin/pkill", "-9", "say"], capture_output=True)
527
  return "Sovereign Command: Essence Silenced."
528
  except Exception as e:
529
  logger.error(f"Failed to kill audio essence: {e}")
 
533
  """Triggers a native macOS awakening greeting."""
534
  try:
535
  script = 'Sovereign systems online. I am at your command, Sir.'
536
+ subprocess.Popen(["/usr/bin/say", "-v", "Samantha", script])
537
  return "Awakening Greeting Dispatched."
538
  except Exception as e:
539
  logger.error(f"Failed to dispatch greeting: {e}")