Fix: prevent auto-incrementing memory name suffix when only permissions change (#16750)

This commit is contained in:
euvre
2026-07-08 20:12:45 +08:00
committed by GitHub
parent a41fef49d0
commit 74d3508a37
2 changed files with 17 additions and 13 deletions

View File

@@ -452,19 +452,26 @@ func (s *MemoryService) CreateMemory(tenantID string, req *CreateMemoryRequest)
func (s *MemoryService) UpdateMemory(tenantID string, memoryID string, req *UpdateMemoryRequest) (*CreateMemoryResponse, error) {
updateDict := make(map[string]interface{})
currentMemory, err := s.memoryDAO.GetByID(memoryID)
if err != nil {
return nil, fmt.Errorf("memory '%s' not found", memoryID)
}
if req.Name != nil {
memoryName := strings.TrimSpace(*req.Name)
if err := common.ValidateName(memoryName); err != nil {
return nil, err
}
memoryName, err := common.DuplicateName(func(name string, tid string) bool {
existing, _ := s.memoryDAO.GetByNameAndTenant(name, tid)
return len(existing) > 0
}, memoryName, tenantID)
if err != nil {
return nil, err
if memoryName != strings.TrimSpace(currentMemory.Name) {
memoryName, err := common.DuplicateName(func(name string, tid string) bool {
existing, _ := s.memoryDAO.GetByNameAndTenant(name, tid)
return len(existing) > 0
}, memoryName, tenantID)
if err != nil {
return nil, err
}
updateDict["name"] = memoryName
}
updateDict["name"] = memoryName
}
if req.Permissions != nil {
@@ -552,11 +559,6 @@ func (s *MemoryService) UpdateMemory(tenantID string, memoryID string, req *Upda
}
}
currentMemory, err := s.memoryDAO.GetByID(memoryID)
if err != nil {
return nil, fmt.Errorf("memory '%s' not found", memoryID)
}
if len(updateDict) == 0 {
return formatRetDataFromMemory(currentMemory), nil
}