Skip to content

fix(ndc): file compressed memory under the day it came from (#141) - #164

Merged
fdaviddpt merged 3 commits into
mainfrom
fix/141-ndc-day-boundary
Jul 26, 2026
Merged

fdaviddpt merged 3 commits into
mainfrom
fix/141-ndc-day-boundary

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Closes #141.

NDC compression only fires on a save and carries an hour-long cooldown, so now.md routinely still holds the evening's entries when the first save after midnight arrives. The target filename was built from the date the run happened to fall on, so that evening's work landed at the top of the new day's today-*.md, and consolidation then attributed it to the wrong day.

Entries carry ## HH:MM and nothing else. Once now.md crosses midnight there is nothing in the content that says which day it came from — which is the whole difficulty, and why the fix has to record the day rather than infer it.

The day is recorded when now.md starts

In tmp/now-day, beside the file rather than inside it.

I wrote it into the file first, as the issue suggested. It became now.md's first line — which is the first thing session start injects into context, the first thing the summarizer reads, and where the entry header lives. Four existing tests failed on that immediately. A fact only the pipeline needs does not belong in the memory itself, and keeping it outside means no reader has to strip it back out.

What review found

Round 1 — the restamp used a frozen clock. Compression hands its work to a detached subshell and the parent exits; the Haiku call can take 180s. $TODAY_DATE was computed once, before all of that. So a compression starting before midnight stamped the bytes a newer save appended with the previous day — not the day they were appended (which is all the documented residual concedes), and not their own day, but a third stale one belonging to an earlier run. The same window that once let compression eat live entries in #142.

It re-reads the clock when compression finishes now. Tested by shimming date so the day flips between the parent's reads and the restamp, which is what midnight does to a long compression.

Round 2 — the same shape one level down, and left in place deliberately. The bytes kept across a compression can themselves straddle midnight, and they take a single stamp; two saves inside one window on opposite sides of midnight share a day. Splitting that range needs each entry to carry its own day, which is exactly what now.md lacks and the reason the stamp exists. That is the flush-at-the-boundary design, bigger than this issue asked for.

Residuals, stated rather than smoothed over

Both need a flush at the day boundary rather than a stamp, and both are bounded by the compression cooldown:

  • an entry written after midnight, before the next compression, is filed with the day it was appended to
  • two saves inside one compression window on opposite sides of midnight share a stamp

Each is far narrower than misfiling an entire evening, which is what the issue reported. They are documented in the code at the point where the trade is made.

Tests

  1. Four discriminate against the pre-fix behaviour, including the reported scenario end to end and the midnight-crossing race; three guard side invariants (an unstamped now.md still compresses, a forged stamp cannot escape the store, the day never leaks into now.md).

677 passing.

Florian DAVID added 3 commits July 26, 2026 03:11
Compression only fires on a save and carries an hour-long cooldown, so
now.md routinely still holds the evening's entries when the first save
after midnight arrives. The target filename was built from the date the
run fell on, so that evening's work landed at the top of the NEW day's
today-*.md, and consolidation then attributed it to the wrong day.

Entries carry `## HH:MM` and nothing else, so nothing in the content says
which day it is from. The day is recorded when now.md starts, and
compression files by that rather than by the clock.

Recorded in tmp/now-day, beside now.md rather than inside it. I wrote it
into the file first: it became now.md's first line, which is the first
thing session start injects into context and the first thing the
summarizer reads, and it broke four existing tests that read the entry
header off line one. A fact only the pipeline needs does not belong in
the memory itself.

Residual, deliberately: an entry written after midnight before the next
compression is filed with the day it was appended to. Bounded by the
cooldown, far narrower than misfiling a whole evening, and closing it
needs a flush at the boundary — a bigger change than this issue asked for.

Co-Authored-By: Max <noreply>
Review found the race I flagged as the part I trusted least, and it was
real. $TODAY_DATE is computed once in the parent; compression runs in a
detached subshell whose Haiku call can take 180s. So a compression that
started before midnight stamped the bytes a NEWER save appended during it
with the previous day — not the day they were appended, which is all the
documented residual concedes, and not their own day, but a third stale
one belonging to an earlier run. Misfiled memory, and the same #142
window that once let compression eat live entries.

The restamp calls _remember_date again instead.

Tested by shimming the clock so it moves between the parent's reads and
the restamp, which is what midnight does to a long compression. Fails on
the previous commit.

Co-Authored-By: Max <noreply>
Review round 2: the bytes kept across a compression can themselves span
midnight, and they take one stamp. Splitting them needs each entry to
carry its own day — the thing now.md lacks, and the reason the stamp
exists at all. Documented where the code makes the trade, and filed
rather than half-fixed.

Co-Authored-By: Max <noreply>
@fdaviddpt
fdaviddpt merged commit f198fbb into main Jul 26, 2026
12 checks passed
@fdaviddpt
fdaviddpt deleted the fix/141-ndc-day-boundary branch July 26, 2026 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NDC files compressed content by run date — after-midnight compression lands prior-day entries in the new day's today-*.md

1 participant