5.1 KiB
id, title, status, type, team, supporting_teams, roadmap_item, priority
| id | title | status | type | team | supporting_teams | roadmap_item | priority | |
|---|---|---|---|---|---|---|---|---|
| TASK-196-fix-ranking-snapshot-cli-json-serialization | Fix ranking snapshot CLI JSON serialization | done | backend | Backend Senior |
|
foundation | high |
TASK-196 - Fix ranking snapshot CLI JSON serialization
Goal
Correct the generate-ranking-snapshot CLI output path so it can print the generated payload as JSON without failing on datetime or date values.
Context
The weekly ranking snapshot command already generates and persists snapshots correctly in PostgreSQL. Production validation confirmed ranking_snapshots.snapshot_status=ready, item_count=20, source_matches_count=41, and /api/ranking?timeframe=weekly&metric=kills&limit=20 returns snapshot_status=ready with fallback_used=false.
The remaining bug is only in the CLI print path inside backend/app/rcon_historical_leaderboards.py, where _main() currently calls json.dumps({"status": "ok", "data": payload}, ensure_ascii=True, indent=2) and can still receive native datetime values inside payload.
Preserve the current product identity: Spanish-speaking HLL Vietnam community, military/Vietnam/tactical/sober visual direction and controlled repository evolution.
Steps
- Read the listed files first.
- Apply only the scoped JSON serialization fix for the CLI output path.
- Reuse an existing serialization pattern if a safe local helper already exists.
- Validate scripts, local serialization behavior and CLI output behavior when possible.
- Document root cause, applied change and validation results.
Files to Read First
AGENTS.mdai/repo-context.mdai/architecture-index.mdbackend/app/rcon_historical_leaderboards.pybackend/app/main.pyscripts/run-stats-validation.ps1
Expected Files to Modify
backend/app/rcon_historical_leaderboards.pyscripts/run-stats-validation.ps1ai/tasks/done/TASK-196-fix-ranking-snapshot-cli-json-serialization.md
Constraints
- Keep the change minimal.
- Fix only the CLI JSON serialization path.
- Do not change snapshot generation logic.
- Do not change
/api/ranking. - Do not touch frontend, assets or design.
- Do not reactivate Elo/MMR.
- Do not reintroduce Comunidad Hispana #03.
- Do not change annual behavior except reusing a generic serializer pattern if it already exists.
Validation
Before completing the task ensure:
powershell -ExecutionPolicy Bypass -File scripts/run-stats-validation.ps1powershell -ExecutionPolicy Bypass -File scripts/run-integration-tests.ps1- local import validation proves the payload from
generate_ranking_snapshot(...)can be serialized withjson.dumps - if the environment allows it, execute the CLI and confirm it prints JSON without
TypeError git diff --name-onlymatches the expected scope
Outcome
Document:
-
Root cause:
generate_ranking_snapshot(...)already generated and persisted the snapshot correctly.- the CLI failure happened afterwards in
_main(), whenjson.dumps({"status": "ok", "data": payload}, ensure_ascii=True, indent=2)received nativedatetime/dateobjects insidepayload. - the bug only affected CLI JSON printing and did not affect PostgreSQL snapshot persistence or
/api/ranking.
-
Applied change:
backend/app/rcon_historical_leaderboards.py- added a local controlled
_json_default(...)serializer fordatetimeanddate - serializes
datetimethrough the module's existing_to_iso(...)helper - serializes
datewithisoformat() - updated the CLI
json.dumps(...)call to usedefault=_json_default
- added a local controlled
scripts/run-stats-validation.ps1- extended the CLI regression to return a payload containing both
datetimeanddate - verifies
_main(...)exits successfully - verifies stdout JSON contains ISO strings instead of failing with
TypeError
- extended the CLI regression to return a payload containing both
-
Validation executed:
powershell -ExecutionPolicy Bypass -File scripts/run-stats-validation.ps1powershell -ExecutionPolicy Bypass -File scripts/run-integration-tests.ps1- local import validation with
json.dumps(..., default=app.rcon_historical_leaderboards._json_default) - local
_main(...)validation with a monkeypatchedgenerate_ranking_snapshot(...)payload containingdatetimeanddate - local CLI execution:
python -m app.rcon_historical_leaderboards generate-ranking-snapshot --timeframe weekly --server-key all --metric kills --limit 20 --sqlite-path backend/data/hll_vietnam_dev.sqlite3
-
Validation notes:
- the live backend at
http://127.0.0.1:8000was not available in this environment, so route-contract validation completed through local Python imports. - the local CLI command printed JSON successfully and no longer raised
TypeError: Object of type datetime is not JSON serializable. - production behavior described in the task context remains confirmed: snapshot generation already worked, and the observed failure was only the final CLI JSON print step.
- the live backend at
Change Budget
- Prefer fewer than 5 modified files.
- Prefer changes under 200 lines when feasible.
- Split the work into follow-up tasks if limits are exceeded.