Code-fence-aware message truncation #632

Closed
opened 2026-10-27 13:37:07 +00:00 by sam · 0 comments
Owner

Truncate outbound messages to a platform's length limit (e.g. Telegram's 4096 chars) without ever cutting inside a ``` code fence — a truncation mid-fence leaves the rest of the message rendered as broken/unclosed markdown on the client.

Context for implementers

No truncation helper exists yet in internal/gateway. This is distinct from the Markdown→HTML conversion trap documented in CLAUDE.md ("EscapeMarkdown does the inverse of formatting" / go-telegram/bot's SendRichMessage) — that trap is about format conversion, this issue is about length-based cropping. Keep the two concerns separate: this helper should decide where to cut; rendering is a separate step.

Acceptance Criteria

A message longer than the platform limit is truncated at a safe boundary: never inside an open code fence, preferring a paragraph/sentence boundary before the limit. If truncation would land inside a fence, the cut point backs up to before the fence opens (or the fence is closed and reopened on continuation, if multi-part delivery is in scope — confirm with the maintainer which behavior is wanted before implementing). Covered by a table-driven test with fenced and unfenced inputs at/over the limit.

Close reason

Implemented code-fence-aware Telegram message splitting with bounded continuation handling and regression coverage [Closure restored 2026-08-24: originally closed 2026-08-22, lost when the beads DB was rebuilt (.beads.backup-pre-recovery).]


Imported from beads archie-core-1786637492559-106-5ea2315d · GitHub #127 · type task · priority P2 · created 2026-08-08 · closed 2026-08-24

Truncate outbound messages to a platform's length limit (e.g. Telegram's 4096 chars) without ever cutting inside a ``` code fence — a truncation mid-fence leaves the rest of the message rendered as broken/unclosed markdown on the client. ### Context for implementers No truncation helper exists yet in `internal/gateway`. This is distinct from the Markdown→HTML conversion trap documented in `CLAUDE.md` ("`EscapeMarkdown` does the *inverse* of formatting" / `go-telegram/bot`'s `SendRichMessage`) — that trap is about format conversion, this issue is about length-based cropping. Keep the two concerns separate: this helper should decide *where* to cut; rendering is a separate step. ### Acceptance Criteria A message longer than the platform limit is truncated at a safe boundary: never inside an open code fence, preferring a paragraph/sentence boundary before the limit. If truncation would land inside a fence, the cut point backs up to before the fence opens (or the fence is closed and reopened on continuation, if multi-part delivery is in scope — confirm with the maintainer which behavior is wanted before implementing). Covered by a table-driven test with fenced and unfenced inputs at/over the limit. ### Close reason Implemented code-fence-aware Telegram message splitting with bounded continuation handling and regression coverage [Closure restored 2026-08-24: originally closed 2026-08-22, lost when the beads DB was rebuilt (.beads.backup-pre-recovery).] --- _Imported from beads `archie-core-1786637492559-106-5ea2315d` · GitHub #127 · type task · priority P2 · created 2026-08-08 · closed 2026-08-24_
sam added the mediumtask labels 2026-10-27 13:37:07 +00:00
sam self-assigned this 2026-10-27 13:37:07 +00:00
sam closed this issue 2026-10-27 13:37:07 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#632