vxcontrol/pentagi · error
failed to delete merged source directory %q: %w
Error message
failed to delete merged source directory %q: %w
What it means
After relocating entries during a directory merge, the merge deletes each source subdirectory row that was emptied into the destination. This error wraps a failed delete of one such source directory row (identified by %q of its path), aborting the transaction so the merge is atomic.
Source
Thrown at backend/pkg/server/services/resources.go:1110
if err := tx.Delete(&dest).Error; err != nil {
return result, fmt.Errorf("failed to delete destination for overwrite: %w", err)
}
result.DeletedBefore = append(result.DeletedBefore, convertResource(dest))
if dest.Hash != "" {
result.OrphanHashes = append(result.OrphanHashes, dest.Hash)
}
}
updated, err := updateMovedResource(tx, entry, newPath, now)
if err != nil {
return result, err
}
result.Updated = append(result.Updated, convertResource(updated))
}
for _, dir := range sourceDirsToDelete {
if err := tx.Delete(&dir).Error; err != nil {
return result, fmt.Errorf("failed to delete merged source directory %q: %w", dir.Path, err)
}
result.DeletedAfter = append(result.DeletedAfter, convertResource(dir))
}
if sourceRoot != nil {
if err := tx.Delete(sourceRoot).Error; err != nil {
return result, fmt.Errorf("failed to delete source directory %q: %w", sourceRoot.Path, err)
}
result.DeletedAfter = append(result.DeletedAfter, convertResource(*sourceRoot))
}
return result, nil
}
func listResourceTree(tx *gorm.DB, uid uint64, rootPath string) ([]models.UserResource, error) {
escapedRoot := resources.EscapeLike(rootPath)
var entries []models.UserResource
if err := tx.Where(
"user_id = ? AND (path = ? OR path LIKE ?)",View on GitHub (pinned to ea665308ba)
Solutions
- Check the wrapped DB error for the offending constraint or driver error
- Add ON DELETE CASCADE or clean up referencing rows before merging
- Avoid concurrent writes to the source subtree; retry after contention clears
Defensive patterns
Strategy: try-catch
Try / catch
err := svc.MoveResource(ctx, uid, srcDir, dstDir, true)
if err != nil && strings.Contains(err.Error(), "failed to delete merged source directory") {
// log wrapped cause; transaction rolled back, safe to retry
} Prevention
- Remove external references to source directories before merging
- Add ON DELETE CASCADE to all referencing tables
- Keep merge transactions short to reduce lock windows
When it happens
Trigger: moveDirResourceMerge collected source subdirectories to delete, and tx.Delete on one fails — FK constraints referencing the directory row, lock contention, or connection loss.
Common situations: Other flows/records still referencing the source directory while a merge is in flight; migrations lacking cascade rules; DB instability during large merges.
Related errors
- failed to delete source directory %q: %w
- failed to delete destination for overwrite: %w
- failed to delete assistant %d: %w
- failed to delete subtasks for task %d: %w
- failed to delete provider: %w
AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01).
Data as JSON: /api/errors/09ae07eed947ac30.
Report an issue: GitHub.