Auto merge dev → main (#1361)

* fix: don't freeze tournament brackets that overrun their scheduled end

date_end (TSS dateEndTournament) is only the *scheduled* end; tournaments
overrun it. compute_status now trusts in_active (GetActiveTournaments
presence) over date_end, and needs_scan no longer disables re-scans past
date_end + buffer. Fixes brackets stuck while their final was still pending.

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

* refactor: split _store_scan_sync into reusable upsert helpers

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

* feat: store_schedule writes meta/matches/standings without wiping battles

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

* refactor: extract gather_structure_sync; add fetch_schedule_sync (no battles)

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

* feat: reconcile_battles gap-fills replay links for played matches only

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

* feat: debounced schedule refresh coalesces game bursts into one TSS call

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

* feat: maybe_link_battle links replays from game match_id with zero TSS calls

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

* feat: route received games through maybe_link_battle (fast-path bracket link)

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

* tss_tournaments: three small final-review cleanups

- link_battle_sync: drop unused team_a_name/team_b_name from SELECT and
  fix status index from r[3] to r[1]
- _replace_battles: add clarifying comment about fast-path caveat and
  that schedule refresh deliberately skips this function
- store_scan / store_schedule: dispatch sqlite writes off the event loop
  via run_in_thread instead of calling sync writers directly

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

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
NotSoToothless
2026-06-29 04:23:34 -07:00
committed by GitHub
parent 43c2837f6d
commit a5abecb918
3 changed files with 592 additions and 124 deletions
+6 -5
View File
@@ -178,13 +178,14 @@ async def _handle_game(game: Dict[str, Any]) -> None:
await publish_replay_batch([game])
except Exception as exc:
log.warning("[TSS-BRIDGE] Failed to forward replay batch for %s: %s", sid, exc)
# If this game belongs to a tournament we haven't indexed (or one that's live
# and stale), scan its authoritative bracket in the background. Never blocks.
# Link this game's replay to its bracket slot from tss.match_id (zero TSS
# calls) and request a debounced schedule refresh; unknown matches fall back
# to a full scan inside maybe_link_battle. Never blocks ingest.
try:
from BOT.tss_tournaments import maybe_scan_tournament
await maybe_scan_tournament(game)
from BOT.tss_tournaments import maybe_link_battle
await maybe_link_battle(game)
except Exception as exc:
log.error("tournament scan trigger failed for %s: %s", sid, exc)
log.error("tournament link trigger failed for %s: %s", sid, exc)
# Autolog match/dispatch (no-ops in standalone mode where no bot is set).
try:
await autolog_process_game(game)