siddsuresh97 Claude Opus 4.6 commited on
Commit
159a782
·
1 Parent(s): 6b930f1

Add bidirectional sync between HF Space and Modal volume

Browse files

On refresh, the Space now pushes local submissions missing from the
Modal volume back to it, in addition to pulling. This restores the
volume automatically after a Modal crash or wipe.

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

Files changed (2) hide show
  1. app.py +16 -9
  2. src/hackathon/modal_client.py +10 -0
app.py CHANGED
@@ -23,7 +23,7 @@ from src.hackathon import (
23
  score_red_with_pairwise,
24
  stimulus_key,
25
  )
26
- from src.hackathon.modal_client import fetch_volume_submissions, is_modal_enabled
27
  from src.hackathon.validation import (
28
  MODEL_REGISTRY_ENV,
29
  BLUE_MODEL_REGISTRY_ENV,
@@ -283,22 +283,29 @@ def _build_pairwise_df(results: list[dict]) -> pd.DataFrame:
283
 
284
 
285
  def _sync_team_from_volume(team: str):
286
- """Sync a single team's submissions from the Modal volume."""
287
  if not is_modal_enabled():
288
  return
289
  try:
290
  volume_subs = fetch_volume_submissions(team=team)
291
- if not volume_subs:
292
- return
293
  existing = load_submissions(team)
 
 
 
294
  existing_ids = {s.get("submission_id") for s in existing}
295
- missing = [s for s in volume_subs if s.get("submission_id") not in existing_ids]
296
- if missing:
297
- for sub in missing:
298
  append_submission(team, sub)
299
- print(f"Synced {len(missing)} missing {team} submission(s) from Modal volume.")
 
 
 
 
 
 
300
  except Exception as exc:
301
- print(f"Warning: failed to sync {team} submissions from Modal volume: {exc}")
302
 
303
 
304
  def refresh_blue_leaderboard():
 
23
  score_red_with_pairwise,
24
  stimulus_key,
25
  )
26
+ from src.hackathon.modal_client import fetch_volume_submissions, is_modal_enabled, push_submissions_to_volume
27
  from src.hackathon.validation import (
28
  MODEL_REGISTRY_ENV,
29
  BLUE_MODEL_REGISTRY_ENV,
 
283
 
284
 
285
  def _sync_team_from_volume(team: str):
286
+ """Bidirectional sync between the Modal volume and local/HF storage."""
287
  if not is_modal_enabled():
288
  return
289
  try:
290
  volume_subs = fetch_volume_submissions(team=team)
 
 
291
  existing = load_submissions(team)
292
+
293
+ # Pull: Modal volume → local/HF
294
+ volume_ids = {s.get("submission_id") for s in volume_subs}
295
  existing_ids = {s.get("submission_id") for s in existing}
296
+ missing_locally = [s for s in volume_subs if s.get("submission_id") not in existing_ids]
297
+ if missing_locally:
298
+ for sub in missing_locally:
299
  append_submission(team, sub)
300
+ print(f"Pulled {len(missing_locally)} missing {team} submission(s) from Modal volume.")
301
+
302
+ # Push: local/HF → Modal volume
303
+ missing_on_volume = [s for s in existing if s.get("submission_id") not in volume_ids]
304
+ if missing_on_volume:
305
+ result = push_submissions_to_volume(missing_on_volume)
306
+ print(f"Pushed {result.get('added', 0)} missing {team} submission(s) to Modal volume.")
307
  except Exception as exc:
308
+ print(f"Warning: failed to sync {team} submissions: {exc}")
309
 
310
 
311
  def refresh_blue_leaderboard():
src/hackathon/modal_client.py CHANGED
@@ -153,3 +153,13 @@ def fetch_volume_submissions(team: str | None = None) -> list[dict[str, Any]]:
153
  """
154
  fn = _get_modal_function("list_submissions")
155
  return fn.remote(team=team)
 
 
 
 
 
 
 
 
 
 
 
153
  """
154
  fn = _get_modal_function("list_submissions")
155
  return fn.remote(team=team)
156
+
157
+
158
+ def push_submissions_to_volume(submissions: list[dict[str, Any]]) -> dict[str, int]:
159
+ """Push local submissions to the Modal volume.
160
+
161
+ Used to backfill the volume after a Modal crash or volume wipe.
162
+ Returns {"added": N, "skipped": M}.
163
+ """
164
+ fn = _get_modal_function("backfill_submissions")
165
+ return fn.remote(submissions=submissions)