feat(freshness-monitor): template-aware trading-day-axis resolution for historical probe#341
Merged
Merged
Conversation
…or historical probe Closes the calendar-vs-trading-day mismatch surfaced by PR #339's historical probe — research_signals was registered as signals/{date}/signals.json + cadence=saturday_sf but the producer writes to Friday trading-day keys (signals/2026-05-22/, /05-15/, /05-08/...). The pre-fix probe correctly reported the Saturday keys absent — but the operator-facing display showed 9/12 gaps when the true gap rate was lower; the registry just wasn't asking the right question. Restructure: - _iter_sf_firing_dates: returns the SF cron's calendar firing dates (last N Saturdays for saturday_sf, last N Mon-Fri for weekday_sf / eod_sf). No change from prior calendar-naive behavior at this layer. - _resolve_axis_dates: NEW. Translates firing dates to the date-axis the template actually uses. {date} → calendar firing date; {trading_day} → previous_trading_day(firing_date) for saturday_sf/weekday_sf, or firing_date itself for eod_sf (EOD writes today's close). alpha_engine_lib.trading_calendar.previous_trading_day IS NYSE- holiday-aware, so Memorial-Day-style holidays resolve correctly. - _iter_historical_cycle_dates: now takes optional template arg and composes the two helpers. Backward-compat: callers omitting template get calendar-axis (pre-PR behavior). - _handle_historical: passes spec.s3_key_template to the resolver. 6 new unit tests cover the trading_day-axis path for all three cadences + NYSE-holiday skip via the lib + backward-compat for the template-less call signature. Full suite: 27 passed (21 prior + 6 new). Live smoke (post-deploy + historical invoke after companion alpha-engine-config registry flip): research_signals — 12/12 gaps (under {date}) → 5/12 gaps (under {trading_day}). 4 cycles correctly recovered. Composes with alpha-engine-config registry PR (this branch's sibling): flips research_signals, research_consolidated_morning, scanner_candidates_json from {date} → {trading_day}. 4 backtest_* entries documented + held at {date} pending producer-side audit (backtester writes to ad-hoc current-date-of-write, neither {date} nor {trading_day}). Per the system's now_dual() convention codified in alpha-engine-docs/private/DATE_CONVENTIONS.md — trading_day = last_closed_trading_day(now); this PR brings the registry + historical probe into compliance with that convention. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the calendar-vs-trading-day mismatch surfaced by PR #339's historical probe. Producer artifacts mostly write to
{trading_day}keys (Fri for sat_sf, prev weekday for weekday_sf, today for eod_sf) per the system-widenow_dual()convention, but the registry had multiple entries templated with{date}— so the probe was looking at the wrong S3 keys.Restructure
_iter_sf_firing_dates: returns the SF cron's calendar firing dates (no change from prior behavior at this layer)_resolve_axis_dates: NEW. Translates firing dates to the date-axis the template uses:{date}→ calendar firing date{trading_day}+ saturday_sf/weekday_sf →previous_trading_day(firing_date)(NYSE-holiday-aware viaalpha_engine_lib.trading_calendar){trading_day}+ eod_sf → firing date itself (EOD writes today's close)_iter_historical_cycle_dates: now takes optionaltemplatearg; backward-compat for template-less callsLive smoke results (post-deploy + companion registry flip)
research_signalsresearch_consolidated_morningscanner_candidates_jsonThe remaining gaps are real producer-side absences (not template mismatch).
Test plan
Composes with
{date}→{trading_day}. Backtest_* entries documented + held at{date}pending producer-side audit (backtester writes to ad-hoc current-date-of-write).trading_day = last_closed_trading_day(now))🤖 Generated with Claude Code