Repository navigation
fix: NDC must drop only the bytes it compressed, not the whole file (#142) - #151
Merged
Merged
Conversation
fdaviddpt
force-pushed
the
fix/142-ndc-truncate-race
branch
from
July 25, 2026 15:14
270e44e to
c455005
Compare
…142) The compression step snapshots now.md, hands it to a Haiku call allowed up to 180s, then truncated the file with `: >`. Every gate that could have serialized that is already released by then: the parent's EXIT trap removes the save lock and the script ends without waiting for the disowned subshell, and the save cooldown marker is written at extract time — before the 10-30s summarization — so the next save becomes eligible well inside the NDC window. post-tool-hook only checks the parent PID, which is dead. So a newer save legitimately appends an entry, and the truncate erases it. That entry's position was already advanced at the append, so the content is unrecoverable, and nothing is logged: the memory is simply not there. Keep everything past the snapshot offset instead, and log the bytes preserved. NDC_SRC_BYTES was already in scope — it was only being used for a percentage in a log line. The regression test appends to now.md from inside the stubbed NDC call, which is exactly the window, and fails on main. Co-Authored-By: Max <noreply>
fdaviddpt
force-pushed
the
fix/142-ndc-truncate-race
branch
from
July 25, 2026 15:17
c455005 to
e6906ef
Compare
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 #142. Silent, unlogged data loss.
The window
save-session.shsnapshotsnow.md(NDC_SRC_BYTES, thenbuild-ndc-prompt), runs compression in a backgrounded( … ) &, and truncated with: >when it finished — up to 180s later.By that point every gate that could have serialized this is gone:
cleanup()EXIT trap removes the save lock, and the script ends withoutwaiting for the disowned subshellpost-tool-hook.shonly checks the parent PID, which is already dead--forcebypasses the cooldown entirelySo a newer save appends an entry, and the truncate erases it. Its position was already advanced at the append, so the content is unrecoverable, and nothing is logged — the memory is just missing.
The fix
Keep everything past the snapshot offset (
tail -c +$((NDC_SRC_BYTES+1))+mv) and log how many bytes were preserved.NDC_SRC_BYTESwas already in scope — it was only feeding a percentage in a log line.Tests
tests/test_ndc_truncate_race.pyappends tonow.mdfrom inside the stubbed NDC call, which is precisely the window. Fails on main, passes here. A second test pins that the fix didn't become a no-op: the compressed span still leavesnow.mdand lands intoday-*.md.528 passed.