Repository navigation
fix: prevent memory name from auto-appending (1) on description update - #16714
Conversation
📝 WalkthroughWalkthroughThe ChangesMemory Name Update Deduplication
Estimated code review effort: 1 (Trivial) | ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
api/db/services/memory_service.py (1)
152-155: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd logging for the new dedup-gating flow.
The new branch decides whether to trigger
duplicate_namebased on comparing the incoming name to the stored one, but there's no logging for this decision path (e.g. when dedup is skipped vs. triggered), making it hard to trace name-change/duplication behavior in production.📝 Suggested logging addition
if "name" in update_dict: existing = cls.model.select().where((cls.model.id == memory_id) & (cls.model.tenant_id == tenant_id)).first() if not existing or existing.name != update_dict["name"]: + logging.info(f"Memory {memory_id}: name change detected ('{existing.name if existing else None}' -> '{update_dict['name']}'), deduplicating.") update_dict["name"] = duplicate_name(cls.query, name=update_dict["name"], tenant_id=tenant_id)As per coding guidelines, "Add logging for new flows" applies to
**/*.py.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@api/db/services/memory_service.py` around lines 152 - 155, Add logging to the new name dedup-gating branch in memory_service’s update path so it’s clear when `duplicate_name` is skipped versus triggered. In the `existing` lookup / `update_dict["name"]` comparison flow, log the memory id, tenant id, incoming name, stored name, and the decision outcome before calling `duplicate_name` or leaving the name unchanged. Use the surrounding update logic in `memory_service` (the branch that checks `existing.name != update_dict["name"]`) to place the log statements so production traces can follow name-change behavior.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@api/db/services/memory_service.py`:
- Around line 152-155: Add logging to the new name dedup-gating branch in
memory_service’s update path so it’s clear when `duplicate_name` is skipped
versus triggered. In the `existing` lookup / `update_dict["name"]` comparison
flow, log the memory id, tenant id, incoming name, stored name, and the decision
outcome before calling `duplicate_name` or leaving the name unchanged. Use the
surrounding update logic in `memory_service` (the branch that checks
`existing.name != update_dict["name"]`) to place the log statements so
production traces can follow name-change behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5130c784-46d0-4f00-93e5-53a2cc0bbe9b
📒 Files selected for processing (1)
api/db/services/memory_service.py
wangq8
left a comment
There was a problem hiding this comment.
Review Summary
PR: #16714 — fix: prevent memory name from auto-appending (1) on description update
Author: @euvre
Scope: 3 additions, 1 deletion in api/db/services/memory_service.py
Status: LGTM with one optional suggestion
What the fix does
In MemoryService.update_memory, before passing the name through duplicate_name(), the code now fetches the existing memory row and only calls duplicate_name when the existing record is missing or its stored name differs from the incoming name.
This prevents the (1) suffix from being appended whenever a user saves unrelated field changes (e.g., description) on the memory settings page.
Correctness
The logic is sound:
| Scenario | existing ? |
existing.name != update_dict["name"] ? |
duplicate_name called? |
Outcome |
|---|---|---|---|---|
| New record (not yet persisted) | None/falsy |
N/A | Yes | Correct — dedup still runs |
| Name actually changed | Found | True |
Yes | Correct — dedup still runs |
| Name unchanged, other field updated | Found | False |
No | Bug fixed — no unwanted suffix |
Regression risk
Very low. The guard only skips duplicate_name where it was previously always called. The old behavior in that case was demonstrably buggy, so removing it is strictly an improvement. No downstream callers are affected.
Edge cases considered
- Empty/None
update_dict: Already handled by the guard at the top of the method. - Missing
namekey: Already handled by theif "name" in update_dictcheck. - Concurrent updates: Minor TOCTOU window exists, but this is a pre-existing concern, not introduced by this change.
- Multiple memories sharing a name under the same tenant: Still handled correctly —
duplicate_nameruns when the name actually differs.
Code quality
Clean, minimal, self-documenting. Consistent with the rest of the method style.
Tests
Manual verification confirmed the fix. No automated test, which is acceptable for a 3-line bugfix.
Optional suggestion
Adding logging for the dedup-gating decision path (as CodeRabbit suggested) would be nice for production traceability, but is entirely optional.
Verdict: Good catch and well-scoped fix. Merge when ready.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16714 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
When updating a memory's description (or any other field) via the memory settings page, the backend always runs the name through
duplicate_name, even if the name in the update request matches the current name. This causes the name to be appended with(1)every time the form is saved, even though the user did not change the name.Fix
In
MemoryService.update_by_id, check the existing memory name for the currentmemory_idand only callduplicate_namewhen the requested name is actually different from the current one.Verification
The issue was reproduced on the memory settings page: after saving a description change, the memory name changed from
mmrtommr(1). With the fix, the name staysmmrwhile the description is updated./ci