Skip to content

NDC and consolidation take two different locks over the same today-*.md file, so nothing serializes an append against a merge #225

Closed

Description

@fdaviddpt

The two locks

Both use the same lib-lock.sh primitive, so each is internally sound. They just are not the same lock, and holding one says nothing about the other.

The gap

today-YYYY-MM-DD.md is written by one and read-then-merged-away by the other, with no shared mutual exclusion. The NDC append is not atomic — it is [ -s "$TODAY_FILE" ] && echo "" >> "$TODAY_FILE" followed by cat "$HAIKU_TEXT_FILE" >> "$TODAY_FILE", two separate appends — so a consolidation run reading between them sees a file with a trailing blank line and no summary, and a run reading during the second could see a partial one.

What I have and have not established

I have not shown this is reachable. Consolidation targets past-day files and NDC normally appends to today's, so the day boundary may well make the overlap empty in practice. The candidate windows are the obvious ones — a save whose NDC round starts before midnight and commits after (the exact case NOW_DAY_FILE and #141 exist to handle, so $NDC_DAY can legitimately name yesterday), and a consolidation run firing while such a round is in flight.

Filing it unproven and saying so, rather than either fixing it blind or dropping it. "NDC and consolidation do not share a lock" is a sentence that reads badly in hindsight if it turns out to matter, and the cost of writing it down now is one issue.

What would settle it

Whether $NDC_DAY can name a day that consolidation considers past, while consolidation is eligible to run. If yes, this is real and the fix is a shared lock (or ordering) around today-*.md. If no, close it and leave the reasoning on the record so the next person does not re-derive it.

Found while fixing #223 (PR #224), by the agent working that issue. Deliberately not folded into that PR — different files, different lock, and bundling an unproven concurrency change into a proven one would put both at risk.

Activity

  1. added a commit that references this issue on Jul 30, 2026
  2. added 2 commits that reference this issue on Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions