Skip to content

[BUG] [v0.0.7] cortex run --dry-run --format json truncates message_preview at 100 chars while text output allows 200 chars #53374

@nightmare0329

Description

@nightmare0329

Project

Repository: CortexLM/cortex
Version: v0.0.7
Component: cortex run --dry-run command (src/cortex-cli/src/run_cmd/execution.rs)

Description

When using cortex run --dry-run, the message_preview field is truncated differently depending on output format:

  • JSON output (--format json): message_preview is truncated at 100 characters
  • Text output (default): message is truncated at 200 characters

This means a 150-character message will appear complete in text output but truncated by 50 characters in JSON output, creating an inconsistency between the two formats. Users parsing JSON output will receive less information than users reading text output for the same dry-run operation.

Error Message

# No explicit error — the bug manifests as silent data truncation in JSON output
$ cortex run --dry-run --format json "This is a 150-character test message that is long enough to trigger the inconsistent truncation behavior between JSON and text output formats in cortex"

JSON output message_preview field is cut at 100 chars, while text output shows the full 150 chars.

Debug Logs

# Text output (default) - shows up to 200 chars
$ cortex run --dry-run "This is a test message that is exactly 150 characters long padding padding padding padding padding padding padding padding ENDOFMSG"
  Dry Run Preview
  ---------------
  Message: This is a test message that is exactly 150 characters long padding padding padding padding padding padding padding padding ENDOFMSG
  # ^ Full 150 chars shown

# JSON output - truncates at 100 chars
$ cortex run --dry-run --format json "This is a test message that is exactly 150 characters long padding padding padding padding padding padding padding padding ENDOFMSG"
{
  "message_preview": "This is a test message that is exactly 100 characters long padding padding padding pa...",
  # ^ Truncated at 100 chars with "..." even though message is 150 chars
}

System Information

$ cortex --version
cortex 0.0.7

$ uname -a
Linux ubuntu 6.17.0-20-generic #20-Ubuntu SMP x86_64 GNU/Linux

$ rustc --version
rustc 1.86.0 (05f9846f8 2025-03-31)

Screenshots

Figure 1 — Side-by-side comparison showing truncation inconsistency (JSON at 100 chars vs text at 200 chars):

dry-run message_preview truncation inconsistency

Figure 2 — Source code showing the two different truncation limits in execution.rs:

dry-run truncation source code

Steps to Reproduce

  1. Clone CortexLM/cortex v0.0.7 and build the CLI
  2. Prepare a message longer than 100 characters (e.g., 150 chars):
    MSG="This is a test message that is exactly 150 characters long padding padding padding padding padding padding padding padding ENDS"
  3. Run with text output (default):
    cortex run --dry-run "$MSG"
    Observe the message preview shows all 150 characters.
  4. Run with JSON output:
    cortex run --dry-run --format json "$MSG"
    Observe the message_preview field is truncated at 100 characters with ... appended.

Expected Behavior

The message_preview truncation limit should be consistent between JSON and text output formats. Both should use the same limit (either 100 or 200 characters), or JSON should use the same 200-character limit as text output. Users who rely on --format json for scripting or automation should receive the same amount of information as users reading text output.

Actual Behavior

Two different truncation limits are hardcoded in src/cortex-cli/src/run_cmd/execution.rs:

JSON output path (line ~837):

"message_preview": if message.len() > 100 {
    format!("{}...", &message[..100])  // truncates at 100 chars
} else {
    message.to_string()
}

Text output path (line ~876):

let preview = if message.len() > 200 {
    format!("  {}...", &message[..200])  // truncates at 200 chars
} else {
    format!("  {}", message)
};

For any message between 101 and 200 characters:

  • Text output: shows the full message (under the 200-char limit)
  • JSON output: truncates at 100 chars with ... appended

The 2× discrepancy in truncation limits (100 vs 200) means JSON consumers systematically receive less data than text readers for the same dry-run operation.

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