Repository navigation
fix(ndc): file compressed memory under the day it came from (#141) - #164
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #141.
NDC compression only fires on a save and carries an hour-long cooldown, so
now.mdroutinely 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'stoday-*.md, and consolidation then attributed it to the wrong day.Entries carry
## HH:MMand nothing else. Oncenow.mdcrosses 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.mdstartsIn
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_DATEwas 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
dateso 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.mdlacks 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:
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
now.mdstill compresses, a forged stamp cannot escape the store, the day never leaks intonow.md).677 passing.