Skip to content

refactor(data): unify source-health tracking on one shared router (P1.3)#66

Merged
Jcstack merged 1 commit into
mainfrom
refactor/p1-unify-source-router
Jun 26, 2026
Merged

refactor(data): unify source-health tracking on one shared router (P1.3)#66
Jcstack merged 1 commit into
mainfrom
refactor/p1-unify-source-router

Conversation

@Jcstack

@Jcstack Jcstack commented Jun 26, 2026

Copy link
Copy Markdown
Owner

Closes #49. There were two overlapping failover/health mechanisms with no single source of truth: the daily fetcher's inline cascade recorded no health, while realtime/news each built their own DataSourceRouter and /admin created a third, empty one — so health was fragmented and the dashboard showed nothing real.

Fix — unify on a shared router, without touching the proven cascade

  • source_router.py: get_source_router() process-wide singleton + reset_source_router().
  • fetcher.py: record per-source success (on fresh data) / failure (on exception) at the 4 cascade points. Stale data is data lag, not a source failure → not recorded. Recording is wrapped defensively so it can never break a fetch.
  • realtime.py / news_fetcher.py / admin.py: default to the shared router, so all sources feed (and /admin reads) one health view.
  • conftest.py: autouse reset for test isolation (health is in-memory + shared).

Behavior-preserving

Cascade order / retry / freshness logic is unchanged — only additive health instrumentation on a hot path, wrapped to be failure-proof. ruff clean; 69 data/router/realtime/news tests green (incl. 5 new proving the singleton is shared and the fetcher records into it).

Scope note: making the cascade consult the router to skip DOWN sources (routing-aware failover) is a deliberate Phase-2 follow-up — higher risk on the hot path; this PR establishes the single health brain first. Simulation-only; not investment advice.

Closes #49 (P1.3). There were two overlapping failover/health mechanisms, and
no single source of truth: the daily fetcher's inline cascade recorded NO
health, while realtime/news each created their own DataSourceRouter and the
/admin view created a third, empty one — so source health was fragmented and
the dashboard showed nothing real.

Unify on a process-wide shared router without touching the proven cascade logic:
- source_router.py: add get_source_router() singleton + reset_source_router().
- fetcher.py: record per-source success (on fresh data) / failure (on exception)
  into the shared router at the 4 cascade points. Stale data is data lag, not a
  source failure, so it is not recorded. Recording is wrapped defensively — it
  can never break a data fetch.
- realtime.py / news_fetcher.py / admin.py: default to the shared router, so all
  data sources now feed (and /admin reads) one health view.
- conftest.py: autouse reset of the shared router for test isolation.

Behavior-preserving: the cascade order/retry/freshness logic is unchanged — only
additive health instrumentation. ruff clean; 69 data/router/realtime/news tests
green (incl. 5 new). Routing-aware cascade (skipping DOWN sources via the router)
is a deferred Phase-2 follow-up noted on the issue.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Jcstack
Jcstack merged commit 4a1c823 into main Jun 26, 2026
6 checks passed
@Jcstack
Jcstack deleted the refactor/p1-unify-source-router branch June 26, 2026 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P1.3] Two overlapping data-failover mechanisms — unify

1 participant