pi-mono/packages
robopipi[bot] e7a0df27c0
fix(coding-agent): pick the smaller of PNG and JPEG when resizing images (#11577)
When an image needs resizing, `resizeImageInProcess` builds a list of
encodings: PNG first, then JPEG at decreasing qualities. It returned the
first one under `maxBytes`. Since PNG was always first, it was used
whenever it fit, even when it was many times larger than the JPEG. The
doc comment says "Try both PNG and JPEG formats, pick the smaller one",
and the code worked that way before v0.62.0. Because of this, photos
were sent as multi-MB PNGs, which made requests large enough to fail or
time out.

This change compares PNG with JPEG at the configured quality at each
size step and tries the smaller one first. It tries the other one next,
and the lower JPEG qualities only after that. Screenshots and other
images where PNG is smaller still go out as PNG.

**Testing**
- Added a regression test to `test/image-processing.test.ts`: a
generated photo-like 1200×800 JPEG resized to 1000 px must come back as
`image/jpeg`. The test fails without the fix (PNG is returned) and
passes with it.
- `node ../../node_modules/vitest/dist/cli.js --run
test/image-processing.test.ts test/image-resize-callers.test.ts`: all
pass.
- `npm run check`: no issues in the changed files. It does report type
errors, all in `packages/ai/test` (model ID unions), which this change
does not touch.
- Reproduction with a photo-like 2400×1620 JPEG (460 KB base64):
  - before: `image/png`, 4,008,480 bytes base64, at 2000×1350
  - after: `image/jpeg`, 255,316 bytes base64, at 2000×1350

Fixes #11551

Requested by @davidbrai

Co-authored-by: triagent <triagent@localhost>
2026-10-29 16:14:56 +01:00
..
agent fix(ai,chord,durable,coding-agent): parse streamed tool-call arguments incrementally (fixes #9265) 2026-10-24 08:00:07 +00:00
ai fix(ai): do not retry Zhipu usage limit errors (code 1308) (#11572) 2026-10-29 15:37:07 +01:00
chord docs(chord): slice 7b spec: reload in the kernel 2026-10-29 13:05:53 +00:00
codemode fix: update deps for security advisories 2026-10-22 11:24:50 +02:00
coding-agent fix(coding-agent): pick the smaller of PNG and JPEG when resizing images (#11577) 2026-10-29 16:14:56 +01:00
durable feat(chord): Chord v2 slice 8, registries and host.root 2026-10-28 21:34:56 +00:00
env docs(env): Windows commands' descendants survive a terminated daemon 2026-10-28 21:09:58 +01:00
evals feat(coding-agent): add prompt template documentation eval (#10261) 2026-10-28 12:12:19 +02:00
mcp fix(ai,chord,durable,coding-agent): parse streamed tool-call arguments incrementally (fixes #9265) 2026-10-24 08:00:07 +00:00
telemetry fix(ai): resolve pi-telemetry from source in workspace tests 2026-10-26 21:05:54 +00:00
tui fix(tui): stop writing OSC 133 prompt markers in regular mode (#11565) 2026-10-29 14:00:16 +01:00