Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions deeptutor/services/memory/consolidator/modes/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,10 +624,13 @@ def _extract_json_object(raw: str) -> str | None:
if text.rstrip().endswith("```"):
text = text.rstrip()[:-3]
start = text.find("{")
end = text.rfind("}")
if start == -1 or end <= start:
if start == -1:
return None
return text[start : end + 1]
try:
_parsed, end = json.JSONDecoder().raw_decode(text[start:])
except json.JSONDecodeError:
return None
return text[start : start + end]


def _append_facts_to_doc(
Expand Down
16 changes: 16 additions & 0 deletions tests/services/memory/test_update_facts_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Regression: memory update fact JSON tolerates trailing brace prose."""

from __future__ import annotations

from deeptutor.services.memory.consolidator.modes import update as update_mode


def test_parse_facts_tolerates_trailing_brace_prose() -> None:
raw = (
'{"facts":[{"text":"hello","section":"Notes","refs":["a:b"]}]}'
" trailing {note}"
)
facts = update_mode._parse_facts(raw)
assert len(facts) == 1
assert facts[0].text == "hello"
assert facts[0].section == "Notes"