docir — design documents Graph

Documents / Issues / issue-5e61f46f19f8

A forced --replace-body erased a hand edit the daemon had already re-indexed

Why the stale-write guard never fired with the daemon up, why refetching with get could not clear it without one, and what it compares now.

issue-5e61f46f19f8issueresolved#integrity#cli
View as Markdown◉ View in graph

Symptom

With the daemon running — the default — docir update <id> --replace-body --force erased a paragraph somebody had typed into the file by hand, and exited 0.

  1. docir get <id> — the agent reads the document.
  2. A person appends a paragraph to the file.
  3. About a second later, docir update <id> --replace-body --force --body "..." exits 0, and the paragraph is gone.

Reproduced four times in acceptance testing of 0.30.4. With --no-daemon the same steps were refused with exit 6 (StaleWriteError, "changed on disk since it was indexed; refetch with docir get"), and that refusal could not be cleared: get answered from the index, so the refetch returned the version without the paragraph and changed nothing. The refusal held until somebody ran docir reindex.

Cause

The guard compared the file's content_hash with the index's. That measures whether the index has caught up with the file, not whether anybody has seen the file. The daemon's watcher runs reindex --changed on every change under docs/, so within a second of a hand edit the two agreed again and the guard had nothing to refuse. Without the daemon, nothing re-indexed the file, and get showed the index's copy, so the instruction in the error message could not be followed.

Resolution

The guard now compares the file with acknowledged_hash: the content_hash of the version docir last wrote, or last returned in full through get. A rebuild or the watcher never advances it. get reads the file, so the refetch shows the hand edit and clears the refusal, with or without the daemon. Why each write path does or does not advance it is in the decision this issue relates to.

Pinned by tests/modules/documents/test_replace_body_acknowledgement.py, which runs the watcher's own reindex --changed request between the hand edit and the replace.

To amend: Re-verify: