Skip to content

Latest commit

 

History

History
157 lines (114 loc) · 4.57 KB

File metadata and controls

157 lines (114 loc) · 4.57 KB

Output Truncation Fix

Overview

Fixed a critical issue where the agent was truncating command output to 500 characters, causing incomplete display of list commands and other verbose output.

Problem

When users ran commands like list resumes, the output was being cut off mid-display:

========================================================================================================================
📋 RESUME LIST (9 total)
========================================================================================================================
#   Resume Name                                    Master   Updated           Description                             
-------------------------------------------------------------------------------------------------------------------

💡 What would you like to do next?
   1. Review the output
   2. Run related commands
   3. Check the results

The actual resume data was missing because the ResultAnalyzer was truncating all output to 500 characters.

Root Cause

File: src/agent/result_analyzer.py
Lines: 181, 190, 193, 199
Issue: Hardcoded 500-character limit on all command output

# Old code - truncates everything to 500 chars
clean_output = output.strip()[:500]

Solution

Implemented context-aware truncation that:

  1. Detects list/display commands
  2. Uses 10,000 character limit for list commands
  3. Keeps 500 character limit for other commands
  4. Passes command context to the formatter

Changes Made

File: src/agent/result_analyzer.py

  1. Updated _format_message() method signature to accept command parameter
  2. Added list command detection logic
  3. Implemented dynamic max_output_length based on command type
  4. Updated analyze() method to pass command to formatter

File: tests/test_result_analyzer.py

  1. Updated existing test to pass command parameter
  2. Added test_list_command_full_output() - verifies list commands show full output
  3. Added test_non_list_command_truncation() - verifies other commands still truncate

List Commands Detected

The following commands now show full output (up to 10,000 characters):

  • list_resumes.py
  • list_job_listings.py
  • list_experiences.py
  • Commands with --list flag
  • Commands with --show flag
  • Commands with --format simple flag
  • Commands with --format json flag

Results

Before Fix

Resume entries shown: 0 (truncated)
Output length: ~500 characters

After Fix

Resume entries shown: 9 (all resumes)
Output length: ~1,945 characters
All resume data visible and properly formatted

Testing

Unit Tests

python -m pytest tests/test_result_analyzer.py -v
# Result: ✅ 18 passed

Manual Testing

# Through agent API
curl -X POST http://localhost:5000/api/agent/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "run: python src/utils/list_resumes.py"}'

# Result: ✅ All 9 resumes displayed with full formatting

Impact

Fixed Issues

  • ✅ Resume list now displays all resumes
  • ✅ Job listings display completely
  • ✅ Experience lists show all entries
  • ✅ Any verbose output is now visible

Backward Compatibility

  • ✅ Non-list commands still truncate at 500 chars (prevents token bloat)
  • ✅ Error messages still truncated appropriately
  • ✅ All existing tests pass

Configuration

To adjust truncation limits, modify src/agent/result_analyzer.py:

# Line ~180 in _format_message()
max_output_length = 10000 if is_list_command else 500

Change these values to:

  • Increase list command limit: Change 10000 to desired value
  • Increase other command limit: Change 500 to desired value

Related Issues

  • Resolves: Agent Output Truncation Issue (.github/ISSUE_TEMPLATE/agent_output_truncation.md)
  • Implements: Option 4 from proposed solutions (Command-Specific Handling)

Future Enhancements

  1. Configurable Limits: Add environment variables for truncation limits
  2. Pagination: Implement "show more" functionality for very large outputs
  3. Smart Truncation: Preserve complete lines when truncating
  4. Output Caching: Cache full output for later retrieval

Files Modified

  • src/agent/result_analyzer.py - Core fix
  • tests/test_result_analyzer.py - Added tests
  • src/utils/list_resumes.py - Windows emoji encoding fix (related)

Verification Checklist

  • All unit tests pass (18/18)
  • Manual testing confirms full output display
  • List commands show complete data
  • Non-list commands still truncate appropriately
  • Error handling unchanged
  • Backward compatible with existing code