#8172: fix(sessions_list): strip base64 image data to prevent context overflow
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
#5817: fix: strip old images during compaction to prevent 413 session bloat
by jduartedj · 2026-02-01
81.0%
#10786: fix: strip thinking signatures from sessions_list and add includeTh...
by 1kuna · 2026-02-07
78.4%
#23639: fix(agents): stop re-resizing session history images on every turn ...
by yinghaosang · 2026-02-22
78.1%
#9598: fix(agents): check base64 string length against 5MB API limit
by BlockBB · 2026-02-05
77.2%
#10465: Context pruning: strip image blocks instead of skipping
by quentintou · 2026-02-06
77.2%
#9026: fix(session-memory): sanitize content to prevent binary data in mem...
by Flamrru · 2026-02-04
76.8%
#19135: fix(agents): prune excess images from conversation history (#19099)
by pierreeurope · 2026-02-17
76.4%
#18219: fix: validate base64 image data before sending to LLM APIs
by Grynn · 2026-02-16
76.1%
#14328: fix: strip incomplete tool_use blocks from errored/aborted messages...
by Kropiunig · 2026-02-12
75.7%
#15050: fix: transcript corruption resilience — strip aborted tool_use bloc...
by yashchitneni · 2026-02-12
75.3%