Skip to content

Consolidation's retire mv overwrites an existing today-*.done.md when a retired day is re-opened by NDC #509

Closed

Description

@Kreuterberg

Summary

run-consolidation.sh retires a staging file with mv "$staging_path" "$staging_done". When a today-YYYY-MM-DD.md is re-created for a day that was already retired (NDC filing content under its content-day stamp per #141/#164 after that day's consolidation ran), the second consolidation's mv silently overwrites the existing today-YYYY-MM-DD.done.md. The first retired span (a full day of NDC entries) is gone from disk; only the second, much smaller span survives under the .done.md name.

recent.md is intact (both spans were merged there), so this is not a memory-injection loss — but the hourly detail layer that the README describes as "searchable, not injected" is destroyed without any log line, which is exactly the class of silent loss #178 / #142 set out to eliminate.

Observed sequence (v0.20.0, macOS, TZ Europe/Berlin)

Day D = 2026-09-01. A session started on D stayed open past midnight.

  1. During D, NDC appended 9 entries to today-D.md (last one 21:31).
  2. D+1 13:44 — first session start of the day → consolidation: done: 1 files consolidated, today-D.md → today-D.done.md (9 entries). Correct.
  3. D+1 13:55 — the still-open session saved. now.md still carried a tail from D, so the now-day marker was D and NDC wrote now.md → today-D.md — a fresh today-D.md with 2 entries (log: 632→591b). By design per NDC files compressed content by run date — after-midnight compression lands prior-day entries in the new day's today-*.md #141, fine.
  4. D+1 14:53 — next session start → consolidation: done: 1 files consolidated, then mv today-D.md today-D.done.md replaced the 9-entry .done.md from step 2 with the 2-entry file. No WARN/ERROR logged.

Relevant log lines (paths trimmed):

memory-D.log:    21:31:55 [ndc] now.md → today-2026-09-01.md
memory-D+1.log:  13:44:22 [consolidation] start
memory-D+1.log:  13:44:42 [consolidation] done: 1 files consolidated
memory-D+1.log:  13:56:08 [ndc] now.md → today-2026-09-01.md
memory-D+1.log:  13:56:31 [ndc] 632→591b (-6%)
memory-D+1.log:  14:53:34 [consolidation] start
memory-D+1.log:  14:54:26 [consolidation] done: 1 files consolidated

Resulting today-2026-09-01.done.md holds only the two entries from step 3; the nine from step 1 are unrecoverable (they exist only as the merged paragraph in recent.md).

Expected

Retiring into an existing .done.md should append (or write a numbered sibling such as today-D.done-2.md, in the spirit of the -2 archive rotation), never replace. At minimum it should log a WARN when the target already exists.

Suggested fix

In the retire loop of run-consolidation.sh (both mv branches and the head -c … > "$staging_done" branch), check [ -e "$staging_done" ] first and append with cat "$staging_path" >> "$staging_done" && rm "$staging_path" (same-directory, under staging.lock as today), or choose a non-colliding sibling name. The head -c branch currently truncates an existing .done.md too (>), so it needs the same guard.

Workaround

Do not keep a session running across midnight; start a new session on the new day so NDC does not re-open a retired day's staging file.

Activity

  1. self-assigned this
    on Sep 3, 2026
  2. added
    priority:high
    on Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

priority:high

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions