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

推荐订阅源

宝玉的分享
宝玉的分享
B
Blog RSS Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
MyScale Blog
MyScale Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
Y
Y Combinator Blog
月光博客
月光博客
IT之家
IT之家
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
L
LangChain Blog
博客园_首页
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
博客园 - Franky
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
V
Visual Studio Blog
小众软件
小众软件
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
N
Netflix TechBlog - Medium

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(gateway): route text-only chat images to media unders...
steipete · 2026-04-28 · via Recent Commits to openclaw:main

@@ -794,28 +794,45 @@ function buildChatSendTranscriptMessage(params: {

794794

};

795795

}

796796797-

// Stages non-image offloads into the agent sandbox synchronously so chat.send

797+

function stripTrailingOffloadedMediaMarkers(message: string, refs: OffloadedRef[]): string {

798+

if (refs.length === 0) {

799+

return message;

800+

}

801+

const removableRefs = new Set(refs.map((ref) => ref.mediaRef));

802+

const lines = message.split(/\r?\n/);

803+

while (lines.length > 0) {

804+

const last = lines[lines.length - 1]?.trim() ?? "";

805+

const match = /^\[media attached:\s*(media:\/\/inbound\/[^\]\s]+)\]$/.exec(last);

806+

if (!match?.[1] || !removableRefs.delete(match[1])) {

807+

break;

808+

}

809+

lines.pop();

810+

}

811+

return lines.join("\n").trimEnd();

812+

}

813+814+

// Stages media-path offloads into the agent sandbox synchronously so chat.send

798815

// can surface 5xx before respond(). Throws MediaOffloadError on any staging

799816

// failure (ENOSPC / EPERM / partial-stage) so the outer chat.send handler can

800817

// map it to UNAVAILABLE (5xx); plain Error would be misclassified as 4xx. All

801818

// offloaded refs are cleaned up from the media store before rethrow.

802819

// Callers MUST set ctx.MediaStaged=true when this runs so the dispatch

803820

// pipeline skips its own stageSandboxMedia pass.

804821

//

805-

// Returned paths are ABSOLUTE (pointing into the sandbox workspace when sandbox

806-

// is enabled, or the media-store origin when it is not). applyMediaUnderstanding

807-

// runs before any further staging in get-reply.ts and uses

808-

// `path.isAbsolute(raw) ? raw : path.resolve(raw)` against the gateway CWD, so

809-

// any relative path here would make media-understanding target the wrong host

810-

// path and silently skip file analysis.

811-

async function prestageNonImageOffloads(params: {

822+

// Returned paths are absolute media-store paths when no sandbox is active, or

823+

// sandbox-relative paths plus `workspaceDir` when sandboxing is active. Host-side

824+

// media-understanding uses MediaWorkspaceDir to resolve those relative paths.

825+

async function prestageMediaPathOffloads(params: {

812826

offloadedRefs: OffloadedRef[];

827+

includeImageRefs?: boolean;

813828

cfg: OpenClawConfig;

814829

sessionKey: string;

815830

agentId: string;

816831

}): Promise<{ paths: string[]; types: string[]; workspaceDir?: string }> {

817-

const nonImage = params.offloadedRefs.filter((ref) => !ref.mimeType.startsWith("image/"));

818-

if (nonImage.length === 0) {

832+

const mediaPathRefs = params.offloadedRefs.filter(

833+

(ref) => params.includeImageRefs || !ref.mimeType.startsWith("image/"),

834+

);

835+

if (mediaPathRefs.length === 0) {

819836

return { paths: [], types: [] };

820837

}

821838

@@ -828,33 +845,33 @@ async function prestageNonImageOffloads(params: {

828845

});

829846

if (!sandbox) {

830847

return {

831-

paths: nonImage.map((ref) => ref.path),

832-

types: nonImage.map((ref) => ref.mimeType),

848+

paths: mediaPathRefs.map((ref) => ref.path),

849+

types: mediaPathRefs.map((ref) => ref.mimeType),

833850

};

834851

}

835852836853

// stageSandboxMedia caps each file at STAGED_MEDIA_MAX_BYTES (=

837854

// MEDIA_MAX_BYTES, 5MB) and silently skips oversized files. The parse cap

838855

// (resolveChatAttachmentMaxBytes, default 20MB) is higher, so a sandboxed

839-

// session receiving a non-image file between the two caps would otherwise

856+

// session receiving a file between the two caps would otherwise

840857

// pass parse, fail staging, and surface as a retryable 5xx even though

841858

// retry cannot succeed. Reject here as a client-side 4xx instead.

842-

const oversizedForSandbox = nonImage.filter((ref) => ref.sizeBytes > MEDIA_MAX_BYTES);

859+

const oversizedForSandbox = mediaPathRefs.filter((ref) => ref.sizeBytes > MEDIA_MAX_BYTES);

843860

if (oversizedForSandbox.length > 0) {

844861

const details = oversizedForSandbox

845862

.map((ref) => `${ref.label} (${ref.sizeBytes} bytes)`)

846863

.join(", ");

847864

throw new UnsupportedAttachmentError(

848865

"non-image-too-large-for-sandbox",

849-

`non-image attachments exceed sandbox staging limit (${MEDIA_MAX_BYTES} bytes): ${details}`,

866+

`attachments exceed sandbox staging limit (${MEDIA_MAX_BYTES} bytes): ${details}`,

850867

);

851868

}

852869853870

const stagingCtx: MsgContext = {

854-

MediaPath: nonImage[0].path,

855-

MediaPaths: nonImage.map((ref) => ref.path),

856-

MediaType: nonImage[0].mimeType,

857-

MediaTypes: nonImage.map((ref) => ref.mimeType),

871+

MediaPath: mediaPathRefs[0].path,

872+

MediaPaths: mediaPathRefs.map((ref) => ref.path),

873+

MediaType: mediaPathRefs[0].mimeType,

874+

MediaTypes: mediaPathRefs.map((ref) => ref.mimeType),

858875

};

859876

const stageResult = await stageSandboxMedia({

860877

ctx: stagingCtx,

@@ -871,14 +888,14 @@ async function prestageNonImageOffloads(params: {

871888

// (STAGED_MEDIA_MAX_BYTES = 5MB); check the returned `staged` map so any

872889

// missing source becomes a 5xx MediaOffloadError the client can retry.

873890

const stagedSources = stageResult.staged;

874-

const missing = nonImage.filter((ref) => !stagedSources.has(ref.path));

891+

const missing = mediaPathRefs.filter((ref) => !stagedSources.has(ref.path));

875892

if (missing.length > 0) {

876893

throw new Error(

877-

`non-image attachment staging incomplete: ${stagedSources.size}/${nonImage.length} paths staged into sandbox workspace (missing: ${missing.map((ref) => ref.path).join(", ")})`,

894+

`attachment staging incomplete: ${stagedSources.size}/${mediaPathRefs.length} paths staged into sandbox workspace (missing: ${missing.map((ref) => ref.path).join(", ")})`,

878895

);

879896

}

880897

const stagedPaths = stagingCtx.MediaPaths ?? [];

881-

const stagedTypes = stagingCtx.MediaTypes ?? nonImage.map((ref) => ref.mimeType);

898+

const stagedTypes = stagingCtx.MediaTypes ?? mediaPathRefs.map((ref) => ref.mimeType);

882899883900

// Keep stagedPaths sandbox-relative (e.g. `media/inbound/foo.pdf`) so the

884901

// agent inside the container can read them. Host-side media-understanding

@@ -897,7 +914,7 @@ async function prestageNonImageOffloads(params: {

897914

throw err;

898915

}

899916

throw new MediaOffloadError(

900-

`[Gateway Error] Failed to stage non-image attachments into agent workspace: ${formatErrorMessage(err)}`,

917+

`[Gateway Error] Failed to stage attachments into agent workspace: ${formatErrorMessage(err)}`,

901918

{ cause: err },

902919

);

903920

}

@@ -1896,9 +1913,9 @@ export const chatHandlers: GatewayRequestHandlers = {

18961913

let parsedImages: ChatImageContent[] = [];

18971914

let imageOrder: PromptImageOrderEntry[] = [];

18981915

let offloadedRefs: OffloadedRef[] = [];

1899-

let nonImageMediaPaths: string[] = [];

1900-

let nonImageMediaTypes: string[] = [];

1901-

let nonImageMediaWorkspaceDir: string | undefined;

1916+

let mediaPathOffloadPaths: string[] = [];

1917+

let mediaPathOffloadTypes: string[] = [];

1918+

let mediaPathOffloadWorkspaceDir: string | undefined;

19021919

const timeoutMs = resolveAgentTimeoutMs({

19031920

cfg,

19041921

overrideMs: p.timeoutMs,

@@ -1971,25 +1988,35 @@ export const chatHandlers: GatewayRequestHandlers = {

19711988

supportsSessionModelImages ||

19721989

explicitOriginTargetsAcpSession(explicitOriginResult.value) ||

19731990

explicitOriginTargetsPlugin;

1991+

const routeImageOffloadsAsMediaPaths = !supportsImages;

19741992

try {

19751993

const parsed = await parseMessageWithAttachments(inboundMessage, normalizedAttachments, {

19761994

maxBytes: resolveChatAttachmentMaxBytes(cfg),

19771995

log: context.logGateway,

19781996

supportsImages,

1979-

// chat.send routes non-image offloadedRefs into ctx.MediaPaths below

1997+

// chat.send routes selected offloadedRefs into ctx.MediaPaths below

19801998

// so the auto-reply stage pipeline can surface them to the agent.

19811999

acceptNonImage: true,

19822000

});

1983-

parsedMessage = parsed.message;

2001+

parsedMessage = stripTrailingOffloadedMediaMarkers(

2002+

parsed.message,

2003+

routeImageOffloadsAsMediaPaths

2004+

? parsed.offloadedRefs.filter((ref) => ref.mimeType.startsWith("image/"))

2005+

: [],

2006+

);

19842007

parsedImages = parsed.images;

1985-

imageOrder = parsed.imageOrder;

2008+

imageOrder = routeImageOffloadsAsMediaPaths ? [] : parsed.imageOrder;

19862009

offloadedRefs = parsed.offloadedRefs;

19872010

({

1988-

paths: nonImageMediaPaths,

1989-

types: nonImageMediaTypes,

1990-

workspaceDir: nonImageMediaWorkspaceDir,

1991-

} = await prestageNonImageOffloads({

2011+

paths: mediaPathOffloadPaths,

2012+

types: mediaPathOffloadTypes,

2013+

workspaceDir: mediaPathOffloadWorkspaceDir,

2014+

} = await prestageMediaPathOffloads({

19922015

offloadedRefs,

2016+

// Text-only image offloads need ctx.MediaPaths so media-understanding

2017+

// can describe them via agents.defaults.imageModel. Vision-capable

2018+

// image offloads stay as prompt refs for native image loading.

2019+

includeImageRefs: routeImageOffloadsAsMediaPaths,

19932020

cfg,

19942021

sessionKey,

19952022

agentId,

@@ -2100,17 +2127,17 @@ export const chatHandlers: GatewayRequestHandlers = {

21002127

GatewayClientScopes: client?.connect?.scopes ?? [],

21012128

...pluginBoundMediaFields,

21022129

};

2103-

if (nonImageMediaPaths.length > 0) {

2104-

// Inject non-image offloads via the same MsgContext fields the channel

2130+

if (mediaPathOffloadPaths.length > 0) {

2131+

// Inject offloads via the same MsgContext fields the channel

21052132

// path uses so buildInboundMediaNote renders a real `[media attached:

21062133

// <workspace-relative-path>]` line into the agent prompt. Marker

21072134

// blocks the dispatch pipeline from re-running stageSandboxMedia; see

2108-

// prestageNonImageOffloads.

2109-

ctx.MediaPath = nonImageMediaPaths[0];

2110-

ctx.MediaPaths = nonImageMediaPaths;

2111-

ctx.MediaType = nonImageMediaTypes[0];

2112-

ctx.MediaTypes = nonImageMediaTypes;

2113-

ctx.MediaWorkspaceDir = nonImageMediaWorkspaceDir;

2135+

// prestageMediaPathOffloads.

2136+

ctx.MediaPath = mediaPathOffloadPaths[0];

2137+

ctx.MediaPaths = mediaPathOffloadPaths;

2138+

ctx.MediaType = mediaPathOffloadTypes[0];

2139+

ctx.MediaTypes = mediaPathOffloadTypes;

2140+

ctx.MediaWorkspaceDir = mediaPathOffloadWorkspaceDir;

21142141

ctx.MediaStaged = true;

21152142

}

21162143