raylim Claude Opus 4.5 commited on
Commit
e1e8689
·
unverified ·
1 Parent(s): 48fff21

Fix telemetry upload by uploading on heartbeat and after analysis

Browse files

HF Spaces may go to sleep without triggering atexit handlers, causing
telemetry data to be lost. This change uploads telemetry:
- Immediately after each analysis completes
- On every heartbeat (every 5 minutes)

This ensures telemetry is persisted to HuggingFace before the Space
can go to sleep.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Files changed (1) hide show
  1. src/mosaic/ui/app.py +8 -0
src/mosaic/ui/app.py CHANGED
@@ -366,6 +366,10 @@ def analyze_slides(
366
  gpu_type=GPU_TYPE,
367
  )
368
 
 
 
 
 
369
  progress(0.99, desc="Analysis complete, wrapping up results")
370
 
371
  except Exception as e:
@@ -984,10 +988,14 @@ This tool is for research purposes only and not approved for clinical diagnosis.
984
  atexit.register(cleanup_on_exit)
985
 
986
  # Start heartbeat thread for telemetry (every 5 minutes)
 
987
  def heartbeat_worker():
988
  while not _shutdown_requested:
989
  time.sleep(tracker.config.heartbeat_interval_sec)
990
  tracker.log_heartbeat()
 
 
 
991
 
992
  heartbeat_thread = threading.Thread(target=heartbeat_worker, daemon=True)
993
  heartbeat_thread.start()
 
366
  gpu_type=GPU_TYPE,
367
  )
368
 
369
+ # Upload telemetry immediately after analysis to ensure data is saved
370
+ # before HF Spaces potentially goes to sleep
371
+ tracker.upload_to_hf()
372
+
373
  progress(0.99, desc="Analysis complete, wrapping up results")
374
 
375
  except Exception as e:
 
988
  atexit.register(cleanup_on_exit)
989
 
990
  # Start heartbeat thread for telemetry (every 5 minutes)
991
+ # Also uploads telemetry on each heartbeat to ensure data is saved before HF Spaces sleep
992
  def heartbeat_worker():
993
  while not _shutdown_requested:
994
  time.sleep(tracker.config.heartbeat_interval_sec)
995
  tracker.log_heartbeat()
996
+ # Upload telemetry on each heartbeat to avoid data loss when HF Spaces goes to sleep
997
+ # (atexit handlers may not run when the container is frozen/killed)
998
+ tracker.upload_to_hf()
999
 
1000
  heartbeat_thread = threading.Thread(target=heartbeat_worker, daemon=True)
1001
  heartbeat_thread.start()