fix(cloud-agent-next): retry attachment downloads and hide raw stream errors - #5898
Open
maphew wants to merge 1 commit into
Open
fix(cloud-agent-next): retry attachment downloads and hide raw stream errors#5898maphew wants to merge 1 commit into
maphew wants to merge 1 commit into
Conversation
… errors Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
Contributor
Code Review SummaryStatus: 2 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
Files Reviewed (2 files)
Fix these issues in Kilo Cloud Reviewed by grok-4.6 · Input: 169.3K · Output: 23.9K · Cached: 705.9K Review guidance: REVIEW.md from base branch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Pasting an image into a Kilo Cloud Agent thread can silently fail: the wrapper's attachment materialization (
services/cloud-agent-next/wrapper/src/session-bootstrap.ts) catches any error while fetching the presigned R2 attachment URL inside the sandbox and interpolates the raw error into a synthetic text part:The
(undefined is not a function)text is a raw JSTypeErrorleaking into the user-visible transcript. It matches a known class of Bun Web Streams bugs where reading afetch()Response.bodywhose bytes arrive after the response head throws exactlyTypeError: undefined is not a function(oven-sh/bun#34302, oven-sh/bun#28952, oven-sh/bun#28953). The failure is intermittent (network-latency dependent), there is no retry, and a transient failure permanently drops the image from the prompt. The agent then "carries on" without the image.Repro evidence: iterating a delayed-body
Response.bodyon Bun 1.3.12 fails 100/100 with the identical message; the failure disappears when the body is read viagetReader().read()orarrayBuffer().Fix
MAX_ATTACHMENT_DOWNLOAD_ATTEMPTS(3) attempts with short backoff (250ms, then 750ms). Non-2xx429/5xxresponses and fetch/read/timeout errors are retried;4xx(except 429) and size-cap overflows are permanent.response.arrayBuffer()(the workaround Bun's maintainers verified never hits the stream race) whencontent-lengthis present and within the 20 MiB cap; otherwise the existing bounded streaming read is used.attachment <name> could not be retrieved (download failed after 3 attempts)and the underlying reason goes to the wrapper log instead of the transcript. Overflow keeps its typedAttachment too large: ...message, and non-retryable HTTP statuses still reportHTTP <status>.Each attachment still degrades independently: one failed attachment never blocks the rest of the prompt.
Tests
Fixes #5883