Skip to content

fix(agent-core): scope [image] config limits to the owning core#1521

Merged
RealKai42 merged 3 commits into
mainfrom
kaiyi/scoped-image-limits
Jul 9, 2026
Merged

fix(agent-core): scope [image] config limits to the owning core#1521
RealKai42 merged 3 commits into
mainfrom
kaiyi/scoped-image-limits

Conversation

@RealKai42

Copy link
Copy Markdown
Collaborator

Problem

[image] max_edge_px / read_byte_budget (shipped in #1508) were pushed into
module-global state via setConfiguredMaxImageEdgePx /
setConfiguredReadImageByteBudget, applied by KimiCore on config load and
reload. A second core constructed in the same process (the node-sdk's
multi-client pattern, or an embedded harness) restamps the module state, so
every existing session silently starts compressing images with another core's
settings. The same stamp-one-global pattern did not match the
experimental-flag resolver it was modeled on, whose config overrides live in a
per-core FlagResolver instance.

What changed

  • New ImageLimits — an owner-scoped resolver with the same lifecycle as
    FlagResolver: the owner creates one instance, pushes its config on load
    and reload via setConfig(), and consumers resolve through the instance
    they were handed. Per value, precedence stays env var > owning config >
    built-in default; the env vars stay process-level on purpose (operator
    override), exactly like the experimental-flag env switches.
  • No more module state: the setters and the two module-level
    configured* variables are deleted. KimiCore creates the instance,
    reloads push setConfig(config.image), and it flows core → Session → Agent (mirror of experimentalFlags\) into ReadMediaFile, the MCP output pipeline, and the core-process service for daemon-side ingestion (server prompt routes read it per request). ImageLimits` is exported from
    the package root.
  • Ownerless paths unchanged: resolveMaxImageEdgePx /
    resolveReadImageByteBudget become env-only fallbacks for consumers that
    have no config owner (TUI clipboard paste, ACP adapter), which is what those
    processes already used in practice — the module stamp only ever ran
    in-process of a core.
  • Config reloads stay live: every consumer resolves per call (no snapshot),
    so a reloaded [image] section takes effect on the next image read without
    touching the deprecated snapshot kimiConfig on the Agent — that is
    deliberately not the source, because it is frozen at construction time.

Tests

New coverage pins the regression itself and the reload semantics:

  • ImageLimits unit tests: per-instance resolution, env-invalid fallback,
    setConfig replace/clear, and two instances staying isolated.
  • ReadMediaFile: two tools honoring their own limits independently (one tight
    budget, one custom edge cap).
  • KimiCore integration: two cores with different [image] sections —
    reloading one does not restamp the other; a single core picks up [image]
    changes on reload and falls back to built-ins when the section is removed.

Full monorepo typecheck, lint, and test suite pass; the only failures are 6
pre-existing preflight.test.ts cases that fail identically on the base
branch. Changeset included.

@changeset-bot

changeset-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1020eb0

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 force-pushed the kaiyi/scoped-image-limits branch from 7d17f88 to e56d571 Compare July 9, 2026 11:26
@pkg-pr-new

pkg-pr-new Bot commented Jul 9, 2026

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

commit: 1020eb0

@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: 7d17f88dae

ℹ️ 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".

Comment on lines +20 to +25
import {
MAX_IMAGE_EDGE_PX,
maxImageEdgeFromEnv,
READ_IMAGE_BYTE_BUDGET,
readImageByteBudgetFromEnv,
} from './image-compress';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Export the env parsers before importing them

This new file is included by packages/agent-core/tsconfig.json's src include, but image-compress.ts does not export maxImageEdgeFromEnv or readImageByteBudgetFromEnv (repo-wide search only finds these names here). Any agent-core typecheck/build that loads src will fail on these missing exports before the package can ship.

Useful? React with 👍 / 👎.

readImageByteBudgetFromEnv,
} from './image-compress';

export class ImageLimits {

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 Wire ImageLimits into the compression pipeline

The resolver is added but never used: rg ImageLimits only finds this file, while KimiCore still calls the module-global setConfigured* setters and ReadMediaFile still resolves via resolveReadImageByteBudget(). In the multi-core scenario this change is meant to fix, constructing or reloading core B still restamps the global image config used by core A, so [image] limits remain process-global despite the changeset.

Useful? React with 👍 / 👎.

@RealKai42 RealKai42 merged commit 046b6c4 into main Jul 9, 2026
9 of 10 checks passed
@RealKai42 RealKai42 deleted the kaiyi/scoped-image-limits branch July 9, 2026 12:55
@github-actions github-actions Bot mentioned this pull request Jul 9, 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