Claude Code Claude Opus 4.6 commited on
Commit
f855457
·
1 Parent(s): bf23adc

Claude Code: Add worker heartbeat daemon - write timestamp to memory/worker_heartbeat.txt every 5s for file-based thread-alive verification

Browse files
Files changed (1) hide show
  1. app.py +11 -0
app.py CHANGED
@@ -657,6 +657,10 @@ def run_worker():
657
  data_dir = Path(os.environ.get("OPENCLAW_DATA_DIR", "/data"))
658
  status_file = data_dir / "cain_status.json"
659
 
 
 
 
 
660
  running = True
661
 
662
  def handle_shutdown(signum, frame):
@@ -679,6 +683,13 @@ def run_worker():
679
  with open(status_file, "w") as f:
680
  json.dump(data, f, indent=2)
681
 
 
 
 
 
 
 
 
682
  # Worker is alive - sleep and repeat
683
  time.sleep(5)
684
 
 
657
  data_dir = Path(os.environ.get("OPENCLAW_DATA_DIR", "/data"))
658
  status_file = data_dir / "cain_status.json"
659
 
660
+ # Heartbeat file for thread-alive verification (bypasses logging buffering)
661
+ heartbeat_path = Path("memory/worker_heartbeat.txt")
662
+ heartbeat_path.parent.mkdir(parents=True, exist_ok=True)
663
+
664
  running = True
665
 
666
  def handle_shutdown(signum, frame):
 
683
  with open(status_file, "w") as f:
684
  json.dump(data, f, indent=2)
685
 
686
+ # Write heartbeat timestamp to file (file-based truth check)
687
+ try:
688
+ with open(heartbeat_path, "w") as f:
689
+ f.write(datetime.utcnow().isoformat() + "+00:00\n")
690
+ except Exception as e:
691
+ logger.warning(f"[Cain Worker] Failed to write heartbeat: {e}")
692
+
693
  # Worker is alive - sleep and repeat
694
  time.sleep(5)
695