Skip to content

fix: first image turn loads every bundled media-understanding provider plugin even when the model handles the image natively - #159234

Merged
obviyus merged 2 commits into
openclaw:mainfrom
alexeysophia:fix/lazy-media-provider-registry
Oct 1, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
alexeysophia:fix/lazy-media-provider-registry

Conversation

@alexeysophia

@alexeysophia alexeysophia commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes #159233

What Problem This Solves

Fixes: the first turn carrying an image in a gateway process loads every bundled
media-understanding provider plugin (249 new modules vs. 29 with the build deferred in a traced
pair, and about 220 more modules unpatched under a second trace hook), even when the active model
reads the image natively and nothing in the turn uses those plugins. On current main (a source build of 32dcd029, no plugins.allow) that first image turn first-loads 590 modules, 284 of them the registry cascade across 8 bundled media-understanding providers, against 306 and none with this change (see Evidence). The cost of that load is
modest: on a local Docker rig (5 fresh containers per variant, no instrumentation preloads, both
variants already carrying the sibling native-vision-probe patch from #159232; rig numbers, not
a real deployment) that first photo turn measured median peak RSS +70.9 MiB and 1616 ms elapsedMs
unpatched vs. +65.9 MiB and 1399 ms with the registry build deferred — about 5 MiB of peak and about
0.2 s. This fix is best read together with #159232: both remove an unconditional load on the
same image-turn call chain, ahead of the same native-vision skip decision; #159232's own effect on
that turn is much larger. See Evidence for what the measured patch was and for the deployment context
this fix's small effect sits alongside.

User Impact

Any deployment whose active model already declares native image support and configures no explicit
tools.media.models override stops paying, on its first image-bearing turn in a fresh process, a
provider-registry build that turn never reads, whichever provider is active: in the rig, about 220
provider-cascade modules not loaded into the process (249 vs. 29 in the traced pair), and about
5 MiB of peak RSS and 0.2 s on that turn (+70.9 vs. +65.9 MiB peak, 1616 vs. 1399 ms; see Evidence).
Later image turns in the same process were not measured.
Deployments with an explicit tools.media.models override, or whose active model does not support
vision natively, still build the registry on their image turns, as before, because they need it
(confirmed on the patched build, see Evidence).

On current main, a restrictive plugins.allow that omits the bundled media providers already keeps
them out of the registry, so such a config loads the same modules with or without this change (measured
on a source build, see Evidence); the saving applies to the default config without such an allowlist.

A registry build failure keeps its existing outcome: the build is attempted once per turn and the
error still leaves applyMediaUnderstanding, reaching the caller's whole-turn raw-content fallback.

Why This Change Was Made

applyMediaUnderstanding (src/media-understanding/apply.ts) builds the registry once and shares it
across every capability handler for the turn (image, audio, video), which is the right amortization
when the registry is actually going to be read — the problem is only the when: it is built before
any handler runs, not when the first one that needs it runs. runCapability's own native-vision skip
branch (runner.ts) can, and on this project's config does, return before ever reading the registry:
its one pre-skip-decision reader, hasExplicitImageUnderstandingConfig, calls
Array.prototype.some over cfg.tools?.media?.models ?? [], and .some never invokes its predicate
on an empty array — so on a config with no explicit media-model overrides, the registry is
read by nothing on that turn.

This change makes the registry's construction lazy and memoized, shared across the turn exactly as
before, but paid for only once something actually dereferences it:

  • apply.ts no longer calls buildProviderRegistry eagerly. It instead builds a small memoized
    factory, providerRegistry(), and passes it, unevaluated, into runMediaCapability (i.e.
    runCapability) for every capability in the turn, exactly as it passed the built value before. The
    factory builds the registry on first read and memoizes it. If the build throws, the error is memoized
    too (providerRegistryError, so no capability retries the build) and rethrown right after the
    capabilities settle, before any context mutation — so it still leaves applyMediaUnderstanding and
    reaches the caller's whole-turn raw-content fallback, as the eager throw did.
  • runner.ts gets a new type, LazyProviderRegistry = ProviderRegistry | (() => ProviderRegistry),
    and a one-line resolver, resolveProviderRegistry, that returns a concrete registry unchanged or
    calls the factory. runCapability's own providerRegistry field is retyped from ProviderRegistry
    to LazyProviderRegistry.
  • hasExplicitImageUnderstandingConfig's field is retyped the same way, and its one dereference is
    wrapped: providerRegistry: resolveProviderRegistry(params.providerRegistry) — but this call sits
    inside the .some() predicate, so it is only reached when cfg.tools.media.models actually has
    at least one entry to check. An empty array still short-circuits before the factory is ever called.
  • Every other consumer of providerRegistry inside runCapability (resolveModelEntries,
    resolveAutoEntries, runAttachmentEntries, resolveAutoAudioEntries) is only reached after
    the native-vision skip branch's own early return. Rather than retype all of those functions too,
    runCapability resolves the lazy value into one concrete local,
    const providerRegistry = resolveProviderRegistry(params.providerRegistry);, immediately after the
    skip-check block and before any of those calls — so their own signatures and every downstream file
    are untouched.

Bound: on a successful build, the underlying buildMediaUnderstandingRegistry(...) call runs at
most once per turn
— the memoized thunk in apply.ts is shared by every capability's
runCapability call the same way the eagerly-built value used to be, so a mixed image+audio turn
(image skips it, audio's own non-skip path resolves it) still builds it exactly once, not once per
capability. This bound relies on buildMediaUnderstandingRegistry being synchronous: capabilities run
concurrently, but because the thunk body has no await, one logical call always runs to completion
(and sets the memo) before the event loop can enter a second concurrent call to the same thunk — there
is no race.

The exception path (unchanged outcome), and six shapes checked (mixed attachments, concurrency, a throwing builder, per-capability config, document-only attachments)

The exception path keeps the eager build's outcome. Before this change, a throw from
buildProviderRegistry propagated out of applyMediaUnderstanding and reached the caller's
whole-turn raw-content fallback (applyMediaUnderstandingIfNeeded in get-reply-preprocessing.ts,
and dispatch-acp.ts). The deferred build now runs inside runMediaCapability, whose catch would
turn it into a per-capability outcome: "failed"; the first revision of this PR let that happen. The
second commit memoizes the failure and rethrows it after the capability loop, before
MediaUnderstandingDecisions or any other context field is written, so the caller sees the same
exception it saw before and falls back to raw content for the whole turn. The build is attempted at
most once per turn on the failure path too. The one intended difference: a turn that never reads the
registry (the native-vision skip) no longer fails just because a build it does not need would have
thrown.

No new I/O and no new catalog read are introduced by this change. The success path's own control
flow changes only in when the registry is built, never in what it reads, returns, or does with I/O.

What does not change: buildMediaUnderstandingRegistry itself, the resolution's own
all-eligible-owners shape for the mediaUnderstandingProviders key (see Evidence's root-cause trace),
hasExplicitImageUnderstandingConfig's matching logic, and every downstream resolution function's own
behavior once it has a concrete registry. This diff only changes when the registry is constructed,
never what it contains or how anything reads it.

Six more shapes worth being explicit about (only the first was also run on the rig; the rest are
argued from source and tests):

  • The two configs that must still build the registry: an explicit tools.media.models entry, and
    a model without image input.
    Both were run on the patched 2026.9.2 build with the ESM load
    trace (Evidence below): with tools.media.models set to one entry the photo turn loaded 242 new
    modules, and with the model's input hot-reloaded to ["text"] it loaded 249, in both cases
    including the bundled vendor provider chunks, the same shape as the unpatched build.
  • A mixed image+audio (or image+video) attachment turn. A turn with both an image and an audio
    attachment resolves the registry exactly once — via audio's own unconditional resolve, sharing the
    same memoized thunk image's call also holds — even though image's own skip branch never reads
    it. Covered by a new regression-test case.
  • Concurrency. Two capability calls can both reach resolveProviderRegistry(...) in the same
    turn. The at-most-once bound holds only because buildMediaUnderstandingRegistry itself is fully
    synchronous; if a future change made the builder asynchronous, this bound would need revisiting.
  • A throwing builder. See "The exception path" above. Covered by two cases in this PR's own
    test file: a failing build on a turn that needs the registry rejects the whole apply, is attempted
    exactly once for an image+audio turn, and writes no decisions to the context; and a builder that
    would throw is never called on the native-vision skip path.
  • An explicit per-capability tools.media.image config. hasExplicitImageUnderstandingConfig
    only ever reads the global cfg.tools?.media?.models list, never a per-capability
    tools.media.image block, so a per-capability config does not change which turns build the
    registry either way — this diff does not touch that decision. Separately, three of runCapability's
    own early returns (config.enabled === false, an attachment-free selection, a scope-denied turn)
    all happen before the native-vision skip check, so those turns now also never build the registry.
    The same holds for processingMode: "files-only".
  • Document/file-only attachments. PDF and other non-image/audio/video attachments never take a
    providerRegistry parameter at all, and every capability's runCapability call returns before
    reading the registry when its own capability's attachments are absent. The eager call built the
    registry for such a turn anyway; after this change it never does.

Evidence

Real-behavior proof from this PR's own build (source build, not a dist patch)

Built from source at 32dcd029 (merge base) and 08fb5a2c (this PR) with pnpm install && pnpm build
in node:24 (Node 24.21.0, pnpm 12.5.0). Each run: fresh gateway process and state dir,
node openclaw.mjs gateway --verbose; one first image turn through a channel plugin's inbound route
(runChannelInboundEvent path; applyMediaUnderstanding is not called directly); model provider
openai-responses with one model declaring input: ["text","image"] as the primary model;
tools.media.models unset; no plugins.allow. ESM first-load trace via module.register, gateway
process only, bucketed by the turn's own start/end. Same 960×1280 JPEG (143,737 bytes) every run.

run build modules first-loaded during the turn provider-registry cascade bundled media-understanding-provider.js loaded image bytes the model received turn
A1–A3 base 32dcd029 590 / 589 / 589 284 / 283 / 283 8 (codex, deepinfra, groq, mistral, moonshot, opencode, qwen, zai) 263108 ×3 delivered ×3
B1–B3 PR 08fb5a2c 306 / 306 / 306 0 0 263108 ×3 delivered ×3
C1–C2 PR + tools.media.models: [{provider, capabilities:["image"]}] 590 / 590 284 8 263108 ×2 delivered ×2 (entry has no model → "requires model id", native fallback)
C3 PR + same entry with model 591 284 8 143737 (understanding) + 263108 delivered; Media understanding image: success (1/1)

B's load set is a strict subset of A's (B − A = 0). The cascade on the base runs before the skip
decision (A1):

LOAD t=16:19:47.662Z dist/apply-Dlz0xkJL.mjs
LOAD t=16:19:47.725Z … 16:19:47.927Z  dist/extensions/{deepinfra,groq,mistral,moonshot,opencode,qwen,zai,codex}/media-understanding-provider.js
16:19:48.233 Skipping image understanding: primary model supports vision natively

Delivery line from the model mock, identical on base and PR:
{"path": "/v1/responses", "model": "gpt-5.4", "input_items": 3, "has_image_input": true, "input_images": [{"has_data_url": true, "decoded_bytes": 263108, "detail": "auto"}]}

Scope note: with a restrictive plugins.allow that omits the bundled media providers, the base
already loads none of them (bundled plugins outside the allowlist are not registry candidates on
this main), so base and PR are identical there (295/296 modules, 3+3 runs, plus 2 runs with
tools.media.models) — the PR is neutral in that configuration.

Regression tests in the repo toolchain (node scripts/run-vitest.mjs, Node 24.21.0):

  • apply.provider-registry-lazy.test.ts: 6 passed (6), including "a registry build failure still
    rejects the whole apply (caller's raw-content fallback), built once" and "a registry that would
    fail to build is never built on the native-vision skip path"; Duration 48.67s
  • runner.vision-skip.test.ts: 22 passed (22); Duration 41.09s
  • src/media-understanding/: Test Files 48 passed | 1 skipped (49), Tests 654 passed | 5 skipped
    (659) (skips are the Windows-only file-URL tests); Duration 75.26s

Earlier measurements on a dist-level patch of the released 2026.9.2

Kept for the memory and latency effect size: the source-build runs above carry the ESM trace hook,
which adds per-module cost, so they are proof of mechanism, not an effect-size measurement.

Rig: a local Docker container rig (not upstream CI), cgroup v1, memory capped at -m 1g — the
rig numbers below are sandbox numbers, not measurements from a real deployment by themselves; a staging-deployment
deployment's numbers follow separately, as context only.

Root-cause trace: the exact resolution gate on both OpenClaw versions checked

applyMediaUnderstanding calls buildProviderRegistry(params.providers, cfg) — an alias for
buildMediaUnderstandingRegistry — which, when given no preparedProviders, calls
resolvePluginCapabilityProviders({key: "mediaUnderstandingProviders", cfg}). The mechanism differs
between the pinned tag this report's rig measured and current main, and is not, on either
version, "narrows only when a caller supplies a provider id" or "falls back to every plugin only when
the active provider id fails to match a bundled one". The 249-module symptom below is rig-measured;
the exact gate that produces it on the pinned tag is a source read, not something this rig observed
firing directly:

  • On v2026.9.2: mediaUnderstandingProviders is not in the set of keys whose manifest providers
    always merge when active, and the requested-provider-id collector for this key reads only
    cfg.tools.media.models — never the active/configured provider id. With this report's own config
    (tools.media.models unset), requested is empty, so the resolver reaches its own
    already-active short-circuit test, activeProviders.length > 0 && !requestedProviders && !mergeManifestProviders. activeProviders for this key is itself filtered by plugins.allow, and
    the fallback load path that reaches the 249 modules always passes activate: false, so nothing
    loaded through that path ever registers as active for a later call either. Whether
    activeProviders.length is 0 because "nothing of this capability type has activated yet" (a
    fresh-process, first-call-only reading) or because, on this report's own config, it can never
    become non-zero at all
    is unresolved by this rig — either reading falls through to the same
    unfiltered plugin-id resolution (no providerId, no providerIds), which matches every plugin that
    declares the contract at all. This is the path this report's rig measured (249 modules); on neither
    reading is the gate "the provider id doesn't match a bundled plugin".
  • On current main (source read, not separately rig-measured): the always-merge-when-active set
    was extended to also cover mediaUnderstandingProviders, and the requested-id collector for this key
    no longer feeds a requested-id set under any config. Because mergeManifestProviders is now
    unconditionally true for this key, the short-circuit can never fire — every call falls through to
    the same plugin-id resolution described above, on every call, not just the first one in a
    fresh process, regardless of whether anything is already active for this key. Candidates are still
    filtered by control-plane policy (isManifestPluginAvailableForControlPlane): a bundled plugin
    outside a restrictive plugins.allow is not a candidate unless one of its channels is configured or
    bundled-provider compat discovery is on. So on main, the eager full-plugin load is reached by any
    config without such an allowlist, which is the default. Both sides of that were measured on a source
    build of 32dcd029 (see the source-build proof above): 8 bundled providers loaded without an
    allowlist, none with this project's allowlist.

What the patched runs measured: a dist-level patch on 2026.9.2, not this diff. In
dist/apply-DQXe2OOG.js the eager buildProviderRegistry(params.providers, cfg) call was replaced
by a lazily-built new Proxy({}, {get, has}) whose get/has traps build the real registry on
first access. On the measured path nothing touches the registry, so the Proxy and this diff's
memoized thunk behave the same there; this diff's runner.ts changes (the typed resolve calls) were
not part of the measured build. Every patched run below used that same Proxy replacement; every
unpatched A/B run used the same image with the original dist/apply-DQXe2OOG.js bind-mounted back
over it.

Effect size: clean, uninstrumented A/B, 5 fresh containers per variant, 2026-09-26. Same image,
config and 960×1280 JPEG photo (143,737 B); no Node preloads; the gateway's VmRSS read from
/proc/<pid>/status. Each container: one text-only warm-up turn, then the first photo turn. +Peak
is the highest sample from the start of the photo turn to 5 s after it returned, over the settled
pre-photo baseline. Both variants already carry the sibling native-vision-probe patch: "unpatched"
here is that patch alone, "build deferred" is both patches:

Variant (median of 5) Baseline Peak +Peak (range) first-photo elapsedMs (range)
unpatched (native-vision-probe only) 401.4 MiB 474.8 MiB +70.9 MiB (+67.8…+73.4) 1616 (1526…1668)
build deferred (both patches) 397.1 MiB 462.8 MiB +65.9 MiB (+64.5…+66.7) 1399 (1282…1405)

Peak and latency separate cleanly (every deferred run's peak and latency below every unpatched run's
own range). So the eager build costs about 5 MiB of peak RSS and about 0.2 s on the first photo turn
of a process — real, and small. Every decoded_bytes value the model mock logged across the A/B was
263108, so the image reached the model natively on both variants.

As context only: the same host's staging-deployment numbers, dominated by the other fix. On a staging
deployment (real Telegram photo through the deployment's own channel-inbound turn path, Azure VM
host, cgroup v2, 1200 MiB container memory limit, OpenClaw 2026.9.2 with this fix and the
native-vision fix (#159232) both applied, uninstrumented — real openclaw-gateway process VmRSS at
1 Hz), a fresh gateway's first photo (960×1280 JPEG, 143,737 bytes) measured baseline 436.5 MiB, peak
+58.2 MiB, settled at 120 s +54.3 MiB, thread count 11 → 11; the same host's pre-fix measurement
(neither fix applied, same photo shape) went 425.7 → 718.3 MiB (+292.6 MiB) on one photo, and on a
heavier assistant crossed the 1200 MiB limit and was kernel-OOM-killed
(anon-rss:1187204kB). That combined-effect number is not this fix's own size — per the rig A/B
above, this fix's own share is small (about 5 MiB of the roughly 227 MiB saved); the dominant share is
#159232's fix. Included here only as deployment context for the same code path.

Mechanism (ESM load trace), the registry-still-built control runs, and the secondary instrumented attribution set

Mechanism: ESM loader-hook trace (module.register) — the robust signal, since a module count
does not depend on how RSS is sampled or on what else is loaded in-process. Separate runs from the
A/B, 960×1280 JPEG photo, same image before and after the patch, each photo turn sent right after
one text-only warm-up turn in a fresh gateway process:

profsmoke (unpatched, photo turn): 249 first-loaded modules -- excerpt:
file:///usr/local/lib/node_modules/openclaw/dist/apply-DQXe2OOG.js
file:///usr/local/lib/node_modules/openclaw/dist/gemini-web-search-provider-BeX2RNTy.js
file:///usr/local/lib/node_modules/openclaw/dist/minimax-web-search-provider-Cp0SzvUg.js
file:///usr/local/lib/node_modules/openclaw/dist/realtime-voice-provider-factory-B9nV9wg6.js
file:///usr/local/lib/node_modules/openclaw/dist/tts-C8ig6oIX.js
file:///usr/local/lib/node_modules/openclaw/dist/xai-oauth-entry-C77mqHiR.js

proftext (unpatched, text-only turn): 10 first-loaded modules -- all shown (generic
settle-window/session-utils modules, not provider plugins):
file:///usr/local/lib/node_modules/openclaw/dist/command-poll-backoff-DeKW-baq.js
file:///usr/local/lib/node_modules/openclaw/dist/command-poll-backoff.runtime-BN5DegRr.js
file:///usr/local/lib/node_modules/openclaw/dist/command-poll-backoff.runtime.js
file:///usr/local/lib/node_modules/openclaw/dist/installed-plugin-index-records-DGtSxIvi.js
file:///usr/local/lib/node_modules/openclaw/dist/managed-npm-retention-D-XbPuXW.js
file:///usr/local/lib/node_modules/openclaw/dist/placement-session-runtime-sgw8-ikl.js
file:///usr/local/lib/node_modules/openclaw/dist/server-retained-plugin-cleanup-DSzsOO27.js
file:///usr/local/lib/node_modules/openclaw/dist/service-Chz8JfM5.js
file:///usr/local/lib/node_modules/openclaw/dist/session-utils-BBUt1qHh.js
file:///usr/local/lib/node_modules/openclaw/dist/tool-result-truncation-D1rCMIMx.js

lazyprof2 (patched, photo turn): 29 first-loaded modules -- excerpt, all of
them (runner.js/apply.js's own dependency graph, the image codec, or generic
per-turn plumbing), none of them provider-vendor plugins:
file:///usr/local/lib/node_modules/openclaw/dist/apply-DQXe2OOG.js
file:///usr/local/lib/node_modules/openclaw/dist/media-understanding/apply.runtime.js
file:///usr/local/lib/node_modules/openclaw/dist/runner-3MXvZszK.js
file:///usr/local/lib/node_modules/openclaw/dist/runner.entries-B6FlBFiO.js
file:///usr/local/lib/node_modules/openclaw/node_modules/@silvia-odwyer/photon-node/photon_rs.js

Reproduced with a second trace hook. A second loader hook, one fresh container per variant,
counted only the load lines inside the photo turn's own window:

Setup unpatched build deferred Vendor provider chunks in the turn window
agent added to the already-running gateway beforehand (that step itself first-loads 136 modules), then the photo turn 245 25 unpatched: 10 (gemini-cli-provider-*, music-generation-provider-* ×2, realtime-voice-provider-* ×2, realtime-voice-provider-factory-*, video-generation-provider-* ×3, xai-oauth-entry-*); deferred: none
the photo turn is the agent's very first turn (so it also first-loads those ~136) 374 154 unpatched: several (gemini-cli-provider-*, music-generation-provider-*, realtime-voice-provider-*, …); deferred: none

Counts are comparable only within a row, not across rows; both rows put the cascade at about 220
modules, consistent with the 249 → 29 pair above. One further patched run with the first hook recorded
249 first-loaded modules, the unpatched count, and this rig could not determine why (candidates not
ruled out: the patched dist not being mounted for that one run, or some other run-to-run rig
variation); its photo-turn latency (2484 ms) is close to the unpatched trace run's (2567 ms) and far
from the other patched run's (1507 ms), which fits the first candidate but does not prove it.

The registry is still built where it is needed (patched build, ESM trace). Two more fresh
containers on the patched image, each with its config edited before the photo turn, counted new
module loads between a settled log before the turn and a settled log after it:
tools.media.models set to [{"provider":"usage-proxy","model":"gpt-5.4","capabilities":["image"]}]
→ 242 new module loads; the model's input hot-reloaded to ["text"] → 249. Both include the
bundled vendor provider chunks, the same shape as the unpatched build.

Secondary, instrumented: attribution runs under in-process preloads. Before the A/B, single
attribution runs on the same image and photo carried in-process preloads (V8 heap sampling, an ESM
load-trace hook, and image-codec/worker tracers) and sampled RSS every 0.1 s. Their unpatched deltas
are much larger than the uninstrumented A/B's, so they are not the effect size; kept because the
no-resize and text-only controls exist only in this set:

Run (instrumented) +Peak RSS elapsedMs decoded_bytes
unpatched (rig-attr1, one run) +184.7 MiB 1992 263108
unpatched (rig-smoke1, one run) +165.1 MiB 2041 263108
build deferred (rig-lazyreg1..3, median of 3: +68.8, +67.4, +75.4) +68.8 MiB 1163 (1165, 1163, 1086) 263108
no-resize control, unpatched (rig-noresize1, one run; a photo that needs no resize/decode call) +132.6 MiB 1457 145914
text-only control (rig-text1, one run) +12.2 MiB 368 n/a

decoded_bytes identical (263108) across the runs sharing the same source photo confirms the image
reaches the model natively in every one of them; the no-resize control's own decoded_bytes (145914)
is its own differently sized source photo, delivered unresized. A traced A/B isolating the ESM
load-trace hook (3 fresh containers per variant, ~9 Hz) measured +72.1 MiB / 1969 ms unpatched vs.
+61.0 MiB / 1142 ms deferred — it reproduces the latency gap but not the memory gap (the hook adds
~50 MiB to the baseline, not the turn); the likely explanation for the rest of the unpatched peak in
this set is the remaining preloads, not established further.

Regression test — run locally, quoted below (disclosing honestly what was run locally and what is
left to CI):
a faithful extraction of this diff's two new pieces (resolveProviderRegistry, and
both the Before and After bodies of hasExplicitImageUnderstandingConfig) plus a minimal stand-in for
runCapability's own statement order around the skip branch, run in an isolated scratch directory
(npm i -D vitest typescript @types/node) on **Node 22.22.2 — not this repo's own `>=24.16.0 <25 ||

=26.1.0floor**; the tested logic is plain closures,Array.prototype.some, and object/function-type checks with no Node-version-sensitive behavior, so this is a reasonable substitute, but CI should still run the real regression test (below) on the real floor. 13 cases: the native-vision-skip and still-builds-it-as-before cases; a mixed image+audio turn (built exactly once, not zero and not twice); a throwing builder is not memoized by ??=and is retried on the next read in the same turn (standalone only; this described the first revision, and the second commit replaced that behavior with a memoized failure that is rethrown to the caller, covered by the repo-toolchain tests above); and a direct demonstration that reverting the fix's laziness (resolving the registry outside the.some()` predicate instead of inside it) breaks exactly the tests
that guard the property:

$ npx vitest run lazy-provider-registry.test.ts

 RUN  v5.0.2 /scratch/lazy-registry-standalone

 Test Files  1 passed (1)
      Tests  13 passed (13)
   Start at  01:07:48
   Duration  288ms (transform 69%, import 20%, tests 7%, worker 3%)

$ npx tsc --version
Version 7.0.2

$ npx tsc --noEmit --strict --noUncheckedIndexedAccess --target es2022 --module esnext \
    --moduleResolution bundler --types node --skipLibCheck \
    lazy-provider-registry.ts lazy-provider-registry.test.ts
$ echo $?
0

Regression-guard check (reverting the After variant to resolve the registry before .some()
instead of inside its predicate — the exact regression this fix must not reintroduce). The run's
FAIL, AssertionError and summary lines, verbatim; all other output lines omitted:

 FAIL  lazy-provider-registry.test.ts > hasExplicitImageUnderstandingConfig: Before forces an eager registry, After does not > After: an empty models array never calls the factory at all
AssertionError: expected "vi.fn()" to not be called at all, but actually been called 1 times
 FAIL  lazy-provider-registry.test.ts > evaluateImageTurn: the fix's end-to-end shape (mirrors runCapability's own skip-check ordering) > native vision active + no explicit media config -> registry factory never built
AssertionError: expected "vi.fn()" to not be called at all, but actually been called 1 times
 FAIL  lazy-provider-registry.test.ts > evaluateImageTurn: the fix's end-to-end shape (mirrors runCapability's own skip-check ordering) > mixed image+audio turn: image's own skip branch never reads the registry, audio's non-skip path does -- built exactly once, not zero and not twice
AssertionError: expected "vi.fn()" to not be called at all, but actually been called 1 times
 Test Files  1 failed (1)
      Tests  3 failed | 10 passed (13)

Repository regression test in upstream CI, current head 08fb5a2c (Node 24.21.0, vitest 5.0.1):
apply.provider-registry-lazy.test.ts passed 6/6 in
checks-node-changed-compact-large-34
(shard core-runtime-media-ui-support; the job was cancelled later by fail-fast, after this file had
passed). Verbatim, shard prefix removed:

 ✓  media-understanding  src/media-understanding/apply.provider-registry-lazy.test.ts > applyMediaUnderstanding - lazy provider registry > native vision active, no explicit tools.media.models -> registry never built 4ms
 ✓  media-understanding  src/media-understanding/apply.provider-registry-lazy.test.ts > applyMediaUnderstanding - lazy provider registry > native vision active, but an explicit tools.media.models entry is configured -> registry built as before 2ms
 ✓  media-understanding  src/media-understanding/apply.provider-registry-lazy.test.ts > applyMediaUnderstanding - lazy provider registry > a non-vision active model -> registry built as before (catalog fallback path) 1ms
 ✓  media-understanding  src/media-understanding/apply.provider-registry-lazy.test.ts > applyMediaUnderstanding - lazy provider registry > mixed image+audio attachment turn: image's own skip branch never reads the registry, audio's non-skip path does -- built exactly once 5ms
 ✓  media-understanding  src/media-understanding/apply.provider-registry-lazy.test.ts > applyMediaUnderstanding - lazy provider registry > a registry build failure still rejects the whole apply (caller's raw-content fallback), built once 2ms
 ✓  media-understanding  src/media-understanding/apply.provider-registry-lazy.test.ts > applyMediaUnderstanding - lazy provider registry > a registry that would fail to build is never built on the native-vision skip path 1ms

Measured cost: 15 ms of test time for the 6 cases in CI. check-lint, check-prod-types, and
check-test-types (all stripes) pass on 08fb5a2c.

CI status of the current head. The one red node shard is
checks-node-changed-compact-large-9:
src/gateway/session-history-worker.integration.test.ts > waits for a missing projection and serves the original history request (SessionTranscriptProjectionUnavailableError, reason: 'rebuilding').
That is gateway transcript-projection code this PR does not touch; the same test failed the same way
on the unrelated #159232, and I found no [CI] issue for it. Earlier heads: check-lint failed on
oxfmt line-wrapping in the new test file (ours, fixed); the other red shards were
session-catalog.performance.test.ts and Slack ingress.test.ts (not ours; the latter fixed on main
by 02fd48695).

Additional maintainer verification

Exact-head Gateway controls, live GPT-4.1-mini image proof, focused tests, and inherited CI attribution.

No overlap with Pash/Sarah changes.

@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 5:26 PM ET / 21:26 UTC (Revision 7).

ClawSweeper review

What this changes

The PR defers loading media-understanding providers until attachment processing needs them, while preserving raw-content recovery when loading fails.

Merge readiness

✅ Ready for maintainer review

This PR remains necessary: current main and the latest release still perform the unused registry build. The earlier fallback finding is fixed, the recorded runtime proof covers the changed path, and no blocking patch defect remains.

Priority: P2
Reviewed head: 08fb5a2cc52bd11190403f570bd56ed8eba0183f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct repair with strong production-boundary evidence and the prior recovery defect resolved.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): Exact-head source-build Gateway inbound image turns exercise applyMediaUnderstanding and show the unused registry cascade avoided while image delivery succeeds; required-provider and injected-error controls preserve understanding and raw-content recovery. Additional real-provider image turns corroborate delivery. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (logs): Exact-head source-build Gateway inbound image turns exercise applyMediaUnderstanding and show the unused registry cascade avoided while image delivery succeeds; required-provider and injected-error controls preserve understanding and raw-content recovery. Additional real-provider image turns corroborate delivery. No stored-data contract changes.
Evidence reviewed 9 items Verified introduced patch: The pinned merge-base-to-head delta changes only registry construction, registry resolution, and six focused regression cases. Endpoint drift and the stale test merge were not used to attribute changes.
Still needed on current main and release: Fetched main retains the eager build before capability execution; inspection of v2026.9.7 shows the same eager call. The production-file comparison confirms main has neither the lazy factory nor the error memoization.
Prior fallback finding resolved: The factory memoizes construction errors, and apply rethrows after capability settlement but before publishing context changes. Both preprocessing callers catch that exception and continue with raw content. Existing concrete-map callers remain supported.
Findings None None.
Security None None.

How this fits together

Media understanding preprocesses incoming image, audio, and video attachments before the agent replies. Images supported natively by the active model bypass provider processing and continue directly to the model.

flowchart TD
  A[Incoming attachments] --> B[Media preprocessing]
  B --> C{Provider processing needed?}
  C -->|No| D[Native image delivery]
  C -->|Yes| E[Shared lazy provider registry]
  E --> F[Attachment understanding]
  E -->|Build fails| G[Raw-content recovery]
  D --> H[Agent reply]
  F --> H
  G --> H
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +32, Tests +165. Total +197 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 40 8 +32
Tests 1 165 0 +165
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 205 8 +197

Review metrics

Metric Value Why it matters
Regression execution cost 6 cases; 15 ms combined CI test time The new suite protects load avoidance, required discovery, sharing, and failure recovery at low measured execution cost.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #159233
Summary: This PR owns the registry-load repair; the neighboring catalog-load work is complementary and distinct.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Keep provider discovery demand-driven within the existing preprocessing owner, sharing one successful build or failure across the turn.

Do we have a high-confidence way to reproduce the issue?

Yes: current main visibly builds the registry before the native-vision skip, and recorded isolated Gateway comparisons reproduce that unnecessary load. This read-only review did not execute contributor code.

Is this the best way to solve the issue?

Yes: deferring the existing synchronous builder preserves one registry owner, existing callers, provider selection, and raw-content fallback without adding configuration or a parallel implementation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 61485d58172b.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded first-attachment performance repair with successful delivery preserved and no independently proven urgent outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): Exact-head source-build Gateway inbound image turns exercise applyMediaUnderstanding and show the unused registry cascade avoided while image delivery succeeds; required-provider and injected-error controls preserve understanding and raw-content recovery. Additional real-provider image turns corroborate delivery. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. Exact-head source-build Gateway inbound image turns exercise applyMediaUnderstanding and show the unused registry cascade avoided while image delivery succeeds; required-provider and injected-error controls preserve understanding and raw-content recovery. Additional real-provider image turns corroborate delivery. No stored-data contract changes.

Evidence

What I checked:

  • Verified introduced patch: The pinned merge-base-to-head delta changes only registry construction, registry resolution, and six focused regression cases. Endpoint drift and the stale test merge were not used to attribute changes. (src/media-understanding/apply.ts:152, 08fb5a2cc52b)
  • Still needed on current main and release: Fetched main retains the eager build before capability execution; inspection of v2026.9.7 shows the same eager call. The production-file comparison confirms main has neither the lazy factory nor the error memoization. (src/media-understanding/apply.ts:152, 61485d58172b)
  • Prior fallback finding resolved: The factory memoizes construction errors, and apply rethrows after capability settlement but before publishing context changes. Both preprocessing callers catch that exception and continue with raw content. Existing concrete-map callers remain supported. (src/media-understanding/apply.ts:204, 08fb5a2cc52b)
  • Contributor proof and captured body identity: The retrieved body matches captured SHA-256 4ff5e2ddde95e1078d69a5f63caadebdef7db45193c4414199c7ee8fb192eedb. Exact-head source-build Gateway inbound turns record zero provider cascade loads versus 283–284 on the baseline, identical image delivery, and successful explicit-provider controls. Historical dist-patch measurements are distinguished from this source-build proof. (08fb5a2cc52b)
  • Additional production-boundary verification: fix: first image turn loads every bundled media-understanding provider plugin even when the model handles the image natively #159234 (comment) records unchanged-head Gateway comparisons, successful text-only-model understanding, injected registry-error raw-content recovery, and two real GPT-4.1-mini image turns recognizing the synthetic image with zero registry builds. RSS samples are explicitly inconclusive about memory savings. (08fb5a2cc52b)
  • Regression coverage and CI distinction: The body records six cases passing with 15 ms combined CI test time; additional verification records 28 focused tests and the exact 425-test media slice passing. The existing CI run remains failed/cancelled, with the reported substantive failure in transcript-projection rebuilding outside the introduced patch. These observations do not establish a green CI gate. (src/media-understanding/apply.provider-registry-lazy.test.ts:70, 08fb5a2cc52b)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (6 earlier review cycles)
  • reviewed 2026-09-26T22:59:36.470Z sha 539db8381c4edfe5bf6566718e4492ee0f59d64b :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-26T23:07:21.023Z sha 539db8381c4edfe5bf6566718e4492ee0f59d64b :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-27T12:23:20.530Z sha 4ae2627 :: needs real behavior proof before merge. :: [P1] Preserve the raw-content fallback on registry-build errors
  • reviewed 2026-09-27T13:19:00.529Z sha 4ae2627 :: needs real behavior proof before merge. :: [P1] Preserve raw-content recovery when registry construction fails
  • reviewed 2026-09-27T13:43:15.567Z sha 08fb5a2 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-27T18:57:16.407Z sha 08fb5a2 :: needs maintainer review before merge. :: none

…r plugin even when the model handles the image natively

applyMediaUnderstanding built the full media-understanding provider registry
unconditionally, before any capability handler ran -- even on a turn whose
native-vision skip branch (runner.ts) never reads it. Defer the build behind
a memoized factory shared across the turn's capabilities, and resolve it
lazily in the one pre-skip-decision reader
(hasExplicitImageUnderstandingConfig) and once, up front, in every other
runCapability path that already needs it.

Adds apply.provider-registry-lazy.test.ts covering the skip-and-never-build
case, the two unchanged catalog-load cases (explicit tools.media.models,
non-vision model), and a mixed image+audio attachment turn (built exactly
once, shared by both capabilities).
@alexeysophia
alexeysophia force-pushed the fix/lazy-media-provider-registry branch from 539db83 to 4ae2627 Compare September 27, 2026 12:13
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 27, 2026
@alexeysophia

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The new regression test now has a CI result. On head 4ae26279, apply.provider-registry-lazy.test.ts passed 4/4 in upstream CI (job) using 17 ms of test time, inside a 32.31 s sub-shard. Verbatim output is in the Evidence section. Otherwise the head differs from 539db838 only by an oxfmt reformat of the test file (which was our check-lint failure) and a rebase onto main@32dcd029; no production line changed. The one red node shard (session-catalog.performance.test.ts) is in gateway code this PR does not touch. There is no [CI] issue for it; details are in Evidence. This round does not yet address the exact-build real-turn trace or the registry-build failure-policy question.

@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

…fails to build

Deferring the registry build moved it inside runMediaCapability, whose catch
turned a build exception into a failed decision per capability instead of
letting it escape applyMediaUnderstanding to the caller's raw-content
fallback, as the eager build did. Memoize the build failure (no retry per
capability) and rethrow it once the capabilities settle, before any context
mutation, so the whole-turn fallback behaves as before.
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 27, 2026
@alexeysophia

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Both open items are addressed on head 08fb5a2c.

[P1] Preserve raw-content recovery when registry construction fails: fixed in code, no policy change requested. The second commit (08fb5a2c) memoizes a registry build failure in applyMediaUnderstanding and rethrows it right after the capability loop, before MediaUnderstandingDecisions or any other context field is written. The caller (applyMediaUnderstandingIfNeeded, dispatch-acp.ts) therefore sees the same exception as with the eager build and falls back to raw content for the whole turn. The build is attempted at most once per turn on the failure path too, so capabilities no longer retry it. The only intended difference: a native-vision turn that never reads the registry no longer fails because a build it does not need would have thrown. Two new cases in apply.provider-registry-lazy.test.ts cover this. The first: a failing build on an image+audio turn rejects the whole apply, is attempted once, and leaves no decisions in the context. The second: a builder that would throw is never called on the skip path. 6/6 pass in upstream CI on this head (job). The "disclosed behavior change" text is removed from the body, since that behavior no longer exists.

Real behavior proof from this PR build. Evidence now opens with a source build of this head and of the merge base 32dcd029 (pnpm install && pnpm build, Node 24.21.0, pnpm 12.5.0). Each run is a fresh gateway process with one first image turn through a channel plugin inbound route (runChannelInboundEvent), measured with an ESM first-load trace:

  • base: 589–590 modules first-loaded during the turn, 284 of them the registry cascade (the media-understanding-provider.js of 8 bundled plugins), loaded before Skipping image understanding: primary model supports vision natively;
  • this PR: 306 modules and no cascade (n=3 each), with the same decoded_bytes (263108) reaching the model on every run;
  • with tools.media.models set, the PR still builds the registry and the turn completes, including a successful understanding call.

In the same section, the regression tests in the repo toolchain: 6/6 in the new file, 22/22 in runner.vision-skip.test.ts, and 654 passed / 5 skipped (Windows-only) across src/media-understanding/.

Scope correction. The source build also showed that on main a restrictive plugins.allow keeps non-allowlisted bundled providers out of the registry candidates. With such an allowlist, base and this PR load the same modules, so the change is neutral there. I corrected the root-cause section, which had claimed the opposite from a source read, and the User Impact now states this.

The red compact-large-9 shard is session-history-worker.integration.test.ts, which is gateway code this PR does not touch. It failed the same way on the unrelated #159232; I found no [CI] issue for it.

@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 27, 2026
@obviyus

obviyus commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Additional maintainer verification on unchanged head 08fb5a2cc52bd11190403f570bd56ed8eba0183f:

  • Reproduced the eager registry build on current main 3dd99d187a2120f4032c0766159800d5c8e3df8e through an isolated, built Gateway and a channel-inbound image turn. The six regression cases fail twice on main (unused registry built; unused failing registry aborts preprocessing) and all pass on the candidate.
  • Compared the candidate with a matched revert baseline (its two production files restored from 32dcd02906ef4b2d7fbc5479d57dfb90a2ccdea9). Two fresh Gateways per variant, Node 24.16.0/Linux arm64, same synthetic PNG and mock OpenAI endpoint. Import tracing recorded one registry build per baseline turn and zero on the candidate; extension-file loads during the turn were 170 versus 54. Both variants delivered the original image to the model and delivered the final reply.
Measurement Revert baseline Candidate
First-turn latency, two samples 2509 / 2515 ms 2377 / 2305 ms
Sampled process peak RSS 1501.3 / 1513.6 MiB 1546.8 / 1494.0 MiB

These are instrumented rig observations, not a general benchmark. Module avoidance is clear; RSS noise in these samples does not establish a memory saving.

Controls also passed through fresh Gateways: a text-only primary model built the registry, successfully described the image through media understanding, and returned the final reply; an injected registry-construction error reached the whole-turn raw-content fallback and still delivered the image and reply.

The real-provider gate passed twice on openai/gpt-4.1-mini: each fresh Gateway's first image turn described a red square and transcribed P159233, with zero registry builds. There were six small-model POST starts rather than the intended four-call ceiling because ambient utility recaps also ran (four HTTP-200 responses were captured). No further live calls were made; the temporary credential and live container were deleted.

Focused candidate checks: 28 tests passed across the lazy-registry and native-vision files. The exact 32-file media-understanding slice from cancelled CI job checks-node-changed-compact-large-34 also passed locally: 425 tests, 26.44 s wrapper wall time. This does not claim a replay of every unrelated cancelled shard.

CI remains red on the existing contributor run, not from a new push: run 36322984494. The substantive failure is checks-node-changed-compact-large-9, session-history-worker.integration.test.ts > waits for a missing projection and serves the original history request, raising SessionTranscriptProjectionUnavailableError with reason rebuilding. The same case and error occur on the separate PR #159232 run 36318301355; transcript-projection worker rebuilding is outside this media-registry diff. openclaw/ci-gate fails consequently. There are 37 cancelled jobs. No jobs were rerun and no push was made merely to refresh CI.

The contributor's commits and credit are unchanged; #159232 remains separate and was not folded into this PR.

@obviyus

obviyus commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Maintainer override on head 08fb5a2cc52bd11190403f570bd56ed8eba0183f. ClawSweeper's exact-head review is ready.

Red CI and cancelled coverage (run 36322984494):

Proof: a fresh built Gateway.

  • main: builds the media provider registry eagerly on the first image turn.
  • This head: doesn't build it, and still delivers the image. Extension-file loads drop from 170 to 54, and first-turn latency from about 2.5 s to 2.3–2.4 s.
  • Controls: non-vision media understanding and the whole-turn fallback still work.
  • Live check on this head: real gpt-4.1-mini correctly described a test image (a red square with the text P159233), and the registry was never built.

Evidence: #159234 (comment)

@obviyus
obviyus merged commit 6d5bb1b into openclaw:main Oct 1, 2026
191 of 231 checks passed
@obviyus

obviyus commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Landed as 6d5bb1b. Thanks @alexeysophia, and congrats on your first OpenClaw PR!

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 2, 2026
…r plugin even when the model handles the image natively (openclaw#159234)

* fix: first image turn loads every bundled media-understanding provider plugin even when the model handles the image natively

applyMediaUnderstanding built the full media-understanding provider registry
unconditionally, before any capability handler ran -- even on a turn whose
native-vision skip branch (runner.ts) never reads it. Defer the build behind
a memoized factory shared across the turn's capabilities, and resolve it
lazily in the one pre-skip-decision reader
(hasExplicitImageUnderstandingConfig) and once, up front, in every other
runCapability path that already needs it.

Adds apply.provider-registry-lazy.test.ts covering the skip-and-never-build
case, the two unchanged catalog-load cases (explicit tools.media.models,
non-vision model), and a mixed image+audio attachment turn (built exactly
once, shared by both capabilities).

* fix(media): keep the raw-content fallback when the provider registry fails to build

Deferring the registry build moved it inside runMediaCapability, whose catch
turned a build exception into a failed decision per capability instead of
letting it escape applyMediaUnderstanding to the caller's raw-content
fallback, as the eager build did. Memoize the build failure (no retry per
capability) and rethrow it once the capabilities settle, before any context
mutation, so the whole-turn fallback behaves as before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

2 participants