-
Notifications
You must be signed in to change notification settings - Fork 936
feat: keep image-heavy sessions within provider request-size limits #1508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
83808d9
feat(kosong): classify HTTP 413 request-body-too-large as a dedicated…
RealKai42 ed67a15
feat(agent-core): lower default image downscale cap to 2000px and mak…
RealKai42 64b40fd
Merge remote-tracking branch 'origin/main' into kaiyi/perth-v2
RealKai42 13ce515
feat(agent-core): strip media to text markers and retry when the comp…
RealKai42 6ea1aa1
feat(agent-core): cap model-initiated image reads with a configurable…
RealKai42 4bea536
feat(agent-core): resend with degraded media when the provider reject…
RealKai42 0228ac3
test(agent-core): add explicit timeouts to encode-heavy image budget …
RealKai42 ab89efb
feat: add WebP decoding support with wasm integration
RealKai42 8022765
chore(changeset): consolidate this PR's entries into one
RealKai42 c670b53
fix(nix): update pnpmDeps hash for merged lockfile
RealKai42 ea208ec
merge: keep updated pnpmDeps hash after merging main
RealKai42 9509645
feat(agent-core): refuse HEIC/HEIF reads with platform-matched conver…
RealKai42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@moonshot-ai/kimi-code": patch | ||
| --- | ||
|
|
||
| Keep image-heavy sessions within provider request-size limits: model-read images now honor a 256 KB per-image budget and a 2000px downscale cap (configurable via `[image]` in config.toml or `KIMI_IMAGE_*` env vars), oversized WebP is compressed as well, HEIC/HEIF reads are refused with a platform-matched conversion command instead of poisoning the session, and a request-too-large rejection (HTTP 413) now recovers automatically — the request and /compact both retry with older media replaced by text markers instead of failing the session. | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /** | ||
| * Regenerate `src/tools/support/webp-dec-wasm.ts` from the installed | ||
| * `@jsquash/webp` package. | ||
| * | ||
| * The WebP decoder wasm is committed as a base64 string module because the | ||
| * published CLI bundles every dependency into a single file with no runtime | ||
| * node_modules — a file-path lookup for the .wasm would break there, while a | ||
| * string constant survives every packaging (vitest on sources, tsdown | ||
| * bundling, nix builds) unchanged. Run this after bumping @jsquash/webp: | ||
| * | ||
| * node scripts/generate-webp-dec-wasm.mjs | ||
| */ | ||
| import { createRequire } from 'node:module'; | ||
| import { readFileSync, writeFileSync } from 'node:fs'; | ||
| import { resolve } from 'node:path'; | ||
|
|
||
| const packageRoot = resolve(import.meta.dirname, '..'); | ||
| const require = createRequire(resolve(packageRoot, 'package.json')); | ||
|
|
||
| const wasmPath = require.resolve('@jsquash/webp/codec/dec/webp_dec.wasm'); | ||
| const version = require('@jsquash/webp/package.json').version; | ||
| const wasm = readFileSync(wasmPath); | ||
|
|
||
| const target = resolve(packageRoot, 'src/tools/support/webp-dec-wasm.ts'); | ||
| writeFileSync( | ||
| target, | ||
| `// GENERATED FILE — do not edit by hand. | ||
| // WebP decoder wasm from @jsquash/webp@${version} (codec/dec/webp_dec.wasm), | ||
| // base64-encoded so the bundled CLI needs no on-disk wasm asset. | ||
| // Regenerate with: node scripts/generate-webp-dec-wasm.mjs | ||
|
|
||
| export const WEBP_DECODER_WASM_BASE64 = | ||
| '${wasm.toString('base64')}'; | ||
| `, | ||
| ); | ||
| console.log(`Wrote ${target} (${wasm.length} bytes of wasm)`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the 413 is caused by one or two large media parts, this returns the original messages unchanged because
mediaCount <= keepRecent. That can happen with defaultReadMediaFilereads despite the new read budget, since the compressor still passes through guarded/unsupported inputs (for example a >64 MB image under the 100 MB media limit, or an inline video), so the single retry inexecuteLoopStepresends the same oversized body and the session remains stuck. The fallback needs a way to drop or shrink recent media when those parts alone exceed the provider request limit.Useful? React with 👍 / 👎.