fix(hooks): session-start memory.sh check bounded by timeout 2

An unbounded registry check could stall every session start; it now uses the digest's timeout shape. SD16 proves a hung check returns under 3.5 s.
This commit is contained in:
bchanot committed 2026-11-06 16:36:16 +01:00
1 parent 9b3961e622
commit d93f06cb9b
2 files changed
+15 -2

No files matched your search

+5 -2
View File
@@ -316,12 +316,15 @@ fi
# The lib names each v1 registry on stderr (`memory: v1: <file>`).
_mem_lib="$(dirname "${BASH_SOURCE[0]}")/../lib/memory.sh"
if [ -f "$_mem_lib" ] && [ -d .claude/memory ]; then
_v1=$(bash "$_mem_lib" check .claude/memory 2>&1 >/dev/null \
# a hung memory.sh must not stall every session start
_ss_tmo=()
command -v timeout >/dev/null 2>&1 && _ss_tmo=(timeout 2)
_v1=$("${_ss_tmo[@]}" bash "$_mem_lib" check .claude/memory 2>&1 >/dev/null \
| grep -c '^memory: v1:' || true)
if [ "${_v1:-0}" -gt 0 ]; then
printf "│ ⚠️ %-44s│\n" "registry v1: ${_v1} file(s) (memory.sh check)"
fi
unset _v1
unset _v1 _ss_tmo
fi
unset _mem_lib
+10
View File
@@ -195,6 +195,16 @@ check SD12-rc "$rc" 0
check SD12-banner "$(printf '%s' "$out" | grep -c 'make doctor')" 1
check SD12-no-digest "$(printf '%s' "$out" | grep -c 'memory digest:')" 0
# SD16: a memory.sh whose `check` hangs costs under 3.5 s, exit 0
printf '#!/usr/bin/env bash\ncase "$*" in *check*) sleep 10 ;; esac\n' \
> "$WORK/sd9/lib/memory.sh"
p=$(mkproj sd16)
t0=$(now_ms)
out=$(run "$p" - "$S9"); rc=$?
t1=$(now_ms)
check SD16-hang-bounded "$([ $((t1 - t0)) -lt 3500 ] && echo yes || echo no)" yes
check SD16-rc "$rc" 0
# mkhome <name> [json]: a HOME that links the real ~/.claude entries and
# holds the given memory.json (none when omitted); prints its path.
mkhome() {