Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/dispatch_shadow_signal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
description: "Bridge provider"
required: false
type: choice
default: "auto"
default: "codex"
options:
- auto
- api
Expand Down Expand Up @@ -39,7 +39,7 @@ jobs:
BRIDGE_REPOSITORY: ${{ vars.CODEX_AUDIT_BRIDGE_REPOSITORY || 'QuantStrategyLab/AIAuditBridge' }}
BRIDGE_REF: ${{ vars.CODEX_AUDIT_BRIDGE_REF || 'main' }}
BRIDGE_TASK: long_horizon_signal_shadow
BRIDGE_PROVIDER: ${{ github.event.inputs.provider || 'auto' }}
BRIDGE_PROVIDER: ${{ github.event.inputs.provider || 'codex' }}
SOURCE_REF: ${{ github.event.inputs.source_ref || 'main' }}
SHADOW_SIGNAL_LABEL: long-horizon-shadow
steps:
Expand Down
18 changes: 18 additions & 0 deletions scripts/build_context_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

import argparse
import datetime as dt
import json
import sys
from pathlib import Path
Expand All @@ -18,6 +19,7 @@
normalize_symbols,
write_context_bundle,
)
from research_signal_context_pipelines.research_context_adapter import ResearchContextAdapter # noqa: E402
from research_signal_context_pipelines.theme_universe import ( # noqa: E402
build_theme_context,
load_symbol_theme_exposure,
Expand Down Expand Up @@ -50,9 +52,13 @@ def main() -> int:
default="data/output/context_bundle/latest_context_bundle.json",
help="Output JSON context bundle path",
)
parser.add_argument("--web-research-sources", help="Optional JSON config with whitelist and web research sources")
parser.add_argument("--web-research-timeout", type=float, default=10.0, help="Timeout in seconds for web research fetches")
parser.add_argument("--web-research-max-entries", type=int, default=8, help="Maximum web research entries to include")
args = parser.parse_args()

symbols = normalize_symbols(args.symbols)
generated_at = dt.datetime.now(dt.timezone.utc)
theme_context = None
if not args.no_theme_context:
theme_taxonomy_path = Path(args.theme_taxonomy)
Expand All @@ -62,6 +68,14 @@ def main() -> int:
exposures = load_symbol_theme_exposure(theme_exposure_path, known_theme_ids=themes)
theme_context = build_theme_context(symbols=symbols, themes=themes, exposures=exposures)

web_research_context = None
if args.web_research_sources:
web_research_context = ResearchContextAdapter(
Path(args.web_research_sources),
timeout_seconds=args.web_research_timeout,
max_entries=args.web_research_max_entries,
).build_context(pit_timestamp=generated_at)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid current web data in historical bundles

When the CLI is run with both --end-date and --web-research-sources, this stamps/fetches web research at the current generated_at while the price context is limited to the requested historical end date. That produces a bundle whose as_of is historical but whose web_research contains current articles, which contaminates any point-in-time replay/evidence built from --end-date; either disable web research for historical builds or pass/filter by the requested as-of date.

Useful? React with 👍 / 👎.


try:
bundle = build_context_from_source(
symbols=symbols,
Expand All @@ -70,7 +84,9 @@ def main() -> int:
end_date=args.end_date,
lookback_days=args.lookback_days,
theme_context=theme_context,
web_research_context=web_research_context,
allow_partial_downloads=not args.strict_downloads,
generated_at=generated_at,
)
except Exception as exc:
if not args.allow_download_errors:
Expand All @@ -79,6 +95,8 @@ def main() -> int:
symbols=symbols,
error=f"{type(exc).__name__}: {exc}",
theme_context=theme_context,
web_research_context=web_research_context,
generated_at=generated_at,
)
output_path = Path(args.output)
write_context_bundle(bundle, output_path)
Expand Down
2 changes: 1 addition & 1 deletion scripts/post_shadow_signal_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Create or update a long-horizon shadow signal issue.")
parser.add_argument("--repo", required=True)
parser.add_argument("--source-ref", default="main")
parser.add_argument("--provider", default="auto")
parser.add_argument("--provider", default="codex")
parser.add_argument("--bridge-repository", default="QuantStrategyLab/AIAuditBridge")
parser.add_argument("--as-of-date")
parser.add_argument("--context-file", help="Optional JSON context bundle to embed in the issue body")
Expand Down
16 changes: 15 additions & 1 deletion src/research_signal_context_pipelines/context_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ def build_context_bundle(
symbols: list[str],
generated_at: dt.datetime | None = None,
theme_context: Mapping[str, Any] | None = None,
web_research_context: Mapping[str, Any] | None = None,
) -> dict[str, Any]:
contexts: dict[str, SymbolContext] = {}
warnings: list[str] = []
Expand Down Expand Up @@ -337,6 +338,8 @@ def build_context_bundle(
}
if theme_context is not None:
bundle["theme_context"] = dict(theme_context)
if web_research_context is not None:
bundle["web_research"] = dict(web_research_context)
return bundle


Expand All @@ -347,6 +350,7 @@ def build_error_context_bundle(
as_of_date: dt.date | None = None,
generated_at: dt.datetime | None = None,
theme_context: Mapping[str, Any] | None = None,
web_research_context: Mapping[str, Any] | None = None,
) -> dict[str, Any]:
as_of = as_of_date or dt.date.today()
timestamp = generated_at or dt.datetime.now(dt.timezone.utc)
Expand Down Expand Up @@ -375,6 +379,8 @@ def build_error_context_bundle(
}
if theme_context is not None:
bundle["theme_context"] = dict(theme_context)
if web_research_context is not None:
bundle["web_research"] = dict(web_research_context)
return bundle


Expand All @@ -395,7 +401,9 @@ def build_context_from_source(
lookback_days: int = 420,
fetch_fn: Callable[..., Mapping[str, Any]] | None = None,
theme_context: Mapping[str, Any] | None = None,
web_research_context: Mapping[str, Any] | None = None,
allow_partial_downloads: bool = False,
generated_at: dt.datetime | None = None,
) -> dict[str, Any]:
end = parse_price_date(end_date) if end_date else dt.date.today()
start = parse_price_date(start_date) if start_date else end - dt.timedelta(days=int(lookback_days))
Expand All @@ -409,7 +417,13 @@ def build_context_from_source(
fetch_fn=fetch_fn,
allow_partial=allow_partial_downloads,
)
return build_context_bundle(rows, symbols=symbols, theme_context=theme_context)
return build_context_bundle(
rows,
symbols=symbols,
generated_at=generated_at,
theme_context=theme_context,
web_research_context=web_research_context,
)


def write_context_bundle(bundle: Mapping[str, Any], path: Path) -> None:
Expand Down
Loading
Loading