Skip to content

Commit 6689f50

Browse files
committed
fix(memory): soft-delete orphaned messages with legacy-only tool content (#2529)
strip_mid_history_orphans only soft-deleted messages when content was completely empty. Messages with legacy bracket strings (e.g. [tool_use: memory_save(...)]) in content were never soft-deleted, causing the orphan WARN to repeat on every session restart. Add has_meaningful_content() helper that strips [tool_use:], [tool_result:], and [tool output:] bracket markers before deciding whether content is meaningful. The body-skip search uses PREFIXES-based lookup to avoid false negatives when tool output contains JSON arrays or other bracket characters. Update the three emptiness-check sites in strip_mid_history_orphans and load_history. Add 20 unit tests and 3 integration tests covering the regression scenario, idempotency across sessions, and the mixed text+tool-tag preservation invariant. Closes #2529
1 parent 775f676 commit 6689f50

File tree

2 files changed

+498
-3
lines changed

2 files changed

+498
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
3434
- fix(memory): spreading activation recall timeout is now configurable via `[memory.graph.spreading_activation] recall_timeout_ms` (default `1000`, increased from the previous hardcoded `500ms`); a value of `0` is clamped to `100ms` at runtime with a warning to prevent silently disabling recall (closes #2514)
3535
- fix(memory): tier promotion `promote_to_semantic` now uses `BEGIN IMMEDIATE` (via `zeph_db::begin_write`) instead of `DEFERRED`, eliminating the read-to-write lock upgrade race that caused `SQLITE_BUSY` under concurrent agent writes; `merge_cluster_and_promote` additionally retries the DB write up to 3 times with 50/100/200ms exponential backoff on `SQLITE_BUSY` — retry is scoped to the cheap DB write only, not the expensive LLM merge (closes #2511)
3636
- fix(memory): orphaned tool-pair messages removed by `sanitize_tool_pairs` are now soft-deleted from SQLite after each `load_history` call, preventing the same orphan warnings from reappearing on every restart; deletion is non-fatal (warning on error, debug on success) (closes #2507)
37+
- fix(memory): `strip_mid_history_orphans` now soft-deletes messages whose `content` field contains only legacy tool bracket strings (e.g. `[tool_use: ...]`) after all `ToolUse`/`ToolResult` parts are stripped; previously the non-empty `content` prevented soft-delete and caused the orphan `WARN` to repeat on every session restart (closes #2529)
3738

3839
### Added
3940

0 commit comments

Comments
 (0)