Commit Graph

184 Commits

Author SHA1 Message Date
OoO
71ea819d06 refactor(routes): 刪除 app.py 首頁重複路由
ADR-017 Phase 3f-1 dashboard sprint;首頁改由 dashboard_bp 接管,並更新 url_for('index') 相容引用。
2026-04-29 21:11:45 +08:00
OoO
aa56479c66 refactor(routes): 刪除 dashboard brand_assets 重複路由
ADR-017 Phase 3f-1 dashboard/misc sprint
2026-04-29 21:09:26 +08:00
OoO
8fad8ebff0 refactor(routes): 刪除 app.py edm festival 重複路由
ADR-017 Phase 3f-1 edm sprint
2026-04-29 21:07:16 +08:00
OoO
1f88c2817b refactor(routes): 刪除 app.py import monthly 重複路由
ADR-017 Phase 3f-1 import/monthly sprint
2026-04-29 21:06:00 +08:00
OoO
512f93c6b1 refactor(routes): 刪除 app.py api 重複路由
ADR-017 Phase 3f-1 api sprint
2026-04-29 21:04:56 +08:00
OoO
43a2c5f638 refactor(routes): 刪除 app.py export 重複路由
ADR-017 Phase 3f-1 export sprint
2026-04-29 21:03:54 +08:00
OoO
f4149d4c05 fix(db): 補全 metadata model import 與 realtime sales ORM
ADR-017 Phase 3f-0
2026-04-29 21:00:46 +08:00
OoO
8be332728e docs: ADR-016 daily_sales cache fingerprint + 4/28-29 history log + CLAUDE.md ADR 索引補 015/016
- 新增 docs/adr/ADR-016:daily_sales cache TTL → TTL+DB fingerprint,棄用
  N-POST broadcast hack(命中率 9.4%),引述 debugger/web-researcher/migration-engineer
  三方共識;殘留 HIGH-2(app.py 43 處 _SALES_PROCESSED_CACHE)列管
- docs/memory/history_logs.md 新增 4/28-29 條目:app.py -10.8%、4 個改進版死碼揭發、
  cache 機制重構、hook 9 PoC 強化、12 Agent 並行作戰實踐
- CLAUDE.md 補上 ADR-015/016 索引項

Memory(個人 auto-memory,未入 repo)同步:
- feedback_flask_blueprint_shadow.md(first-registered wins)
- feedback_cache_invalidation_pattern.md(DB fingerprint vs N-POST)
- feedback_agent_dispatch_order.md(critic 必須先於 fullstack)
- feedback_cloud_vs_local_automation.md(LAN 專案禁雲端 routine)
- project_phase3e_refactor_progress.md(11 commits 戰果)
2026-04-29 19:56:48 +08:00
OoO
136e65b400 chore(hooks): momo-db 守門 9 PoC 強化(vuln-verifier 補丁)
All checks were successful
CD Pipeline / deploy (push) Successful in 1m8s
回應 vuln-verifier 對前版規則 3e 的 8/9 PoC 繞過警告。

新增/強化擋點:
- psql -f / heredoc / 重定向:hook 看不到 SQL 內容 → 一律擋
- multi-statement: ; 後接內容(去 -- 與 /* */ 註解後判斷)→ 擋
- writable CTE: WITH ... DELETE/INSERT/UPDATE → 擋
- /run/secrets, /proc/*/environ → 擋
- pg_read_file / pg_read_binary_file / lo_export / lo_import → 擋
- COPY ... FROM PROGRAM → 擋
- VACUUM FULL / REINDEX / REFRESH MATERIALIZED / CLUSTER 加入寫入黑名單
- env 加 (?!\\s+\\w+=) lookahead,避免誤殺 env VAR=value
- alias/function 包裝 docker exec:警告(無法靜態判斷後續呼叫)
- 白名單 prefix 不收 WITH(防 writable CTE 漏網),改收 SELECT/EXPLAIN/SHOW/VALUES/TABLE

settings.json: 累積本輪 session 的 read-only 工具放行(py_compile、python3)。
2026-04-29 09:12:26 +08:00
OoO
3971fd4020 fix(daily_sales): cache 失效改 DB fingerprint + clear_cache 加 @login_required
All checks were successful
CD Pipeline / deploy (push) Successful in 1m12s
回應 critic 對 8fefea0 的 4 個 HIGH finding(debugger/web-researcher/migration-engineer 三方共識):

HIGH-3 修復:
- /api/daily_sales/clear_cache 加 @login_required,避免外部 DoS 攻擊清快取

HIGH-4 修復(核心):
- 新增 _get_data_fingerprint(engine):SELECT MAX(snapshot_date), COUNT(*) FROM daily_sales_snapshot
- _is_cache_valid 改雙閘:TTL(保險絲)+ DB fingerprint(強一致)
- 三個 cache 寫入點同步記錄 fingerprint
- 移除 services/import_service.py 的 4-worker N-POST hack(命中率僅 9.4%,
  coupon collector 機率:4!/4^4 = 0.094)
- 資料寫入後指紋自動跳號,4 worker 下次 request 各自偵測失效並重載 → 強一致

附帶修:
- 統一 export/export_marketing 兩處 cache 寫入結構(補 timestamp/fingerprint),
  解決 db-expert 標記的「export 端點 cache 缺 timestamp 導致主看板每次都重讀」瑕疵

未處理(留待後續):
- HIGH-2: app.py 仍有 43 處 _SALES_PROCESSED_CACHE(sales_analysis 等其他路由的獨立 cache)
  待後續 P9 統一抽 services/cache_manager.py

[P7-COMPLETION]
方案: critic + debugger + web-researcher + migration-engineer 四方共識的方案 B
影響: routes/daily_sales_routes.py + services/import_service.py 兩檔
Regression: 每 request 多 1 次 SELECT MAX/COUNT(< 5ms),其餘行為等價
2026-04-29 09:10:23 +08:00
OoO
8fefea05da fix(daily_sales): 啟用 bp 版改進邏輯 + import 後跨 worker 清 cache,根除 #24 隱形 bug
All checks were successful
CD Pipeline / deploy (push) Successful in 1m6s
- 從 app.py 刪除 396 行的 /daily_sales、/daily_sales/export、/daily_sales/export_marketing
  三條 @app.route(行 5911-6306),讓 routes/daily_sales_routes.py 的 daily_sales_bp
  生效(first-registered wins,原 app.py 版本 shadow 了 bp)。
- bp 版改進點:_is_cache_valid() 帶 5 分鐘 TTL、/api/daily_sales/clear_cache 端點、
  完整模板參數(datetime_now / active_page)。
- services/import_service.py process_daily_sales_import return True 前,
  新增跨 gunicorn worker 清 daily_sales cache 邏輯:依 GUNICORN_WORKERS 次數呼叫
  internal /api/daily_sales/clear_cache,避免 4 worker 各持 5 分鐘舊快取
  導致「匯入 15323 筆但當日業績看不到」隱形 bug。

[P7-COMPLETION]
- 方案正確: 雙重佐證(refactor-specialist + web-researcher)確認 Flask first-registered
  wins,刪 app.py 內 route 即可讓 bp 接管;helper 函式(preprocess_daily_sales_data 等)
  為 dead code 但保守保留不影響執行。
- 影響完整: 全 repo grep 確認 _SALES_PROCESSED_CACHE 在 app.py 仍有 30+ 處使用
  (sales_analysis 等其他路由),未動到;helper 函式無外部 caller。
- Regression 風險: 低,bp 版簽名與行為相容;新 cache 清除走 internal HTTP 帶 try/except
  不影響主流程;若 GUNICORN_WORKERS 未設則默認 4 與生產一致。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 21:18:17 +08:00
OoO
e6768408e1 refactor(app.py): 抽出 /api/test_url + /brand_assets 至 misc_routes Blueprint
All checks were successful
CD Pipeline / deploy (push) Successful in 1m5s
- 新增 routes/misc_routes.py(40 行,2 routes:POST /api/test_url, GET /brand_assets)
- app.py 7012 → 6986(-26 行)
- requests 改為模組頂層 import(移除函數內 import 異味)
- 註冊位置貼齊 category_bp 後方

Phase 3e route handlers Blueprint 化第二棒,收納雜項小型 routes
2026-04-28 21:10:01 +08:00
OoO
8fce73bd4b refactor(app.py): 抽出 /api/categories CRUD 至 category_routes Blueprint
All checks were successful
CD Pipeline / deploy (push) Successful in 1m9s
- 新增 routes/category_routes.py(46 行,3 routes:POST/PUT/DELETE)
- app.py 7053 → 7012(-41 行)
- 沿用 services.json_storage.load_categories/save_categories
- 註冊位置貼齊 system_bp 後方

Phase 3e route handlers Blueprint 化首棒,邊界最小、無共用狀態
2026-04-28 21:04:40 +08:00
OoO
333fc159ae fix: CodeReview Gemini 模型從已下架 preview 換成 gemini-2.5-flash
All checks were successful
CD Pipeline / deploy (push) Successful in 1m6s
services/code_review_pipeline_service.py:41 OPENCLAW_MODEL 預設值
gemini-2.5-flash-preview-05-20 已被 Google 下架(404 not found),
改為穩定 GA 版本 gemini-2.5-flash。

驗證:直接 API 測試
- gemini-2.5-flash → 200 
- gemini-2.5-flash-preview-05-20 → 404 

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 21:01:44 +08:00
ooo
c91dc273f0 refactor(p1-01f): JSON 持久化抽到 services/json_storage.py
All checks were successful
CD Pipeline / deploy (push) Successful in 1m9s
- load_categories / save_categories / load_scheduler_stats 三個函數搬出
- CATEGORIES_JSON_PATH / SCHEDULER_STATS_PATH 常數同步搬移
- app.py 改 import 維持原呼叫路徑

行數變化: app.py 7,070 → 7,053 (-17)
2026-04-28 19:42:05 +08:00
ooo
f114c209ce refactor(p1-01e): repair_database_schema 抽到 database/schema_repair.py
All checks were successful
CD Pipeline / deploy (push) Successful in 1m7s
- 80 行 schema 修復邏輯抽出,搭配 _ensure_column helper 去除 7 個 promo_products 欄位重複碼塊
- app.py 改為 from database.schema_repair import repair_database_schema 維持原呼叫
- 行為 100% 對齊(含 SQLite WAL 啟用、products.created_at 補資料)

行數變化: app.py 7,151 → 7,070 (-81)
2026-04-28 15:51:44 +08:00
ooo
dea94d2e0f refactor(p1-01d): routes/ 移除 safe_read_sql/validate_table_name/find_col 三份重複定義
All checks were successful
CD Pipeline / deploy (push) Successful in 1m6s
- routes/sales_routes.py 移除 find_col、validate_table_name、safe_read_sql 各自實作(-40 行)
- routes/daily_sales_routes.py 移除 validate_table_name、safe_read_sql 各自實作(-26 行)
- 兩檔改為 from utils.security import ... 的 re-export,行為對齊單一權威來源

注意:原本 routes 自己的 validate_table_name 較寬鬆(只 regex),
改用 utils.security 後升級為「白名單 + SQL 關鍵字」雙重防護。
所有 call site 都用 'realtime_sales_monthly' 或 'daily_sales_snapshot',皆在白名單內,行為相容。
2026-04-28 15:50:21 +08:00
ooo
17cb012be7 refactor(p1-01c): 整併 utils/security 與 utils/validators 重複實作
All checks were successful
CD Pipeline / deploy (push) Successful in 1m6s
發現 utils/validators.py 已存在且完整重複 utils/security.py 的 9 個函數。
不收拾的話會繼續腐爛 — 立刻整併為單一權威來源。

變更:
- utils/security.py 增加 safe_read_sql(取自 validators.py 較完整版本,含 limit + params)
- utils/security.py ALLOWED_TABLES 取兩份聯集(補上 monthly_summary_analysis,
  realtime_sales_daily),避免破壞既有呼叫者
- utils/validators.py 改為純 re-export shim(保 from utils.validators import 不破)
- app.py 移除原 safe_read_sql 重複定義(35 行),改 import utils.security

routes/import_routes.py 不變(它 from utils.validators 走得到 re-export,等下輪統一)。

行數變化: app.py 7,187 → 7,151 (-36)
2026-04-28 15:48:41 +08:00
ooo
0a3f6cb22d refactor(p1-01b): app.py 文字/顏色/數字工具抽到 utils/text_helpers.py
All checks were successful
CD Pipeline / deploy (push) Successful in 1m7s
- slugify, get_color_for_string, extract_snapshot_date_from_filename, number_format
- @app.template_filter('number_format') 保留為 Jinja 註冊薄殼,實作走 utils
- app.py: 7,206 → 7,187 (-19)
2026-04-28 15:44:15 +08:00
ooo
f7a5f8505f refactor(p1-01a): app.py 安全工具抽到 utils/security.py
All checks were successful
CD Pipeline / deploy (push) Successful in 1m8s
從 app.py 抽出純驗證邏輯 (~180 行) 到 utils/security.py:
- ALLOWED_TABLES 白名單常數
- validate_table_name / validate_column_names (SQL injection 防護)
- safe_join (路徑遍歷防護)
- ALLOWED_UPLOAD_EXTENSIONS / ALLOWED_MIME_TYPES
- secure_filename_unicode / allowed_file / validate_upload_file (上傳驗證)

app.py 保留 from utils.security import * 維持 backward compat,
讓 tests/test_path_traversal.py、tests/test_sql_security.py、
tests/test_file_upload.py 不需修改即可繼續使用 from app import xxx。

行數變化: app.py 7,386 → 7,206 (-180)
2026-04-28 15:42:44 +08:00
ooo
841e136425 refactor(app.py): find_col 去重 — 改用 utils/df_helpers.py 共用實作
All checks were successful
CD Pipeline / deploy (push) Successful in 1m7s
- 移除 app.py 第 803 行的重複 find_col 定義(與 routes/daily_sales_routes.py 重複,已抽至 utils)
- 改為 from utils.df_helpers import find_col
2026-04-28 15:39:17 +08:00
ooo
d4ea555030 refactor(p1-06/07): daily_sales 純函數抽到 services/
All checks were successful
CD Pipeline / deploy (push) Successful in 1m14s
- 新增 utils/df_helpers.py 放共用 find_col(避免 routes/services 雙向依賴)
- 新增 services/daily_sales_service.py 收:
  * get_taiwan_holiday(date)
  * prepare_calendar_data(df, selected_month)
  * prepare_marketing_summary(df, ...)
- routes/daily_sales_routes.py 改為 import service,行數 949 → 713(-236)
- 行為 100% 保留,僅檔案位置搬移
2026-04-28 15:37:07 +08:00
OoO
832030b6de fix(cd): sync 模式改用 compose up -d 取代 restart,根除 502 復發
All checks were successful
CD Pipeline / deploy (push) Successful in 1m13s
根因:cd.yaml sync 模式用 `docker compose restart`,對「不存在的容器」
直接報錯 → 任何外力(人工 docker rm、orphan 清理、別專案連動)清掉容器後,
下次 sync 部署 100% 失敗 → 健康檢查 5 連 502。

修法:
- sync 模式改 `docker compose up -d --no-deps`:image 未變時對既存容器
  no-op(觸發熱掛載),對不存在則自動 create
- 緊急回滾 step 同步從 `docker restart momo-pro-system ...` 改 `compose up -d`,
  否則容器不存在時連回滾都救不回

驗證:2026-04-28 15:33 跑 P0 救急已成功讓 4/4 容器 healthy + HTTP 200。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 15:34:30 +08:00
OoO
421395eb86 config: 暫停 valentine_520 與 labor_day 爬蟲(LPN 不存在)
Some checks failed
CD Pipeline / deploy (push) Failing after 1m50s
- 520 情人節主會場尚未上線(預計 5/10~5/15 momo 才會發布)
- 勞動節 momo 歷年無獨立主會場,常合併進春日/桃金日活動
- 清空兩者 lpn_code 避免共用 mothers_day LPN 灌入錯誤標籤資料
- 加註 pause_reason 與 paused_date 供後續 LPN 補回時參考

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 15:26:20 +08:00
ooo
f4aed94eb7 fix(adr-011): postgres service profile-gated, 核心三容器移除 depends_on postgres
Some checks failed
CD Pipeline / deploy (push) Has been cancelled
- postgres service 加 profiles: [bundled-db],預設不啟動,避免 docker compose up -d 自動建出 momo-postgres 與生產 momo-db 撞
- momo-app / scheduler / telegram-bot 三核心服務移除 depends_on postgres(生產主機使用獨立 momo-db)
- pgadmin / metabase / postgres-exporter 維持 depends_on postgres(profile-gated,只在 monitoring/bi profile 啟用時生效)
2026-04-28 15:19:00 +08:00
OoO
ffeb28be95 docs: 補齊 .env.example — INITIAL_ADMIN_PASSWORD/BOT_API_TOKEN/SSH_JUMP_* 2026-04-28 14:59:19 +08:00
OoO
0b72e7040f fix(post-3.5g): Dockerfile CMD restore gunicorn 4-workers (HIGH-5)
All checks were successful
CD Pipeline / deploy (push) Successful in 9m13s
從 4349db2~1 撈回 production 啟動指令。

問題:
- 4349db2 改回 `CMD ["python", "app.py"]` 用 Flask dev server 跑 production,
  單進程、無 worker pool、debug 邏輯保留、效能與安全都不適合對外。
- EXPOSE 5000 與 docker-compose / k8s 實際使用 port 80 不符
  (reference_docker_topology.md 確認 momo-pro-system 是 port 80)。

修法:
- CMD 改回:gunicorn --bind 0.0.0.0:80 --workers 4 --timeout 300
  --access-logfile - --error-logfile - app:app
- EXPOSE 5000 → EXPOSE 80(對齊容器內實際綁定)
- requirements.txt 已含 gunicorn>=20.1,build 不需要其他改動

驗證:
- grep 確認 CMD 與 EXPOSE 已更新
- gunicorn 在 requirements.txt 中(line 不需求動)

Critic finding: HIGH-5
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 14:40:22 +08:00
OoO
d276853e54 fix(post-3.5g): restore _is_authorized fail-closed for callback + message (CRIT-2 + HIGH-3)
從 4349db2~1 撈回 _is_authorized() 並重新套用到 callback 與 message handler。

問題:
- CRIT-2 (callback fail-open):原本只擋 group/supergroup 不匹配,
  private chat 任何人都能觸發 callback 指令(按鈕 menu/await/cmd)。
- HIGH-3 (message short-circuit fail):`if ALLOWED_USERS and _uid not in ALLOWED_USERS`
  在 OPENCLAW_ALLOWED_USERS 環境變數未設時 → ALLOWED_USERS 為空 set →
  `if False and ...` 整段不執行 → 所有 private 訊息都通過。

修法(fail-closed 三檢查):
1. 在頂部 import 區下方還原 `_is_authorized(chat_type, chat_id, user_id)`:
   - group/supergroup:chat_id 必須等於 ALLOWED_GROUP
   - private:user_id 必須在 ALLOWED_USERS(空 set → 全拒)
   - channel / 未知 / 缺欄位 → 拒絕
2. callback handler 替換為 `if not _is_authorized(chat_type, chat_id, cq_from_id)`
   並從 cq.get('from') 取 user_id(之前完全沒取)。
3. message handler 替換為統一檢查,未授權回 403 + 靜默(不回 Telegram 避免偵察)。

驗證:
- AST parse OK
- 模擬測試:999999 私訊 → False;111(在白名單)私訊 → True;
  錯誤群組 → False;channel → False;None → False
- grep 結果:剩下兩處 `_is_authorized` 呼叫(callback 5195, message 5255),
  舊的 `ALLOWED_USERS and _uid not in ALLOWED_USERS` 已移除(只留註解描述歷史)。

Critic findings: CRIT-2 + HIGH-3
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 14:40:22 +08:00
OoO
b49b704e82 fix(post-3.5g): restore generate_embedding for KM dual-write (CRIT-1)
從 4349db2~1 撈回 OllamaService.generate_embedding,補齊被誤刪的方法。

問題:
- services/openclaw_learning_service.py:67 仍呼叫 ollama_service.generate_embedding(...)
- 4349db2 大改時把這個方法刪掉,導致每次 NemoTron 寫入學習資料時觸發
  AttributeError: 'OllamaService' object has no attribute 'generate_embedding'
- pgvector KM 因此完全停寫,違反 ADR-007 雙寫鐵律

修法:
- 把 method paste 回 OllamaService 末端(line 508)
- 對齊現代 config:os 已在檔案頂部 import,移除方法內重複 import
- embedding 走 EMBEDDING_HOST(Hermes 主機,內網免認證)
- model 預設 bge-m3:latest(ADR-003 對齊)

驗證:
- AST parse OK
- grep 'def generate_embedding' 已存在

Critic finding: CRIT-1
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 14:40:22 +08:00
OoO
d1fc71c6a3 fix: 新增 Vue.js 模板頁面支援的策略 3 和策略 4
All checks were successful
CD Pipeline / deploy (push) Successful in 1m19s
2026-04-28 14:26:41 +08:00
OoO
5d0a9606d6 config: 填入 LPN 代碼並啟用三個促銷活動爬蟲 (O7ylWdZJHj8)
All checks were successful
CD Pipeline / deploy (push) Successful in 1m14s
2026-04-28 14:10:31 +08:00
OoO
af260c4a01 feat: 新增三個促銷活動爬蟲支援(母親節、520情人節、勞動節)
All checks were successful
CD Pipeline / deploy (push) Successful in 1m12s
- 新增通用促銷活動爬蟲函式 run_promo_event_task()
- 更新 crawler_config_loader.py 新增三個活動配置
- 更新 run_scheduler.py 動態註冊促銷活動爬蟲
- 新增 API 端點 /api/run_promo_event_task
- 新增三個前端儀表板路由(/edm/mothers_day, /edm/valentine_520, /edm/labor_day)
- 更新所有儀表板頁籤列表
- 新增配置檔案 services/data/crawler_config.json
- 新增使用文件 docs/guides/promo_event_crawler_guide.md
- 更新 agent_actions.py 允許重試列表
2026-04-28 13:57:44 +08:00
OoO
227b114101 fix(ci): use docker compose restart instead of hardcoded container names in sync mode
All checks were successful
CD Pipeline / deploy (push) Successful in 1m13s
2026-04-28 13:36:23 +08:00
OoO
1d49c66159 fix(ci): use --no-cache for docker build to bypass cache snapshot corruption
Some checks failed
CD Pipeline / deploy (push) Failing after 57s
2026-04-28 13:15:38 +08:00
OoO
0906c4be60 fix: mount routes directory for telegram-bot and scheduler
Some checks failed
CD Pipeline / deploy (push) Failing after 1m49s
2026-04-28 12:44:10 +08:00
OoO
1ecec162dd fix: increase Ollama health check timeout to prevent false offline status
All checks were successful
CD Pipeline / deploy (push) Successful in 1m18s
2026-04-28 12:35:58 +08:00
OoO
7bb97ed252 fix: remove hardcoded Telegram Bot token to resolve AiderHeal security warning
All checks were successful
CD Pipeline / deploy (push) Successful in 1m21s
2026-04-28 12:34:29 +08:00
OoO
7125ba09d3 fix(post-3.5e): openclaw_answer 三個 store_conversation 呼叫點對齊新簽章
All checks were successful
CD Pipeline / deploy (push) Successful in 1m16s
承接前一個 commit「store_conversation 簽章改 6 參數」後,遠端先前
b766edf 的「呼叫端縮成 3 args + 改用 chat_id」修法有兩個問題:

1. openclaw_answer(question) 函式 scope 中根本沒有 chat_id 變數,
   原本的 args=(chat_id, ...) 在執行時會 NameError,
   被 thread 內 except 吞掉,bug 還是發生(剛好相反方向)。
2. b766edf 漏改 L4166(Gemini 直接路徑),三個呼叫點不一致。

本 commit 將 L4113 / L4214 改回 6 個 positional args:
  (user_id=0, chat_id=0, question, response, source, used_sources)

對齊新簽章 (user_id, chat_id, user_message, bot_response, source='', used_sources=None)
全部 metadata(source / used_sources / chat_id)保留進 ai_insights.metadata_json。

Out-of-scope(暫不處理):
- user_id / chat_id 寫死 0 不修(待 openclaw_answer 函式接收 chat_id 參數的後續重構)
2026-04-28 12:29:48 +08:00
OoO
d67d309ada fix(post-3.5e): store_conversation 簽章對齊呼叫端 (E4 P1 bug)
問題:3 個呼叫點傳 6 個 positional args,但定義只接 3 個,
TypeError 被 thread 內 except 吞掉,OpenClaw 答題對話沉澱靜默失敗,
違反 ADR-007 持久化鐵律(AI 學習數據必雙寫 DB+KM)。

修法(方案 A 元數據保留):
- 簽章:(user_id, user_message, bot_response)
       → (user_id, chat_id, user_message, bot_response, source='', used_sources=None)
- chat_id / source / used_sources 全部進 metadata,給未來分析用
- 呼叫點不需改動(args 已是 6 個,對齊新簽章)

驗證:AST inspect 確認 3 個呼叫點全部對齊新簽章。

Out-of-scope(暫不處理):
- 呼叫端寫死 user_id=0、chat_id=0,留給下一輪修
- 內部 store_insight 雙寫邏輯不動

錨點:services/openclaw_learning_service.py:330
呼叫點:routes/openclaw_bot_routes.py:4113, 4166, 4214
2026-04-28 12:29:48 +08:00
OoO
433e37d241 fix: remove strict 30s timeout for Ollama chat
Some checks failed
CD Pipeline / deploy (push) Has been cancelled
2026-04-28 12:28:57 +08:00
OoO
b766edfde2 fix: store_conversation signature, MCP model, and AI fallback message
All checks were successful
CD Pipeline / deploy (push) Successful in 1m18s
2026-04-28 12:26:49 +08:00
OoO
8331c15d1b fix(post-3.5c): .env.example 補齊 HERMES_URL + DISABLE_LOGIN
All checks were successful
CD Pipeline / deploy (push) Successful in 1m19s
P1-19:
- 既有 LOGIN_PASSWORD/SECRET_KEY 補上「[必填]」註解
- 新增 DISABLE_LOGIN(auth.py:13 在用,但 .env.example 沒有)
- 新增 Hermes 區塊:HERMES_URL、HERMES_TIMEOUT、EMBEDDING_HOST(註解)
- 統一格式:每條前面加「[必填] / [預設 X]」標註

注意:Elephant Alpha 區塊既有 ELEPHANT_ALPHA_HERMES_URL 是 Elephant 專用,
與本次新增的 HERMES_URL(Hermes Module 2 用)不同變數,分開保留。
2026-04-28 12:15:59 +08:00
OoO
dff19ee835 fix(post-3.5c): ai_routes hermes_stats model 顯示字串清理
Item #9:
- routes/ai_routes.py:1640 hermes_stats['model'] 寫死 'hermes3:latest'
- 改為 'Hermes 3' 更易讀;保留語意(model identifier 給未來可能的下游讀者)

調查確認此 key 為 dead code:
- _build_footprint_block / _build_footprint_json (nemoton_dispatcher_service.py:276,303)
  只讀 duration_sec 和 tokens,不讀 model key
- hermes_analyst_service.py:419 自組 _last_stats 也不放 model key
- 改動不影響 footprint 顯示與 DB 寫入
2026-04-28 12:15:59 +08:00
OoO
67509a4e42 fix(post-3.5c): Hermes 降級 logger 等級從 error → warning
Item #5:
- services/hermes_analyst_service.py:122 降級到規則引擎是預期 fallback
  路徑(不是錯誤),改用 logger.warning 與同檔 :175 一致

調查範圍(已查 grep "logger.error" + "降級|hermes|fallback"):
- services/nemoton_dispatcher_service.py:486 NIM content 解析失敗 → 真錯誤,保留 error
- services/nemoton_dispatcher_service.py:564 fallback 派發單筆失敗 → 真錯誤,保留 error
- routes/openclaw_bot_routes.py:4168 無 logger.error,候選位置無此 pattern(已查,無異狀)
2026-04-28 12:15:59 +08:00
OoO
8b51d2d94f fix(post-3.5c): config.py 新增 EMBEDDING_HOST 常數(C-2 部分達成)
餘震 C-2 局部完成:
- config.py 新增 EMBEDDING_HOST 常數(env: EMBEDDING_HOST → fallback HERMES_URL)
- 原計畫同步修 services/ollama_service.py:515,520 的 hardcoded fallback,
  但 origin/main 4349db2 (feat: AiderHeal) 已主動移除整個
  generate_embedding() 方法 — rebase 衝突解決時採納 origin 決定(--ours),
  不重新引入已被刪除的方法
- IP 殘留 fix 自動隨方法刪除而消失;EMBEDDING_HOST 常數保留於 config 以
  供未來若恢復 embedding 路徑時集中化使用

ADR-008 集中化原則仍然完整:所有殘留的 IP 硬編碼已都改為 config 讀取
(services/nemoton_dispatcher_service.py:287 已於前個 commit 處理)。
2026-04-28 12:15:59 +08:00
OoO
b954cc37cf fix(post-3.5c): nemoton dispatcher IP 殘留集中化
餘震 C-1:
- services/nemoton_dispatcher_service.py:287 env fallback hardcoded
  192.168.0.111,違反 ADR-008 集中化原則
- 改從 config.HERMES_URL 集中讀取

Out-of-scope finding(不在本次修復範圍):
- line 286 仍寫死 "qwen2.5:7b-instruct",但實際模型是 hermes3:latest
  (與 hermes_analyst_service.py:30 不一致,應由後續 PR 處理)
2026-04-28 12:15:59 +08:00
OoO
60a7917634 fix(post-3.5c): 修正 hermes_analyst_service docstring 模型名稱誤導
餘震 B:
- services/hermes_analyst_service.py:7 註解寫 qwen2.5:7b-instruct
  但實際 line 30 HERMES_MODEL = "hermes3:latest"
- 同步修正 host 描述為「HERMES_URL(預設 192.168.0.111:11434)」
2026-04-28 12:15:59 +08:00
OoO
5340475570 fix(post-3.5c): hermes timeout 雙標統一 + 補 keep_alive
餘震 A — 昨天 Hermes timeout 真因(incident 核心):
- services/hermes_analyst_service.py:158 硬編碼 timeout=10,與 :406 用
  HERMES_TIMEOUT=120 雙標;payload 也沒帶 keep_alive,被別模型擠下後
  冷啟動 30+s 必中 timeout
- HERMES_TIMEOUT 從檔內常數提升至 config.py 集中管理(ADR-008)
- 兩個 payload (intent/batch) 都補 keep_alive=24h(ADR-012)
- intent 路徑 timeout 從 10s 改用 HERMES_TIMEOUT;keep_alive 確保熱駐留時
  實測仍 < 10s,不會撐到 120s 上限

檔案:
- config.py: 新增 HERMES_TIMEOUT 常數
- services/hermes_analyst_service.py: 移除檔內 HERMES_TIMEOUT、新增
  HERMES_KEEP_ALIVE、補 payload keep_alive、line 158 timeout 統一
2026-04-28 12:15:59 +08:00
OoO
32ac92b8f0 fix: _ssh_exec signature in ElephantAlpha
Some checks failed
CD Pipeline / deploy (push) Has been cancelled
2026-04-28 12:15:42 +08:00
OoO
3dd73dce03 fix: missing sqlalchemy text import and _ssh_exec in ElephantAlpha
All checks were successful
CD Pipeline / deploy (push) Successful in 1m20s
2026-04-28 12:13:44 +08:00