8.8 KiB
id, title, status, type, team, supporting_teams, roadmap_item, priority
| id | title | status | type | team | supporting_teams | roadmap_item | priority | |
|---|---|---|---|---|---|---|---|---|
| TASK-271 | Split RCON live ingestion from historical materialization | done | backend | Backend Senior |
|
current-match | high |
TASK-271 - Split RCON live ingestion from historical materialization
Goal
Separate near-real-time AdminLog ingestion for current-match freshness from the slow historical materialization path so /api/current-match/kills and /api/current-match/players can stay fresh without waiting on heavy historical work.
Context
Production evidence shows the current combined worker design is starving the current-match read model:
- production service
hll-vietnam-rcon-historical-worker-1currently runspython -m app.rcon_historical_worker loop - configured interval is
HLL_RCON_HISTORICAL_CAPTURE_INTERVAL_SECONDS=2 - configured AdminLog lookback is
HLL_BACKEND_RCON_ADMIN_LOG_LOOKBACK_MINUTES=10 - real
rcon_historical_capture_runsdurations are around15-30minutes - recent runs overlapped and one failed with PostgreSQL deadlock
- each cycle materializes roughly
838kplayer-stat rows and updates roughly392-394materialized matches /api/current-match/killsand/api/current-match/playersreadrcon_admin_log_events, not live CRCON/RCON per public request
This means the current-match feed problem is not primarily frontend rendering. The source table is not being refreshed frequently enough because live AdminLog ingestion is coupled to heavy historical materialization.
This task must preserve the current product identity and must not change frontend layout, CSS, assets, RCON hosts, ports, passwords, server list, 27001, ranking semantics, Elo/MMR activation, or reintroduce comunidad-hispana-03.
Steps
- Inspect the current historical worker, current-match worker, AdminLog ingestion/storage, materialization path, API read path and Portainer deployment.
- Implement a dedicated lightweight live AdminLog worker that only refreshes
rcon_admin_log_events. - Reduce repeated PostgreSQL schema initialization in the live path by moving obvious DDL/init work out of hot loops and request reads.
- Add no-overlap protection for heavy historical materialization so concurrent heavy runs skip cleanly instead of overlapping.
- Update Portainer deployment so live ingestion and heavy historical materialization run as separate services with safe cadences.
- Add or update focused tests and refresh the current-match freshness documentation with post-deploy validation commands.
Files to Read First
AGENTS.mdai/architecture-index.mdai/repo-context.mdai/orchestrator/backend-senior.mdbackend/app/rcon_historical_worker.pybackend/app/rcon_current_match_worker.pybackend/app/rcon_admin_log_ingestion.pybackend/app/rcon_admin_log_storage.pybackend/app/postgres_rcon_storage.pybackend/app/payloads.pydeploy/portainer/docker-compose.nas.ymldocs/current-match-adminlog-freshness.md
Expected Files to Modify
ai/tasks/in-progress/TASK-271-split-rcon-live-ingestion-from-historical-materialization.mdbackend/app/rcon_current_match_worker.pybackend/app/rcon_admin_log_storage.pybackend/app/postgres_rcon_storage.pybackend/app/rcon_historical_storage.pybackend/app/rcon_historical_worker.pybackend/tests/test_rcon_current_match_worker.pybackend/tests/test_rcon_historical_worker.pybackend/tests/test_current_match_payload.pydeploy/portainer/docker-compose.nas.ymldocs/current-match-adminlog-freshness.md
Constraints
- Do not run
ai-platform run. - Do not commit or push.
- Do not use
git add .. - Do not touch
ai/system-metrics.md. - Do not include
tmp/. - Do not include TASK-204, TASK-242 or unrelated in-progress/done tasks.
- Do not touch weapon assets, map assets or clan assets.
- Do not touch frontend layout or CSS.
- Do not change RCON hosts, ports, passwords,
27001or the configured server list. - Do not reintroduce
comunidad-hispana-03. - Do not reactivate Elo/MMR.
- Do not change ranking semantics or fabricate support rankings.
- Do not change annual tops/player search behavior except where explicitly needed to stop them from blocking live ingestion.
- Keep the change backend/deployment/documentation scoped and reviewable.
Validation
Before completing the task ensure:
python -m compileall backend/appcd backend; python -m unittest tests.test_current_match_payloadcd backend; python -m unittest tests.test_rcon_historical_workercd backend; python -m unittest tests.test_rcon_current_match_workergit diff --name-onlymatches the intended scope- no unrelated dirty files were modified
- documentation reflects the new live worker split and post-deploy checks
Outcome
Implemented scope:
- dedicated live AdminLog worker path kept in
backend/app/rcon_current_match_worker.py - live worker storage initialization moved out of the hot loop body and out of per-target persistence calls
- live worker no longer waits on the shared long-running backend writer lock
- current-match persistence stays idempotent through the existing
rcon_admin_log_eventsdedupe path - historical capture/materialization path gained a single-running historical guard and returns
skippedwithalready-runningwhen a heavy run is still active - Portainer deployment now splits
rcon-live-adminlog-workerfromrcon-historical-worker - heavy historical cadence was set explicitly to
900seconds in the Portainer compose file
Validation completed:
python -m compileall backend/appcd backend; python -m unittest tests.test_current_match_payloadcd backend; python -m unittest tests.test_rcon_historical_workercd backend; python -m unittest tests.test_rcon_current_match_worker
Post-deploy hotfix note:
- live AdminLog PostgreSQL startup now initializes only AdminLog tables instead of the full historical/materialization schema path
- the old
idx_rcon_historical_single_running_historicalunique index is removed from schema bootstrap and dropped when present - PostgreSQL historical single-running protection now uses a runtime advisory lock on the heavy historical worker path
- duplicate or stale historical
runningrows no longer crash the live worker startup path
Follow-up intentionally left out of central scope:
TEAM KILLparser correctness remains a separate follow-up task unless handled later with a tiny isolated patch
Production Hotfix Root Cause
The TASK-271 split originally added the PostgreSQL unique index
idx_rcon_historical_single_running_historical as a schema-level historical
single-running guard. Production already had more than one
rcon_historical_capture_runs row with mode='historical', so full PostgreSQL
schema initialization attempted to create a unique index over non-unique
existing data and failed with psycopg.errors.UniqueViolation.
The live AdminLog worker called initialize_rcon_admin_log_storage() on startup.
Before the hotfix, that PostgreSQL path delegated to full RCON schema bootstrap,
so live AdminLog ingestion could crash because of historical capture-run state.
Production Hotfix Fix
- Removed creation of
idx_rcon_historical_single_running_historicalfrom runtime PostgreSQL schema SQL. - Added an idempotent
DROP INDEX IF EXISTS idx_rcon_historical_single_running_historicalcleanup to full PostgreSQL bootstrap. - Added
initialize_postgres_admin_log_storage()so the live AdminLog worker initializes onlyrcon_admin_log_eventsand profile snapshot tables. - Replaced PostgreSQL historical overlap protection with
pg_try_advisory_lock()on the heavy historical path only. - Kept SQLite historical overlap protection query-based with stale
runningrows marked after the existing runtime timeout.
Production Hotfix Validation
- Live worker startup is independent from duplicate or stale
mode='historical'capture rows. - The live worker persists AdminLog rows idempotently and does not call
materialize_rcon_admin_log. - The historical worker returns
skippedwith reasonalready-runningwhen the PostgreSQL advisory lock is unavailable. - Runtime schema code no longer creates
idx_rcon_historical_single_running_historical.
Remaining Risks
- Existing stale PostgreSQL
runningrows remain historical audit data; they no longer provide locking semantics and should be interpreted through worker logs plus advisory-lock behavior. - Live freshness still depends on RCON AdminLog availability and credentials per configured trusted target.
TEAM KILLAdminLog parser correctness remains a separate follow-up.
Change Budget
- Prefer fewer than 5 modified files when feasible, but accept a slightly larger backend/deploy/docs scope if required to complete the split safely.
- Prefer focused edits over broad refactors.
- Split out follow-up correctness issues instead of expanding scope unnecessarily.