Repository navigation
fix(save-session): a failed last-entry read must not read as "(no previous entry)" (#251) - #275
Merged
Merged
Conversation
…s entry)" `A && B || C` is not if/else: when `tail` failed, the fallback ran too and its `>` overwrote the partial read, so a read error reached the summarizer as a factual claim about now.md — rc 0, nothing logged. Three states now, not two: no header yet, now.md unreadable, read failed. Only the first renders as "(no previous entry)"; the other two send an explicit unavailable marker and log an ERROR. The save still completes — losing a span to protect the prompt is the wrong direction. The `grep | tail | cut` pipeline above it reported cut's status, which succeeds on empty input, so a grep error was indistinguishable from no match. grep is checked on its own; tail and cut are gone from that path. Closes #251 Co-Authored-By: Max <noreply>
fdaviddpt
force-pushed
the
fix/251-tail-failure-overwrites
branch
from
July 31, 2026 16:27
714ee79 to
419b110
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.
What
save-session.shStep 2 built the summarizer's dedup context withA && B || Cis not if/else. When the guard holds andtailfails,Cruns as well and its>overwrites whateverBwrote. A read failure was therefore rendered as a factual claim aboutnow.md— rc 0, nothing logged, no marker.Reproduced before fixing, with a
tailshim that fails only that one invocation:now.mdheld a real entry and the prompt said there was none.Why it matters
prompts/save-session.prompt.txtgives the previous entry to Haiku for two decisions — do not repeat it, and returnSKIPwhen the span is the same work. A false empty removes both anchors at once, so the model writes the previous span back intonow.mdas new. That is the duplication #142/#224/#250 close from the other end, reached through the prompt rather than through the file.Three states, not two
##header yet (or nonow.md)(no previous entry)— unchangednow.mdexists but is not readable(previous entry unavailable — …)+ ERROR log(previous entry unavailable — …)+ ERROR logThe marker is written for a model, not a person: it says the field is missing rather than empty, and states the consequence (
earlier work may already be recorded) so a failed read is not treated as a fresh buffer. It deliberately does not push towardSKIP— nudging a model to skip on missing context spends a real span to protect the prompt.The failure chosen
The save still completes, rc 0. Failing here would trade the loud bug for the quiet one: an entry written without dedup context is visible in
now.mdand recoverable; a span that never reaches memory is neither. Same trade the NDC tail arm at Step 8 already makes.What else that block did wrong
grep -n '^## ' … | tail -1 | cut -d: -f1returnedcut's exit status, andcutsucceeds on empty input — so grep failing on an unreadable file was indistinguishable from grep finding no header. The same false empty, one line earlier, and it would have survived a fix aimed only at the&&/||.grepnow runs for its own status (1 = no match, >1 = error) and the last line is taken with parameter expansion, removingtailandcutfrom that path rather than checking them.Correction to the issue's second half
The issue and the brief describe
>truncating beforetailwrites as a second defect. It is not reachable:$TMP_LAST_ENTRYcomes straight frommktempand is always empty, so the truncate destroys nothing. The partial-write concern is real but its only cause isCoverwritingB— one defect, not two. A test pins the partial case anyway, since the fix's handling of it is a deliberate choice (discard the partial, send the marker).Tests
tests/test_last_entry_read_failure_251.py— 7 tests, RED before the fix on the 4 that assert the new behaviour (the 3 guards for the legitimately-empty states passed before and after, which is the point of having them). Uses the repo's existing PATH-shim idiom fromtest_ndc_tail_failure_no_truncate.py, narrowed totail -n +N <now.md>sotail -1elsewhere still runs the real binary;command -pwithoutexecfor the dash-on-Ubuntu reason documented there.STUB_LAST_ENTRY_SNAPSHOTadded to the sharedbuild-promptstub — env-gated, no effect on existing tests. It is the only way to observe the last-entry file as the summarizer receives it; the script's cleanup trap unlinks it.Full suite: 1223 passed, 42 skipped locally (bash 3.2, macOS).
bash -nandshellcheckclean on the edited region.Not in this PR
Two more
A && B || Cinstances inscripts/log.sh(268, 332), noted in the issue comment. There the branches concatenate, so the caller gets the value followed by the default — a different and arguably worse consequence, and they are config readers with their own callers. Left for the sweep the comment proposes;claude-supertool#665(shellcheck SC2015) would catch all three at edit time.Closes #251