4.5 KiB
4.5 KiB
id, title, status, type, team, supporting_teams, roadmap_item, priority
| id | title | status | type | team | supporting_teams | roadmap_item | priority | ||
|---|---|---|---|---|---|---|---|---|---|
| TASK-177-harden-annual-ranking-snapshot-operations | Harden annual ranking snapshot operations | done | backend | Backend Senior |
|
foundation | medium |
TASK-177-harden-annual-ranking-snapshot-operations - Harden annual ranking snapshot operations
Goal
Improve annual ranking snapshot reliability for production use without recalculating on public requests or changing visible frontend behavior.
Context
The annual snapshot flow is implemented and documented, but edge cases around missing data, empty years, unsupported years/metrics, and limit normalization should be hardened with small, verifiable backend improvements.
Steps
- Read the listed files first.
- Review generation and read flow for annual ranking snapshots.
- Apply small validation and response consistency improvements in backend code.
- Ensure snapshot behavior remains stable for ready/empty/missing and unsupported metric states.
- Document any follow-up work that should remain a separate task instead of broadening this one.
Files to Read First
- AGENTS.md
- ai/repo-context.md
- ai/architecture-index.md
- docs/stats-section-functional-plan.md
- docs/annual-ranking-snapshot-runbook.md
- backend/app/routes.py
- backend/app/rcon_annual_rankings.py
- backend/app/rcon_historical_leaderboards.py
- ai/tasks/done/TASK-171-validate-stats-section-with-backend-data.md
- ai/tasks/done/TASK-173-add-annual-ranking-snapshot-runbook.md
Expected Files to Modify
- backend/app/rcon_annual_rankings.py
- backend/app/routes.py only if endpoint mapping/validation requires changes
- docs/annual-ranking-snapshot-runbook.md only if documented operations change
- ai/tasks/done/TASK-177-harden-annual-ranking-snapshot-operations.md
Constraints
- No frontend modifications unless a strict critical backend-related bug requires it (and document the reason).
- No new architecture.
- No major migrations.
- Do not re-enable Elo/MMR.
- Do not reintroduce Comunidad Hispana #03.
- Do not use public scoreboard as primary source.
- Do not recalculate annual ranking in each public request.
- Keep changes small and independently verifiable.
Validation
- Run
powershell -ExecutionPolicy Bypass -File scripts/run-integration-tests.ps1. - Test annual ranking endpoint for:
- current year with
metric=kills - past year with no data
- future year missing snapshot
- unsupported metric
- low limit, e.g.
3 - high limit, verifying normalization if applicable
- current year with
- Run
git diff --name-onlyand verify scoped files only.
Outcome
Applied hardening:
- Added explicit annual year normalization in
backend/app/rcon_annual_rankings.pyfor supported1..9999values. - Added reusable limit normalization in the annual snapshot reader/generator with a bounded cap of
100. - Added response metadata for annual snapshot reads:
requested_limiteffective_limitsnapshot_limititem_count
- Hardened effective-limit resolution so a ready snapshot serves no more rows than:
- the requested limit,
- the persisted snapshot limit,
- and the actual stored item count.
- Wrapped the annual route payload build in a
ValueErrorguard so invalid annual requests return controlled400payloads.
Documentation updated:
docs/annual-ranking-snapshot-runbook.mdnow documents annual limit metadata and explains whyeffective_limitcan be lower thanrequested_limitfor ready snapshots.
Validated responses:
- current year with
metric=kills->200 - past year with no guaranteed data -> controlled
200withreadyormissingdepending on stored snapshot presence - future year without snapshot ->
200withsnapshot_status="missing" - unsupported metric ->
400 - low limit
3->200,requested_limit=3,effective_limit<=3 - high limit
101->400 - unsupported year
10000->400
Validation run:
- Inline Python route validation for the annual endpoint cases above
powershell -ExecutionPolicy Bypass -File scripts/run-integration-tests.ps1
Known limits:
- The API still keeps
limitaligned with the served effective limit for ready snapshots so current frontend behavior remains unchanged. - This task does not add scheduling or regeneration automation; it only hardens the existing read/generate contract.
Future task recommendation:
- If operations need stronger guarantees, create a follow-up task for scheduled annual snapshot generation/audit reporting rather than broadening this read-path hardening further.