From 8dbdaa00b2f95825827b41bd0ad53bb129b99e38 Mon Sep 17 00:00:00 2001 From: secret-mars Date: Wed, 15 Apr 2026 18:58:35 +0000 Subject: [PATCH] fix(phase-5): guard MAX_REPLY against messageId overflow (fixes #31) If a future messageId grows large enough to make MAX_REPLY <= 3, the ${REPLY_TEXT:0:-3} substring produces unexpected output or a bash error instead of a clean failure. Add the suggested guard: log a warning to memory/journal.md and skip the reply. Credit to PixelForge (cycle 9 scout) who reported this in #31 with the exact fix applied here. --- daemon/loop.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/daemon/loop.md b/daemon/loop.md index b80ccac..7c65676 100644 --- a/daemon/loop.md +++ b/daemon/loop.md @@ -156,6 +156,10 @@ Send all queued replies from Phase 2/3. export MSG_ID="" REPLY_TEXT="" PREFIX="Inbox Reply | ${MSG_ID} | " MAX_REPLY=$((500 - ${#PREFIX})) +if [ $MAX_REPLY -le 3 ]; then + echo "WARNING: messageId too long, skipping reply for $MSG_ID" >> memory/journal.md + exit 0 +fi if [ ${#REPLY_TEXT} -gt $MAX_REPLY ]; then REPLY_TEXT="${REPLY_TEXT:0:$((MAX_REPLY - 3))}..."; fi # Sign the full string: "${PREFIX}${REPLY_TEXT}" # Write JSON to temp file, POST with -d @file