Skip to content

DRU-1009 -- Read a chat bridge answer in chunks until its newline - #1119

Open
p-r-a-v-i-n wants to merge 1 commit into
czpython:mainfrom
p-r-a-v-i-n:dru-1009-chat-bridge-large-answer
Open

p-r-a-v-i-n wants to merge 1 commit into
czpython:mainfrom
p-r-a-v-i-n:dru-1009-chat-bridge-large-answer

Conversation

@p-r-a-v-i-n

Copy link
Copy Markdown
Collaborator

Bridge.request reads the bridge's answer in chunks until its newline, so a chat answer over 2 MiB arrives whole and the reply is no longer lost.

The bridge sends one JSON line per answer. Druks read it with readline() on the asyncssh channel. When the receive buffer reaches the channel's window (2 MiB by default), asyncssh pauses reading, and readuntil returns what it holds as a partial line. The events answer of a turn that read a large file was cut mid-string, json.loads failed, and each retry of the step got the same cut.

read(64 * 1024) empties the buffer and resumes reading, so the loop collects chunks until one holds the newline and parses the joined bytes once. It stops at the newline, not at the end of the stream, because the drukbox gateway's forward does not signal the end. The bridge escapes newlines inside the JSON and ends the socket after the line, so the newline is the end of the answer. An empty answer still raises ChatBridgeUnavailable, and an answer that is not JSON still raises ChatBridgeError.

The test sends a 3 MB answer with no end of stream through a loopback reader.

The 2 MiB cut was also the only limit on the answer's size. DRU-1010 tracks keeping large tool output out of the chat events.

@p-r-a-v-i-n
p-r-a-v-i-n requested a review from czpython as a code owner November 6, 2026 15:48
@p-r-a-v-i-n
p-r-a-v-i-n marked this pull request as draft November 6, 2026 15:52
@p-r-a-v-i-n
p-r-a-v-i-n marked this pull request as ready for review November 7, 2026 07:06

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant