Skip to content

[BUG] [v0.0.7] cortex agent list panics with byte index not a char boundary when agent description contains multi-byte UTF-8 (list.rs:102) #53420

Description

@nightmare0329

Bug Report

Version: v0.0.7
File: src/cortex-cli/src/agent_cmd/handlers/list.rs

Description

When cortex agent list is run and any agent has a description longer than 38 bytes containing multi-byte UTF-8 characters (CJK, accented letters, emoji), the command panics with "byte index 35 is not a char boundary". The truncation logic at line 102 uses raw byte indexing instead of character-aware slicing.

Screenshot

cortex agent list panics on UTF-8 agent description

Root Cause

// src/cortex-cli/src/agent_cmd/handlers/list.rs, lines 100-107
let desc = agent
    .description
    .as_ref()
    .map(|d| {
        if d.len() > 38 {                     // byte length check
            format!("{}...", &d[..35])         // BYTE SLICE at index 35 → PANIC if mid-char
        } else {
            d.clone()
        }
    })
    .unwrap_or_else(|| "-".to_string());

A description like "中文描述测试中文描述测试abc" (12 CJK chars × 3 bytes + 3 ASCII = 39 bytes) triggers the condition d.len() > 38, then &d[..35] slices at byte 35 which falls inside a multi-byte character.

Steps to Reproduce

# Create agent with CJK description (>38 bytes, <38 chars)
cat > ~/.cortex/agents/test-agent.toml << EOF
[agent]
name = "test-agent"
description = "中文描述测试中文描述测试abc"
EOF

cortex agent list
# PANIC: byte index 35 is not a char boundary

Expected Behavior

cortex agent list should display a truncated description like 中文描述测试中文描...

Fix

if d.chars().count() > 35 {
    let truncated: String = d.chars().take(32).collect();
    format!("{}...", truncated)
} else {
    d.clone()
}

Hotkey: 5CzBkL6CJWFa7QSFoWxqiodobsGmxD6oLxLQa24tNxvsT9dn
UID: 137

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem right

    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