Files
ewoooc/requirements.txt
OoO 5daa1a45d8 fix(strategist): plug stale gate gaps in daily/monthly + psutil dep + complete stale shape (critic post-review)
critic post-review 對 commit 9158bbe 找到 3 個 BLOCKER,本 patch 補完。

#1 daily/monthly 路徑沒套 stale gate(Critical)
- generate_daily_report() 在 _fetch_sales_summary(7) 後立刻檢查 sales.get("stale"),
  避免 daily_sales_snapshot 過期時每天 09:00 復發 NT$0 偽日報
- generate_monthly_report() 在 _fetch_monthly_sales_summary 後檢查
  revenue==0 and sku_count==0(_fetch_monthly_sales_summary 沒內建 stale 機制,
  以「無資料」當訊號),避免月初產出 NT$0 偽月報
- 抽出 _send_data_stale_alert(report_type, last_date, period) 統一三條路徑共用,
  以 ai_insights 表查近 24h 同 report_type 的 data_stale_alert 紀錄做 dedupe,
  避免每天 daily/weekly 三份報告同時觸發 → 一天送多次告警噪音
- weekly stale 分支改用 _send_data_stale_alert(return shape 維持 status="error"
  不動,保 9158bbe weekly dedupe/cache 機制下游語意)
- daily/monthly 採 critic 建議的 status="skipped";scheduler 既有 task 不檢查
  status 也不 raise,EventRouter 不會被誤觸

#2 psutil 沒在 requirements.txt(Critical)
- requirements.txt 加 psutil>=5.9(ADR-019 Phase 2 要求 production 必裝)
- elephant_alpha_autonomous_engine._get_system_load_percentage 加註解:
  ImportError fallback 是 queue-based 估算(pending=14→70%、≥18→90%),
  與真實 CPU 無關,僅 dev defensive;prod 觸發即代表容器映像漏裝

#9 _fetch_sales_summary stale 分支 return shape 不完整(High)
- stale 分支補完 daily/current_7d_revenue/prev_7d_revenue/wow_pct/sku_count
- 數值欄位用 None(非 0):未套 stale gate 的上游 caller 在 prompt template
  `:,.0f` 會 raise TypeError,比靜默 0 明顯,迫使呼叫端必須 stale gate

三問自審:
- 方案正確:daily 不再發 NT$0(_fetch_sales_summary 後立刻 gate);psutil 會被
  pip install;stale shape None 在所有 caller 路徑要嘛被 gate 擋下要嘛 raise
- 影響完整:grep 確認 _fetch_sales_summary 三 caller(weekly/daily/monthly via
  _fetch_monthly_sales_summary)皆已加 gate;無下游依賴 data_stale return 字串
- Regression 風險:stale shape 改 None 為純擴充無 caller 取數值欄位;scheduler
  只讀 period/chart_count/action_count 不檢查 status;monthly revenue=0 gate
  在實務 P0 異常時告警,比靜默產 NT$0 月報可接受

不在本 patch scope(critic 任務描述明示禁動):
- 9158bbe weekly dedupe/cache 機制(_acquire_weekly_strategy_send_lock 等)
- elephant_alpha Phase 1 已修部分(trigger/dispatch/method raise)
- run_scheduler.py 排程設定
- tests/ 內任何測試

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 01:54:21 +08:00

30 lines
727 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Flask>=2.3
Flask-WTF
gunicorn>=20.1
pandas>=1.5
pytz
openpyxl
SQLAlchemy>=1.4
psycopg2-binary>=2.9
schedule
pyngrok
selenium
requests
numpy
python-dotenv
google-auth
google-auth-oauthlib
google-auth-httplib2
google-api-python-client
google-generativeai
feedparser
beautifulsoup4
lxml
prometheus-client
python-telegram-bot[job-queue]>=20.0
pgvector>=0.2
paramiko # ADR-013: AIOps SSH 跳板修復
python-pptx # ADR-014: PPT 簡報系統
matplotlib # 圖表生成(日報/週報/月報)
matplotlib-inline # Jupyter 相容層(可選)
psutil>=5.9 # ADR-019 Phase 2: ElephantAlpha system load 真實量測production 必裝;缺失時 fallback 為 queue-based 估算)