Skip to content

Remaining UTF-8 char boundary panics in channel.rs and signal.rs (incomplete fix from #273) #518

@chandima

Description

@chandima

Environment

  • Spacebot Version: v0.3.3
  • OS: macOS (Apple Silicon M1, 8GB RAM)

Description

Issue #273 fixed a UTF-8 char boundary panic in cortex_chat.rs, but the same unsafe &s[..200] pattern exists in two other files, causing runtime panics when truncating strings containing multi-byte characters (em dashes, CJK, emoji, etc.).

Panic observed

thread 'tokio-runtime-worker' (14991) panicked at src/agent/channel.rs:2907:45:
byte index 200 is not a char boundary; it is inside '—' (bytes 199..202) of
`Here's today's meetings (America/Phoenix local time, 2026-03-31)...`

This crash prevented Spacebot from delivering a calendar summary response via Slack — the calendar data was fetched successfully but the worker result truncation panicked.

Affected locations

  1. src/agent/channel.rs:2834 — branch conclusion truncation for working memory
  2. src/agent/channel.rs:2907 — worker result truncation for working memory
  3. src/messaging/signal.rs:900 — Signal typing indicator error body truncation

Fix

Replace &s[..200] with char-boundary-safe truncation:

let end = s.floor_char_boundary(200);
&s[..end]

floor_char_boundary is stable since Rust 1.82.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions