ISSUE DESCRIPTION jarvis agents list Traceback Description Learning OpenJarvis on a…
- User
ISSUE DESCRIPTION
jarvis agents list Traceback
Description
Learning OpenJarvis on a Windows machine with WSL2. I was wondering what would happen on a clean reboot and listed the agents. This worked the first two times and listed the "... My Assistant │ deep_research ...". I even used the ID to ask it questions which worked (jarvis agents ask b0e6dece007b "How can I contribute to the OpenJarvis Project"). I had not loaded the model (Gemma 4 31b) into Ollama (this was direct from an open WSL Ubuntu window). My alias for jarvis is jarvis() { cd "@" }
Assistant
Let me analyze the issue. The error occurs when running
jarvis agents listafter using an agent. The traceback shows:rich.errors.MarkupError: closing tag '[/red]' at position 65 doesn't match any open tagThis error is in the
list_agentsfunction at/src/openjarvis/cli/agent_cmd.py, line 91:console.print(f"[red]Error: {exc}[/red]")The issue is that when an exception
excis printed, it may contain the text[red]or[/red]as part of its message, which breaks the rich markup formatting.Let me start by exploring the repository structure and finding the relevant code.
Assistant
Let me look for the agent_cmd.py file that contains the
list_agentsfunction.Assistant
Now let me read the file to see the
list_agentsfunction around line 91.Assistant
Now I can see the issue clearly. On line 91, the code is:
console.print(f"[red]Error: {exc}[/red]")The problem is that when
exccontains special characters like[or]or markup tags like[/red], it can break the rich markup. The error message says:closing tag '[/red]' at position 65 doesn't match any open tagThis happens when the exception message itself contains text that looks like rich markup. The fix is to use the
escapefunction from rich or wrap the message properly.Let me check if there are other occurrences of this pattern in the file and look for similar issues:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "console.print.[red].[/red]" /OpenJarvis/src/openjarvis/cli/agent_cmd.py </tool_call>
Assistant
Let me search for the pattern properly.
Assistant
Now I can see there are multiple occurrences of this pattern. The issue is at line 91, but there are many similar occurrences at lines 111, 141, 163, 176, 189, 202, 233, 258, 291, 319, etc.
The fix should use
rich.escape()to properly escape the exception message, or use a different approach to safely print the error message. Let me check the rich library's documentation for how to handle this.Looking at line 91:
console.print(f"[red]Error: {exc}[/red]")The fix should be to escape the exception message before inserting it into the markup. Rich has a
rich.escape()function that can be used for this purpose.Let me check what imports are already present and then fix the issue:
<tool_call> <function=bash_terminal> <parameter=command> head -15 /OpenJarvis/src/openjarvis/cli/agent_cmd.py </tool_call>
Assistant
Let me look at the imports in the file.
Assistant
Now I understand the issue. The problem is that when printing exception messages with rich's markup syntax, if the exception message contains special characters like
[or]or markup tags, it breaks the parsing. The fix is to userich.escape()to escape the exception message before inserting it into the formatted string.Let me first add the import for
escapefrom rich.markup and then fix all the error print statements in the file:Assistant
I'll add the import for
escapefromrich.markupand fix the error handling. Let me edit the file:Assistant
Good, the import was added. Now I need to fix all the error handling lines where we print error messages with the markup tags. The issue is that
exc(the exception) can contain special characters that break the markup. I need to useescape(exc)for all the error messages.Let me fix each occurrence:
- Line 92:
console.print(f"[red]Error: {exc}[/red]")should becomeconsole.print(f"[red]Error: {escape(str(exc))}[/red]") - Line 111: Same pattern
- Line 141: Same pattern
- etc.
Let me use sed to fix all occurrences of this pattern.
<tool_call> <function=bash_terminal> <parameter=command> sed -i 's/console.print(f"[red]Error: {exc}[/red]")/console.print(f"[red]Error: {escape(str(exc))}[/red]")/' /OpenJarvis/src/openjarvis/cli/agent_cmd.py </tool_call>
- Line 92:
Assistant
Let me fix the sed command - the backslashes need to be properly escaped in bash.
Assistant
Let me use a different delimiter for sed to avoid conflicts with the forward slashes in the pattern:
Assistant
The command completed successfully. Let me verify that all the error print statements have been fixed.
Assistant
All error print statements have been fixed. Let me verify the fix looks correct by viewing the file around line 92:
Assistant
Now let me verify the fix by running existing tests:
Assistant
Let me search for tests specifically related to agent_cmd or agents:
Assistant
Let me look for CLI tests specifically.
Assistant
Let me search for CLI tests related to agents:
<tool_call> <function=bash_terminal> <parameter=command> ls -la /OpenJarvis/tests/ </tool_call>
Assistant
Let me look at the tests directory structure.
Assistant
Let me check the CLI tests directory for tests related to agents.
Assistant
Now let me look at the test_agent_cmd.py to see if there are any existing tests for the list_agents function and run them.
<tool_call> <function=bash_terminal> <parameter=command> cat /OpenJarvis/tests/cli/test_agent_cmd.py </tool_call>
Assistant
Let me run the bash command properly to view the test file.
Assistant
Now let me run the existing CLI tests to make sure my changes don't break anything. Let me run the specific test file for agent_cmd.
<tool_call> <function=bash_terminal> <parameter=command> cd /OpenJarvis && python -m pytest tests/cli/test_agent_cmd.py -v 2>&1 | head -50 </tool_call>
Assistant
Let me run the pytest command properly.
Assistant
I need to set up the Python path first. Let me check how to properly run the tests.
Assistant
Let me check how to set up the environment:
Assistant
The repository has a
.venvfolder. Let me use it to run the tests.Assistant
All 17 tests passed. Now let me create a simple test script to reproduce the issue and confirm that the fix works.
Assistant
Let me run the Python test script properly.
Assistant
Let me try a different approach to create the file.
Assistant
It seems like the heredoc syntax is having issues. Let me try a simpler approach using echo and tee, or write the test inline.
Assistant
Let me use a simpler test without single quotes in the exception message:
Assistant
I need to use the .venv Python to run the test.
<tool_call> <function=bash_terminal> <parameter=command> OpenJarvis/.venv/bin/python -c " from rich.console import Console from rich.markup import escape
Test that escape() fixes the markup issue
console = Console(stderr=True) exc = Exception('Error: closing tag /red does not match any open tag')
Old way - would fail
try: console.print(f'[red]Error: {exc}[/red]') print('OLD: OK (unexpected)') except Exception as e: print(f'OLD: FAILED ({type(e).name})')
New way - should work
try: console.print(f'[red]Error: {escape(str(exc))}[/red]') print('NEW: OK') except Exception as e: print(f'NEW: FAILED ({type(e).name})') " </tool_call>
Assistant
Let me use the correct path syntax without the dot before the folder name.
Assistant
Let me test with the exact error message that was in the traceback:
Assistant
Let me write the test to a file to avoid escaping issues:
Assistant
The test confirms that:
- The OLD way fails with MarkupError when the exception message contains markup-like text
- The NEW way (with escape()) works correctly
Now let me verify the fix I made is complete by checking that all occurrences have been fixed:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "console.print.*Error:.*exc" /OpenJarvis/src/openjarvis/cli/agent_cmd.py </tool_call>
Assistant
Let me run the grep command to verify the fix is complete.
Assistant
All the error print statements have been fixed with the
escape()function. Let me also check if there are any other error handling patterns in the same file that might need fixing, like the Agent not found message on line 123:<tool_call> <function=bash_terminal> <parameter=command> sed -n '120,145p' /OpenJarvis/src/openjarvis/cli/agent_cmd.py </tool_call>
Assistant
Let me check that specific line with a bash command to look at the file content.
Assistant
The "Agent not found" message on line 123 doesn't contain any variable that could have markup-like characters, so it's safe. The agent_id parameter is user-provided, but it's unlikely to cause issues.
Let me also check if there are any other files in the cli directory that might have the same issue:
<tool_call> <function=bash_terminal> <parameter=command> grep -l "console.print.*Error:.exc" /OpenJarvis/src/openjarvis/cli/.py 2>/dev/null </tool_call>
Assistant
Let me run the grep command to find other files that might have the same issue.
Assistant
There are other files with the same issue. However, the issue description specifically mentions the traceback from
agent_cmd.py, and the main focus is to fix the issue reported. While there are other files that could have similar issues, the user reported the issue in the context ofjarvis agents list.Let me focus on making sure the fix for the reported issue is complete. Let me run the existing tests again to make sure everything passes.
<tool_call> <function=bash_terminal> <parameter=command> cd /OpenJarvis && .venv/bin/python -m pytest tests/cli/test_agent_cmd.py -v </tool_call>
Assistant
Let me run the pytest command properly.
Assistant
All tests pass. Let me also run a few more related tests to make sure the fix doesn't break anything:
<tool_call> <function=bash_terminal> <parameter=command> cd /OpenJarvis && .venv/bin/python -m pytest tests/cli/test_cli.py -v 2>&1 | head -50 </tool_call>
Assistant
Let me run the command properly - it seems like there was some issue with the bash command execution.
Assistant
Let me check the diff of what was changed:
Assistant
The diff shows that I have made the following changes:
- Added the import
from rich.markup import escapeat line 10 - Changed all error print statements from
console.print(f"[red]Error: {exc}[/red]")toconsole.print(f"[red]Error: {escape(str(exc))}[/red]")
This fixes the MarkupError issue by escaping the exception message before inserting it into the rich markup string.
Let me now submit the changes.
<tool_call> <function=bash_terminal> <parameter=command> cd /OpenJarvis && git status </tool_call>
- Added the import
Assistant
Let me check the git status properly.
Assistant
The changes are ready to be submitted. Let me submit them now.
<tool_call> <function=submit> </tool_call>
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.