Skip to content

[BUG] [v0.0.6] Multiple UTF-8 char boundary panics in agent_cmd handlers (list.rs:95, show.rs:142, generate.rs:123) #3920

@jamescolliins

Description

@jamescolliins

Project

cortex

Description

The agent_cmd handlers contain multiple unsafe string slicing operations that panic when agent descriptions or prompts contain multi-byte UTF-8 characters (emojis, international text) near truncation boundaries.

Affected locations:

  1. agent_cmd/handlers/list.rs:95 - &d[..35] panics on agent descriptions
  2. agent_cmd/handlers/show.rs:142 - &prompt[..500] panics on agent prompts
  3. agent_cmd/handlers/generate.rs:123 - &generated.system_prompt[..500] panics on generated prompts

This is NOT intentional behavior because:

  1. Agent descriptions and prompts are user-defined and commonly contain emojis/international text
  2. The same bug class was fixed elsewhere in the codebase (showing awareness of the issue)
  3. A panic crashes the entire CLI, making it unusable

Error Message

$ cortex agent list
thread 'main' panicked at 'byte index 35 is not a char boundary; it is inside 'ñ' (bytes 34..36)',
cortex-cli/src/agent_cmd/handlers/list.rs:95

$ cortex agent show my-agent
thread 'main' panicked at 'byte index 500 is not a char boundary',
cortex-cli/src/agent_cmd/handlers/show.rs:142

Debug Logs

**Bug 1: list.rs:95**

for agent in &filtered {
    let desc = agent
        .description
        .as_ref()
        .map(|d| {
            if d.len() > 38 {
                format!("{}...", &d[..35])  // PANIC: byte slice on multi-byte char!
            } else {
                d.clone()
            }
        })


**Bug 2: show.rs:142**

if let Some(ref prompt) = agent.prompt {
    let preview = if prompt.len() > 500 {
        format!(
            "{}...\n\n(truncated, {} chars total)",
            &prompt[..500],  // PANIC: byte slice on multi-byte char!
            prompt.len()
        )


**Bug 3: generate.rs:123**

let prompt_preview = if generated.system_prompt.len() > 500 {
    format!(
        "{}...\n\n    (truncated, {} chars total)",
        &generated.system_prompt[..500],  // PANIC: byte slice on multi-byte char!
        generated.system_prompt.len()
    )

System Information

v0.0.6
Darwin 25.2.0

Screenshots

No response

Steps to Reproduce

Bug 1 - Agent list panic:

# Create agent with emoji in description near char 35
cortex agent create test-agent --description "This is a test agent with emoji 🎉 here"
cortex agent list  # PANIC!

Bug 2 - Agent show panic:

# Create agent with emoji near char 500 in prompt
cortex agent create test-agent --prompt "$(python3 -c "print('A' * 498 + '🎉')")"
cortex agent show test-agent  # PANIC!

Expected Behavior

Safe UTF-8 aware truncation:

// Use char_indices or chars().take() for safe truncation
let truncated: String = text.chars().take(35).collect();

Actual Behavior

Byte-based slicing causes panic when a multi-byte character spans the truncation boundary.

Additional Context

Evidence this is clearly a bug, not intentional:

  1. Users commonly use emojis in agent descriptions (e.g., "🤖 My AI assistant")
  2. International users use non-ASCII characters in their native language
  3. The truncation is meant to display nicely, not crash the CLI
  4. Similar bugs were reported for other commands, showing this is a known issue class

NOT a duplicate of:

This bug is specifically about the agent command handlers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcortexIssues related to CortexLM/cortex repositoryvalidValid issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions