Skip to content

fix(bots): fit bot pictures sent over a paired connection under its 1 MiB request limit - #52725

Merged
nwparker merged 2 commits into
stablyai:mainfrom
sibrash4:fix/bot-avatar-paired-request-budget
Nov 30, 2026
Merged

nwparker merged 2 commits into
stablyai:mainfrom
sibrash4:fix/bot-avatar-paired-request-budget

Conversation

@sibrash4

@sibrash4 sibrash4 commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

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: uploadBotAvatar is 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: new pairedHostAvatarPng(png) returns the picture unchanged if its base64 fits in PAIRED_REQUEST_PARAMS_MAX_BYTES - 1024 (781,184 chars). Otherwise it decodes it, redraws the 512 px square and fits it. squareAvatarPng and the refit share withSquareAvatar for the bitmap and canvas lifecycle. Encoding uses async canvas.toBlob plus blobToBase64 (FileReader) instead of a JS per-byte loop.
  • src/shared/bots/bot-avatar-square.ts: the phone's softening step moves here as fitBotAvatarPng(square, encode, maxBase64Chars). It draws the square at fewer pixels, scales it back up with nearest-neighbour, and loops through the shared encodeClipboardImageWithinLimit. It releases its temporary canvases, and throws BOT_AVATAR_TOO_BUSY when 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: botErrorMessage maps BOT_AVATAR_TOO_BUSY to the new bots.errors.avatarTooBusy string, 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.upload request. A paired host's WebSocket has maxPayload set to REMOTE_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

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below
  • Every added test fails without this change and avoids the test anti-patterns

Reproduction probe. The probe runs the real squareAvatarPng → uploadBotAvatar → serializeRemoteRuntimeRpcRequest → NaCl sealing path into a ws server with maxPayload = 1 MiB, using a Skia canvas:

input 512 px PNG chars main this PR (paired and Orca Web)
RGB8 grain 40 (like #52345) 843,120 1,124,876 B frame, closed 1009 604,956 chars, 807,324 B frame, accepted
RGB8 grain 80 981,232 1,309,024 B, closed 1009 866,748 B, accepted
JPEG photo 2400x1600 941,728 1,256,352 B, closed 1009 912,720 B, accepted
pure RGBA noise 1,380,436 1,841,296 B, closed 1009 945,024 B, accepted
flat 800 px 2,976 accepted unchanged, accepted
  • Desktop-local output matches main in every case.
  • Fitted output stays 512x512, and fitting it again gives the same result.
  • Boundary: 781,184 chars is accepted; 800,000 is closed.

Real Chromium (headless, on a separate Mac):

  • Fitted frames of 851–887 KB are accepted, and a follow-up call on the same socket succeeds. On main, the follow-up fails after the 1009 close.
  • Local squareAvatarPng output 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 throws BOT_AVATAR_TOO_BUSY.
  • These pass alongside the existing bot-presentation, use-bot-picture-setting, avatar-generation-requests and mobile bot-avatar-uploads tests.

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.

  • Desktop local intake: same single async toBlob as 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.
  • Paired upload that already fits: adds one length check.
  • Over-limit paired upload (failed outright on main): adds a base64 decode (about 1 ms), createImageBitmap, and async toBlob encodes until one fits (2 in every probe case). No single block is over 16 ms.

Risk

Level: Low

  • Riskiest part: a very busy picture sent to a paired host is now saved slightly pixelated, while the local preview stays sharp. On main the upload failed and dropped the connection. The phone already does the same.
  • Desktop-local uploads and mobile are unchanged.
  • No saved data, settings or protocol change, and older hosts are unaffected. A plain revert backs it out.

Review

Original fix by @sibrash4 in #52725. Their authorship is credited with Co-authored-by. On top of their shared softening step, maintainer changes:

  • Moved the fit to the send boundary, for paired hosts only.
  • Kept encoding async.
  • Covered Orca Web.
  • Added tests and translations.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

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

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge; no blocking issues remain.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issues remain.

Summary

The PR fits oversized bot pictures before sending them over paired connections, while leaving desktop-local uploads unchanged.

  • Detailed bot pictures fit paired uploads without changing desktop-local pictures.

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

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Avatar PNGs now use shared fitting logic to reduce image detail when needed to meet character limits. The mobile photo path and renderer paired-host uploads use this fitting. Desktop local uploads continue to send the original PNG. When an image cannot fit, the renderer displays a translated message suggesting a simpler image.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to feab4

Oversized bot-avatar uploads to paired hosts are now fitted before sending, and an image that still cannot fit gets a clear message. Desktop-local uploads behave as before. No merge-blocking risk was found. A full upload against a real paired server was not run.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: bot pictures sent over a paired connection are fitted under the 1 MiB request limit. It matches the objectives (PR #52725 and issue #52345) and the changed files (bot-…
Description check Passed The description follows the repository template closely. It includes ELI5, What Changed, Why, Linked Issue (Fixes #52345), Visual Proof (N/A with reason), Testing with a reproduction probe and unit te…
Linked Issues check Passed [#52345] The issue accepts either of two outcomes: a valid 512 px PNG saves and stays visible on the paired host, or the UI shows an actionable rejection reason. The PR implements both paths. (1) `upl…
Out of Scope Changes check Passed All changed areas connect to the #52345 objective. bot-avatar-square.ts holds the shared fit and the BOT_AVATAR_TOO_BUSY constant. bot-avatar-upload.ts and bot-avatar-rpc.ts apply the fit at t…
Full details: Title check

Explanation

The title names the main change: bot pictures sent over a paired connection are fitted under the 1 MiB request limit. It matches the objectives (PR #52725 and issue #52345) and the changed files (bot-avatar-rpc.ts, bot-avatar-upload.ts, bot-avatar-square.ts). It uses the conventional fix(bots) prefix and is 87 characters, which is slightly long but still clear.

Full details: Description check

Explanation

The description follows the repository template closely. It includes ELI5, What Changed, Why, Linked Issue (Fixes #52345), Visual Proof (N/A with reason), Testing with a reproduction probe and unit test details, Performance (a 'None, because' line is replaced with a full explanation), Risk with level Low and a revert path, Review, and Checklist. Some items remain open: the manual-test checkbox is unchecked, the lint/typecheck/test/build checkbox is unchecked, and the AI Disclosure section is blank. The Linked Issue section has a bare number, which is acceptable. The description is mostly complete.

Full details: Linked Issues check

Explanation

[#52345] The issue accepts either of two outcomes: a valid 512 px PNG saves and stays visible on the paired host, or the UI shows an actionable rejection reason. The PR implements both paths. (1) uploadBotAvatar in bot-avatar-rpc.ts now calls pairedHostAvatarPng for non-local runtime targets and for Orca Web's 'local' host. pairedHostAvatarPng in bot-avatar-upload.ts returns the PNG unchanged when its base64 length is at most PAIRED_REQUEST_PARAMS_MAX_BYTES - 1024. Otherwise it re-fits the image through the shared fitBotAvatarPng in src/shared/bots/bot-avatar-square.ts. Desktop-local uploads skip this step. (2) When no detail level fits, fitBotAvatarPng throws BOT_AVATAR_TOO_BUSY. botErrorMessage in bot-presentation.ts maps that error to the translated bots.errors.avatarTooBusy string. Unit tests cover local versus paired upload behavior, fit-until-fits behavior, temp canvas release, and the too-busy rejection. The 1009 root cause is supported by the PR's probe and headless Chromium results. The end-to-end upload to a real paired Linux server was not run, so the reported failure is not verified as fixed on that host. This does not change the coding result, because the code path implements the requirement.

Full details: Out of Scope Changes check

Explanation

All changed areas connect to the #52345 objective. bot-avatar-square.ts holds the shared fit and the BOT_AVATAR_TOO_BUSY constant. bot-avatar-upload.ts and bot-avatar-rpc.ts apply the fit at the paired-transport boundary. bot-presentation.ts and the locale files add the user-facing rejection message. The tests cover these changes. mobile/src/bots/bot-avatar-photo.ts replaces its local softening routine with the shared fitBotAvatarPng. The PR states that the mobile budget and encoder are unchanged, and the shared function keeps the same softening approach. This is a supporting refactor that removes duplicate logic, not an unrelated change. The incremental changes since the previous reviewed heads add the paired-host fit in uploadBotAvatar and the shared-fit refactor, and both stay within the same objective.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 65fc496e-7177-4021-bc20-af9a83924609
Commits

Reviewing files that changed from the base of the PR and between 8088c07 and feab474.

Files selected for processing: 1

  • src/shared/bots/bot-avatar-square.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

…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]>
@nwparker
nwparker force-pushed the fix/bot-avatar-paired-request-budget branch from ca43c64 to 8088c07 Compare November 30, 2026 00:10
@nwparker nwparker changed the title fix(bots): fit uploaded bot pictures under a paired server's request limit fix(bots): fit bot pictures sent over a paired connection under its 1 MiB request limit Nov 30, 2026
@nwparker
nwparker force-pushed the fix/bot-avatar-paired-request-budget branch from 1b02117 to feab474 Compare November 30, 2026 00:25
@nwparker
nwparker merged commit 46239ac into stablyai:main Nov 30, 2026
58 checks passed
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.

[Bug]: Custom bot avatar upload fails from macOS UI to paired server with generic error

2 participants