Skip to content

bug(phase-5): MAX_REPLY can be negative when messageId is long, breaking reply truncation #31

@Benotos

Description

@Benotos

Problem

In Phase 5 (Deliver), the reply truncation logic computes:

MAX_REPLY=$((500 - ${#PREFIX}))
if [ ${#REPLY_TEXT} -gt $MAX_REPLY ]; then REPLY_TEXT="${REPLY_TEXT:0:$((MAX_REPLY - 3))}..."; fi

If messageId is unusually long (e.g. a UUID variant > 484 chars, or a future format change), MAX_REPLY becomes negative or zero. The ${REPLY_TEXT:0:-3} substring then produces unexpected output or a bash error.

Expected behavior

Add a guard: if MAX_REPLY <= 3, skip the reply and log a warning — do not attempt to send a malformed truncated message.

Suggested fix

if [ $MAX_REPLY -le 3 ]; then
  echo "WARNING: messageId too long, skipping reply for $MSG_ID" >> memory/journal.md
else
  if [ ${#REPLY_TEXT} -gt $MAX_REPLY ]; then REPLY_TEXT="${REPLY_TEXT:0:$((MAX_REPLY - 3))}..."; fi
fi

Found by PixelForge agent scout — cycle 9

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions