fix(analytics): momentum loop starvation, statements period mismatch, empty-snapshot guards #79
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
gertjan/bodega!79
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/nightly-analytics-silent-failures"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Follow-up to #78: its honest-status fix surfaced a momentum failure on night one; pulling that thread found three more silent production failures. Full evidence trail in the session; summary:
Momentum (
_OperationCancelledat save, nightly)_percentile_ranklinear-scans the full ~24k-value universe per symbol per window — ~1.9 billion Python comparisons (~9 min, 03:08→03:18 in last night's log) on the event loop. pymongo's heartbeats starve, and the save'sdelete_manygets its connection cancelled — the same mechanism that killed the correlation persist. Worse: the delete had already executed server-side, so momentum_snapshot is currently empty in production (stale meta only).Fixed: sort-once +
bisectranking (O(N log N)) on a worker thread; bars processed per fetch batch instead of accumulating ~6.5M pydantic objects; save retried once via a sharedretry_once(correlation_refresh now uses it too).Statements period vocabulary (four months of empty fundamentals)
FinancialStatementsRepositoryqueries{"period": "annual"}, but the collection has stored FMP's vocabulary (FY,Q1..Q4) since the 2026-03-09 refetch. Every reader got nothing: ERP computed 0 symbols every run since March, scores silently lost their fundamentals inputs, and the/batch+/assetsstatement endpoints returned empty. Queries now translate at the repo boundary (annual→FY,quarter→Q1..Q4, raw values pass through).Destructive saves + empty-snapshot guards
Momentum and ERP both used delete-then-insert. ERP's 0-symbol run "successfully" replaced its snapshot with an empty one (currently live:
total_symbols: 0). Both repos now upsertsnapshot_ts-stamped docs first and prune stale after (the #78 correlation pattern), and both tasks and repos refuse to persist an empty snapshot — upstream data regressions must fail loudly instead of quietly overwriting good data.Tests
_build_rank_docsranks/dispersion/sector edge casesAfter merge (restores)
Momentum and ERP snapshots are both empty in prod right now. Tonight's crons (03:00 / 04:00) should restore them with this fix deployed — ERP for the first time since March.
🤖 Generated with Claude Code
https://claude.ai/code/session_01JRnthdVhGGt5FeSQ8m3aUA