Skip to content

fix(agent): stop unprocessable image retry loops#3424

Merged
tatoalo merged 1 commit into
mainfrom
posthog-code/guard-read-image-output
Jul 14, 2026
Merged

fix(agent): stop unprocessable image retry loops#3424
tatoalo merged 1 commit into
mainfrom
posthog-code/guard-read-image-output

Conversation

@tatoalo

@tatoalo tatoalo commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Problem

Once an image the API cannot process enters a cloud session, the same image-processing error can reappear after subsequent tool calls and on later resumes. The agent may continue working, but repeatedly resubmitting the invalid image wastes time and usage and persisted session transcripts can then replay the same invalid content on every resume.

closes #3422

Changes

  • Reject unsupported or oversized direct image attachments before they enter the model payload
  • Replace invalid images in Read tool output through PostToolUse before the next model request, preventing same-turn retry loops
  • Heal persisted session transcripts by replacing invalid top-level and nested tool_result images with a short text notice
  • Share the image-size limit, base64 estimator, and neutralization rules across all three paths

@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 65e8755.

@tatoalo tatoalo changed the title fix(agent): guard Read image output before model delivery fix(agent): stop unprocessable image retry loops Jul 14, 2026
@tatoalo tatoalo changed the base branch from posthog-code/heal-unprocessable-image-in-session to main July 14, 2026 12:21
@trunk-io

trunk-io Bot commented Jul 14, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@tatoalo tatoalo self-assigned this Jul 14, 2026
@tatoalo tatoalo marked this pull request as ready for review July 14, 2026 12:24
@tatoalo tatoalo added the Stamphog This will request an autostamp by stamphog on small changes label Jul 14, 2026
github-actions[bot]
github-actions Bot previously approved these changes Jul 14, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid defensive fix for a concrete infinite-retry bug. All three layers (input conversion, PostToolUse hook, session JSONL healer) are purely additive guards — valid images are untouched, only images that would 400 anyway are replaced with text notices. The estimateBase64Bytes extraction from cloud-prompt.ts to @posthog/shared is a clean deduplication with identical logic, and all placements respect the project's import rules. Test coverage is thorough across all new paths including the URL-sourced image (unchanged) edge case.

@greptile-apps

greptile-apps Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix(agent): guard Read image output befo..." | Re-trigger Greptile

Comment thread packages/agent/src/adapters/claude/image-sanitization.ts
Comment thread packages/agent/src/adapters/claude/image-sanitization.ts
Prevent invalid direct attachments and Read image output from reaching the model, and heal persisted session transcripts that already contain invalid image blocks.
@github-actions github-actions Bot dismissed their stale review July 14, 2026 12:32

New commits pushed (delta classified non_trivial_delta) — stamphog approval dismissed; re-review running automatically.

@tatoalo tatoalo force-pushed the posthog-code/guard-read-image-output branch from 005ddbe to 65e8755 Compare July 14, 2026 12:32

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid defensive fix for a concrete infinite-retry bug — valid images pass through unchanged; only images that would 400 anyway are replaced with text notices. The three layers (input conversion, PostToolUse hook, session JSONL healer) are purely additive, import boundaries are respected, and test coverage is thorough across all new paths including the greptile-bot-flagged edge cases (empty data, bare array wrapping) that were fixed in follow-up commits.

@tatoalo tatoalo enabled auto-merge (squash) July 14, 2026 12:37
@tatoalo tatoalo merged commit 92b0323 into main Jul 14, 2026
26 checks passed
@tatoalo tatoalo deleted the posthog-code/guard-read-image-output branch July 14, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Stamphog This will request an autostamp by stamphog on small changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent loops re-encountering a removed unprocessable image, burning tokens/credits

1 participant