Merge pull request 'fix: corrupted memory state + regex bug in update_user_profile' (#41) from fix/corrupted-memory-state into main

This commit is contained in:
2026-03-14 12:56:52 -04:00

View File

@@ -50,6 +50,14 @@ class HotMemory:
def update_section(self, section: str, content: str) -> None:
"""Update a specific section in MEMORY.md."""
# Guard against empty or excessively large writes
if not content or not content.strip():
logger.warning("HotMemory: Refusing empty write to section '%s'", section)
return
if len(content) > 2000:
logger.warning("HotMemory: Truncating oversized write to section '%s'", section)
content = content[:2000] + "\n... [truncated]"
full_content = self.read()
# Find section
@@ -205,10 +213,11 @@ class VaultMemory:
content = profile_path.read_text()
# Simple pattern replacement
# Simple pattern replacement — use lambda to avoid regex-interpreting value
pattern = rf"(\*\*{re.escape(key)}:\*\*).*"
if re.search(pattern, content):
content = re.sub(pattern, rf"\1 {value}", content)
safe_value = value.strip()
content = re.sub(pattern, lambda m: f"{m.group(1)} {safe_value}", content)
else:
# Add to Important Facts section
facts_section = "## Important Facts"