Agent returns empty/invalid JSON response on update_agent, causing JSONDecodeError
- Dominant language
- Python
- Stars
- 125
- Forks
- 147
- Avg merge
- 17h 20m
- Merged PRs (30d)
- 17
Description
### Summary
When attempting to update the agent using the `update_agent` method, the agent responds with an empty or invalid JSON response, causing a `requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)` error on the client side (press app).
### App Versions
```
{
"frappe": "15.75.0",
"press": "0.7.0"
}
```
### Route
```
Form/Database Server/m1.zinyecloud.com
```
### Traceback
```
Traceback (most recent call last):
File "env/lib/python3.10/site-packages/requests/models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3.10/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.10/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "apps/frappe/frappe/app.py", line 115, in application
response = frappe.api.handle(request)
File "apps/frappe/frappe/api/__init__.py", line 49, in handle
data = endpoint(**arguments)
File "apps/frappe/frappe/api/v1.py", line 36, in handle_rpc_call
return frappe.handler.handle()
File "apps/frappe/frappe/handler.py", line 51, in handle
data = execute_cmd(cmd)
File "apps/frappe/frappe/handler.py", line 84, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File "apps/frappe/frappe/__init__.py", line 1754, in call
return fn(*args, **newargs)
File "apps/frappe/frappe/handler.py", line 334, in run_doc_method
response = doc.run_method(method)
File "apps/frappe/frappe/model/document.py", line 1007, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File "apps/frappe/frappe/model/document.py", line 1367, in composer
return composed(self, method, *args, **kwargs)
File "apps/frappe/frappe/model/document.py", line 1349, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File "apps/frappe/frappe/model/document.py", line 1004, in fn
return method_object(*args, **kwargs)
File "apps/frappe/frappe/utils/typing_validations.py", line 32, in wrapper
return func(*args, **kwargs)
File "apps/press/press/press/doctype/server/server.py", line 475, in update_agent
return agent.update()
File "apps/press/press/agent.py", line 1173, in update
return self.post("update", data={"url": url, "branch": branch})
File "apps/press/press/agent.py", line 880, in post
return self.request("POST", path, data, raises=raises)
File "apps/press/press/agent.py", line 920, in request
self.handle_request_failure(agent_job, response)
File "apps/press/press/agent.py", line 909, in request
json_response = response.json()
File "env/lib/python3.10/site-packages/requests/models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
```
### Request Data
```
{
"type": "POST",
"args": {
"docs": "{\"name\":\"m1.zinyecloud.com\", ... }",
"method": "update_agent"
},
"headers": {},
"error_handlers": {},
"url": "/api/method/run_doc_method",
"request_id": null
}
```
### Response Data
```
{
"exception": "requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)",
"exc_type": "JSONDecodeError",
"_exc_source": "press (app)"
}
```
### Additional Information
- This started occurring in the new setups.
- The agent should always return a valid JSON response, even on error.
- There may be an unhandled exception or crash in the agent code.
- Please investigate recent changes and ensure robust error handling for all endpoints.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in press/press/agent.py at request() and handle_request_failure(), then trace the update_agent entry point in press/press/doctype/server/server.py. Reproduce the update_agent request against a new setup and inspect the response handling. Done means agent endpoints return valid JSON for both successful responses and errors without raising JSONDecodeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100