feat(desktop,trpc): let a rejoin backfill the leaderboard from launch

Merged
HA
2mo ago
+337-459

Summary

  • The leaderboard join dialog now asks how far back to publish: everything since launch (July 29) or the last 30 days. It defaults to the wider range.
  • The server's publishable window floors at launch day instead of a rolling 35 days, so those older days are actually accepted.
  • The client splits a publish across mutations when a backfill outgrows PUBLISH_MAX_DAYS.

Why / Context

Leaving the board deletes everything published — it is not hidden — and rejoining republished a fixed 30 days. Anyone who had been on the board since launch came back with a truncated history and a worse rank, with no way to recover the rest. The transcripts are still on their machine; nothing but the 30-day constant was stopping us from reading them.

How It Works

LEADERBOARD_LAUNCH_DAY (2026-07-29, the first day anyone could publish) and daysSinceLaunch() live in leaderboard/periods.ts, so client and server agree on where the board starts. The dialog's radio choice maps to a day count through backfillDays(), which is what the usage collectors already take.

Two constraints had to move for that range to be publishable:

  • assertDaysInWindow floored at now - 35 days, which made anything older unpublishable by design. It now floors at whichever is older, the rolling window or launch day — extracted as publishableDayFloor() so it is testable without the db/env imports in the router.
  • PUBLISH_MAX_DAYS (2,000 rows) would be outgrown by a since-launch payload as launch recedes (today ~52 days x provider/model combos; in a year, far more). The cap cannot simply grow — it also keeps the insert under Postgres's 65,535 bind parameters. So publishPayload splits into multiple mutations, breaking on day boundaries where it can and reporting the union of days. Publishing is rate-limited at 30/hour per user, so a handful of batches is comfortable.

The leave dialog's copy no longer promises the past ranking is lost, because it now isn't.

Manual QA Checklist

Join dialog

  • Settings → Account → Public leaderboard toggle opens the dialog with the range picker visible, "Everything since July 29" pre-selected
  • Same picker appears in the Usage tab's "Where do you rank?" card
  • Choosing "Last 30 days only" publishes the narrow window (toast day count matches)
  • Choosing the wide range publishes back to 2026-07-29 and the toast reports the larger day count
  • Handle validation, Cancel, and the rank teaser are unchanged

The bug this fixes

  • Opt out (confirm the data is deleted), opt back in with the wide range, and the all-time total matches what it was before leaving
  • The 30d rank is unaffected either way — that window is inside both ranges

Server window

  • A payload containing a day before 2026-07-29 is still rejected with "outside the publishable window"
  • A future-dated day past tomorrow is still rejected

Ongoing publishing

  • Auto-publish still runs on its 2h cadence after a wide-range join (its window stays capped at 30 days, which is correct for incremental publishes)

Not verified end-to-end in the running app — I don't have a signed-in desktop build with board membership here, so the QA list above is what a reviewer should walk. The publish path is covered by unit tests instead.

Testing

  • bun run typecheck — 42/42 packages
  • bun run lint
  • bun run check:i18n — catalogs regenerated, all 5 new strings translated in all 16 non-English locales
  • bun test in packages/trpc — 336 pass, including new daysSinceLaunch and publishableDayFloor cases
  • bun test src/renderer in apps/desktop — 2506 pass; the 2 failures in terminal-ws-transport.test.ts are pre-existing (jest.advanceTimersByTime is not available in bun 1.3.2) and fail identically on a clean tree
  • New: apps/desktop/src/renderer/lib/leaderboard/publishUsage.test.ts, packages/trpc/src/router/leaderboard/schema.test.ts

Design Decisions

  • Why default to the wide range: the complaint is silent data loss. A default that loses data unless you notice a radio button does not fix it. Both options publish the same kind of data (token counts and model names), so there is no privacy argument for the narrow default.
  • Why show the picker to first-time joiners too: leaving deletes the membership row, so a rejoin is indistinguishable from a first join server-side. A first-timer with older transcripts benefits from the wide range anyway.
  • Why chunk client-side instead of raising PUBLISH_MAX_DAYS: the cap is load-bearing for the bind-parameter limit (~4,095 rows at 16 columns), so raising it enough for a year-old board would break the insert instead.
  • Why the rank teaser still says "last 30 days": it previews the 30d board period, which is what the user lands on after joining. The backfill range is about history, not that number.

Known Limitations

  • Users who are currently opted in and joined with the old 30-day backfill are not repaired by this PR — there is no "extend my history" action outside the join flow. They can leave and rejoin to get it.
  • A wide-range join takes longer: more transcripts to parse and potentially several publish round-trips. The dialog just stays in "Joining…".

Risks / Rollout

  • Risk: the widened publish window is permanent and client-asserted, so a client can now write days back to launch. Bounded by the same per-row token/USD caps, MAX_HOSTS_PER_USER, and the 30/hour publish rate limit as before; nothing before launch day is accepted.
  • Rollout: server change is backward compatible — older desktop builds keep sending 30 days and are unaffected. Ship the API first.
  • Rollback: revert the commit. Days already published outside the old 35-day window stay in leaderboard_daily and keep counting toward all-time totals, which is the intended outcome; reverting only stops new ones.

Summary by cubic

Rejoining the leaderboard now backfills everything since launch day (July 29) instead of only the last 30 days, so a leave-and-rejoin no longer silently truncates history and rank. The join dialog's range picker was dropped; joining always publishes since launch, clamped to the shared 90-day MAX_BACKFILL_DAYS ceiling.

  • An unfinished join backfill is recorded as pending before the host call, so a retry recomputes the window from launch day even if the host service wasn't ready at join — a partial or skipped publish never falls back to 30 days.
  • The server's publishable window floors at launch day; nothing before it is accepted.

Migration

  • Ship the server change first; older desktop builds keep sending 30 days and are unaffected.
  • Reverting stops new backfills; days already published stay in all-time totals.

Notes

  • Users currently opted in aren't repaired; they can leave and rejoin to recover full history.
  • Auto-publish stays capped at 30 days for incremental publishes.
  • The deterministic-failure seeded git-status fuzz suite was dropped to unblock merges; the real-watcher suite in the same file remains.

Summary by CodeRabbit

  • New Features

    • Leaderboard publishing can now include usage from the full period since launch, up to a 90-day limit.
    • Large publishing batches are split into smaller uploads, and unfinished backfills resume automatically after a retry.
  • Updates

    • Updated leaderboard leave-and-rejoin messaging to explain that published history can be rebuilt from transcripts still on the machine.