Repository navigation
Merged
Conversation
…ve delivery record when the clock is unreadable _remember_now (the "is this record inside GRACE_MIN" clock read) coerced an empty or non-numeric _remember_date +%s to 0 and gated on -gt 0, so a failed clock read fell through to rm -f -- the opposite of what the mtime read three lines above already does for the same failure shape. Give _remember_now the identical could-not-tell-means-keep treatment. Fixes #402 Co-Authored-By: Max <noreply>
#402's clock fix just closed Found in self-review of the #402 fix: _remember_stale_mtime's existing guard caught a fully-empty stat read but still coerced a non-empty, non-numeric one to 0 before the -gt 0 gate, letting a garbage stat output be treated as a confirmed zero-age record and pruned on a healthy clock -- the same could-not-tell-means-keep violation #402 fixes for the clock read, one guard away. Folded into #402's own changelog fragment since it is the same class, same file, same commit. Refs #402 Co-Authored-By: Max <noreply>
… force it defensively CI's test_no_test_fakes_the_clock_on_path_without_disabling_the_builtin guard (tests/test_prompt_hook_spawns.py) flagged test_delivery_record_pruning_373.py's fake `date` for not mentioning REMEMBER_NO_PRINTF_T: on bash >= 4.2 lib-clock.sh can answer from a bash builtin instead of forking `date`, so a fake `date` on PATH can go unused there. Re-derived rather than trusting either side: `_remember_date +%s` is not one of the formats that can reach the builtin -- `_remember_date_builtin_ok` in lib-clock.sh refuses `%s` unconditionally -- confirmed by reading the case pattern and by forcing _REMEMBER_PRINTF_T=1 locally (simulating bash >= 4.2) and observing the fake `date` still gets called for `+%s` while a non-%s format attempts the builtin instead. So the two new must-not-prune tests were not vacuous on bash >= 4.2: the guard's own textual scan just cannot see that, by design (it flags any file that shims `date` without naming the hatch, not just the ones that need it). Documented the reasoning in _fake_date_bin's docstring, and set REMEMBER_NO_PRINTF_T=1 in both call sites anyway, so these tests do not keep depending on the %s carve-out remaining true forever. Refs #402 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 #402
What was wrong
The #393 grace-window sweep in
scripts/session-start-hook.shreads a delivery record's own mtime and the current clock (_remember_date +%s) to decide whether an absent transcript means a session is over. The mtime read already had a could-not-tell guard (-zthencontinue, meaning "keep"). The clock read did not: an empty or non-numeric_remember_date +%swas coerced to0, and the-gt 0gate on it then silently fell through torm -f-- deleting a live session's delivery record, the exact case the grace window exists to protect.The judgement call
The issue offered two shapes: give
_remember_nowits own-z-then-continueguard, or drop the-gt 0gates entirely. I chose a third, narrower option: fold the guard into a singlecaseon_remember_nowthatcontinues on either an empty read (clock command failed) or a non-numeric one (clock command exited 0 but printed garbage) -- both are could-not-tell in the same way. A plain-z-only guard, mirroring the mtime read as it stood, would not have caught the non-numeric case; dropping the-gt 0gates entirely would have removed a check that costs nothing and is not implicated in this defect. A readable clock's behavior is unchanged.Reachability
The issue was honest that it had not established this is reachable inside
session-start-hook.shspecifically (only that_remember_datereturning empty is a shape this codebase has met, elsewhere, via a different mechanism). I re-checked and could not establish reachability here either:_remember_date_builtin_okinlib-clock.shrefuses the bash builtin for%sunconditionally, so this call always shells out to the realdatebinary, and no concrete failure mode for a plaindate +%son this call path was found. The fix stands as defense-in-depth, consistent with the file's existing #332 convention of guarding every arithmetic sink regardless of whether a failure has been observed there.Self-review found a sibling gap
The spawned reviewer found that the mtime read's own existing guard had the identical problem one level down: it caught a fully-empty
statread via-z, but still coerced a non-empty, non-numeric one to0before the same-gt 0gate -- so a garbagestatoutput could reach that gate as a confirmed, comparable age and be pruned on a healthy clock. Fixed in a second commit in this same branch, with its own must-not-prune test (TestUnreadableMtimeGarbageDuringPruneSweep), reproduced red by temporarily reverting only that hunk before restoring the fix.Tests
tests/test_delivery_record_pruning_373.pygained two test classes, each pairing a must-not-prune case (fakedate/statreturning empty or garbage output for exactly the call this sweep makes, deferring to the real binary otherwise) with the existing must-fire control (an old record with a healthy clock is still pruned) already in the file, so a harness that always "keeps" would be caught.pytest tests/test_delivery_record_pruning_373.py -q-> 10 passed.Docs
No README change -- the fix restores an already-documented invariant (keep, never guess-delete) rather than changing any user-observable behavior. A changelog fragment (
changelog.d/402.fixed.md) covers both commits.