fix: security price sync reliability (TwelveData errors, offline resolver, health checker, missing names)
Merged
GF
1mo ago+1128+1128+0123456789012345678901234567890123456789-95-95-01234567890123456789
Fixes #3097
Summary
Provider::TwelveData#default_error_transformernow parses the real API error body instead of surfacing Faraday's generic HTTP status message, so the existing plan-restriction detection (Security.plan_upgrade_required?) actually works and real messages like "available starting with the Grow or Venture plan" reach the debug log/UI instead of a meaningless "status 404".Security::Resolverdistinguishes a technical provider-search failure (rate limit/timeout) from a genuine "no match" — technical failures getoffline_reason: "resolution_pending"instead of the generic offline fallback, so a future retry can pick them up.Security::Resolver#reactivate_if_provider_available!now also reactivates when the caller explicitly passed aprice_provider(i.e. the user picked this exact security+provider from search results), not only whenoffline_reason == "provider_disabled"— matching the trust levelHoldingsController#remap_securityalready applies unconditionally.Security::HealthCheckeronly deletes a security's price history on an offline transition if it never had a successfully-fetched price; existing history is preserved. It also no longer counts "no provider available" as a fetch failure, so it can't silently overwrite a more specificoffline_reason(e.g."provider_disabled") over time.Security#find_or_fetch_pricenow logs failed provider fetches to the debug event log (deduped to at most once per security per day).Provider::YahooFinance#fetch_chart_datalogs its previously-swallowed FX fetch errors; its Faraday retry middleware now also retries transient 5xx statuses, not only 429.Security::Resolver#find_or_create_provider_match!now backfillsnamedirectly from the search result (only when blank, never overwriting an existing name) instead of relying entirely on a separatefetch_security_info//profilecall, which appears to be plan-gated for effectively all symbols on TwelveData.- Daily market data import time is now configurable via
/settings/hosting(mirrors the existingauto_sync_time/AutoSyncSchedulerpattern), replacing the hardcoded22:00 UTCentry inconfig/schedule.yml. Default behavior is unchanged unless actively reconfigured.
See #3097 for the full writeup of each bug with root cause.
Test plan
-
bin/rails test— full suite, no regressions (pre-existing environmental failures only: Snaptrade/Stripe/AI config gaps unrelated to this change) - New/updated unit tests for every change (resolver, health checker, provided, twelve_data, yahoo_finance, market_data_scheduler, hostings_controller)
-
bin/rubocop— clean -
bin/brakeman— 0 warnings - Live-verified in a real self-hosted instance against the live TwelveData API:
- Confirmed the real plan-restriction message now surfaces for a restricted symbol
- Confirmed a security stuck offline reactivates when re-selected with a valid provider
- Confirmed price history survives an offline transition
- Confirmed the configurable import cron job fires at the configured time and completes
- Confirmed a security name now populates immediately from search results
🤖 Generated with Claude Code
Summary by CodeRabbit
-
New Features
- Added settings to enable daily market-data synchronization and choose its run time and timezone.
- Synchronization updates automatically when settings change and follows local weekday schedules.
- Added validation and safe defaults for invalid schedule times.
-
Bug Fixes
- Improved provider error messages and retries for temporary service failures.
- Preserved historical prices during outages and improved security recovery behavior.
- Better distinguishes temporary provider failures from genuine no-match results.
- Added clearer warnings, structured diagnostics, and reduced duplicate failure notifications.
- Disabling synchronization now removes its scheduled job.