Fix AttributeError on bullet lines in extract_memory_from_chat (#873)

The fallback memory extractor (used by routes/memory_routes.py when the LLM
extractor fails) matched list items with `r'^[-*•]|\d+\.\s*(.*)'`. Operator
precedence makes that `(^[-*•]) | (\d+\.\s*(.*))`, so the capture group only
exists on the numbered-list branch.

A bullet line ("- foo") matches the first branch, so `group(1)` is None and
`text_match.group(1).strip()` raises AttributeError — crashing extraction for
any assistant message that contains a bullet list (i.e. most of them). Numbered
lists happened to work.

Group both markers — `r'^(?:[-*•]|\d+\.)\s*(.*)'` — so the capture applies to
bullets and numbers alike.

Adds tests/test_memory_bullet_extraction.py (red before, green after).
This commit is contained in:
mist
2026-06-02 05:46:06 +03:00
committed by GitHub
parent 2b39412355
commit f13d897093
2 changed files with 32 additions and 2 deletions

View File

@@ -59,8 +59,12 @@ class MemoryManager:
line = line.strip()
# Look for bullet points or numbered lists that might contain memories
if re.match(r'^[-*•]|\d+\.', line):
# Extract the text after the bullet/number
text_match = re.match(r'^[-*•]|\d+\.\s*(.*)', line)
# Extract the text after the bullet/number. Group both
# markers so the capture applies to either — the previous
# `^[-*•]|\d+\.\s*(.*)` put the group on the numbered branch
# only, so a bullet line matched with group(1)=None and
# crashed on .strip().
text_match = re.match(r'^(?:[-*•]|\d+\.)\s*(.*)', line)
if text_match:
text = text_match.group(1).strip()
if text: