Skip to content

fix(core): keep image trimming stable across turns - #51986

Open
carson2222 wants to merge 2 commits into
anomalyco:v2from
carson2222:fix/stable-image-trim
Open

carson2222 wants to merge 2 commits into
anomalyco:v2from
carson2222:fix/stable-image-trim

Conversation

@carson2222

Copy link
Copy Markdown

Issue for this PR

Closes #51985

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

boundImages trims old images once a request carries more than 25 MiB of them, down to 15 MiB. It recomputes the cutoff from the full history on every request, so each new image changes which old images get replaced. The start of the history changes every turn and the Anthropic prompt cache misses every turn.

This removes images in whole 10 MiB steps, the gap between the trigger and the target. The replaced set now stays the same from one request to the next until the image total crosses the next step. Retained images never go over 25 MiB. Between steps they sit anywhere from 15 to 25 MiB instead of always being cut back to 15 MiB.

How did you verify your code works?

Added a test that grows a history one image at a time. Before the change, 26, 30 and 35 images replaced 11, 15 and 20 of them. Now all three replace 10, and the 36th image moves the cutoff to 20.

Ran bun run test and bun typecheck in packages/core, plus the pre-push bun run check. The core suite has 16 failures on my Mac (shell, plugin reload, MCP, watcher). The same 16 fail on unmodified v2.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant