{"record":{"id":"568b9d690aacf9ae","repo":"vxcontrol/pentagi","slug":"failed-to-check-destination-conflicts-w","errorCode":null,"errorMessage":"failed to check destination conflicts: %w","messagePattern":"failed to check destination conflicts: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/server/services/resources.go","lineNumber":1610,"sourceCode":"\tsourceByNewPath := make(map[string]models.UserResource, len(srcEntries))\n\tnewPathBySourcePath := make(map[string]string, len(srcEntries))\n\tfor _, e := range srcEntries {\n\t\tnewPath := resources.ReplacePrefixPath(e.Path, srcPath, dstPath)\n\t\tif destExists {\n\t\t\tif e.Path == srcPath {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\trel := strings.TrimPrefix(e.Path, srcPath+\"/\")\n\t\t\tnewPath = resources.FilePath(dstPath, rel)\n\t\t}\n\t\tnewPaths = append(newPaths, newPath)\n\t\tsourceByNewPath[newPath] = e\n\t\tnewPathBySourcePath[e.Path] = newPath\n\t}\n\n\texisting, err := findResourcesByPaths(tx, uid, newPaths)\n\tif err != nil {\n\t\treturn result, fmt.Errorf(\"failed to check destination conflicts: %w\", err)\n\t}\n\tif len(existing) > 0 && !force {\n\t\treturn result, errResourceConflict\n\t}\n\n\texistingSet := make(map[string]models.UserResource, len(existing))\n\tfor _, e := range existing {\n\t\tsrcEntry := sourceByNewPath[e.Path]\n\t\tif e.IsDir != srcEntry.IsDir {\n\t\t\treturn result, errResourceConflict\n\t\t}\n\t\texistingSet[e.Path] = e\n\t}\n\n\tfor _, e := range srcEntries {\n\t\tif destExists && e.Path == srcPath {\n\t\t\tcontinue\n\t\t}","sourceCodeStart":1592,"sourceCodeEnd":1628,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/server/services/resources.go#L1592-L1628","documentation":"During a directory copy, copyDirResource queries findResourcesByPaths to learn which destination paths already exist. This error wraps a database failure of that lookup (not a conflict — conflicts return errResourceConflict separately). The copy transaction is aborted.","triggerScenarios":"findResourcesByPaths fails due to DB connectivity loss, query timeout with very large directory trees (huge newPaths IN-list), or schema/driver errors while calling the copy directory API.","commonSituations":"Copying a directory with thousands of entries on a slow or flaky database; connection pool exhaustion under load.","solutions":["Retry the copy request after checking DB health (the wrapped %w cause identifies the actual failure)","Reduce directory size or batch the copy if the IN-list is too large","Check Postgres logs and connection pool settings (max open/idle conns)","Ensure migrations are up to date for the user_resources table"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := copyDir(uid, src, dst, force); err != nil {\n    if strings.Contains(err.Error(), \"failed to check destination conflicts\") {\n        // transient DB issue: retry with backoff\n        return retryWithBackoff(3, func() error { return copyDir(uid, src, dst, force) })\n    }\n    return err\n}","preventionTips":["Keep directory trees reasonably sized; archive old subtrees","Tune DB connection pool and statement timeouts","Alert on DB health so listing/conflict queries don't fail under load"],"tags":["gorm","database","copy","conflict-check"],"backgroundTag":"database-query-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}