OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

cp/mv delete a pre-existing target when the vector transfer fails

Open Kiko0301 opened this issue 3 weeks ago • 0 comments

cp/mv delete a pre-existing target when the vector transfer fails

Bug Description

VikingFS.cp and VikingFS.mv run two stages: the content transfer prepared by _prepare_transfer_entries, followed by _update_vector_store_uris. When the vector stage raises, both operations call _cleanup_transfer_target, which recursively removes the destination (openviking/storage/viking_fs/_ops.py).

That cleanup assumes the destination belongs to this operation. But both operations explicitly accept an existing target: _ensure_transfer_target_type allows overwriting an existing file and merging into an existing directory, and the content stage has already overwritten/merged into it. If the vector transfer then fails, the catch block deletes the whole destination — including files that existed before the call and were never part of this transfer.

A transient vector-store error therefore destroys pre-existing user content, and the raised exception gives no indication that data was lost.

Steps to Reproduce

  1. Create viking://resources/target.md with content A and a source viking://resources/source.md with content B.
  2. Make the vector-store transfer (_update_vector_store_uris) raise, e.g. a temporary backend error.
  3. Call cp("viking://resources/source.md", "viking://resources/target.md") (or the same with mv).
  4. After the expected exception, stat the target: it is gone. For a directory target, files that were already in it before the call are gone as well.

Expected Behavior

The failed operation raises, and the destination that existed before the call keeps its content. Only a destination created by the failed operation is removed (so no partial output is left behind).

Actual Behavior

_cleanup_transfer_target removes the entire destination, deleting pre-existing files that the failed operation did not create.

Environment

  • OS: Windows 11
  • OpenViking version/commit: main @ 37a74437

Additional Context

Fix submitted as PR #7563: _ensure_transfer_target_type now reports whether the target already exists, _prepare_transfer_entries returns that flag, and cp/mv only run _cleanup_transfer_target when the target did not exist before the call. Four regression tests cover file and directory targets for both cp and mv; all fail on unmodified main and pass with the fix.

Kiko0301 avatar Nov 13 '26 12:11 Kiko0301