From 1aeb4a4b8ecc58b43387ecf4515aca39db637d30 Mon Sep 17 00:00:00 2001 From: OoO Date: Wed, 13 May 2026 11:54:16 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=20AI=20logger=20=E6=9C=AA?= =?UTF-8?q?=E7=94=A8=20stack=20=E6=8E=A8=E6=96=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../claude_inventory_validation_20260513.md | 2 +- services/ai_call_logger.py | 16 ---------------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/docs/memory/claude_inventory_validation_20260513.md b/docs/memory/claude_inventory_validation_20260513.md index 06ec7a9..13a6382 100644 --- a/docs/memory/claude_inventory_validation_20260513.md +++ b/docs/memory/claude_inventory_validation_20260513.md @@ -22,7 +22,7 @@ - Google Drive import:`services/import_service.py` 的日期 `IN (...)` 刪除/驗證查詢已改為 SQLAlchemy bind params,不再把 DataFrame 日期值拼進 SQL 字串。 - OpenClaw Bot:中文字型下載、趨勢同期 DB 查詢、匯入格式業績預覽解析等 best-effort 區塊已補 debug/exception/warnings,避免真正錯誤完全無跡可查。 - Telegram polling bot:舊 callback 正規化失敗、空 `momo:eig:` event_id 回覆失敗仍保持 fail-safe,但已補 debug log。 -- `ai_call_logger._write_to_db` 不是死函數:它是 `_async_write()` 的 daemon thread target;decorator token 自動抽取與 stack caller 推斷的 best-effort 失敗也已補 debug log。 +- `ai_call_logger._write_to_db` 不是死函數:它是 `_async_write()` 的 daemon thread target;`infer_caller_from_stack()` 確認無 caller 後已移除。 - `cache_manager.FingerprintCache` 與 dashboard shared cache 清理維持 fail-open / best-effort,但已補 debug log,避免 cache fingerprint 或檔案清理失敗完全沉默。 ## 已驗證為已修或過期 diff --git a/services/ai_call_logger.py b/services/ai_call_logger.py index fe5ac04..9c91b16 100644 --- a/services/ai_call_logger.py +++ b/services/ai_call_logger.py @@ -24,7 +24,6 @@ services/ai_call_logger.py from __future__ import annotations import hashlib -import inspect import logging import os import threading @@ -438,18 +437,3 @@ def _safe_meta_json(meta: Dict[str, Any]) -> str: except Exception as e: logger.warning("[AICallLogger] meta json dump failed: %s", e) return '{}' - - -# ───────────────────────────────────────────────────────────────────────────── -# 工具:caller 自動推斷(caller 沒給時用) -# ───────────────────────────────────────────────────────────────────────────── -def infer_caller_from_stack(default: str = 'unknown') -> str: - """從 inspect.stack() 推斷 caller(取上 1 層的 module 名末段)。""" - try: - frame = inspect.stack()[2] - module = inspect.getmodule(frame.frame) - if module and module.__name__: - return module.__name__.split('.')[-1][:64] - except Exception: - logger.debug("[AICallLogger] infer caller from stack failed", exc_info=True) - return default