Skip to content

feat(metrics): generate strategy_metrics.json for AIAuditBridge watcher#119

Merged
Pigbibi merged 2 commits into
mainfrom
feat/strategy-metrics-generation
Jul 7, 2026
Merged

feat(metrics): generate strategy_metrics.json for AIAuditBridge watcher#119
Pigbibi merged 2 commits into
mainfrom
feat/strategy-metrics-generation

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

背景

AIAuditBridge 的 Strategy Optimization Watcher 每天 cron 检查策略指标退化情况。它需要 strategy_metrics.json 文件作为输入,该文件预期由 monthly_publish workflow 产出。

问题

strategy_metrics.json 目前不存在于任何地方。data/output/*.gitignore 排除,所以文件不会在 git 中。AI 审计桥需要从 CI artifact 中获取这个文件。

此 PR 的变更

scripts/generate_strategy_metrics.py(新文件)

  • 读取 monthly_shadow_build_summary.json 和各 track 的 release_index.csv
  • 提取 current_metrics(最新一期)和 baseline_metrics(全历史均值)
  • 输出到 data/output/strategy_metrics.json
  • 同时处理 official baseline 和 shadow candidate tracks
  • 格式兼容 AIAuditBridge 的 strategy_watch.py schema

.github/workflows/monthly_publish.yml

  • shadow build 之后运行 generate_strategy_metrics.py
  • strategy_metrics.json 拷贝到 monthly report bundle artifact 中
  • AIAuditBridge watcher 的 artifact 下载步骤会自动找到该文件

数据流

monthly_publish.yml
  → run_monthly_shadow_build.py  (产出 shadow build summary)
  → generate_strategy_metrics.py  **[NEW]**  (产出 strategy_metrics.json)
  → run_monthly_report_bundle.py  (组装 bundle)
  → upload-artifact               (包含 strategy_metrics.json)

AIAuditBridge strategy_optimization_watcher.yml
  → gh run download  (下载最新的 Monthly Publish artifact)
  → find strategy_metrics.json
  → run_strategy_optimization_watcher.py  (评估退化信号)

注意事项

当前包含的指标是 release_index.csv 中可用的结构性指标(pool_stability、pool_churn 等)。AIAuditBridge 的默认退化策略检查 sharpecagrcalmarwin_ratemax_dd 这些回测衍生指标——它们在当前 pipeline 中尚未计算,因此 watcher 暂时不会发现退化信号。回测指标的接入可以在后续迭代中添加。

🤖 Generated with Claude Code

## Changes

### scripts/generate_strategy_metrics.py (new)
- Reads monthly_shadow_build_summary.json and per-track release_index.csv
- Extracts current (latest period) and baseline (all-time average) metrics
- Writes strategy_metrics.json in the format expected by the
  AIAuditBridge strategy optimization watcher
- Handles both official baseline and shadow candidate tracks

### .github/workflows/monthly_publish.yml
- Run generate_strategy_metrics.py after shadow build completes
- Include strategy_metrics.json in the monthly report bundle artifact
  so the AIAuditBridge watcher can download it

The watcher gracefully skips metrics it doesn't understand, so
omitting backtest-derived metrics (sharpe, cagr, etc.) is safe —
they can be added as the pipeline evolves.

Co-Authored-By: Claude <noreply@anthropic.com>
@cursor

cursor Bot commented Jul 7, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

Co-Authored-By: Claude <noreply@anthropic.com>
@cursor

cursor Bot commented Jul 7, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 080acfd2b7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

)
continue

index = pd.read_csv(index_path)

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 Handle empty release indexes without failing

When a shadow track produces zero eligible releases, build_shadow_release_history still creates release_index.csv from an empty DataFrame, which pandas writes as an effectively empty file. In that case this pd.read_csv(index_path) raises EmptyDataError before _track_metrics() can return empty metrics, so the new Monthly Publish step fails after publishing instead of emitting an empty snapshot for the watcher. This can happen for new/short-history candidate tracks or configurations where len(eligible) < pool_size for every scheduled release.

Useful? React with 👍 / 👎.

Comment on lines +91 to +93
python scripts/generate_strategy_metrics.py
env:
STRATEGY_METRICS_REPO: ${{ github.repository }}

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 Pass the repository override into the generator

When this workflow runs outside the default QuantStrategyLab/CryptoLivePoolPipelines repository, this step exports STRATEGY_METRICS_REPO but never passes it to the script, and generate_strategy_metrics.py does not read that environment variable. The generated artifact therefore embeds the hard-coded default repo, which the AIAuditBridge watcher rejects when its validated SOURCE_REPO is the actual fork/renamed repo, so metrics from those runs cannot be processed.

Useful? React with 👍 / 👎.

@Pigbibi Pigbibi merged commit 8c654a7 into main Jul 7, 2026
5 of 6 checks passed
@Pigbibi Pigbibi deleted the feat/strategy-metrics-generation branch July 7, 2026 08:54
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.

1 participant