From 8fcbb2d38976f737afc4d70ab5535db4f794c9c0 Mon Sep 17 00:00:00 2001 From: FlyM1ss Date: Sat, 31 Oct 2026 23:50:53 -0400 Subject: [PATCH 1/9] fix(live): name the board Live Leaderboard from one owner in service.py Co-Authored-By: Claude Sonnet 5.5 --- dashboard/backend/api/routers/backtests.py | 4 +- dashboard/backend/api/routers/leaderboard.py | 4 +- dashboard/backend/domain/leaderboard/live.py | 10 ++--- .../backend/domain/leaderboard/service.py | 19 +++++++-- .../market_data/us_market_calendar.py | 2 +- .../backend/tests/test_backtests_router.py | 5 ++- .../backend/tests/test_leaderboard_api.py | 3 +- .../backend/tests/test_leaderboard_season.py | 4 +- .../backend/tests/test_live_leaderboard.py | 39 ++++++++++++++++++- dashboard/scripts/refresh_live_leaderboard.py | 4 +- 10 files changed, 73 insertions(+), 21 deletions(-) diff --git a/dashboard/backend/api/routers/backtests.py b/dashboard/backend/api/routers/backtests.py index a98b0a4e1..86633644d 100644 --- a/dashboard/backend/api/routers/backtests.py +++ b/dashboard/backend/api/routers/backtests.py @@ -3798,8 +3798,8 @@ class BacktestRunRequest(BaseModel): # params or a JSON body, so validation runs on the merged effective values in the # handler rather than only on the Pydantic body. MAX_STRATEGY_PROMPT_CHARS = 4000 -# Two weeks, matching the fortnight the Live Trading Leaderboard's seasons use -# so the product has one window vocabulary. It was 31, set when the fixed +# Two weeks, chosen to match the two-week seasons the Live Leaderboard had +# then (seasons are calendar months now). It was 31, set when the fixed # parent budget was the only bound: a 31-day window is ~22 weekdays x ~7 hourly # bars = ~154 decision bars, and a pipeline multiplies that by its step count, # so the UI permitted a window roughly 3x the modal default against a constant diff --git a/dashboard/backend/api/routers/leaderboard.py b/dashboard/backend/api/routers/leaderboard.py index 4a957ec12..6f551ba36 100644 --- a/dashboard/backend/api/routers/leaderboard.py +++ b/dashboard/backend/api/routers/leaderboard.py @@ -74,7 +74,7 @@ def api_get_leaderboard( Pass ?refresh=true to recompute (e.g. after config change); operators only, with X-Leaderboard-Refresh-Secret or an admin session, else 403. Pass ?period=daily for the rolling one-day board (weekends show Friday). - Pass ?period=live for the current calendar-month Live Trading Leaderboard + Pass ?period=live for the current calendar-month Live Leaderboard (freeze-window snapshots under leaderboard-live; GET never deploys models). """ # Public, unauthenticated endpoint: no exception text reaches the caller. @@ -181,7 +181,7 @@ def api_refresh_live_leaderboard( force: bool = Query(default=False, description="Replay the whole month from the 1st."), x_leaderboard_refresh_secret: str | None = Header(default=None, alias="X-Leaderboard-Refresh-Secret"), ): - """Cron hook: enqueue a Live Trading Leaderboard increment (non-blocking). + """Cron hook: enqueue a Live Leaderboard increment (non-blocking). Uses the same ``LEADERBOARD_DAILY_REFRESH_SECRET`` as the daily board. Returns **202 Accepted**; model steps run in a background thread. Public GET diff --git a/dashboard/backend/domain/leaderboard/live.py b/dashboard/backend/domain/leaderboard/live.py index e920518ca..8aa18e210 100644 --- a/dashboard/backend/domain/leaderboard/live.py +++ b/dashboard/backend/domain/leaderboard/live.py @@ -1,4 +1,4 @@ -"""Calendar-month Live Trading Leaderboard. +"""Calendar-month Live Leaderboard. This board is not Daily stretched to 30 days and not the fixed contest window. One continuous paper-trading month per entry: the chart axis is the current @@ -347,8 +347,8 @@ def live_freeze_config( "end_date": freeze_end, "reference_start_date": reference_start_date(month_start, None), "period": "live", - "board_title": "Live Trading Leaderboard", - "phase_label": "Season 0", + "board_title": lb_service.LIVE_BOARD_TITLE, + "phase_label": lb_service.LIVE_PHASE_LABEL, "standings_label": "Performance", } @@ -1939,8 +1939,8 @@ def get_live_leaderboard( return { "period": "live", - "board_title": "Live Trading Leaderboard", - "phase_label": "Season 0", + "board_title": lb_service.LIVE_BOARD_TITLE, + "phase_label": lb_service.LIVE_PHASE_LABEL, "standings_label": "Performance", "window": { "start_date": start_date, diff --git a/dashboard/backend/domain/leaderboard/service.py b/dashboard/backend/domain/leaderboard/service.py index 284f07778..9ab856e3b 100644 --- a/dashboard/backend/domain/leaderboard/service.py +++ b/dashboard/backend/domain/leaderboard/service.py @@ -604,6 +604,17 @@ def verify_daily_refresh_secret(provided: Optional[str]) -> None: # explicitly the one whose results nobody should read as a standing. Mirrors # PREVIEW_SEASON_NUMBER in dashboard/frontend/js/leaderboard.js. PREVIEW_SEASON_NUMBER = 0 +# The Live board's name and season label have exactly one owner: this pair. +# resolve_leaderboard_config("live"), live.live_freeze_config and the payload +# live.get_live_leaderboard serves all read them, and the static fallbacks in +# app.html / js/live-leaderboard.js are pinned to them by +# tests/test_frontend_live_leaderboard.py. "Trading" is dropped from the name +# because it read as real orders and collided with the Robinhood live-trading +# docs (docs/superpowers/specs/2026-10-14-atl-direction.md §6). The label is +# built from PREVIEW_SEASON_NUMBER so the number keeps one owner, and says +# "preview" until a season counts (Season 1 waits for the new engine). +LIVE_BOARD_TITLE = "Live Leaderboard" +LIVE_PHASE_LABEL = f"Season {PREVIEW_SEASON_NUMBER} · preview" DEFAULT_SEASON_TRADING_DAYS = 10 # One calendar year of weekday sessions. An upper bound rather than a sanity # check: `season_window` walks the calendar one day at a time and runs inside a @@ -748,7 +759,7 @@ def build_season_payload( config: Dict[str, Any], as_of: Optional[Union[date, datetime]] = None, ) -> Dict[str, Any]: - """The season block the Live Trading tab renders. + """The season block the Live tab renders. NOTHING HERE MAY CLAIM AN ADVANCE. ``last_advanced_date`` stays None and ``trading_days_elapsed`` stays 0 because no season has advanced -- there is @@ -841,11 +852,11 @@ def resolve_leaderboard_config(period: Optional[str] = "contest") -> Dict[str, A "ranking on this board counts. There is no advance engine yet." ), "period": "live", - "board_title": "Live Trading Leaderboard", + "board_title": LIVE_BOARD_TITLE, # Derived, never spelled out: a literal "Season 0" here is a second # owner of the season number, and the first thing the advance engine - # does is bump PREVIEW_SEASON_NUMBER. - "phase_label": f"Season {PREVIEW_SEASON_NUMBER}", + # does is bump PREVIEW_SEASON_NUMBER, which LIVE_PHASE_LABEL is built from. + "phase_label": LIVE_PHASE_LABEL, "standings_label": "Ranking", } return { diff --git a/dashboard/backend/infrastructure/market_data/us_market_calendar.py b/dashboard/backend/infrastructure/market_data/us_market_calendar.py index 6ec4b788b..188026d6e 100644 --- a/dashboard/backend/infrastructure/market_data/us_market_calendar.py +++ b/dashboard/backend/infrastructure/market_data/us_market_calendar.py @@ -1,7 +1,7 @@ """NYSE full-day holidays and early closes, computed by rule (no data file, no dependency). -Shared US market-data infrastructure: the Live Trading Leaderboard walks it +Shared US market-data infrastructure: the Live Leaderboard walks it forward day by day, and the Run Backtest modal's default period (``provider.default_backtest_window``) walks it back week by week. It lived under ``domain/leaderboard/`` while the board was its only reader; a calendar diff --git a/dashboard/backend/tests/test_backtests_router.py b/dashboard/backend/tests/test_backtests_router.py index 1f5d35e82..33d49fc1a 100644 --- a/dashboard/backend/tests/test_backtests_router.py +++ b/dashboard/backend/tests/test_backtests_router.py @@ -2363,8 +2363,9 @@ def test_backtest_window_cap_is_two_weeks(): counted LLM calls. A 31-day window is ~22 weekdays x ~7 hourly bars = ~154 decision bars, and a multi-step pipeline multiplies that by its step count -- far past what the fixed 3600s budget can finish. Two weeks matches the - fortnight the Live Trading Leaderboard's seasons already use, so the - product has one window vocabulary rather than two. + two-week seasons the Live Leaderboard had when this cap was set (seasons + are calendar months now), so the product had one window vocabulary rather + than two. """ assert bt.MAX_BACKTEST_DAYS == 14 diff --git a/dashboard/backend/tests/test_leaderboard_api.py b/dashboard/backend/tests/test_leaderboard_api.py index 211572622..0f3368d9c 100644 --- a/dashboard/backend/tests/test_leaderboard_api.py +++ b/dashboard/backend/tests/test_leaderboard_api.py @@ -866,7 +866,8 @@ def _must_not_run(*_args, **_kwargs): assert resp.status_code == 200 body = resp.json() assert body["period"] == "live" - assert body["board_title"] == "Live Trading Leaderboard" + assert body["board_title"] == "Live Leaderboard" + assert body["phase_label"] == "Season 0 · preview" assert body["standings_label"] == "Performance" assert "live_status" in body status = body["live_status"] diff --git a/dashboard/backend/tests/test_leaderboard_season.py b/dashboard/backend/tests/test_leaderboard_season.py index ff5cdd5d9..4603f62a1 100644 --- a/dashboard/backend/tests/test_leaderboard_season.py +++ b/dashboard/backend/tests/test_leaderboard_season.py @@ -255,7 +255,9 @@ def test_the_live_phase_label_is_derived_from_the_season_number(): """A literal "Season 0" here is a second owner of the season number, and bumping PREVIEW_SEASON_NUMBER is the first act of the advance engine.""" live = service.resolve_leaderboard_config("live") - assert live["phase_label"] == f"Season {service.PREVIEW_SEASON_NUMBER}" + assert service.LIVE_PHASE_LABEL == f"Season {service.PREVIEW_SEASON_NUMBER} · preview" + assert live["phase_label"] == service.LIVE_PHASE_LABEL + assert live["board_title"] == service.LIVE_BOARD_TITLE == "Live Leaderboard" def test_the_route_documents_the_third_period(): diff --git a/dashboard/backend/tests/test_live_leaderboard.py b/dashboard/backend/tests/test_live_leaderboard.py index 63e7e9a61..63ccf0d33 100644 --- a/dashboard/backend/tests/test_live_leaderboard.py +++ b/dashboard/backend/tests/test_live_leaderboard.py @@ -1,4 +1,4 @@ -"""Tests for the calendar-month Live Trading Leaderboard. +"""Tests for the calendar-month Live Leaderboard. Isolated from contest/daily: live freeze uses ``leaderboard-live`` and must not rewrite the contest window. @@ -2221,3 +2221,40 @@ def test_a_row_with_no_seed_at_all_is_undefined_and_logged(no_alpaca, monkeypatc assert deepseek["sharpe_status"] == "undefined" assert deepseek["sharpe_ratio"] is None assert any("not a positive number" in r.getMessage() for r in caplog.records) + + +# ── The board's name and season label have one owner (service.py) ─────────── + + +def test_every_live_surface_reads_the_shared_title_and_phase_label(no_alpaca): + """Three dicts carry the Live board's name and season label: the payload the + public GET serves, the freeze config the refresh writes under, and the + service-side live config. Each used to spell both out, so a rename had three + places to miss and the season number had three owners.""" + as_of = datetime(2026, 8, 27, 17, 39, tzinfo=_ET) + assert lb_service.LIVE_BOARD_TITLE == "Live Leaderboard" + assert lb_service.LIVE_PHASE_LABEL == "Season 0 · preview" + for source in ( + live.get_live_leaderboard(as_of=as_of), + live.live_freeze_config(as_of), + lb_service.resolve_leaderboard_config("live"), + ): + assert source["board_title"] == lb_service.LIVE_BOARD_TITLE + assert source["phase_label"] == lb_service.LIVE_PHASE_LABEL + + +def test_no_backend_text_still_says_live_trading_leaderboard(): + """'Trading' was dropped from the name (direction spec §6): it read as real + orders and collided with the Robinhood live-trading docs. Docstrings, the + OpenAPI text and the refresh CLI's --help are read by people too.""" + from pathlib import Path + + backend = Path(live.__file__).resolve().parents[2] + scripts = backend.parent / "scripts" + offenders = sorted( + str(path.relative_to(backend.parent)) + for path in [*backend.rglob("*.py"), *scripts.rglob("*.py")] + if "tests" not in path.relative_to(backend.parent).parts + and "Live Trading Leaderboard" in path.read_text(encoding="utf-8") + ) + assert offenders == [], f"rename these to 'Live Leaderboard': {offenders}" diff --git a/dashboard/scripts/refresh_live_leaderboard.py b/dashboard/scripts/refresh_live_leaderboard.py index a02b0e3dc..513ef7df6 100644 --- a/dashboard/scripts/refresh_live_leaderboard.py +++ b/dashboard/scripts/refresh_live_leaderboard.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -"""Persist the Live Trading Leaderboard freeze snapshot for the current month. +"""Persist the Live Leaderboard freeze snapshot for the current month. 1. Recomputes cheap baselines (indices + rule-based strategies) for month-open → last settled US cash session under ``leaderboard-live``. @@ -50,7 +50,7 @@ def main() -> int: parser = argparse.ArgumentParser( - description="Refresh the Live Trading Leaderboard freeze snapshot" + description="Refresh the Live Leaderboard freeze snapshot" ) parser.add_argument( "--models", From d456993fe4b930341efa0e0cccb1f21f2722defe Mon Sep 17 00:00:00 2001 From: FlyM1ss Date: Sat, 31 Oct 2026 23:56:10 -0400 Subject: [PATCH 2/9] fix(live): rename the tab, static subtitle and Updated stat, Season 0 preview label Co-Authored-By: Claude Opus 5.5 --- .../backend/tests/test_frontend_fast_boot.py | 2 +- .../tests/test_frontend_live_leaderboard.py | 66 ++++++++++++++++++- .../tests/test_frontend_live_trading_board.py | 16 +++-- .../tests/test_landing_copy_register.py | 2 +- dashboard/frontend/app.html | 24 +++---- dashboard/frontend/js/leaderboard.js | 4 +- dashboard/frontend/js/live-leaderboard.js | 21 +++--- 7 files changed, 98 insertions(+), 37 deletions(-) diff --git a/dashboard/backend/tests/test_frontend_fast_boot.py b/dashboard/backend/tests/test_frontend_fast_boot.py index a306c3ea7..25e044285 100644 --- a/dashboard/backend/tests/test_frontend_fast_boot.py +++ b/dashboard/backend/tests/test_frontend_fast_boot.py @@ -197,7 +197,7 @@ def test_cache_busters_bumped(): assert "app.js?v=164" in APP_HTML assert "js/agent-editor.js?v=33" in APP_HTML assert "styles.css?v=160" in APP_HTML - assert "js/leaderboard.js?v=39" in APP_HTML + assert "js/leaderboard.js?v=40" in APP_HTML assert "home-page.js?v=56" in APP_HTML assert "js/credit-format.js?v=1" in APP_HTML assert "js/credits.js?v=8" in APP_HTML diff --git a/dashboard/backend/tests/test_frontend_live_leaderboard.py b/dashboard/backend/tests/test_frontend_live_leaderboard.py index 1ddf69bfe..01c7c83bc 100644 --- a/dashboard/backend/tests/test_frontend_live_leaderboard.py +++ b/dashboard/backend/tests/test_frontend_live_leaderboard.py @@ -1,4 +1,4 @@ -"""Source guards for the Live Trading Leaderboard tab. +"""Source guards for the Live Leaderboard tab. /app has no JS test toolchain, so these assert against shipped HTML/JS as text. """ @@ -27,7 +27,7 @@ def _strip_js_comments(source: str) -> str: def test_live_subtab_is_visible_and_daily_stays_parked(): assert re.search( - r'data-competition-tab="live"[^>]*>\s*Live Trading Leaderboard', + r'data-competition-tab="live"[^>]*>\s*Live Leaderboard<', _APP_HTML, ) assert 'data-competition-tab="live"' in _APP_HTML @@ -401,3 +401,65 @@ def test_live_sharpe_is_the_competition_formatter_not_a_copy(): f"liveSortValue({json.dumps(_SHARPE_OK)}, 'sharpe')]));", ])) assert alone == [{"main": "—", "sub": "", "title": ""}, None] + + +# ── Naming and header copy (direction spec §6) ────────────────────────────── + + +def _live_view_markup() -> str: + """The #liveLeaderboardView markup, up to the Competition view.""" + return _APP_HTML.split('id="liveLeaderboardView"')[1].split('id="leaderboardView"')[0] + + +def _static_text(html: str, element_id: str) -> str: + """The text inside the element carrying `id=""` (no child tags).""" + match = re.search(rf'id="{element_id}"[^>]*>([^<]*)<', html) + assert match, f"#{element_id} is missing from app.html" + return match.group(1) + + +def test_the_board_is_named_live_leaderboard_on_every_surface(): + """'Trading' read as real orders and collided with the Robinhood + live-trading docs. The static title, the JS fallback and the payload all + resolve to service.LIVE_BOARD_TITLE.""" + from dashboard.backend.domain.leaderboard import service + + assert _static_text(_APP_HTML, "liveBoardTitle") == service.LIVE_BOARD_TITLE + assert f"payload.board_title || '{service.LIVE_BOARD_TITLE}'" in _LIVE_JS + visible = _strip_js_comments(re.sub(r"", "", _APP_HTML, flags=re.DOTALL)) + assert "Live Trading Leaderboard" not in visible + assert "Live Trading Leaderboard" not in _strip_js_comments(_LIVE_JS) + + +def test_the_subtitle_is_static_simulated_forward_only_copy(): + assert ( + _static_text(_APP_HTML, "liveBoardSubtitle") + == "Simulated fills · forward-only · no real money" + ) + source = _strip_js_comments(_LIVE_JS) + assert "liveBoardSubtitle" not in source, ( + "the subtitle is static copy in app.html; rewriting it from JS put " + "'paper trading' back on screen" + ) + assert "paper trading" not in source.lower() + + +def test_the_updated_stat_states_the_cadence_not_the_request_clock(): + """payload.updated_at is the wall clock of the GET, so rendering it always + read 'just now' on a board that last advanced days ago.""" + assert re.search( + r'Updated\s*' + r'Nightly after the close', + _live_view_markup(), + ) + source = _strip_js_comments(_LIVE_JS) + assert "liveUpdatedLabel" not in source + assert "updated_at" not in source + + +def test_the_season_stat_reads_season_0_preview_from_one_owner(): + from dashboard.backend.domain.leaderboard import service + + assert service.LIVE_PHASE_LABEL == "Season 0 · preview" + assert _static_text(_APP_HTML, "livePhaseLabel") == service.LIVE_PHASE_LABEL + assert f"payload.phase_label || '{service.LIVE_PHASE_LABEL}'" in _LIVE_JS diff --git a/dashboard/backend/tests/test_frontend_live_trading_board.py b/dashboard/backend/tests/test_frontend_live_trading_board.py index a429173f7..b46d7625e 100644 --- a/dashboard/backend/tests/test_frontend_live_trading_board.py +++ b/dashboard/backend/tests/test_frontend_live_trading_board.py @@ -1,4 +1,4 @@ -"""Source guards for the Live Trading Leaderboard (frontend/js/leaderboard.js). +"""Source guards for the Live Leaderboard (frontend/js/leaderboard.js). /app has no build step and no JS test toolchain, so these assert against the shipped source as text -- the convention set by test_ai_hedge_fund_frontend.py. @@ -404,22 +404,26 @@ def test_the_season_constants_are_the_same_number_in_all_three_places(): def test_the_board_names_itself_on_screen(): header = _fn_body("updateLeaderboardHeader") - assert "'Live Trading Leaderboard'" in header, ( + assert "'Live Leaderboard'" in header, ( "the board title must name the board; folding the season number in " "here instead leaves it unnamed whenever a season is running" ) - assert 'data-competition-tab="live">Live Trading Leaderboard<' in _APP_HTML + assert 'data-competition-tab="live">Live Leaderboard<' in _APP_HTML + assert "Live Trading Leaderboard" not in _SOURCE, ( + "'Trading' was dropped from the board name (direction spec §6)" + ) def test_the_live_name_is_disclaimed_as_simulated(): - """"Live Trading" is a claim. The About card is where it gets qualified. + """"Live" is a claim about direction, not money. The About card is where + it gets qualified. PR #328's spec puts brokered execution in non-goals and execution/paper_backend.py is still a stub, so a board named for live trading that never says "simulated" is the UI making a promise the system does not keep. """ - about = _APP_HTML_VISIBLE[_APP_HTML_VISIBLE.index("Live Trading Leaderboard") :] + about = _APP_HTML_VISIBLE[_APP_HTML_VISIBLE.index("Live Leaderboard") :] about = about[: about.index("")] lowered = about.lower() assert "simulated" in lowered, "the About card must say the trading is simulated" @@ -427,7 +431,7 @@ def test_the_live_name_is_disclaimed_as_simulated(): def test_about_card_names_the_current_season(): - about = _APP_HTML_VISIBLE[_APP_HTML_VISIBLE.index("Live Trading Leaderboard") :] + about = _APP_HTML_VISIBLE[_APP_HTML_VISIBLE.index("Live Leaderboard") :] about = about[: about.index("")] assert "Season 0" in about, ( "the board is in Season 0; the About card is where that is established" diff --git a/dashboard/backend/tests/test_landing_copy_register.py b/dashboard/backend/tests/test_landing_copy_register.py index db5ff3e83..82f8b3d3c 100644 --- a/dashboard/backend/tests/test_landing_copy_register.py +++ b/dashboard/backend/tests/test_landing_copy_register.py @@ -805,7 +805,7 @@ def _app_html_live_surfaces() -> dict[str, str]: visible = re.sub(r"", "", app_html, flags=re.DOTALL) blurb_at = visible.index('id="homeModuleLiveBtn"') blurb = visible[blurb_at : visible.index("

", blurb_at)] - about_at = visible.index("Live Trading Leaderboard") + about_at = visible.index("Live Leaderboard") about = visible[about_at : visible.index("", about_at)] return {"app.html Home blurb": blurb, "app.html About card": about} diff --git a/dashboard/frontend/app.html b/dashboard/frontend/app.html index dafaad106..fbbcbd481 100644 --- a/dashboard/frontend/app.html +++ b/dashboard/frontend/app.html @@ -67,7 +67,7 @@ if (saved && saved.page === 'playground' && saved.playgroundTab === 'paper') { return Object.assign({}, saved, { playgroundTab: 'agents' }); } - // The Daily Leaderboard became the Live Trading Leaderboard. + // The Daily Leaderboard became the Live Leaderboard. // Anyone whose last visit was that tab has 'daily' in localStorage // (or 'season' from a build of this branch); left alone the key // matches no boot-CSS rule and no panel, so Competition paints @@ -585,7 +585,7 @@

to deny, two clicks upstream of the correction. -->

Every AI model above traded the same fixed window. The - + is the other board — designed to move forward one trading session at a time, on prices nobody has seen yet. It is a Season 0 preview: the current calendar month, updated after each trading session closes. @@ -1572,7 +1572,7 @@

Stop Loss / Take Profit

-

Live Trading Leaderboard

+

Live Leaderboard

This board runs forward, one calendar month at a time, on NYSE trading days. “Live” describes the direction, not the money: this is simulated trading on real market data — no broker account, no real capital, and no order ever leaves this system.

Each night after the US cash close (16:00 ET, or 13:00 on an NYSE early close), each entry is advanced one trading day: the model sees that day's real bars for the first time and its portfolio carries forward from where the previous day left it. Nobody — including us — knows what the next bar does when an entry locks, which is what separates this board from the fixed-window Competition one.

Each entry is one continuous book that starts the month flat at $100,000 and ranks only the days inside it; the board resets on the 1st. Entries are a curated roster of AI models and baselines — there are no user submissions.

@@ -1642,16 +1642,16 @@

Evaluation Metrics

- + From f958218c7b3852f33ac4230249e0182ceeb7de1b Mon Sep 17 00:00:00 2001 From: FlyM1ss Date: Sun, 1 Nov 2026 00:15:50 -0400 Subject: [PATCH 5/9] fix(live): flag catching-up rows and stop calling their curves missing (#586) Co-Authored-By: Claude Opus 5.5 --- .../tests/test_frontend_live_budget.py | 22 +- .../tests/test_frontend_live_leaderboard.py | 280 ++++++++++++++++++ .../tests/test_frontend_live_trading_board.py | 9 + dashboard/frontend/app.html | 4 +- dashboard/frontend/js/live-leaderboard.js | 66 ++++- 5 files changed, 367 insertions(+), 14 deletions(-) diff --git a/dashboard/backend/tests/test_frontend_live_budget.py b/dashboard/backend/tests/test_frontend_live_budget.py index 6efe3596b..6a79fe373 100644 --- a/dashboard/backend/tests/test_frontend_live_budget.py +++ b/dashboard/backend/tests/test_frontend_live_budget.py @@ -46,7 +46,8 @@ "Baselines keep updating." ) -# A board with prints, current, and models cached: the existing banner is hidden. +# A board with prints, current, and a printed model row (_banner_after adds +# it): the existing banner is hidden. _HEALTHY = { "has_prints": True, "snapshot_stale": False, @@ -67,8 +68,25 @@ def _attempt(outcome, kind=None, on="2026-08-27"): } +# The banner reads the rows, not live_status.models_cached (#586): with no +# printed model row it says model curves have not appeared yet. A healthy board +# therefore needs one printed, current model row for the banner to stay hidden. +_PRINTED_MODEL = { + "entry_id": "deepseek_v4_pro", + "model": "DeepSeek V4 Pro", + "is_model": True, + "status": "frozen", + "portfolio_value": 100500, + "snapshot_end": "2026-08-27", +} + + def _banner_after(status): - payload = {"window": {"label": "2026-08-01 — 2026-08-31"}, "entries": [], "live_status": status} + payload = { + "window": {"label": "2026-08-01 — 2026-08-31"}, + "entries": [_PRINTED_MODEL], + "live_status": status, + } return _run_live_js( f"updateLiveHeader({json.dumps(payload)});" "const b = document.getElementById('livePhaseBanner');" diff --git a/dashboard/backend/tests/test_frontend_live_leaderboard.py b/dashboard/backend/tests/test_frontend_live_leaderboard.py index a2a936dcc..a0600ff07 100644 --- a/dashboard/backend/tests/test_frontend_live_leaderboard.py +++ b/dashboard/backend/tests/test_frontend_live_leaderboard.py @@ -478,3 +478,283 @@ def test_neither_board_renders_a_stop_or_take_profit_price(): stripped = _strip_js_comments(source) assert "stop_loss" not in stripped, name assert "take_profit" not in stripped, name + + +# ── #586: catching-up rows are printed, flagged, and not reported missing ─── +# +# These evaluate the whole of js/live-leaderboard.js under node against a fake +# DOM instead of lifting single functions, so a helper another change adds to +# the render path is exercised too rather than raising a ReferenceError here. + +_LIVE_FAKE_DOM = """ +const els = {}; +function el(id) { + if (!els[id]) { + els[id] = { + id, textContent: '', innerHTML: '', hidden: false, dataset: {}, style: {}, + classList: { toggle() {}, add() {}, remove() {}, contains() { return false; } }, + setAttribute() {}, querySelector() { return null; }, + }; + } + return els[id]; +} +globalThis.window = globalThis; +globalThis.document = { + getElementById: el, + querySelector: () => null, + querySelectorAll: () => [], + addEventListener() {}, +}; +globalThis.API_BASE = ''; +""" + + +def _render_catching_up_board(payload, select_id): + """Render `payload` the way loadLiveLeaderboardData does; return the banner, + the table body and the detail panel for the row `select_id`.""" + from dashboard.backend.tests._frontend_source import APP_JS, fn_body, run_node + + script = ( + _LIVE_FAKE_DOM + + fn_body("function escapeHtml(", APP_JS) + + "\n" + + _LIVE_JS + + f"\nconst payload = {json.dumps(payload)};\n" + + "livePayload = payload;\n" + + "updateLiveHeader(payload);\n" + + "populateLiveTable();\n" + + f"renderLiveDetail(payload.entries.find((e) => e.entry_id === {json.dumps(select_id)}));\n" + + "process.stdout.write(JSON.stringify({\n" + + " banner: els.livePhaseBanner.textContent,\n" + + " bannerHidden: els.livePhaseBanner.hidden,\n" + + " table: els.liveLeaderboardTableBody.innerHTML,\n" + + " detail: els.liveSelectedDetail.innerHTML,\n" + + "}));\n" + ) + return run_node(script) + + +def _catching_up_entry(entry_id, name, status, *, value, snapshot_end, is_model=True): + """One board row in the shape live._entry_from_strategy serves.""" + printed = value is not None + return { + "entry_id": entry_id, + "model": name, + "team_name": name, + "team_badge": "Model" if is_model else "Index", + "is_model": is_model, + "status": status, + "rank": None, + "portfolio_value": value, + "cumulative_return": 0.05 if printed else None, + "sharpe_ratio": None, + "max_drawdown": None, + "num_trades": 3 if printed else None, + "snapshot_end": snapshot_end, + "equity_curve": ( + [{"timestamp": "2026-08-03T10:00:00-04:00", "equity": 100000}] if printed else [] + ), + } + + +def _catching_up_payload(*entries): + return { + "period": "live", + "board_title": "Live Leaderboard", + "phase_label": "Season 0 · preview", + "window": {"label": "2026-08-01 — 2026-08-31"}, + "entries": list(entries), + "live_status": { + "has_prints": True, + "snapshot_stale": False, + "frozen_through": "2026-08-27", + "snapshot_end": "2026-08-27", + "session_state": "closed", + # The server counts only ranked (frozen) rows here, so a model + # mid-replay reads 0. Held at 0 in every case: the banner must not + # depend on it. + "models_cached": 0, + "catching_up": [e["entry_id"] for e in entries if e["status"] == "catching_up"], + "trading_days_elapsed": 19, + "trading_days_total": 21, + }, + } + + +_SPY_ROW = _catching_up_entry( + "spy_index", "SPY", "frozen", value=101000.0, snapshot_end="2026-08-27", is_model=False +) + + +def _deepseek(status, *, value=105000.0, snapshot_end="2026-08-20"): + return _catching_up_entry( + "deepseek_v4_pro", "DeepSeek V4 Pro", status, value=value, snapshot_end=snapshot_end + ) + + +@_needs_node +def test_a_catching_up_model_is_printed_and_flagged_with_its_own_date(): + out = _render_catching_up_board( + _catching_up_payload(_SPY_ROW, _deepseek("catching_up")), "deepseek_v4_pro" + ) + row = out["table"].split('data-live-entry="deepseek_v4_pro"')[1].split("")[0] + assert ( + 'Catching up' + ) in row + assert "5.00%" in row, "a catching-up row prints its figures" + assert ( + 'Status' + 'Catching up · through 2026-08-20' + ) in out["detail"] + assert "$105,000.00" in out["detail"] + assert "Awaiting freeze" not in out["detail"] + + +@_needs_node +def test_the_banner_names_the_catching_up_model_instead_of_calling_it_missing(): + out = _render_catching_up_board( + _catching_up_payload(_SPY_ROW, _deepseek("catching_up")), "deepseek_v4_pro" + ) + assert out["bannerHidden"] is False + assert "Model curves appear" not in out["banner"] + assert out["banner"] == ( + "DeepSeek V4 Pro is catching up (through 2026-08-20): it is shown but " + "not ranked until it reaches the latest session." + ) + + +@_needs_node +def test_the_banner_lists_every_catching_up_entry(): + qwen = _catching_up_entry( + "qwen3_7_plus", "Qwen3.7 Plus", "catching_up", value=99000.0, snapshot_end="2026-08-22" + ) + out = _render_catching_up_board( + _catching_up_payload(_SPY_ROW, _deepseek("catching_up"), qwen), "qwen3_7_plus" + ) + assert out["banner"] == ( + "2 entries are catching up (DeepSeek V4 Pro through 2026-08-20, " + "Qwen3.7 Plus through 2026-08-22): they are shown but not ranked " + "until they reach the latest session." + ) + + +@_needs_node +def test_a_model_with_no_curve_still_gets_the_models_pending_banner(): + out = _render_catching_up_board( + _catching_up_payload(_SPY_ROW, _deepseek("pending", value=None, snapshot_end=None)), + "deepseek_v4_pro", + ) + assert out["banner"] == ( + "Baselines frozen through 2026-08-27. Model curves appear once the nightly " + "refresh deploys them; they are never computed on page load." + ) + assert "Catching up" not in out["table"] + assert "Awaiting freeze" in out["detail"] + assert "Status" not in out["detail"] + + +@_needs_node +def test_a_catching_up_row_with_no_value_reads_as_pending_not_catching_up(): + """A row the server marks catching_up but sends no value for cannot print: + it is pending, and a 'Catching up' badge beside 'Awaiting freeze' would say + both at once.""" + out = _render_catching_up_board( + _catching_up_payload(_SPY_ROW, _deepseek("catching_up", value=None)), + "deepseek_v4_pro", + ) + assert "Catching up" not in out["table"] + assert "Status" not in out["detail"] + assert "Awaiting freeze" in out["detail"] + assert out["banner"].startswith("Baselines frozen through 2026-08-27.") + + +@_needs_node +def test_a_stale_snapshot_banner_outranks_the_catching_up_line_and_the_badge_stays(): + payload = _catching_up_payload(_SPY_ROW, _deepseek("catching_up")) + payload["live_status"]["snapshot_stale"] = True + payload["live_status"]["frozen_through"] = "2026-08-28" + out = _render_catching_up_board(payload, "deepseek_v4_pro") + assert out["banner"].startswith("Showing the snapshot through 2026-08-27.") + assert ">Catching up" in out["table"] + + +@_needs_node +def test_a_current_board_shows_no_banner_and_no_badge(): + out = _render_catching_up_board( + _catching_up_payload(_SPY_ROW, _deepseek("frozen", snapshot_end="2026-08-27")), + "deepseek_v4_pro", + ) + assert out["bannerHidden"] is True + assert out["banner"] == "" + assert "Catching up" not in out["table"] + assert "Catching up" not in out["detail"] + + +def _ok_sharpe(value): + """The Sharpe fields boardSharpeValue accepts: status 'ok' plus a finite interval.""" + return { + "sharpe_status": "ok", + "sharpe_ratio": value, + "sharpe_ci_low": value - 1, + "sharpe_ci_high": value + 1, + "sharpe_days": 5, + } + + +@_needs_node +def test_catching_up_rows_sort_after_current_rows_and_before_pending_ones(): + """A catching-up row is shown but not ranked, and its figures are from an + earlier session than the rows beside it. Sorting a column must not slot it + in among the current rows, in either direction: DeepSeek's Sharpe would + sort first descending and Qwen's first ascending.""" + from dashboard.backend.tests._frontend_source import run_node + + rows = [ + _catching_up_entry( + "claude_haiku_4_5", "Claude Haiku 4.5", "pending", value=None, snapshot_end=None + ), + {**_deepseek("catching_up"), **_ok_sharpe(9.0)}, + {**_SPY_ROW, **_ok_sharpe(1.0)}, + { + **_catching_up_entry( + "qwen3_7_plus", "Qwen3.7 Plus", "catching_up", + value=99000.0, snapshot_end="2026-08-22", + ), + **_ok_sharpe(-5.0), + }, + { + **_catching_up_entry( + "equal_weight_djia", "Equal Weight DJIA", "frozen", + value=100800.0, snapshot_end="2026-08-27", is_model=False, + ), + **_ok_sharpe(0.5), + }, + ] + script = ( + _LIVE_FAKE_DOM + + "\n" + + _board_sharpe_js() + + "\n" + + _LIVE_JS + + f"\nlivePayload = {{ entries: {json.dumps(rows)} }};\n" + + "liveSortKey = 'sharpe';\n" + + "liveSortDir = 'desc'; const desc = liveSortedEntries().map((e) => e.entry_id);\n" + + "liveSortDir = 'asc'; const asc = liveSortedEntries().map((e) => e.entry_id);\n" + + "process.stdout.write(JSON.stringify({ desc, asc }));\n" + ) + assert run_node(script) == { + "desc": [ + "spy_index", "equal_weight_djia", + "deepseek_v4_pro", "qwen3_7_plus", + "claude_haiku_4_5", + ], + "asc": [ + "equal_weight_djia", "spy_index", + "qwen3_7_plus", "deepseek_v4_pro", + "claude_haiku_4_5", + ], + } + + +def test_the_banner_no_longer_reads_models_cached(): + assert "models_cached" not in _strip_js_comments(_LIVE_JS) diff --git a/dashboard/backend/tests/test_frontend_live_trading_board.py b/dashboard/backend/tests/test_frontend_live_trading_board.py index d4601fc07..dea130f24 100644 --- a/dashboard/backend/tests/test_frontend_live_trading_board.py +++ b/dashboard/backend/tests/test_frontend_live_trading_board.py @@ -637,3 +637,12 @@ def test_both_about_cards_say_stop_prices_are_not_executed(): "Official rank is by final portfolio value. " "Stop-loss and take-profit prices a model writes are not executed." ) in competition + + +def test_the_about_card_explains_the_catching_up_label(): + about = _APP_HTML_VISIBLE[_APP_HTML_VISIBLE.index("Live Leaderboard") :] + about = about[: about.index("")] + assert ( + "An entry more than one trading session behind is marked Catching up: " + "shown, but not ranked." + ) in about diff --git a/dashboard/frontend/app.html b/dashboard/frontend/app.html index d98519742..6e3be59f2 100644 --- a/dashboard/frontend/app.html +++ b/dashboard/frontend/app.html @@ -1597,7 +1597,7 @@

Live Leaderboard

Each night after the US cash close (16:00 ET, or 13:00 on an NYSE early close), each entry is advanced one trading day: the model sees that day's real bars for the first time and its portfolio carries forward from where the previous day left it. Nobody — including us — knows what the next bar does when an entry locks, which is what separates this board from the fixed-window Competition one.

Each entry is one continuous book that starts the month flat at $100,000 and ranks only the days inside it; the board resets on the 1st. Entries are a curated roster of AI models and baselines — there are no user submissions.

A model may write a stop-loss or take-profit price into its decision. The simulator does not act on either: orders are placed only at decision times, and a position is never sold because the price reached the stop or target the model wrote.

-

We are in Season 0, the shakedown season, so read the standings as a preview rather than an official result. An entry more than one trading session behind is shown but not ranked.

+

We are in Season 0, the shakedown season, so read the standings as a preview rather than an official result. An entry more than one trading session behind is marked Catching up: shown, but not ranked.

Competition Leaderboard

@@ -2541,7 +2541,7 @@

Refund Credits purchase

- +