惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

小众软件
小众软件
博客园 - Franky
罗磊的独立博客
G
Google Developers Blog
The GitHub Blog
The GitHub Blog
P
Proofpoint News Feed
Recent Announcements
Recent Announcements
V
V2EX
F
Fortinet All Blogs
阮一峰的网络日志
阮一峰的网络日志
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
U
Unit 42
GbyAI
GbyAI
A
About on SuperTechFans
WordPress大学
WordPress大学
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
Microsoft Azure Blog
Microsoft Azure Blog
Martin Fowler
Martin Fowler
D
DataBreaches.Net
The Cloudflare Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
MongoDB | Blog
MongoDB | Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix: preserve gateway image refs for text-only models · o...
steipete · 2026-04-24 · via Recent Commits to openclaw:main

@@ -59,8 +59,8 @@ export type ParsedMessageWithImages = {

5959

* do not receive these as inline image blocks.

6060

*

6161

* ⚠️ Call sites (chat.ts, agent.ts, server-node-events.ts) MUST also pass

62-

* `supportsImages: modelSupportsImages(model)` so that text-only model runs

63-

* do not inject unresolvable media:// markers into prompt text.

62+

* `supportsImages: modelSupportsImages(model)` so text-only model runs

63+

* offload images as media refs instead of passing inline image blocks.

6464

*/

6565

offloadedRefs: OffloadedRef[];

6666

};

@@ -82,6 +82,7 @@ type SavedMedia = {

8282

};

83838484

const OFFLOAD_THRESHOLD_BYTES = 2_000_000;

85+

const TEXT_ONLY_OFFLOAD_LIMIT = 10;

85868687

const MIME_TO_EXT: Record<string, string> = {

8788

"image/jpeg": ".jpg",

@@ -271,12 +272,9 @@ function validateAttachmentBase64OrThrow(

271272

* because they are not passed inline to the model.

272273

*

273274

* ## Text-only model runs

274-

* Pass `supportsImages: false` for text-only model runs so that no media://

275-

* markers are injected into prompt text.

276-

*

277-

* ⚠️ Call sites in chat.ts, agent.ts, and server-node-events.ts MUST be

278-

* updated to pass `supportsImages: modelSupportsImages(model)`. Until they do,

279-

* text-only model runs receive unresolvable media:// markers in their prompt.

275+

* Pass `supportsImages: false` for text-only model runs so images are offloaded

276+

* as `media://inbound/<id>` refs instead of being sent as inline image blocks.

277+

* The agent runner can then resolve the refs through the normal media path.

280278

*

281279

* ## Cleanup on failure

282280

* On any parse failure after files have already been offloaded, best-effort

@@ -304,22 +302,11 @@ export async function parseMessageWithAttachments(

304302

return { message, images: [], imageOrder: [], offloadedRefs: [] };

305303

}

306304307-

// For text-only models drop all attachments cleanly. Do not save files or

308-

// inject media:// markers that would never be resolved and would leak

309-

// internal path references into the model's prompt.

310-

if (opts?.supportsImages === false) {

311-

if (attachments.length > 0) {

312-

log?.warn(

313-

`parseMessageWithAttachments: ${attachments.length} attachment(s) dropped — model does not support images`,

314-

);

315-

}

316-

return { message, images: [], imageOrder: [], offloadedRefs: [] };

317-

}

318-319305

const images: ChatImageContent[] = [];

320306

const imageOrder: PromptImageOrderEntry[] = [];

321307

const offloadedRefs: OffloadedRef[] = [];

322308

let updatedMessage = message;

309+

const shouldForceOffload = opts?.supportsImages === false;

323310324311

// Track IDs of files saved during this request for cleanup if a later

325312

// attachment fails validation and the entire parse is aborted.

@@ -377,10 +364,26 @@ export async function parseMessageWithAttachments(

377364378365

let isOffloaded = false;

379366380-

if (sizeBytes > OFFLOAD_THRESHOLD_BYTES) {

367+

if (shouldForceOffload && offloadedRefs.length >= TEXT_ONLY_OFFLOAD_LIMIT) {

368+

log?.warn(

369+

`attachment ${label}: dropping image because text-only offload limit ` +

370+

`${TEXT_ONLY_OFFLOAD_LIMIT} was reached`,

371+

);

372+

updatedMessage += "\n[image attachment omitted: text-only attachment limit reached]";

373+

continue;

374+

}

375+376+

if (shouldForceOffload || sizeBytes > OFFLOAD_THRESHOLD_BYTES) {

381377

const isSupportedForOffload = SUPPORTED_OFFLOAD_MIMES.has(finalMime);

382378383379

if (!isSupportedForOffload) {

380+

if (shouldForceOffload) {

381+

log?.warn(

382+

`attachment ${label}: format ${finalMime} cannot be offloaded for ` +

383+

"text-only model, dropping",

384+

);

385+

continue;

386+

}

384387

// Passing this inline would reintroduce the OOM risk this PR prevents.

385388

throw new Error(

386389

`attachment ${label}: format ${finalMime} is too large to pass inline ` +

@@ -418,7 +421,11 @@ export async function parseMessageWithAttachments(

418421

const mediaRef = `media://inbound/${savedMedia.id}`;

419422420423

updatedMessage += `\n[media attached: ${mediaRef}]`;

421-

log?.info?.(`[Gateway] Intercepted large image payload. Saved: ${mediaRef}`);

424+

log?.info?.(

425+

shouldForceOffload

426+

? `[Gateway] Offloaded image for text-only model. Saved: ${mediaRef}`

427+

: `[Gateway] Intercepted large image payload. Saved: ${mediaRef}`,

428+

);

422429423430

// Record for transcript metadata — separate from `images` because

424431

// these are not passed inline to the model.