← Back to PRs

#8172: fix(sessions_list): strip base64 image data to prevent context overflow

by Flamrru open 2026-02-03 17:33 View on GitHub →
agents stale
## Summary When `sessions_list` returns messages with inline base64 images, the output can be megabytes in size, causing instant context overflow when the result is added to the conversation. This adds a `stripImageData()` function that replaces base64 image data with a placeholder while preserving the message structure. ## The Bug - `sessions_list` with `messageLimit > 0` fetches full message content including inline base64 images - Old Telegram threads with images can return 200KB+ per session - A single `sessions_list` call returned **1.1MB** of data (40 sessions), instantly killing the session - The `/status` command showed only 38k/200k tokens (stale), but the actual context overflowed ## The Fix - Added `stripImageData()` function in `sessions-helpers.ts` - Replaces `data` field in image blocks with `"[base64 image data stripped]"` - Handles both `{ type: "image", data: "..." }` and `{ type: "image", source: { data: "..." } }` formats - Preserves `_strippedBytes` for debugging - Applied in `sessions-list-tool.ts` after `stripToolMessages()` ## Test Plan - [x] Unit tests added (4 tests, all passing) - [x] TypeScript compiles cleanly - [x] Local build tested ## Related Issues This is related to the general context overflow issues: - #1594 (large tool outputs causing context bloat) - #5771, #3154 (context overflow) 🤖 Generated with Claude Code <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR adds a `stripImageData()` helper to remove inline base64 image payloads from session messages (replacing them with a placeholder) and wires it into `sessions_list` output alongside the existing `stripToolMessages()` filtering. It also adds unit tests covering both `image.data` and `image.source.data` shapes, plus malformed/empty inputs, to prevent `sessions_list` responses from ballooning and overflowing conversation context. <h3>Confidence Score: 4/5</h3> - This PR is likely safe to merge and addresses a concrete context overflow issue with limited surface area changes. - Changes are localized to sessions_list output shaping and a new pure helper with unit tests; main residual concerns are consistency of debug metadata placement and coverage of other possible image payload shapes, which are non-breaking but could reduce effectiveness or make debugging harder. - src/agents/tools/sessions-helpers.ts <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs