Vision payloads above 512KB trigger futile history trim (MAX_REQUEST_PAYLOAD_BYTES vs image data)
Context
PR #169 added trimOldMessagesToFitContext with a dual budget: token cap (HISTORY_TRIM_TARGET_RATIO = 0.7) and a hard byte ceiling (MAX_REQUEST_PAYLOAD_BYTES = 512 KB, src/config.ts).
Problem
Image data is counted toward the byte ceiling:
MAX_HISTORY_IMAGES_KEPT = 2images survive history trimming- Images normalize up to
MAX_IMAGE_BASE64_BYTES = 5 MBbase64 each
So a vision payload with one or two images can sit above 512KB even after token trimming already succeeded. The trimmer then drops the entire middle conversation history trying to get under the byte cap, and still fails (falls back to noTrim). Result: the user loses context for no benefit.
Also worth noting: the byte cap itself may be overly conservative. Issue #104 was closed withdrawn after the gateway was confirmed to accept bodies up to ~1.5MB (see #44), so there is no measured hard limit at 512KB.
Suggested fix
Exclude image data (base64 image_url parts) from the byte accounting in payloadBytes() (src/provider/historyTrim.ts), or apply a higher byte cap for payloads carrying image parts.
Related: #109 (the real unbounded-history failure this trim solves), #78 (fetch resilience, also from #169).