Skip to content

fix(agent-core): prevent oversized media from poisoning sessions - #1657

Merged
RealKai42 merged 2 commits into
mainfrom
kaiyi/web-large-image-413
Jul 14, 2026
Merged

fix(agent-core): prevent oversized media from poisoning sessions#1657
RealKai42 merged 2 commits into
mainfrom
kaiyi/web-large-image-413

Conversation

@RealKai42

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue. This addresses a reproducible user report where reading a very large local image left the session stuck on HTTP 413 responses.

Problem

Image compression is intentionally best-effort and returns the original bytes when the input exceeds the safe decode limit or a codec fails. ReadMediaFile previously treated that passthrough as a successful compression result and could attach the original image to every later provider request. Base64 expansion then pushed the request over the provider body limit.

The existing 413 recovery retained the two newest media parts. When the oversized image was recent, the degraded resend still contained it, so the session remained poisoned across turns.

What changed

  • Enforce byte and pixel delivery limits after compression in both agent engines. Unsafe originals are not attached; the tool tells the model to create a smaller copy or crop and read that result.
  • Reject oversized region and full_resolution reads before loading the complete file when safe decoding is impossible.
  • Advance 413 recovery through a bounded normal -> media-degraded -> media-stripped sequence.
  • Capture stripped media by content identity so rejected history remains omitted while a newly created smaller image can still reach the model.
  • Add contract tests, bilingual tool documentation, and a patch changeset.

Validation

  • agent-core targeted tests: 174 passed
  • agent-core-v2 targeted tests: 97 passed
  • agent-core and agent-core-v2 typechecks
  • agent-core-v2 domain-layer check
  • CLI production build
  • documentation build
  • type-aware lint: 0 errors

changeset status is currently blocked by the existing stabilize-approval-test-cleanup changeset on main, which references a package that is not in the workspace. The changeset added by this PR is scoped to @moonshot-ai/kimi-code with a patch bump.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6537c65

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@RealKai42
RealKai42 marked this pull request as ready for review July 14, 2026 02:52

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 64db102488

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


declare const mediaStripSnapshotBrand: unique symbol;

/** Opaque provider-visible media identities captured at a strip transition. */

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Move v2 symbol comments into the file header

packages/agent-core-v2/AGENTS.md says comments in this subtree must be header-only and must never sit beside functions, methods, or statements. This newly added per-symbol doc comment introduces a non-header comment in a v2 contract file, so it violates the local convention; move the explanation into the file header or remove it.

Useful? React with 👍 / 👎.

@pkg-pr-new

pkg-pr-new Bot commented Jul 14, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@6537c65
npx https://pkg.pr.new/@moonshot-ai/kimi-code@6537c65

commit: 6537c65

@RealKai42
RealKai42 merged commit 32a89c3 into main Jul 14, 2026
14 checks passed
@RealKai42
RealKai42 deleted the kaiyi/web-large-image-413 branch July 14, 2026 04:46
@github-actions github-actions Bot mentioned this pull request Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant