From 0ab1ee9378607f36febbb73227f733147144e4d8 Mon Sep 17 00:00:00 2001 From: Kimi Agent Date: Wed, 18 Mar 2026 18:36:59 -0400 Subject: [PATCH] fix: proactive memory status check during thought tracking (#313) Co-authored-by: Kimi Agent Co-committed-by: Kimi Agent --- src/timmy/thinking.py | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/timmy/thinking.py b/src/timmy/thinking.py index bee3d29..7ac8a57 100644 --- a/src/timmy/thinking.py +++ b/src/timmy/thinking.py @@ -308,6 +308,9 @@ class ThinkingEngine: # Post-hook: check workspace for new messages from Hermes await self._check_workspace() + # Post-hook: proactive memory status audit + self._maybe_check_memory_status() + # Post-hook: update MEMORY.md with latest reflection self._update_memory(thought) @@ -564,6 +567,47 @@ class ThinkingEngine: except Exception as exc: logger.warning("Thought distillation failed: %s", exc) + def _maybe_check_memory_status(self) -> None: + """Every N thoughts, run a proactive memory status audit and log results.""" + try: + interval = settings.thinking_memory_check_every + if interval <= 0: + return + + count = self.count_thoughts() + if count == 0 or count % interval != 0: + return + + from timmy.tools_intro import get_memory_status + + status = get_memory_status() + + # Log summary at INFO level + tier1 = status.get("tier1_hot_memory", {}) + tier3 = status.get("tier3_semantic", {}) + hot_lines = tier1.get("line_count", "?") + vectors = tier3.get("vector_count", "?") + logger.info( + "Memory audit (thought #%d): hot_memory=%s lines, semantic=%s vectors", + count, + hot_lines, + vectors, + ) + + # Write to memory_audit.log for persistent tracking + audit_path = Path("data/memory_audit.log") + audit_path.parent.mkdir(parents=True, exist_ok=True) + timestamp = datetime.now(UTC).isoformat(timespec="seconds") + with audit_path.open("a") as f: + f.write( + f"{timestamp} thought={count} " + f"hot_lines={hot_lines} " + f"vectors={vectors} " + f"vault_files={status.get('tier2_vault', {}).get('file_count', '?')}\n" + ) + except Exception as exc: + logger.warning("Memory status check failed: %s", exc) + async def _maybe_file_issues(self) -> None: """Every N thoughts, classify recent thoughts and file Gitea issues.