OoO dda0a06bfd fix(strategist): cast metadata_json text to jsonb for stale alert dedupe
critic post-review #1 (HIGH): `_send_data_stale_alert` 的 dedupe SQL 對
`ai_insights.metadata_json` (Column(Text)) 直接套用 `->>` operator,PG 會
raise `operator does not exist: text ->> unknown`,被外層 try/except 吞掉,
導致 dedupe 完全失效,daily/weekly/monthly 同日 stale 會送 2-3 次告警噪音。

修法:`metadata_json::jsonb->>'report_type'` 即時 cast Text→JSONB 再取 key
(寫入端用 json.dumps,內容為合法 JSON)。

影響:
- 僅修 services/openclaw_strategist_service.py:353 一行
- grep 確認全 repo 僅此一處 `metadata_json->>` 用法
- 不動 dedupe 視窗 / telegram 發送 / _save_to_ai_insights
- 不動 tests / requirements.txt / 其他檔案

Regression:cast 每次 stale 告警跑一次,效能影響可忽略;若歷史 row
metadata_json 內容非合法 JSON,cast 會 raise 並被 try/except 吞掉,
行為退回現狀(dedupe 失效,但不影響告警送出)。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 12:29:22 +08:00
Description
EwoooC — 商品看板 + 業績報表 + AI KM (Flask + pgvector, Docker Compose on 188)
37 MiB
Languages
PostScript 59.7%
Python 30.9%
HTML 4.2%
CSS 2.1%
JavaScript 1.9%
Other 1.1%