[Bug] a non-numeric page raises out of the cloud history query instead of returning the error envelope
English is recommended so global developers can help. 推荐使用英文提交,谢谢 ❤️
- I'm on the latest version and searched existing issues (incl. closed) — no duplicate.
Environment
Version: current master (commit 08f64f7)
OS: any — platform-independent
Python: 3.11 / 3.13 (CI matrix)
Install: any — affects cloud deployments (LinkAI / cloud deployment id)
What happened?
A non-numeric page in a history query raises out of the handler instead of being reported as an error.
_query_history wraps its work in a try/except that returns a
{"status": "error"} envelope for every failure, but the two int() conversions
sat above that block:
def _query_history(self, payload: dict) -> dict:
session_id = payload.get("session_id", "")
page = int(payload.get("page", 1)) # <-- above the try, and above
page_size = int(payload.get("page_size", 20)) # above the session_id check
if not session_id:
return {... "message": "session_id required"}
logger.info(...)
try: # <-- envelope lives from here
...
except Exception as e:
return {... "payload": {"status": "error", "message": str(e)}}on_history returns _query_history(payload) directly, so nothing between the
two converts the exception either.
Steps to reproduce
A history query from the cloud console:
client._query_history({"session_id": "s1", "page": "abc"})
# ValueError: invalid literal for int() with base 10: 'abc'Same for "page": null → TypeError, "page_size": "twenty", "page": [1].
Expected — what every other bad input returns:
{"action": "query", "payload": {"status": "error", "message": "..."}}Actual: ValueError / TypeError propagates out of on_history to the cloud
message loop, so one malformed field in a history request takes down the handler
that was supposed to answer it, rather than answering with a message.
The asymmetry
The session_id check is a hand-written guard returning the same envelope, and
it too sits above the try. So the function already establishes the pattern of
validating cheap fields up front and reporting them — the two int() calls
simply were not written that way.
Suggested fix
Keep session_id's precedence (it is the more fundamental check) and parse the
numbers right after it, inside a guard that returns the same envelope:
if not session_id:
return {... "message": "session_id required"}
try:
page = int(payload.get("page", 1))
page_size = int(payload.get("page_size", 20))
except (TypeError, ValueError):
return {
"action": "query",
"payload": {"status": "error", "message": "page and page_size must be integers"},
}int("2") is still accepted, so a client sending numeric strings is unaffected.
Logs
Not applicable — reproducible by calling _query_history with a non-numeric page.
Source: zhayujie/CowAgent