Repository navigation
Description
Found by the round-two release audit of v0.22.0..HEAD before tagging 0.23.0, exercised with both controls firing. Carry-forward under the two-round cap: non-blocking, ranked fails-to-preserve.
This is an incomplete fix, not a regression -- before #397 the sweep pruned unconditionally, so this is strictly narrower than what shipped in #386.
Symptom
A live session's delivery record is deleted when the clock read fails, which is the case the grace window exists to protect.
Location
scripts/session-start-hook.sh:1113-1119.
scripts/session-start-hook.sh:1101-1105 handles an empty stat result correctly -- continue, meaning keep. The very next lines coerce a bad clock read to 0 and then gate on -gt 0:
_remember_now=$(_remember_date +%s)
case "$_remember_now" in (''|*[!0-9]*) _remember_now=0 ;; esac
if [ "$_remember_now" -gt 0 ] && [ "$_remember_stale_mtime" -gt 0 ] \
&& [ $((10#$_remember_now - 10#$_remember_stale_mtime)) -lt $((GRACE_MIN * 60)) ]; then
continue
fi
rm -f "$_remember_stale_record" 2>/dev/nullAn unreadable clock makes the whole condition false and falls through to rm -f.
Mechanism
The header at scripts/session-start-hook.sh:1041-1045 and the inline comment at :1102-1104 both promise that could-not-tell must never render as either of the other two -- "keep, never guess-delete". _remember_stale_mtime gets that promise. _remember_now does not: it has no -z guard of its own, and the -gt 0 gate turns "I could not read the clock" into "the record is outside the grace window".
Exercised by the audit, transcribing :1106-1119 and driving it on four inputs:
1. live record, healthy clock : KEPT (inside grace window) <- must-keep control
2. old record, healthy clock : PRUNED (rm -f runs) <- must-fire control
3. live record, clock UNREADABLE : PRUNED (rm -f runs) <- the defect
4. live record, stat non-numeric : PRUNED (rm -f runs) <- the defect
Case 3 is the reachable half. _remember_date +%s routes to date, and this repo already documents date from lib-clock.sh failing silently as an observed condition -- scripts/post-tool-hook.sh:639-641. That comment is about a different script, and the audit did not establish the same exhaustion is reachable inside session-start-hook.sh; what it establishes is that "_remember_date returns empty" is a shape this codebase has already met.
Cost, and why fails-to-preserve rather than destroys: what is lost is deliveries and first_delivered for a live session, so its handoff is re-presented as news rather than "already delivered N times". The record regenerates on the next delivery.
What would settle it
Give _remember_now the same -z-then-continue treatment _remember_stale_mtime already has at :1101-1105, or drop the -gt 0 gates and make an unreadable input continue explicitly.
The test needs case 3 above as a must-not-prune, paired with case 2 as the must-prune control in the same fixture -- the pairing that exists today does not cover an unreadable clock in either direction.
Activity
test: name REMEMBER_NO_PRINTF_T where #402's fake `date` is used, and…
fix: session-start-hook.sh no longer prunes a live delivery record on…