fix: pipeline health — stuck docs, price fallback, sentiment normalization, signal-engine scale, quality gate

- Scheduler: lower stale threshold 240→30 min, batch limit 100→500, TTL 14400→3600
- Prediction snapshot: add 24h market_snapshots time-window fallback
- Aggregation: add normalize_impact_scores() z-score normalization
- Helm: signal-engine replicas → 0 (idle when dual pipeline disabled)
- Quality gate: max_snapshot_age_hours 24→48
- Add backfill script for NULL price_at_prediction snapshots
- Add PBT bug condition and preservation tests (14 tests)
This commit is contained in:
Celes Renata
2026-07-10 20:16:01 +00:00
parent a4f51c00e1
commit ca712ad4a0
15 changed files with 1815 additions and 9 deletions
+6 -6
View File
@@ -866,10 +866,10 @@ async def main() -> None:
await rds.close()
# How long a document can sit in "parsed" before we consider it orphaned
# Must be longer than the expected queue drain time to avoid re-enqueuing
# docs that are already queued but not yet processed.
STALE_PARSED_THRESHOLD_MINUTES: int = 240
# How long a document can sit in "parsed" before we consider it orphaned.
# Documents stuck longer than 30 minutes are likely orphaned (Redis lost
# their queue entries during pod restart, OOM, etc.).
STALE_PARSED_THRESHOLD_MINUTES: int = 30
# How long after an extraction failure before we retry
EXTRACTION_FAILED_RETRY_MINUTES: int = 60
@@ -877,7 +877,7 @@ EXTRACTION_FAILED_RETRY_MINUTES: int = 60
# Redis set key for tracking enqueued doc IDs (prevents duplicate enqueuing)
_ENQUEUED_SET = f"{QUEUE_PREFIX}:enqueued"
# How long an enqueued marker lives before it can be re-enqueued (seconds)
_ENQUEUED_TTL = 14400 # 4 hours — matches STALE_PARSED_THRESHOLD_MINUTES
_ENQUEUED_TTL = 3600 # 1 hour — matches the new recovery cadence
async def _enqueue_if_new(
@@ -924,7 +924,7 @@ async def recover_stale_documents(pool: asyncpg.Pool, rds: aioredis.Redis) -> in
SELECT 1 FROM global_events ge WHERE ge.source_document_id = d.id
)
ORDER BY d.created_at ASC
LIMIT 100""",
LIMIT 500""",
STALE_PARSED_THRESHOLD_MINUTES,
)