Skip to content

bug: String truncation fails with "byte index is not a char boundary" for non-ASCII text #3263

@toyamagu-2021

Description

@toyamagu-2021

Bug: String truncation fails with "byte index is not a char boundary" for non-ASCII text

Describe the bug
Goose crashes with byte index is not a char boundary error when truncating text content that contains multi-byte UTF-8 characters (Japanese, Chinese, Korean, emojis, etc.). This occurs because the code uses byte-based string slicing instead of character-boundary-aware slicing.

To Reproduce
Steps to reproduce the behavior:

  1. Use Goose with content containing Japanese/Chinese/Korean text or emojis
  2. Trigger text truncation (large messages, tool responses, or session loading)
  3. See error: byte index is not a char boundary

Expected behavior
Text should be truncated safely at character boundaries without crashing.

Affected Code Locations
The following locations use unsafe byte-based string slicing:

  1. Context Management Truncation (crates/goose/src/context_mgmt/truncate.rs):

  2. Session Storage Truncation (crates/goose/src/session/storage.rs): caused by Session file security updates #3071

  3. etc

Metadata

Metadata

Assignees

Labels

p1Priority 1 - High (supports roadmap)

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions