Skip to content

fix: prevent memory name from auto-appending (1) on description update - #16714

Merged
wangq8 merged 2 commits into
infiniflow:mainfrom
euvre:fix-memory-name-auto-suffix
Jul 7, 2026
Merged

wangq8 merged 2 commits into
infiniflow:mainfrom
euvre:fix-memory-name-auto-suffix

Conversation

@euvre

@euvre euvre commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

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 current memory_id and only call duplicate_name when 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 mmr to mmr(1). With the fix, the name stays mmr while the description is updated.

/ci

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jul 7, 2026
@coderabbitai

coderabbitai Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The update_memory method in MemoryService was modified so that name deduplication only runs when the existing memory record is missing or its name differs from the incoming update, instead of always deduplicating on every name update.

Changes

Memory Name Update Deduplication

Layer / File(s) Summary
Conditional duplicate_name gating
api/db/services/memory_service.py
update_memory now fetches the existing memory row by memory_id and tenant_id, and only calls duplicate_name(...) when the row is missing or its name differs from the incoming name.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Poem

A tiny hop, a subtle fix,
No more duplicate-name tricks,
Only check when names don't match,
A rabbit's tweak, a tidy patch. 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: preventing unwanted (1) suffixes on memory name updates.
Description check ✅ Passed The description matches the template's Summary requirement and adds useful fix and verification context.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
api/db/services/memory_service.py (1)

152-155: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add logging for the new dedup-gating flow.

The new branch decides whether to trigger duplicate_name based 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

📥 Commits

Reviewing files that changed from the base of the PR and between 6cd03d7 and 419aef3.

📒 Files selected for processing (1)
  • api/db/services/memory_service.py

@euvre euvre added the ci Continue Integration label Jul 7, 2026

@wangq8 wangq8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 name key: Already handled by the if "name" in update_dict check.
  • 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_name runs 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

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (705754e) to head (ae138e7).
⚠️ Report is 2 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wangq8
wangq8 merged commit 41801ad into infiniflow:main Jul 7, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants