mirror of
https://github.com/langchain-ai/langserve.git
synced 2026-07-16 09:34:30 -04:00
Bad character in state causes incomplete streaming results, leading RemoteRunnable to issues #252
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @fred913 on GitHub (Sep 9, 2025).
How do we find it
Recently we got the following error in our product using RemoteRunnable. (reproduced error in a minimal client, so error logs is a bit different, but the core is same)
Just to note that, using root in a production environment is a bad idea, so don't imitate us
This is weird and we thought it makes no sense. You see, HTTP is TCP-based, so even though we don't have HTTPS set up for internal servers, partial JSON shouldn't appear in responses.
We set up coredumpy and dowhen in our environment, and we did this.
Coredumpy is a post-mortem tool that stores the current frame state into a static dump file, so you can load and run a Pdb-like debugging console afterwards. Dowhen is a tool that injects a bit of code into a callable, so it's equivent to adding the code below the marked line (marked via the code keyword specified in
when()). We did set it up for thetest_stream()(in the test client) above, so we got the json data where an unexpected end of file appear. This way we got the error json happened in test_stream(), and the original state dumped as json (via orjson, same way as WellKnownLCSerializer)AFAIK, Python's embedded
json.dumpshas aensure_ascii: boolthat prevents those characters from a serialized JSON string, but I didn't see one in orjson. We implement one withjson.dumpsinstead, below:And we re-run our test_client, see it just works. Unfortunately I don't have screenshots for this, but it really just works fine then. The client gets the full fine response.
I'm filing this issue since I'm not sure if this issue belongs to LangServe or FastAPI, or starlette_sse, so any guidance on whether this is expected behavior, a known limitation, or something that should be fixed at the LangServe level, would be much appreciated. Thanks for maintaining this project by the way!
@sorenchiron commented on GitHub (Sep 9, 2025):
same issue, fixed using this solution.
a proper json serializer shall be passed to remote runnable 'serializer' argument.
@fred913 commented on GitHub (Sep 9, 2025):
It turns out it's orjson preserving a \u2029 into JSON, and httpx thought it's a new line. So the \u2029 splits a json into N piecess, where none of the pieces are fine JSON. That's why replacing the orjson serializer with a json one works, since it now produces correct json without a new-line character inside.
I believe this issue now belongs to orjson.
@fred913 commented on GitHub (Sep 10, 2025):
If possible, could any of the maintainers please help me transfer this issue to https://github.com/ijl/orjson? I don't see such an option on my side 🤔