Skip to content

id(fileops): rename/copy onto an existing file merges the replaced file's metadata into the new file — two created values, both files' values for shared keys, and the archive keeps none #2862

Closed

Description

@dezren39

Problem

FileOps::rename and FileOps::copy (pkgs/id/src/fileops.rs) archive a file they replace at the destination — the replaced content gets a blob tag <to>.archive.<unix-ts> — but the replaced file's metadata tags are neither moved to that archive nor removed. The transfer/copy then layers the source file's tags on top of whatever the destination already had:

  • rename (fileops.rs:262-335): archive_existing(&to, ts) archives only the blob tag (archive_existing, fileops.rs:182-194, sets a blob tag and nothing else). Then transfer_all_tags(ns, from, to) (tags.rs:983-1009) copies each source tag onto to with set_tag and deletes the source's tags. Nothing ever reads, moves or deletes to's pre-existing tags.
  • copy (fileops.rs:345-390): same shape via copy_all_tags (tags.rs:1018-1034). Its trailing stamp(&to, true) resets created/modified singletons, but every other pre-existing destination tag survives the same way.

set_tag (tags.rs:820-850) is keyed by (subject, key, value), so tags are multi-valued per key: the same key with a different value is a separate entry, not a replacement. Consequences for a destination that is replaced:

  1. Keys only the replaced file had stay on the new file. E.g. the replaced file's color=red now describes the source's content.
  2. Keys both files had end up with both values. E.g. status is both wip (source) and done (replaced file) after the rename.
  3. Singleton-intended keys duplicate (rename path). created/modified are maintained as singletons everywhere else (stamp uses set_singleton/set_if_absent, fileops.rs:215-247), but rename never stamps, so after a rename onto an existing file the new name carries two created values — its own and the replaced file's.
  4. The archive is left with no metadata at all. The archived version's tags are stranded on the destination name (points 1-3), so the archive tag <to>.archive.<ts> has zero metadata tags: the version it preserves cannot be found by the metadata that described it.

Evidence (verified this run, main 07448571)

Probe on the laptop (~/git/fleet/probe-2026-10-30-laneA2-replacemeta/, a worktree of origin/main with a probe-only test module appended to fileops.rs in the worktree; real FileOps over a MemStore blob store + a real TagStore over in-memory iroh-docs):

Setup for both tests: put a.md (content A), put b.md (content B); a.md gets status=wip, created=111 (singleton); b.md gets status=done, color=red, created=222 (singleton).

BEFORE b.md:        ["color=red", "created=222", "file=b.md", "modified=1793402633", "name=b.md", "status=done"]

rename a.md -> b.md (archived_replaced = "b.md.archive.1793402633"):
AFTER-RENAME b.md:  ["archive.replace=b.md.archive.1793402633", "color=red",
                     "created=111", "created=222", "file=b.md", "modified=1793402633",
                     "name=b.md", "status=done", "status=wip"]
ARCHIVE b.md.archive.1793402633 tags: []

copy a.md -> b.md (fresh store, same seed; archived_replaced = "b.md.archive.1793402633"):
AFTER-COPY b.md:    ["archive.replace=b.md.archive.1793402633", "color=red",
                     "created=1793402633", "file=b.md", "modified=1793402633",
                     "name=b.md", "status=done", "status=wip"]
ARCHIVE b.md.archive.1793402633 tags: []

So after the rename, b.md (now holding content A) has two created values (111 from A, 222 from the replaced B), both status values (wip and done), and B-only color=red — while the archive tag preserving B's content has no metadata at all. Copy shows the same merge; only created escapes duplication there because copy's trailing stamp(..., reset_created=true) happens to reset that one singleton. (In this probe both files' modified values fell in the same second, so that key did not visibly duplicate; it goes through the identical transfer path as created in rename, which never stamps.)

Why it matters

Rename-onto-existing and copy-onto-existing are normal flows (the meta protocol renames with archiving, protocol.rs:572; the web UI exposes both). Metadata is how this system describes files — tag list/search, the web file list's user-visible tags, and archive.* bookkeeping all read it. After such a rename/copy, the destination's metadata is a blend of two different files' metadata, with duplicated created timestamps and contradictory values for the same key, while the archived version that metadata partly belongs to is undiscoverable by it. Nothing errors; the corruption is silent and persists in the synced tag store.

Acceptance criteria

  • After rename or copy replaces a file at the destination, no metadata tag that belonged only to the replaced file remains on the destination name (whether the ruling is move-to-archive-subject or delete-with-the-replace — triage pins it, consistently for both operations).
  • After a rename onto an existing file, the destination has exactly one created and one modified value, belonging to the renamed file.
  • A key both files had carries only the source file's value(s) on the destination after rename/copy.
  • The archive subject (<to>.archive.<ts>), if the ruling is move-to-archive, carries the replaced file's metadata; if the ruling is delete, a test pins that the archive intentionally has none and the destination is clean either way.
  • Regression tests in fileops.rs (real FileOps + TagStore): rename onto an existing file with disjoint and overlapping tag keys; copy onto an existing file likewise; rename/copy onto a fresh name behave exactly as today.
  • Triage pins the ruling for the replaced file's archive.* system tags and for put-style overwrite (which intentionally keeps metadata) so this fix does not change put semantics.

Dedup checked this run: open+closed search for fileops rename/copy metadata — #2856 (delete misses previous-name archives) is the same module but a different operation and defect; #1612/#2462 cover archive blob-tag naming/races only; no issue covers replaced-file metadata handling in rename/copy.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    priority/normalOrdinary priority (the default)
    source/creatorFiled by the new-issue-creator job
    task/triageQueue packet kind: verify, reproduce, and route this item
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    effort/sSmall: expected under 2 hours of work
    on Oct 30, 2026
  2. dezren39 commented on Oct 30, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  3. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 1, 2026
  4. 48 remaining items

  5. added
    status/parkedDeliberately paused with a recorded resume condition
    and removed
    queue/claimedQueue worker lifecycle state
    on Nov 2, 2026
  6. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · parked

  7. added
    queue/claimedQueue worker lifecycle state
    and removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Nov 2, 2026
  8. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    agent-note:v1

  9. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    agent-note:v1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobtask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions