Python
feat(sdk): switch to turn the pipeline log off, keep conversation text out of INFO logs (2.0.8)
alvinfeidc762df78bb2
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 0a44dae..8c519a9 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -76,6 +76,24 @@ Hy Memory and MemHub are versioned and released independently.`hy_node_permissions` proof table. Evidence, governed memories, modelprofiles, SDK stores, and source/host grants are preserved.+## Hy Memory 2.0.8 — 2026-10-28++- New `MEMORY_PIPELINE_LOG_ENABLED` (default `true`) turns the pipeline JSONL+ log (`{MEMORY_LOG_DIR}/<subdir>/<date>.log`) off. With `false` no JSONL+ file or directory is written. When `MEMORY_PIPELINE_TRACE_ENABLED` is also+ `false`, `store_pipeline_log` becomes a no-op that returns `True` at once:+ no timing, redaction, background task or database write. The init log line+ now states whether the JSONL log is on or off.+- Conversation and memory text no longer appears in INFO or WARNING logs. The+ `[add]` input, search queries and rewrites, coding experience tasks, fact+ statements and subjects, reconcile op details, extracted info, embedding+ inputs and unparsable model output moved to DEBUG. INFO lines keep ids,+ counts and character lengths; parse-failure warnings remain but report only+ the length of the output, e.g. `failed to parse output (812 chars)`. The+ `[embed]` INFO line now carries `request.input_chars` instead of+ `request.input`. The `JSON_PARSE_FAILED` error message from extraction no+ longer embeds the model output either.+## Hy Memory 2.0.7 — 2026-10-28- Publisheddiff --git a/docs/env_reference.md b/docs/env_reference.mdindex f26caf9..7bd3841 100644--- a/docs/env_reference.md+++ b/docs/env_reference.md@@ -191,6 +191,7 @@ SDK 不设置 Rerank Search 并发上限。开启后模型在 `HyMemoryClient`| `MEMORY_LOG_FORMAT` | `text` | `text` / `json` || `MEMORY_LOG_DIR` | — | 统一日志根目录 || `MEMORY_TRACE_LOG_DIR` | — | JSONL 日志目录的兼容旧名;优先使用 `MEMORY_LOG_DIR` |+| `MEMORY_PIPELINE_LOG_ENABLED` | `true` | 是否写 pipeline JSONL 日志(`{MEMORY_LOG_DIR}/<subdir>/<date>.log`);`false` 完全不写 || `MEMORY_PIPELINE_TRACE_ENABLED` | `true` | 是否写入 cache 的 pipeline trace 表 || `MEMORY_MEMORY_OPERATIONS_ENABLED` | `false` | 是否写入 memory operation 审计记录 || `MEMORY_HISTORY_ENABLE` | `true` | 是否启用历史记录 |diff --git a/hy_memory/agent/extractor.py b/hy_memory/agent/extractor.pyindex 8861600..5a81f44 100644--- a/hy_memory/agent/extractor.py+++ b/hy_memory/agent/extractor.py@@ -1177,7 +1177,7 @@ class Extractor:if not tc_id:logger.error(f"[extractor] tool_call_id is empty! "- f"raw tc: {json.dumps(tc_raw, ensure_ascii=False, default=str)[:500]}"+ f"raw_keys={list(tc_raw.keys())}")try:t_res = await tool_registry.dispatch(@@ -1311,11 +1311,12 @@ class Extractor:if parsed is None:if not all_tool_calls:logger.warning(- f"[extractor] JSON parse failed: {raw_text[:200]}"+ f"[extractor] JSON parse failed ({len(raw_text)} chars)")+ logger.debug(f"[extractor] unparsable output: {raw_text[:200]!r}")return ExtractResult(success=False,- error=f"JSON parse failed: {raw_text[:200]}",+ error=f"JSON parse failed ({len(raw_text)} chars)",error_code="JSON_PARSE_FAILED",raw_response=raw_text,tokens_used=total_tokens,diff --git a/hy_memory/agent/llm_provider.py b/hy_memory/agent/llm_provider.pyindex 52a70b8..289f1ea 100644--- a/hy_memory/agent/llm_provider.py+++ b/hy_memory/agent/llm_provider.py@@ -129,8 +129,7 @@ def _parse_tool_calls_list(raw_calls: list, _json) -> List[Dict[str, Any]]:tc_id = tc.get("id") or ""if not tc_id:logger.error(- f"[llm] tool_call missing 'id'! raw: "- f"{_json.dumps(tc, ensure_ascii=False, default=str)[:500]}"+ f"[llm] tool_call missing 'id'! keys={list(tc.keys())}")# 保留原始 tc 完整结构,只规范化 argumentsdiff --git a/hy_memory/agent/mem_agent.py b/hy_memory/agent/mem_agent.pyindex 7c8db7b..e9ecb60 100644--- a/hy_memory/agent/mem_agent.py+++ b/hy_memory/agent/mem_agent.py@@ -234,7 +234,7 @@ class MemAgent:f"identity={len(identity)} facts={len(facts)} "f"basic_info={basic_field_count}fields")- logger.info(f"MemAgent: extracted_info={extract_result.info}")+ logger.debug(f"MemAgent: extracted_info={extract_result.info}")# 3. 冲突检测(如果有已有记忆)if mode == ProcessMode.FULL and existing_memories:diff --git a/hy_memory/agent/reconciler.py b/hy_memory/agent/reconciler.pyindex ce676ba..bf55cd4 100644--- a/hy_memory/agent/reconciler.py+++ b/hy_memory/agent/reconciler.py@@ -50,7 +50,7 @@ def is_canonical_state_node(node: Any) -> bool:def _log_ops_detail(ops: List["ReconcileOp"]) -> None:- """以单条 INFO(JSON list)输出 reconcile 的逐条结果,便于线上 debug。"""+ """以单条 DEBUG(JSON list)输出 reconcile 的逐条结果;含记忆正文,不进 INFO。"""if not ops:returnview = [@@ -68,7 +68,7 @@ def _log_ops_detail(ops: List["ReconcileOp"]) -> None:}for o in ops]- logger.info(+ logger.debug(f"[reconciler] ops detail: {json.dumps(view, ensure_ascii=False, default=str)}")@@ -1514,9 +1514,10 @@ class MemoryReconciler:logger.warning(f"[reconciler] RECONCILE JSON parse failed "f"(attempt {_attempt+1}/{_MAX_PARSE_ATTEMPTS}), "- f"retrying: raw="- f"{raw_response[:200] if _log_llm_content_enabled() else '<redacted>'}"+ f"retrying: raw({len(raw_response or '')} chars)")+ if _log_llm_content_enabled():+ logger.debug(f"[reconciler] unparsable raw={raw_response[:200]!r}")recon_elapsed = (_time.perf_counter() - t_recon) * 1000@@ -1806,7 +1807,8 @@ class MemoryReconciler:except Exception as _re:logger.debug(f"[reconciler] json_repair failed: {_re}")if data is None:- logger.warning(f"[reconciler] failed to parse ops JSON: {text[:200]}")+ logger.warning(f"[reconciler] failed to parse ops JSON ({len(text)} chars)")+ logger.debug(f"[reconciler] unparsable ops output: {text[:200]!r}")return []if not isinstance(data, list):@@ -2018,11 +2020,11 @@ class MemoryReconciler:if clash is not None:logger.warning(f"[reconciler] memory_id {clash} already touched by '{touched[clash]}', "- f"current op '{op.op} ({op.reason[:60]})' dropped"+ f"current op '{op.op}' dropped")continuefor t in target_ids:- touched[t] = f"{op.op}({op.reason[:40]})"+ touched[t] = op.opvalidated.append(op)return validateddiff --git a/hy_memory/agent/tools/base.py b/hy_memory/agent/tools/base.pyindex 667bfc6..bf457b3 100644--- a/hy_memory/agent/tools/base.py+++ b/hy_memory/agent/tools/base.py@@ -211,7 +211,9 @@ def parse_tool_calls_from_json(raw: Any) -> List[ToolCall]:try:args = json.loads(args_raw) if args_raw.strip() else {}except json.JSONDecodeError:- logger.warning(f"[tools] failed to parse arguments as JSON: {args_raw[:120]}")+ logger.warning(+ f"[tools] failed to parse arguments as JSON ({len(args_raw)} chars)"+ )args = {}elif isinstance(args_raw, dict):args = args_rawdiff --git a/hy_memory/client.py b/hy_memory/client.pyindex 895a862..8473917 100644--- a/hy_memory/client.py+++ b/hy_memory/client.py@@ -744,7 +744,7 @@ class HyMemoryClient:def _install_pipeline_observability_hooks(self) -> None:"""包装 cache.store_pipeline_log:- - Log:JSONL 文件,始终写入(环节级,不依赖 Trace 开关)+ - Log:JSONL 文件,由 MEMORY_PIPELINE_LOG_ENABLED 控制(默认开启)- Trace:SQLite pipeline_logs,由 MEMORY_PIPELINE_TRACE_ENABLED 控制(Inspector)- 落盘 fire-and-forget,不阻塞 search/write 热路径"""@@ -958,7 +958,7 @@ class HyMemoryClient:parsed_tool_calls = json.loads(raw_tool_calls) if raw_tool_calls else []except Exception:logger.warning(- "tool_calls 是非法 JSON 字符串,已忽略: %r", raw_tool_calls[:200]+ "tool_calls 是非法 JSON 字符串,已忽略 (%d chars)", len(raw_tool_calls))parsed_tool_calls = []raw_tool_calls = parsed_tool_calls if isinstance(parsed_tool_calls, list) else []@@ -3008,13 +3008,13 @@ class HyMemoryClient:f"[add] writing {preview} user={uid} "f"agent_id={agent_id} session_id={session_id} mode={self._mode}")- logger.info(f"[add] messages detail: {[m.to_dict() for m in chat_messages]}")+ logger.debug(f"[add] messages detail: {[m.to_dict() for m in chat_messages]}")else:logger.info(f"[add] writing text({len(content)} chars) user={uid} "- f"agent_id={agent_id} session_id={session_id} mode={self._mode} "- f"content={content}"+ f"agent_id={agent_id} session_id={session_id} mode={self._mode}")+ logger.debug(f"[add] text content={content!r}")# mode → agent_mode 映射# lite: 不调 LLM agent@@ -4034,14 +4034,14 @@ class HyMemoryClient:decided_variant = HyMemoryClient._scene_variant(scene)logger.info(f"[search] scene explicit={decided_scene} (no LLM judge); "- f"target={effective_target_query!r}"+ f"target({len(effective_target_query or '')} chars)")elif not agentic_enabled and not queries_supplied:# 默认 light search 仅指 query="...":固定 normal,绝不调用 LLM。decided_scene = "normal"logger.info(f"[search] search_mode=default single-query scene=normal (no LLM); "- f"target={target_query!r}"+ f"target({len(target_query or '')} chars)")elif agentic_enabled:# agentic:单/多 query 都强制一次 LLM 完成三分类 + rewrite + 时间解析。@@ -4076,14 +4076,18 @@ class HyMemoryClient:rewrite_created_after = ar.get("created_after")logger.info(f"[search] agentic scene={decided_scene} via rewrite-LLM "- f"(classify={want_classify}); orig={target_query!r} "- f"effective={effective_target_query!r} rewrite_used={rewrite_used} "+ f"(classify={want_classify}); rewrite_used={rewrite_used} "f"created_after={rewrite_created_after}")+ logger.debug(+ f"[search] agentic rewrite: orig={target_query!r} "+ f"effective={effective_target_query!r}"+ )else:decided_scene = "normal"logger.info(- f"[search] agentic rewrite-LLM fallback=normal; target={target_query!r}"+ f"[search] agentic rewrite-LLM fallback=normal; "+ f"target({len(target_query or '')} chars)")elif rewrite_enabled and not _too_long:# default + queries= 的原逻辑:配置开启时一次 LLM 做 rewrite/time,@@ -4162,7 +4166,7 @@ class HyMemoryClient:decided_scene = "normal"logger.info(f"[search] default multi-query features disabled; no LLM; "- f"target={target_query!r}"+ f"target({len(target_query or '')} chars)")# ────────────────────────────────────────────────────────────@@ -4215,7 +4219,7 @@ class HyMemoryClient:else:logger.info(f"[search] routing to PRODUCTIVITY path variant={decided_variant}: "- f"target={effective_target_query!r} "+ f"target({len(effective_target_query or '')} chars) "f"workspace_id={workspace_id!r} branch={branch!r}")return await self._search_coding(@@ -4243,9 +4247,11 @@ class HyMemoryClient:# Chat 召回链路(原有逻辑)# ────────────────────────────────────────────────────────────logger.info(- f"[search] query='{effective_target_query}' user_ids={effective_user_ids} "+ f"[search] query({len(effective_target_query or '')} chars) "+ f"user_ids={effective_user_ids} "f"agent_ids={effective_agent_ids} session_ids={effective_session_ids} limit={limit}")+ logger.debug(f"[search] query={effective_target_query!r}")# rewrite 抽出的时间下界与用户显式 created_after 取更晚者(更严格)effective_created_after = created_afterdiff --git a/hy_memory/coding/extractor.py b/hy_memory/coding/extractor.pyindex 1d65cff..82afde6 100644--- a/hy_memory/coding/extractor.py+++ b/hy_memory/coding/extractor.py@@ -1166,7 +1166,10 @@ class CodingMemoryExtractor:obj = Noneif not isinstance(obj, dict):- logger.warning(f"[coding-extract] failed to parse output: {text!r}")+ logger.warning(+ f"[coding-extract] failed to parse output ({len(text or '')} chars)"+ )+ logger.debug(f"[coding-extract] unparsable output: {text!r}")return [], []# "memories" 是双层化之前的 key,老 prompt 缓存 / 旧模型可能还这么回diff --git a/hy_memory/coding/fact_reconciler.py b/hy_memory/coding/fact_reconciler.pyindex 41ea32e..9cc946e 100644--- a/hy_memory/coding/fact_reconciler.py+++ b/hy_memory/coding/fact_reconciler.py@@ -570,9 +570,12 @@ class WorkingFactReconciler:kept.append(fact)if blocked:logger.info(- f"[fact-reconcile] subject gate blocked {len(blocked)} candidate(s) "- f"for subject={draft.subject!r}: "- + ", ".join(f"{f.fact_id}({f.subject!r})" for f in blocked)+ f"[fact-reconcile] subject gate blocked {len(blocked)} candidate(s): "+ + ", ".join(f.fact_id for f in blocked)+ )+ logger.debug(+ f"[fact-reconcile] subject gate: draft subject={draft.subject!r} "+ f"blocked subjects={[f.subject for f in blocked]!r}")result.append(kept)return result@@ -745,7 +748,10 @@ class WorkingFactReconciler:obj = Noneif not isinstance(obj, dict):- logger.warning(f"[fact-reconcile] failed to parse ops output: {text!r}")+ logger.warning(+ f"[fact-reconcile] failed to parse ops output ({len(text or '')} chars)"+ )+ logger.debug(f"[fact-reconcile] unparsable ops output: {text!r}")return {}ops_raw = obj.get("ops")if not isinstance(ops_raw, list):@@ -835,8 +841,11 @@ class WorkingFactReconciler:# 别的主体的状态不是。闸门关掉时这道复查一并跳过,否则闸门就没关干净。if self.subject_gate and _subject_conflict(draft.subject, old.subject):logger.warning(- f"[fact-reconcile] refused cross-subject SUPERSEDE: "- f"{old.fact_id}({old.subject!r}) by draft subject {draft.subject!r}"+ f"[fact-reconcile] refused cross-subject SUPERSEDE: {old.fact_id}"+ )+ logger.debug(+ f"[fact-reconcile] cross-subject: old subject={old.subject!r} "+ f"draft subject={draft.subject!r}")continuetry:diff --git a/hy_memory/coding/judge.py b/hy_memory/coding/judge.pyindex bfa28c1..d005174 100644--- a/hy_memory/coding/judge.py+++ b/hy_memory/coding/judge.py@@ -195,8 +195,10 @@ async def classify_messages_scene(result = _parse_scene_json(resp.content)if result is None:logger.warning(- f"[coding-judge] failed to parse classify_messages output: {resp.content!r}; defaulting to chat"+ f"[coding-judge] failed to parse classify_messages output "+ f"({len(resp.content or '')} chars); defaulting to chat")+ logger.debug(f"[coding-judge] unparsable classify_messages output: {resp.content!r}")await _store_coding_log(cache, request_id=request_id, user_id=user_id, agent_id=agent_id,session_id=session_id, step="CODING_JUDGE", prompt=prompt,@@ -207,9 +209,8 @@ async def classify_messages_scene(return "chat"scene = result["scene"]parsed = {**result, "is_coding": scene != "chat"}- logger.info(- f"[coding-judge] scene={scene} reason={result.get('reason', '')!r}"- )+ logger.info(f"[coding-judge] scene={scene}")+ logger.debug(f"[coding-judge] scene={scene} reason={result.get('reason', '')!r}")await _store_coding_log(cache, request_id=request_id, user_id=user_id, agent_id=agent_id,session_id=session_id, step="CODING_JUDGE", prompt=prompt,@@ -295,8 +296,10 @@ async def classify_queries_scene(result = _parse_scene_json(resp.content)if result is None:logger.warning(- f"[coding-judge] failed to parse classify_queries output: {resp.content!r}; defaulting to chat"+ f"[coding-judge] failed to parse classify_queries output "+ f"({len(resp.content or '')} chars); defaulting to chat")+ logger.debug(f"[coding-judge] unparsable classify_queries output: {resp.content!r}")return "chat"scene = result["scene"]logger.info(f"[coding-judge] queries scene={scene}")@@ -422,15 +425,18 @@ async def classify_and_rewrite_queries(scene = _parse_scene_label(head)if scene is None:logger.warning(- f"[coding-judge] classify_and_rewrite unrecognized head={head!r}; falling back to chat"+ f"[coding-judge] classify_and_rewrite unrecognized head "+ f"({len(head)} chars); falling back to chat")+ logger.debug(f"[coding-judge] classify_and_rewrite unrecognized head={head!r}")return {"scene": "chat", "is_coding": False, "rewrite_query": rewrite, "ok": False}is_coding = scene != "chat"logger.info(f"[coding-judge] classify_and_rewrite scene={scene} "- f"rewrite={rewrite!r}"+ f"rewrite({len(rewrite)} chars)")+ logger.debug(f"[coding-judge] classify_and_rewrite rewrite={rewrite!r}")return {"scene": scene, "is_coding": is_coding, "rewrite_query": rewrite, "ok": True}@@ -569,8 +575,9 @@ async def analyze_queries(parsed_scene = _parse_scene_label(head)if parsed_scene is None:logger.warning(- f"[coding-judge] analyze_queries unrecognized head={head!r}; ok=False"+ f"[coding-judge] analyze_queries unrecognized head ({len(head)} chars); ok=False")+ logger.debug(f"[coding-judge] analyze_queries unrecognized head={head!r}")return {**fallback, "since_raw": ""}scene = parsed_sceneidx = 1@@ -589,9 +596,10 @@ async def analyze_queries(created_after = _since_to_created_after(since_raw, current_time)logger.info(- f"[coding-judge] analyze scene={scene} rewrite={rewrite!r} "+ f"[coding-judge] analyze scene={scene} rewrite({len(rewrite)} chars) "f"since={since_raw!r} created_after={created_after}")+ logger.debug(f"[coding-judge] analyze rewrite={rewrite!r}")return {"scene": scene, "is_coding": scene != "chat", "rewrite_query": rewrite,"created_after": created_after, "since_raw": since_raw, "ok": True,@@ -614,7 +622,10 @@ def _since_to_created_after(since_raw: str, current_time: str) -> Optional[floatreturn dt.timestamp()except (ValueError, TypeError):continue- logger.warning(f"[coding-judge] analyze_queries unparsable SINCE={since_raw!r}")+ logger.warning(+ f"[coding-judge] analyze_queries unparsable SINCE ({len(since_raw)} chars)"+ )+ logger.debug(f"[coding-judge] analyze_queries unparsable SINCE={since_raw!r}")return Nonediff --git a/hy_memory/coding/reconciler.py b/hy_memory/coding/reconciler.pyindex 56aacc7..7cfff82 100644--- a/hy_memory/coding/reconciler.py+++ b/hy_memory/coding/reconciler.py@@ -388,7 +388,10 @@ class CodingMemoryReconciler:obj = Noneif not obj or not isinstance(obj, dict):- logger.warning(f"[coding-reconcile] failed to parse ops output: {text!r}")+ logger.warning(+ f"[coding-reconcile] failed to parse ops output ({len(text or '')} chars)"+ )+ logger.debug(f"[coding-reconcile] unparsable ops output: {text!r}")return []ops_raw = obj.get("ops") or []if not isinstance(ops_raw, list):@@ -441,10 +444,10 @@ class CodingMemoryReconciler:for op in ops:if op.action == "ADD":if op.draft_idx is None or not (0 <= op.draft_idx < len(drafts)):- logger.warning(f"[coding-reconcile] drop invalid ADD: {op.to_dict()}")+ logger.warning(f"[coding-reconcile] drop invalid ADD: {_op_ref(op)}")continueif op.draft_idx in consumed:- logger.warning(f"[coding-reconcile] drop ADD on consumed draft: {op.to_dict()}")+ logger.warning(f"[coding-reconcile] drop ADD on consumed draft: {_op_ref(op)}")continued = drafts[op.draft_idx]memory = self._draft_to_new_memory(d)@@ -458,18 +461,18 @@ class CodingMemoryReconciler:elif op.action == "UPDATE":if op.draft_idx is None or not (0 <= op.draft_idx < len(drafts)):- logger.warning(f"[coding-reconcile] drop invalid UPDATE: {op.to_dict()}")+ logger.warning(f"[coding-reconcile] drop invalid UPDATE: {_op_ref(op)}")continueif not op.target_experience_id:- logger.warning(f"[coding-reconcile] drop UPDATE missing target: {op.to_dict()}")+ logger.warning(f"[coding-reconcile] drop UPDATE missing target: {_op_ref(op)}")continueif not self._target_was_offered(op, candidates_per_draft):logger.warning(- f"[coding-reconcile] drop UPDATE outside authority scope: {op.to_dict()}"+ f"[coding-reconcile] drop UPDATE outside authority scope: {_op_ref(op)}")continueif op.draft_idx in consumed:- logger.warning(f"[coding-reconcile] drop UPDATE on consumed draft: {op.to_dict()}")+ logger.warning(f"[coding-reconcile] drop UPDATE on consumed draft: {_op_ref(op)}")continued = drafts[op.draft_idx]memory = self._draft_to_new_memory(d, experience_id=op.target_experience_id)@@ -488,17 +491,17 @@ class CodingMemoryReconciler:elif op.action == "DELETE":if not op.target_experience_id:- logger.warning(f"[coding-reconcile] drop DELETE missing target: {op.to_dict()}")+ logger.warning(f"[coding-reconcile] drop DELETE missing target: {_op_ref(op)}")continueif not self._target_was_offered(op, candidates_per_draft):logger.warning(- f"[coding-reconcile] drop DELETE outside authority scope: {op.to_dict()}"+ f"[coding-reconcile] drop DELETE outside authority scope: {_op_ref(op)}")continue# DELETE 需要知道 user_id;通过 draft_idx(如有)或第一个 draft 推断user_id = self._infer_user_id(op, drafts)if not user_id:- logger.warning(f"[coding-reconcile] drop DELETE no user_id context: {op.to_dict()}")+ logger.warning(f"[coding-reconcile] drop DELETE no user_id context: {_op_ref(op)}")continuetry:ok = await self.store.delete(op.target_experience_id, user_id=user_id)@@ -585,6 +588,14 @@ class CodingMemoryReconciler:# Helpers# ================================================================+def _op_ref(op: ReconcileOp) -> str:+ """op 的日志引用:只带动作与编号,不带 LLM 写的 reason。"""+ return (+ f"action={op.action} draft_idx={op.draft_idx} "+ f"target={op.target_experience_id}"+ )++def _truncate(s: str, n: int) -> str:if not s:return ""diff --git a/hy_memory/coding/store.py b/hy_memory/coding/store.pyindex e4e6033..0effea1 100644--- a/hy_memory/coding/store.py+++ b/hy_memory/coding/store.py@@ -605,7 +605,11 @@ class CodingMemoryStore:await self._upsert_vec_keys(memory)logger.info(f"[coding-store] inserted experience_id={memory.experience_id} "- f"task={memory.task!r} keys={1 + len(memory.search_keys)}"+ f"keys={1 + len(memory.search_keys)}"+ )+ logger.debug(+ f"[coding-store] inserted experience_id={memory.experience_id} "+ f"task={memory.task!r}")async def update(self, memory: CodingMemory) -> None:@@ -1002,7 +1006,8 @@ class CodingMemoryStore:fact.created_at = datetime.utcnow()await _run_in_pool(self._upsert_fact_sql_sync, fact)await self._upsert_fact_vec(fact)- logger.info(+ logger.info(f"[coding-store] inserted fact_id={fact.fact_id}")+ logger.debug(f"[coding-store] inserted fact_id={fact.fact_id} "f"statement={fact.statement!r}")diff --git a/hy_memory/core/embed_service.py b/hy_memory/core/embed_service.pyindex 0f9de32..96fec8c 100644--- a/hy_memory/core/embed_service.py+++ b/hy_memory/core/embed_service.py@@ -754,16 +754,22 @@ class EmbedService:"""打一条 INFO 级 embedding 请求日志(含 request_id / provider / model / api / 入参 / 出参)。- 出参只含 vector 维度,不含向量数值。request_id 同时写入 message,+ 出参只含 vector 维度,不含向量数值。入参的 input 是待向量化的原文+ (对话 / 记忆 / 查询),INFO 只记每条的字符数(input_chars),原文仅在+ DEBUG 单独输出。request_id 同时写入 message,并依赖 log formatter 的 %(request_id)s(setup_logging 后生效)。"""+ texts = request_payload.get("input")+ info_request = {k: v for k, v in request_payload.items() if k != "input"}+ if isinstance(texts, list):+ info_request["input_chars"] = [len(str(t)) for t in texts]payload = {"request_id": get_request_id(),"status": status,"provider": self._embed_config.provider,"model": self._embed_config.model,"api": api_url,- "request": request_payload,+ "request": info_request,"response": response_payload,}try:@@ -771,6 +777,10 @@ class EmbedService:except Exception:body = str(payload)logger.info(f"[embed] {body}")+ if texts is not None and logger.isEnabledFor(logging.DEBUG):+ logger.debug(+ f"[embed] input: {json.dumps(texts, ensure_ascii=False, default=str)}"+ )async def _embed_openai(self, texts: List[str]diff --git a/hy_memory/pipelines/_retrieval/reconcile_retrieval.py b/hy_memory/pipelines/_retrieval/reconcile_retrieval.pyindex a5081e1..526aa0d 100644--- a/hy_memory/pipelines/_retrieval/reconcile_retrieval.py+++ b/hy_memory/pipelines/_retrieval/reconcile_retrieval.py@@ -115,11 +115,16 @@ class ReconcileHybridRetriever:fused_max = max(fused_all) if fused_all else 0.0base = (- f"[reconcile-hybrid][{req}] pool={pool_size} q_terms={q_terms!r} "+ f"[reconcile-hybrid][{req}] pool={pool_size} q_terms={len(q_terms)} "f"raw_bm25 max={raw_max:.4f} nonzero={raw_nonzero}/{len(raw_bm25)} "f"bm25_norm max={norm_max:.4f} nonzero={norm_nonzero}/{len(bm25_norms)} "f"sem_max={sem_max:.4f} fused_max={fused_max:.4f} "f"kept={kept}/{len(fused_all)} min_score={self._cfg.min_score} "+ f"query({len(query_text or '')} chars)"+ )+ # query 是待对账的新记忆原文,词项与预览只进 DEBUG+ logger.debug(+ f"[reconcile-hybrid][{req}] q_terms={q_terms!r} "f"query={q_preview!r} lemmatized={lem_preview!r}")diff --git a/hy_memory/pipelines/cross_domain_sweeper.py b/hy_memory/pipelines/cross_domain_sweeper.pyindex 700423e..8843e40 100644--- a/hy_memory/pipelines/cross_domain_sweeper.py+++ b/hy_memory/pipelines/cross_domain_sweeper.py@@ -692,9 +692,10 @@ class CrossDomainSweeper:)logger.info(- f"[sweeper] Created L6 core {core_id[:12]}: '{core_content[:60]}' "+ f"[sweeper] Created L6 core {core_id[:12]} "f"from {len(cluster_ids)} basics, evidence_inherited={len(inherited_evidence_ids)}")+ logger.debug(f"[sweeper] L6 core {core_id[:12]} content={core_content[:60]!r}")return 1, 0, [core_id]except Exception as e:diff --git a/hy_memory/pipelines/reader_base.py b/hy_memory/pipelines/reader_base.pyindex bc288d4..8bcacef 100644--- a/hy_memory/pipelines/reader_base.py+++ b/hy_memory/pipelines/reader_base.py@@ -3587,8 +3587,9 @@ class BaseReadPipeline(ReadPipeline):f"hidden_l0={len(hidden_l0_hits)} fwd_l6={len(forward_l6)} rev_l6={len(reverse_l6)} "f"fused_l6={len(fused_l6)} graph_intent={len(graph_intention_hits)} "f"returned={len(final_results)} "- f"query='{request.query[:80]}'"+ f"query({len(request.query or '')} chars)")+ logger.debug(f"[read/{self.VERSION}] query={request.query[:80]!r}")response.success = Truediff --git a/hy_memory/pipelines/system2_agent.py b/hy_memory/pipelines/system2_agent.pyindex d16d242..2ace7a8 100644--- a/hy_memory/pipelines/system2_agent.py+++ b/hy_memory/pipelines/system2_agent.py@@ -2516,7 +2516,8 @@ def _parse_operations_json(text: str) -> Optional[List[Dict[str, Any]]]:return resultreturn Noneexcept json.JSONDecodeError:- logger.warning(f"[S2-agent] JSON parse failed: {json_str[:200]}")+ logger.warning(f"[S2-agent] JSON parse failed ({len(json_str)} chars)")+ logger.debug(f"[S2-agent] unparsable output: {json_str[:200]!r}")return Nonediff --git a/hy_memory/utils/pipeline_log_writer.py b/hy_memory/utils/pipeline_log_writer.pyindex 20220bb..7b3f1b7 100644--- a/hy_memory/utils/pipeline_log_writer.py+++ b/hy_memory/utils/pipeline_log_writer.py@@ -1,6 +1,7 @@# -*- coding: utf-8 -*-"""-Pipeline Log Writer — 环节级 JSONL 日志(始终开启,与 SQLite Trace 分离)。+Pipeline Log Writer — 环节级 JSONL 日志(默认开启,MEMORY_PIPELINE_LOG_ENABLED=false 关闭;+与 SQLite Trace 分离)。目录: {log_dir}/{subdir}/{date}.log每行: request_id, namespace, user_id, agent_id, step, prompt, content, parsed,diff --git a/hy_memory/utils/pipeline_observability.py b/hy_memory/utils/pipeline_observability.pyindex a7d898e..371dc70 100644--- a/hy_memory/utils/pipeline_observability.py+++ b/hy_memory/utils/pipeline_observability.py@@ -1,16 +1,20 @@# -*- coding: utf-8 -*-"""-Pipeline 可观测性:Log(文件 JSONL,始终开启)与 Trace(SQLite pipeline_logs,可关闭)。+Pipeline 可观测性:Log(文件 JSONL,默认开启,可关闭)与 Trace(SQLite pipeline_logs,可关闭)。- Log:运维 tail/grep,每个环节即时一行,不依赖后续步骤成功与否。- Trace:Inspector / 调试,落库 pipeline_logs(需 MEMORY_CACHE_BACKEND=sqlite 等持久化后端)。环境变量:+ MEMORY_PIPELINE_LOG_ENABLED — Log 写 JSONL 文件,默认 true;false 时完全不写MEMORY_PIPELINE_TRACE_ENABLED — Trace 落库,默认 true;OpenClaw C 端可设 falseMEMORY_MEMORY_OPERATIONS_ENABLED — memory_operations 审计表落库,默认 falseMEMORY_LOG_DIR — Log 目录(优先)MEMORY_TRACE_LOG_DIR — Log 目录(兼容旧名)+Log 与 Trace 都关闭时不包装 store_pipeline_log,而是换成立即返回 True 的+空操作:热路径不做任何计时、脱敏或后台任务,也不写库。+子目录({log_dir}/{subdir}/{date}.log)由 PipelineLogWriter 从每条记录的user_id 前缀(第一个 "__" 左侧)切分;无前缀回落 "default"。该前缀是通用 namespace,可用于项目、部署或数据分桶。@@ -94,6 +98,16 @@ def is_pipeline_trace_enabled() -> bool:)+def is_pipeline_log_enabled() -> bool:+ """是否把 pipeline step 写成 JSONL 文件({log_dir}/<subdir>/<date>.log)。默认开启。"""+ return os.getenv("MEMORY_PIPELINE_LOG_ENABLED", "true").strip().lower() in (+ "true",+ "1",+ "yes",+ "on",+ )++def is_memory_operations_enabled() -> bool:"""是否将知识库变动写入 memory_operations 审计表。默认关闭(false)。"""return os.getenv("MEMORY_MEMORY_OPERATIONS_ENABLED", "false").lower() in (@@ -125,7 +139,7 @@ def redact_content(value: str) -> str:def resolve_pipeline_log_dir() -> str:"""- JSONL pipeline log 根目录(始终使用,有默认值)。+ JSONL pipeline log 根目录(MEMORY_PIPELINE_LOG_ENABLED 开启时使用,有默认值)。优先级: MEMORY_LOG_DIR > MEMORY_TRACE_LOG_DIR > {MEMORY_DATA_DIR}/logs/pipeline"""@@ -228,6 +242,7 @@ def wrap_store_pipeline_log() -> Callable[..., Any]:"""包装 cache.store_pipeline_log:计时同步、JSONL/DB 异步落盘,不堵主请求。+ - log_writer 为 None 时不写 JSONL(MEMORY_PIPELINE_LOG_ENABLED=false)- step-to-step elapsed_ms / event_at_ms 在调用瞬间打点(与业务墙钟对齐)- event_at_ms:调用方传入非 0 值则直接复用(App 已在自己被调用的那一刻同步打点,比这里更接近真实事件时刻);传 0 / 不传才用本地 time.time()@@ -410,7 +425,8 @@ def wrap_store_pipeline_log(try:loop = asyncio.get_running_loop()# JSONL 用线程池,与 loop 无亲和,留在当前 loop。- _track_task(loop.create_task(_persist_jsonl()))+ if log_writer is not None:+ _track_task(loop.create_task(_persist_jsonl()))# DB trace 用 cache pool(可能 aiomysql,绑定 owner_loop)。若当前不在# owner_loop(如 search 走独立 loop),派发回 owner_loop 执行,避免跨 loop。if trace_enabled:@@ -446,25 +462,26 @@ def wrap_store_pipeline_log()except RuntimeError:# 无 running loop(极少见):退化为同步写,保证不丢日志- try:- log_writer.write_step(- request_id=request_id,- user_id=user_id,- agent_id=agent_id,- session_id=session_id,- step=step,- prompt=prompt,- response=response,- parsed=parsed,- memory_ids=mem_ids,- elapsed_ms=step_elapsed_ms,- prompt_tokens=prompt_tokens,- completion_tokens=completion_tokens,- total_tokens=total_tokens,- event_at_ms=event_at_ms,- )- except Exception:- pass+ if log_writer is not None:+ try:+ log_writer.write_step(+ request_id=request_id,+ user_id=user_id,+ agent_id=agent_id,+ session_id=session_id,+ step=step,+ prompt=prompt,+ response=response,+ parsed=parsed,+ memory_ids=mem_ids,+ elapsed_ms=step_elapsed_ms,+ prompt_tokens=prompt_tokens,+ completion_tokens=completion_tokens,+ total_tokens=total_tokens,+ event_at_ms=event_at_ms,+ )+ except Exception:+ passif trace_enabled:try:result = original_store(@@ -496,6 +513,11 @@ def wrap_store_pipeline_log(return _store_pipeline_observability+async def _noop_store_pipeline_log(*args: Any, **kwargs: Any) -> bool:+ """Log 与 Trace 都关闭时的 store_pipeline_log:不计时、不写文件、不写库。"""+ return True++def install_pipeline_observability(cache: Any,*,@@ -503,6 +525,9 @@ def install_pipeline_observability() -> None:"""给 cache 安装 JSONL + Trace 包装(fire-and-forget)。+ MEMORY_PIPELINE_LOG_ENABLED=false 时不写 JSONL;若 Trace 也关闭,+ store_pipeline_log 被换成空操作(不包装、不写库)。+在 cache 所属 loop(write loop / _LoopThread)上调用,本函数会捕获该 loop作为 owner_loop 传给包装器:search 走独立 loop 后,从 search loop 触发的 DB落库会被派发回这个 owner_loop,避免跨 loop 用 aiomysql 污染连接池。@@ -514,15 +539,31 @@ def install_pipeline_observability(except RuntimeError:owner_loop = None- log_dir = resolve_pipeline_log_dir()- log_writer = PipelineLogWriter(log_dir)+ log_enabled = is_pipeline_log_enabled()trace_enabled = is_pipeline_trace_enabled()- logger.info(- f"[{log_label}] Pipeline log (JSONL) enabled: {log_dir}/<subdir>/<date>.log "- f"(subdir from user_id prefix before '__', else default) ; "- f"pipeline trace (DB)={'on' if trace_enabled else 'off'} ; "- f"persist=async(fire-and-forget)"- )+ if not log_enabled and not trace_enabled:+ logger.info(+ f"[{log_label}] Pipeline log (JSONL) disabled ; pipeline trace (DB)=off ; "+ f"store_pipeline_log=no-op"+ )+ cache.store_pipeline_log = _noop_store_pipeline_log+ return++ log_writer = None+ if log_enabled:+ log_dir = resolve_pipeline_log_dir()+ log_writer = PipelineLogWriter(log_dir)+ logger.info(+ f"[{log_label}] Pipeline log (JSONL) enabled: {log_dir}/<subdir>/<date>.log "+ f"(subdir from user_id prefix before '__', else default) ; "+ f"pipeline trace (DB)={'on' if trace_enabled else 'off'} ; "+ f"persist=async(fire-and-forget)"+ )+ else:+ logger.info(+ f"[{log_label}] Pipeline log (JSONL) disabled ; "+ f"pipeline trace (DB)=on ; persist=async(fire-and-forget)"+ )cache.store_pipeline_log = wrap_store_pipeline_log(cache.store_pipeline_log,log_writer=log_writer,diff --git a/pyproject.toml b/pyproject.tomlindex c2afd09..1588851 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"[project]name = "hy-memory"-version = "2.0.7"+version = "2.0.8"description = "HY Memory - Industrial-grade dual-system cognitive memory framework"readme = "README.md"requires-python = ">=3.9"diff --git a/tests/coding/test_content_log_levels.py b/tests/coding/test_content_log_levels.pynew file mode 100644index 0000000..6e8e7af--- /dev/null+++ b/tests/coding/test_content_log_levels.py@@ -0,0 +1,140 @@+# -*- coding: utf-8 -*-+"""对话、记忆正文和模型输出只进 DEBUG,不进 INFO / WARNING。++MemHub 等调用方默认以 INFO 运行;这些文本一旦进 INFO,就会写进常驻的+hy_memory.log。这里逐条锁住曾经把正文打在 INFO / WARNING 的日志。+"""++import logging++import pytest++from hy_memory.agent.reconciler import ReconcileOp as AgentReconcileOp+from hy_memory.agent.reconciler import _log_ops_detail+from hy_memory.coding.extractor import CodingMemoryExtractor+from hy_memory.coding.fact_reconciler import WorkingFactReconciler+from hy_memory.coding.judge import classify_and_rewrite_queries+from hy_memory.coding.reconciler import CodingMemoryReconciler+from hy_memory.coding.types import CodingMemory, WorkingFact++from tests.coding._helpers import MockLLMProvider++SECRET = "SECRET-CONVERSATION-TEXT-42"+++def _above_debug(caplog):+ return [+ r.getMessage() for r in caplog.records+ if r.name.startswith("hy_memory") and r.levelno > logging.DEBUG+ ]+++def _debug(caplog):+ return [+ r.getMessage() for r in caplog.records+ if r.name.startswith("hy_memory") and r.levelno == logging.DEBUG+ ]+++def _assert_secret_only_at_debug(caplog):+ assert not [m for m in _above_debug(caplog) if SECRET in m]+ assert [m for m in _debug(caplog) if SECRET in m]+++class TestStoreInsertLogs:+ async def test_experience_task_not_at_info(self, coding_store, caplog):+ caplog.set_level(logging.DEBUG, logger="hy_memory")+ await coding_store.insert(CodingMemory(+ experience_id="e1", user_id="u1", task=SECRET, solution="S",+ ))+ info = [m for m in _above_debug(caplog) if "inserted experience_id=e1" in m]+ assert info+ _assert_secret_only_at_debug(caplog)++ async def test_fact_statement_not_at_info(self, coding_store, caplog):+ caplog.set_level(logging.DEBUG, logger="hy_memory")+ await coding_store.insert_fact(WorkingFact(+ fact_id="f1", user_id="u1", agent_id="a1", session_id="s1",+ workspace_id="ws/a", statement=SECRET,+ ))+ info = [m for m in _above_debug(caplog) if "inserted fact_id=f1" in m]+ assert info+ _assert_secret_only_at_debug(caplog)+++class TestParseFailureWarnings:+ """解析失败仍发 WARNING,但只带长度,模型输出进 DEBUG。"""++ @pytest.mark.parametrize("parse", [+ CodingMemoryExtractor._parse_output,+ CodingMemoryReconciler._parse_ops,+ WorkingFactReconciler._parse_ops,+ ])+ def test_warning_keeps_length_drops_text(self, parse, caplog):+ caplog.set_level(logging.DEBUG, logger="hy_memory")+ bad = f"not json {SECRET}"+ parse(bad)+ warnings = [+ r.getMessage() for r in caplog.records+ if r.levelno == logging.WARNING and "failed to parse" in r.getMessage()+ ]+ assert warnings and f"({len(bad)} chars)" in warnings[0]+ _assert_secret_only_at_debug(caplog)+++class TestJudgeLogs:+ async def test_rewrite_not_at_info(self, caplog):+ caplog.set_level(logging.DEBUG, logger="hy_memory")+ llm = MockLLMProvider(f"1\n{SECRET}")+ result = await classify_and_rewrite_queries(["q"], llm)+ assert result["rewrite_query"] == SECRET+ _assert_secret_only_at_debug(caplog)++ async def test_unrecognized_head_not_at_warning(self, caplog):+ caplog.set_level(logging.DEBUG, logger="hy_memory")+ llm = MockLLMProvider(f"{SECRET}\nrewrite")+ result = await classify_and_rewrite_queries(["q"], llm)+ assert result["ok"] is False+ _assert_secret_only_at_debug(caplog)+++def test_reconciler_ops_detail_is_debug(caplog):+ caplog.set_level(logging.DEBUG, logger="hy_memory")+ _log_ops_detail([AgentReconcileOp(op="ADD", content=SECRET)])+ _assert_secret_only_at_debug(caplog)+++class _StopAfterLogging(Exception):+ pass+++def _add_client():+ from types import SimpleNamespace+ from unittest.mock import AsyncMock++ from hy_memory.client import HyMemoryClient++ client = HyMemoryClient.__new__(HyMemoryClient)+ client._mode = "lite"+ client._config = SimpleNamespace(coding=None)+ writer = SimpleNamespace(+ VERSION="test", write=AsyncMock(side_effect=_StopAfterLogging),+ )+ client._registry = SimpleNamespace(get_writer=AsyncMock(return_value=writer))+ return client++[email protected]("data", [+ SECRET,+ [{"role": "user", "content": SECRET}],+])+async def test_add_does_not_log_input_at_info(data, caplog):+ caplog.set_level(logging.DEBUG, logger="hy_memory")+ client = _add_client()+ with pytest.raises(_StopAfterLogging):+ await client._async_add_impl(data, user_id="u1")+ assert [m for m in _above_debug(caplog) if m.startswith("[add] writing")]+ _assert_secret_only_at_debug(caplog)diff --git a/tests/test_embed_warning_log.py b/tests/test_embed_warning_log.pyindex bb561e5..ae4e90e 100644--- a/tests/test_embed_warning_log.py+++ b/tests/test_embed_warning_log.py@@ -90,7 +90,10 @@ class TestEmbedInfoLog:assert payload["provider"] == "openai"assert payload["model"] == "text-embedding-test"assert payload["api"] == "https://example.com/v1/embeddings"- assert payload["request"]["input"] == ["hello world"]+ # 待向量化的原文不进 INFO,只记每条字符数+ assert "input" not in payload["request"]+ assert payload["request"]["input_chars"] == [11]+ assert "hello world" not in info_msgs[0]assert payload["request"]["dimensions"] == 8assert payload["response"]["vector_dims"] == [8]assert payload["response"]["vector_count"] == 1diff --git a/tests/test_pipeline_observability.py b/tests/test_pipeline_observability.pyindex 40f5b30..e81f81a 100644--- a/tests/test_pipeline_observability.py+++ b/tests/test_pipeline_observability.py@@ -1,4 +1,4 @@-"""Pipeline log(始终)与 trace(可关)分离。"""+"""Pipeline log(默认开,可关)与 trace(可关)分离。"""import asyncioimport json@@ -10,6 +10,7 @@ from hy_memory.config import MemoryConfigfrom hy_memory.data.cache_sqlite import SqliteCachefrom hy_memory.utils.pipeline_observability import (is_llm_content_logging_enabled,+ is_pipeline_log_enabled,is_pipeline_trace_enabled,resolve_pipeline_log_dir,)@@ -39,6 +40,14 @@ class TestPipelineObservabilityConfig:monkeypatch.setenv("MEMORY_DATA_DIR", str(tmp_path / "data"))assert resolve_pipeline_log_dir() == str(tmp_path / "data" / "logs" / "pipeline")+ def test_log_enabled_default(self, monkeypatch):+ monkeypatch.delenv("MEMORY_PIPELINE_LOG_ENABLED", raising=False)+ assert is_pipeline_log_enabled() is True++ def test_log_disabled(self, monkeypatch):+ monkeypatch.setenv("MEMORY_PIPELINE_LOG_ENABLED", "false")+ assert is_pipeline_log_enabled() is False+def test_trace_enabled_default(self, monkeypatch):monkeypatch.delenv("MEMORY_PIPELINE_TRACE_ENABLED", raising=False)assert is_pipeline_trace_enabled() is True@@ -91,6 +100,98 @@ class TestObservabilityHookBehavior:run(_test())+ def test_log_flag_on_writes_jsonl(self, env_setup, monkeypatch):+ """显式开启与默认一致:照常写 JSONL。"""+ monkeypatch.setenv("MEMORY_PIPELINE_LOG_ENABLED", "true")+ monkeypatch.setenv("MEMORY_PIPELINE_TRACE_ENABLED", "false")++ async def _test():+ from datetime import date+ from hy_memory.utils.pipeline_observability import (+ drain_pipeline_log_tasks,+ install_pipeline_observability,+ )++ config = MemoryConfig.from_dict({"cache": {"backend": "sqlite"}})+ cache = SqliteCache(config)+ await cache.initialize()+ install_pipeline_observability(cache, log_label="test")+ await cache.store_pipeline_log(+ request_id="req-on", user_id="u1", agent_id="a1", step="S1_EMBED",+ )+ await drain_pipeline_log_tasks()++ log_file = Path(env_setup) / "default" / f"{date.today().isoformat()}.log"+ assert json.loads(log_file.read_text(encoding="utf-8").strip())["step"] == "S1_EMBED"+ await cache.close()++ run(_test())++ def test_log_off_trace_off_is_noop(self, env_setup, monkeypatch):+ """两者都关:不包装、不写文件、不写库,store_pipeline_log 直接返回 True。"""+ monkeypatch.setenv("MEMORY_PIPELINE_LOG_ENABLED", "false")+ monkeypatch.setenv("MEMORY_PIPELINE_TRACE_ENABLED", "false")++ async def _test():+ from hy_memory.utils.pipeline_observability import (+ _noop_store_pipeline_log,+ drain_pipeline_log_tasks,+ install_pipeline_observability,+ )++ config = MemoryConfig.from_dict({"cache": {"backend": "sqlite"}})+ cache = SqliteCache(config)+ await cache.initialize()+ original_store = cache.store_pipeline_log+ install_pipeline_observability(cache, log_label="test")+ assert cache.store_pipeline_log is _noop_store_pipeline_log++ ok = await cache.store_pipeline_log(+ request_id="req-off", user_id="ns__u1", agent_id="a1",+ step="S1_EMBED", prompt="p", response="r",+ )+ await drain_pipeline_log_tasks()++ assert ok is True+ assert not Path(env_setup).exists()+ # 原始 store 仍能写库,说明表本身可用;空操作确实没写+ assert await cache.get_pipeline_logs(request_id="req-off") == []+ await original_store(+ request_id="req-probe", user_id="u1", agent_id="a1",+ step="PROBE", prompt="", response="",+ )+ assert len(await cache.get_pipeline_logs(request_id="req-probe")) == 1+ await cache.close()++ run(_test())++ def test_log_off_trace_on_writes_db_only(self, env_setup, monkeypatch):+ """只关 Log:不写 JSONL,Trace 照常落库。"""+ monkeypatch.setenv("MEMORY_PIPELINE_LOG_ENABLED", "false")+ monkeypatch.setenv("MEMORY_PIPELINE_TRACE_ENABLED", "true")++ async def _test():+ from hy_memory.utils.pipeline_observability import (+ drain_pipeline_log_tasks,+ install_pipeline_observability,+ )++ config = MemoryConfig.from_dict({"cache": {"backend": "sqlite"}})+ cache = SqliteCache(config)+ await cache.initialize()+ install_pipeline_observability(cache, log_label="test")+ await cache.store_pipeline_log(+ request_id="req-db", user_id="u1", agent_id="a1", step="S1_EMBED",+ )+ await drain_pipeline_log_tasks()++ assert not Path(env_setup).exists()+ logs = await cache.get_pipeline_logs(request_id="req-db")+ assert [row["step"] for row in logs] == ["S1_EMBED"]+ await cache.close()++ run(_test())+def test_store_returns_before_slow_persist(self, env_setup, monkeypatch):"""慢 DB / 慢磁盘不得堵住 await store_pipeline_log。"""monkeypatch.setenv("MEMORY_PIPELINE_TRACE_ENABLED", "true")