-
Notifications
You must be signed in to change notification settings - Fork 27
[BUG] [v0.0.6] Multiple UTF-8 char boundary panics in agent_cmd handlers (list.rs:95, show.rs:142, generate.rs:123) #3920
Copy link
Copy link
Closed as not planned
Closed as not planned
Copy link
Labels
bugSomething isn't workingSomething isn't workingcortexIssues related to CortexLM/cortex repositoryIssues related to CortexLM/cortex repositoryvalidValid issueValid issue
Description
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:
agent_cmd/handlers/list.rs:95-&d[..35]panics on agent descriptionsagent_cmd/handlers/show.rs:142-&prompt[..500]panics on agent promptsagent_cmd/handlers/generate.rs:123-&generated.system_prompt[..500]panics on generated prompts
This is NOT intentional behavior because:
- Agent descriptions and prompts are user-defined and commonly contain emojis/international text
- The same bug class was fixed elsewhere in the codebase (showing awareness of the issue)
- 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:142Debug 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.0Screenshots
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:
- Users commonly use emojis in agent descriptions (e.g., "🤖 My AI assistant")
- International users use non-ASCII characters in their native language
- The truncation is meant to display nicely, not crash the CLI
- Similar bugs were reported for other commands, showing this is a known issue class
NOT a duplicate of:
- [BUG] [v0.0.6]
cortex feedback listpanics on multi-byte UTF-8 characters in messages (char boundary slice) #3907 (feedback_cmd.rs) - Different file, different command - [BUG] [v0.0.6]
cortex run --title ""panics on multi-byte UTF-8 messages due to unsafe byte-index string slicing #3906 (execution.rs) - Different file, different command - [BUG] [v0.0.6]
cortex importpanics on non-ASCII JSON content due to unsafe byte-index string slicing in error preview #3908 (import_cmd.rs) - Different file, different command
This bug is specifically about the agent command handlers.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingcortexIssues related to CortexLM/cortex repositoryIssues related to CortexLM/cortex repositoryvalidValid issueValid issue