Repository navigation
fix(bots): fit bot pictures sent over a paired connection under its 1 MiB request limit - #52725
Conversation
[Medium impact] The PR appears safe to merge; no blocking issues remain. SummaryThe PR fits oversized bot pictures before sending them over paired connections, while leaving desktop-local uploads unchanged.
No new actionable issues were found. Tests were not run during this review. Reviews (3) · Last reviewed commit: "test(bots): track created canvases witho..." · Reviewed by Greptile |
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
…equest limit A bot picture is re-encoded as a 512 px PNG and sent as base64 in one bots.avatar.upload request. A paired server closes the connection when a frame is over 1 MiB, so a busy picture failed with a generic error on paired hosts and in Orca Web. The phone's softening step moves to the shared bot-avatar-square module as fitBotAvatarPng. uploadBotAvatar now fits the picture under PAIRED_REQUEST_PARAMS_MAX_BYTES (less 1 KB for the other params) only when the host is reached over a paired connection: any remote runtime, and Orca Web's 'local' host. The desktop's own runtime still gets the picture as is. A picture that cannot be fitted shows a translated "too much detail" message instead of the generic error. Encoding uses the async canvas.toBlob and native base64 so retries do not block the window. Fixes stablyai#52345 Co-authored-by: Shaukat Ibrahim <[email protected]>
ca43c64 to
8088c07
Compare
… mock Co-authored-by: Shaukat Ibrahim <[email protected]>
1b02117 to
feab474
Compare
ELI5
When you give a bot a very detailed picture while Orca is talking to another computer (a remote environment, or Orca Web), the picture could be too big to send in one message. The other computer would hang up, and you saw a vague "Something went wrong". Now Orca checks the size first. If it is too big, Orca makes the picture slightly less detailed so it fits. Pictures saved on your own computer are not changed. If a picture still cannot fit, you get a clear message.
What Changed
Before: A busy picture uploaded to a bot on a paired host failed. The host closed the WebSocket with code 1009, which also dropped every other call on that connection, and the user saw the generic error. Local uploads worked.
After: The same picture is saved at 512 px with a little less detail, and the upload succeeds. Desktop-local uploads are byte-identical to main. A picture that cannot be fitted shows "That image has too much detail to send. Try a simpler one."
How it works:
src/renderer/src/lib/bot-avatar-rpc.ts:uploadBotAvataris the one place every upload goes through: new bot, Settings, Undo and put-back, and AI-generated pictures. It now fits the PNG only when the host is reached over a paired connection. That means any non-local runtime, plus Orca Web's'local'host, which is really the server it is paired with (isWebClientLocation()).src/renderer/src/components/bots/bot-avatar-upload.ts: newpairedHostAvatarPng(png)returns the picture unchanged if its base64 fits inPAIRED_REQUEST_PARAMS_MAX_BYTES - 1024(781,184 chars). Otherwise it decodes it, redraws the 512 px square and fits it.squareAvatarPngand the refit sharewithSquareAvatarfor the bitmap and canvas lifecycle. Encoding uses asynccanvas.toBlobplusblobToBase64(FileReader) instead of a JS per-byte loop.src/shared/bots/bot-avatar-square.ts: the phone's softening step moves here asfitBotAvatarPng(square, encode, maxBase64Chars). It draws the square at fewer pixels, scales it back up with nearest-neighbour, and loops through the sharedencodeClipboardImageWithinLimit. It releases its temporary canvases, and throwsBOT_AVATAR_TOO_BUSYwhen no detail level fits. The picture stays 512 px, the smallest a host accepts.mobile/src/bots/bot-avatar-photo.ts: uses the shared fit with its existing encoder and budget, so mobile behaviour is unchanged.bot-presentation.ts:botErrorMessagemapsBOT_AVATAR_TOO_BUSYto the newbots.errors.avatarTooBusystring, which is translated in all 11 locales.Why
Every picture is re-encoded as a 512 px RGBA canvas PNG and sent as base64 in one
bots.avatar.uploadrequest. A paired host's WebSocket hasmaxPayloadset toREMOTE_RUNTIME_MAX_INBOUND_FRAME_BYTES(1 MiB). After sealing, that leaves about 782 KB of params. A busy picture's re-encoded PNG goes past this even when the source file is smaller: the reporter's 571 KB RGB8 PNG becomes larger once it is RGBA. The local runtime has no frame limit and accepts up to 2 MB, which is why only paired uploads failed.The fit happens at the transport boundary, not at intake. Intake does not know which host the picture is for, so fitting there would have softened local uploads that the local runtime accepts as they are. The phone already solves the same bridge-frame problem by softening, so both clients now share one implementation.
Linked Issue
Fixes #52345
Visual Proof
N/A. Nothing on screen changes apart from the new error line. The behaviour change is on the wire (closed versus accepted frame), so it is shown with the probe numbers under Testing rather than screenshots.
Testing
Reproduction probe. The probe runs the real
squareAvatarPng→uploadBotAvatar→serializeRemoteRuntimeRpcRequest→ NaCl sealing path into awsserver withmaxPayload = 1 MiB, using a Skia canvas:Real Chromium (headless, on a separate Mac):
squareAvatarPngoutput is byte-identical to main.Unit tests:
src/renderer/src/lib/bot-avatar-rpc.test.ts: desktop'local'uploads are sent as is.'runtime:<env>'and Orca Web'local'uploads are fitted.src/shared/bots/bot-avatar-square.test.ts: an over-limit picture is softened until it fits and its temp canvases are released. A picture that never fits throwsBOT_AVATAR_TOO_BUSY.Static checks: oxlint,
oxfmt --check, anti-slop oxlint, code-quality native plugins, ast-grep,check-changed-code-quality, and the localization catalog and extraction checks are all clean.Not run: a full desktop GUI upload to a real paired Linux server.
Performance
This runs only when a user uploads a bot picture. It is not a hot path, and it changes no store, selector or cache, so nothing scales with the number of tabs or worktrees.
toBlobas main. Base64 now uses FileReader instead of a JS byte loop. In Chromium the longest main-thread block dropped from 7.1–23.9 ms to 5.9–8.9 ms. On a 1.24 MB blob, base64 alone went from 19–23 ms to about 1 ms.createImageBitmap, and asynctoBlobencodes until one fits (2 in every probe case). No single block is over 16 ms.Risk
Level: Low
Review
Original fix by @sibrash4 in #52725. Their authorship is credited with
Co-authored-by. On top of their shared softening step, maintainer changes:Agent skill upstream boundary
Notes
Security, cross-platform, remote and mobile were considered. The change uses only the renderer canvas and the existing remote-runtime limits, the mobile path is unchanged, and it is compatible with mixed-version hosts.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)