Skip to content

fix(gateway,ui): restore managed media transcript persistence in webchat - #69500

Closed
Ittiz wants to merge 115 commits into
openclaw:mainfrom
Ittiz:forge/pr2-managed-media-persistence-rebuild
Closed

Ittiz wants to merge 115 commits into
openclaw:mainfrom
Ittiz:forge/pr2-managed-media-persistence-rebuild

Conversation

@Ittiz

@Ittiz Ittiz commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Problem: assistant replies with managed media, especially image-only replies and agent-run audio replies, could render live in webchat/control UI but fail to persist correctly into transcript/history.
  • Why it matters: users could see a reply in the moment, then lose it from chat.history or get inconsistent follow-up rendering/auth behavior on reload.
  • What changed: tightened the managed-image bridge across gateway + UI, limited bridging to full-image previews, fixed transcript injection/persistence for agent-run webchat audio replies, and hardened the relevant test coverage.
  • What did NOT change (scope boundary): this does not add a new media transport model or redesign the overall chat transcript architecture.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

Root Cause (if applicable)

  • Root cause: the agent-started webchat completion path could skip the transcript append fallback used by the non-agent path, so media replies could be delivered live without being durably recorded. Managed-image handling also had UI/gateway edge cases around preview reconciliation and authenticated media access.
  • Missing detection / guardrail: coverage did not reliably lock in image-only assistant reply persistence plus the agent-run audio transcript path.
  • Contributing context (if known): a few managed-image tests were also flaky because they depended on a broader dispatch path instead of driving the seam directly.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
  • Unit test
  • Seam / integration test
  • End-to-end test
  • Existing coverage already sufficient
  • Target test or file:
  • src/gateway/server.chat.gateway-server-chat.test.ts
  • src/gateway/managed-image-attachments.test.ts
  • ui/src/ui/views/chat.test.ts
  • ui/src/ui/chat/gateway-http-auth.test.ts
  • ui/src/ui/views/chat-image-open.browser.test.ts
  • Scenario the test should lock in: image-only and audio-capable assistant replies that render live must also persist as transcript/history entries and remain reload-safe in UI.
  • Why this is the smallest reliable guardrail: the bug sits at the gateway/UI seam, not in isolated helpers.
  • Existing test that already covers this (if any): some managed-image coverage existed, but it did not reliably cover the failing path.
  • If no new test is added, why not: N/A

User-visible / Behavior Changes

  • Image-only assistant replies are more reliably preserved in chat history.
  • Agent-run webchat audio replies are now durably recorded in transcripts instead of being live-only.
  • Managed image previews/auth behavior is more consistent after reload/reopen.

Diagram (if applicable)

Before:
[assistant media reply] -> [live webchat render] -> [missing/incomplete transcript entry] -> [history/reload inconsistency]

After:
[assistant media reply] -> [gateway transcript append] -> [managed media recorded in transcript] -> [stable history + reload rendering]

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No
  • If any Yes, explain risk + mitigation: N/A

Repro + Verification

Environment

  • OS: Linux
  • Runtime/container: local OpenClaw workspace/dev environment
  • Model/provider: webchat path, agent-run + gateway transcript path
  • Integration/channel (if any): webchat / Control UI
  • Relevant config (redacted): standard local OpenClaw config

Steps

  1. Trigger an assistant reply that contains managed media, especially an image-only or audio reply.
  2. Observe that the reply renders live in webchat.
  3. Reload or inspect transcript/history.
  4. Confirm the assistant media reply is still present and correctly represented.

Expected

  • Assistant media replies render live and persist into transcript/history.

Actual

  • Some replies rendered live but were not durably persisted, causing missing or inconsistent history on reload.

Evidence

  • Passing targeted regression tests after the fix
  • Browser image-open safety test passing in local Playwright/Vitest run
  • Local lint/typecheck passes for the touched gateway/UI paths

Human Verification (required)

  • Verified scenarios:
  • targeted gateway chat tests for managed-image persistence paths
  • targeted UI chat tests
  • targeted managed-image attachment tests
  • browser image-open safety coverage
  • Edge cases checked:
  • image-only assistant replies
  • agent-run audio reply persistence path
  • follow-up preview behavior
  • What you did not verify:
  • broad end-to-end cross-channel coverage outside the targeted webchat/control UI path
  • live webchat audio smoke test after rebuild/restart

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No
  • If yes, exact upgrade steps: N/A

Risks and Mitigations

  • Risk: managed-media rendering and transcript persistence touch both gateway and UI seams.
  • Mitigation: targeted gateway/UI regression coverage was added and hardened.
  • Risk: media auth/reload behavior can regress in subtle ways.
  • Mitigation: explicit UI auth-path coverage and browser validation for the image-open path.

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime size: XL labels Apr 21, 2026
@greptile-apps

greptile-apps Bot commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes two related persistence gaps in the managed-media webchat path:

  1. Gateway: agent-run webchat completions now correctly call the transcript-injection fallback for audio replies, so replies that were delivered live are also durably recorded via appendInjectedAssistantMessageToTranscript.
  2. UI/Gateway bridge: managed image URLs are now validated to be same-origin /api/chat/media/outgoing/ paths before blob-fetching, and hasMeaningfulMarkdownText correctly identifies image-only messages so they render without spurious empty markdown.

All P2 or lower — no blocking issues found. Test coverage for the seam is solid.

Confidence Score: 5/5

Safe to merge; all findings are P2 or lower and the fix is well-scoped.

Thorough review of all 22 changed files found no correctness, data-integrity, or security issues. Auth header priority order is consistent across gateway and UI. Transcript injection logic handles edge cases (audio-only, label prefixing, empty guard) correctly. Cleanup of transient records and orphan files is properly deferred and bounded.

No files require special attention.

Reviews (1): Last reviewed commit: "chore: drop thumbnail and download-url l..." | Re-trigger Greptile

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

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: e4e6201962

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +430 to +432
if (sessionKeyFilter && record.sessionKey !== sessionKeyFilter) {
retainedCount += 1;
continue;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Preserve referenced files when session-filtered cleanup skips records

chat.history now calls cleanupManagedOutgoingImageRecords({ sessionKey }) (src/gateway/server-methods/chat.ts), but this branch skips non-matching records before adding their original.path to referencedPaths; the later orphan sweep then treats other sessions' still-valid files as unreferenced and deletes them. In practice, opening history for one session can silently break managed-image attachments in unrelated sessions.

Useful? React with 👍 / 👎.

Comment on lines 190 to +192
}

const transcriptMediaPaths = Array.isArray(m.MediaPaths)
? m.MediaPaths.filter((value): value is string => typeof value === "string")
: typeof m.MediaPath === "string"
? [m.MediaPath]
: [];
const transcriptMediaTypes = Array.isArray(m.MediaTypes)
? m.MediaTypes
: typeof m.MediaType === "string"
? [m.MediaType]
: [];
for (const [index, mediaPath] of transcriptMediaPaths.entries()) {
if (!isImageTranscriptMediaPath(mediaPath, transcriptMediaTypes[index])) {
return images;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Keep legacy media-path extraction before returning image list

extractImages now returns immediately after scanning content image blocks, so it no longer reads legacy transcript fields (MediaPath/MediaPaths) or input_image variants that were previously supported. Gateway still persists user-upload media in MediaPath(s) on transcript messages (src/gateway/server-methods/chat.ts), so these images can disappear from chat/history rendering after this change.

Useful? React with 👍 / 👎.

Comment on lines +846 to +847
const blobUrl = URL.createObjectURL(blob);
managedImageBlobUrlResolvedCache.set(cacheKey, blobUrl);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Revoke cached blob URLs for managed image previews

Each successful managed-image fetch creates a blob URL and stores it in managedImageBlobUrlResolvedCache, but there is no call site that runs the cleanup helper to revoke unused entries (repo-wide search shows cleanupUnusedManagedImagePreviewBlobUrls is never invoked). This causes blob/object URL retention to grow with every viewed image and can produce unbounded browser memory usage in long sessions.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

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: a96c064dd2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread ui/src/ui/chat/grouped-render.ts Outdated
Comment on lines +770 to +771
const safeUrl = resolveSafeExternalUrl(rawUrl, opts.basePath ?? window.location.href, {
allowDataImage: opts.allowDataImage ?? true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Resolve managed image URLs with an absolute base URL

basePath here is a path prefix like "/openclaw", but resolveSafeExternalUrl expects an absolute base URL; passing a path base makes URL resolution fail and returns null. In base-path deployments this prevents managed image URLs from being recognized/fetched, so previews degrade to unavailable and open/copy actions fail for otherwise valid media URLs.

Useful? React with 👍 / 👎.

Comment on lines +675 to +679
if (savedOriginal.size > limits.maxBytes) {
throw createManagedImageAttachmentError(
`Managed image attachment ${JSON.stringify(alt)} exceeds the ${formatLimitMiB(limits.maxBytes)} byte limit`,
);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Gate byte-limit checks behind image MIME validation

buildAssistantDisplayContentFromReplyPayloads forwards all reply mediaUrl(s) into this helper, including non-image media. This size check runs before the later contentType.startsWith("image/") guard, so large audio/video attachments can throw ManagedImageAttachmentError and fail reply finalization even though non-image media should be skipped by the image-attachment pipeline.

Useful? React with 👍 / 👎.

Comment on lines +197 to +200
const mediaPath = m.MediaPath;
if (typeof mediaPath === "string" && mediaPath.trim()) {
images.push({ url: mediaPath });
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Restore image-type filtering for legacy MediaPath fields

This now unconditionally treats any legacy MediaPath as an image. Transcript messages with audio/video/document media paths will be rendered as image cards (often ending in "Image unavailable" plus image actions), which is a regression from the previous behavior that filtered legacy media-path entries to image-like content.

Useful? React with 👍 / 👎.

@Ittiz

Ittiz commented Apr 21, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the Codex suggestions in 19125e9.

What changed:

  • grouped-render.ts: resolve managed image previews against an absolute base URL instead of a path prefix, so base-path deployments can still recognize and fetch managed media.
  • managed-image-attachments.ts: validate image MIME type before applying image byte-limit checks, so large non-image reply media is skipped instead of aborting reply finalization.
  • grouped-render.ts: restore legacy MediaPath / MediaPaths image-like filtering so audio/video/document media paths are not rendered as image cards.

Validation:

  • pnpm test -- --run ui/src/ui/views/chat.test.ts src/gateway/managed-image-attachments.test.ts
  • staged check:changed gate passed before push

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

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: 12105938d3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread ui/src/ui/chat/grouped-render.ts Outdated
Comment on lines +1113 to +1114
return resolveSafeExternalUrl(rawUrl, opts.basePath ?? window.location.href, {
allowDataImage: true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Resolve non-managed image URLs against an absolute base

In base-path deployments, opts.basePath is typically a path prefix like /openclaw, but this branch passes it directly as the baseHref into resolveSafeExternalUrl; new URL(..., '/openclaw') is invalid, so resolution returns null. Because this path is used for non-managed images, valid transcript/external image URLs will fall back to "Image unavailable" and open/copy actions fail whenever a base path is configured.

Useful? React with 👍 / 👎.

Comment on lines +680 to +681
if (!savedOriginal.contentType?.startsWith("image/")) {
continue;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Delete skipped non-image media files before continuing

Each mediaUrl is saved to outgoing/originals before MIME filtering, but non-image files hit this continue path and bypass the catch cleanup, leaving the just-written file orphaned. Since reply payloads can include audio/video/document URLs, this introduces persistent state-dir growth (and stray copied media) until a later cleanup pass happens to run.

Useful? React with 👍 / 👎.

@Ittiz

Ittiz commented Apr 21, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

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: 2971cd24cc

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +686 to +687
if (!savedOriginal.contentType?.startsWith("image/")) {
continue;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Remove skipped non-image downloads from outgoing/originals

When saveMediaSource(...) fetches a URL whose detected MIME is not image/*, the loop continues without deleting savedOriginal.path, so every non-image mediaUrl leaves a file behind with no record pointing to it. This is a persistent disk leak on normal payloads that include audio/video/document URLs, and those leftovers are only cleaned if a later cleanup pass happens to run.

Useful? React with 👍 / 👎.

Comment thread ui/src/ui/chat/grouped-render.ts Outdated
Comment on lines +1122 to +1124
if (!managedUrl) {
return resolveSafeExternalUrl(rawUrl, opts.basePath ?? window.location.href, {
allowDataImage: true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Route non-managed local image paths through media proxy

For any image URL that is not a managed /api/chat/media/outgoing/... URL, this branch now returns resolveSafeExternalUrl(...) directly. Legacy transcript/local paths like /tmp/openclaw/user-upload.png therefore render as same-origin HTTP paths instead of __openclaw__/assistant-media proxy URLs, so they bypass the existing local-root gating path and typically fail to load after history reload.

Useful? React with 👍 / 👎.

Comment thread ui/src/ui/chat/grouped-render.ts Outdated
Comment on lines +210 to +212
const mediaPath = m.MediaPath;
if (typeof mediaPath === "string" && mediaPath.trim() && isImageLikeLegacyMediaPath(mediaPath)) {
images.push({ url: mediaPath });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Honor MediaType when extracting legacy transcript images

Legacy MediaPath extraction now depends only on filename pattern matching and no longer consults MediaType/MediaTypes. That drops valid history images whose path has no recognized extension (or formats like HEIC/HEIF) even when transcript metadata already marks them as image/*, so previously visible history images disappear.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

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: 2471b91b80

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

limits.maxBytes,
`generated-image-${index + 1}`,
)
: await saveMediaSource(mediaUrl, undefined, "outgoing/originals");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Pass configured maxBytes when saving URL-based managed images

createManagedOutgoingImageBlocks enforces a 12 MiB default limit (limits.maxBytes), but the saveMediaSource(...) branch uses its own default 5 MiB cap because no maxBytes argument is passed. As a result, valid remote/local image sources between 5 MiB and the configured managed-image limit are rejected early, and reply finalization can fail even though those images should be accepted by the managed attachment policy.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

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: 44887e7921

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/gateway/server-methods/chat.ts Outdated
Comment on lines +2194 to +2198
localRoots: getAgentScopedMediaLocalRootsForSources({
cfg,
agentId,
mediaSources,
}),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Keep local audio roots independent from payload media paths

Using getAgentScopedMediaLocalRootsForSources here makes the allowlist depend on mediaSources extracted from the reply payload itself; that helper appends parent directories of local sources, so a crafted mediaUrl like an arbitrary absolute *.mp3/*.wav path can end up self-authorizing and then pass assertLocalMediaAllowed during audio embedding. In the agent-run webchat path this creates a local-file disclosure path for host audio files that were previously blocked by fixed agent roots.

Useful? React with 👍 / 👎.

}
const stateDir = params.stateDir ?? resolveStateDir();
const limits = resolveManagedImageAttachmentLimits(params.limits);
await cleanupManagedOutgoingImageRecords({ stateDir });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Avoid orphan cleanup in the write path for managed images

Calling cleanupManagedOutgoingImageRecords at the start of createManagedOutgoingImageBlocks can race with another concurrent image-create call: one request may have already written a file into outgoing/originals but not yet written its JSON record, and this cleanup pass will treat that file as orphaned and delete it. That can produce intermittent missing-image records or creation failures under parallel chat sends.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

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: d135dc6762

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

limits.maxBytes,
`generated-image-${index + 1}`,
)
: await saveMediaSource(mediaUrl, undefined, "outgoing/originals", limits.maxBytes);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Enforce local-root checks before ingesting mediaUrl file paths

createManagedOutgoingImageBlocks now accepts any non-data mediaUrl and passes it straight to saveMediaSource, which reads local filesystem paths without an allowlist. Because buildAssistantDisplayContentFromReplyPayloads forwards reply mediaUrl(s) into this function, a payload that contains an absolute local image path (outside the agent’s approved media roots) gets copied into managed storage and then served from /api/chat/media/outgoing/..., bypassing the previous local-preview root gate. This creates a local file disclosure path for image files whenever an untrusted reply payload can set mediaUrl.

Useful? React with 👍 / 👎.

Comment on lines +1909 to +1913
${reasoningMarkdown
? html`<div class="chat-thinking">
${unsafeHTML(toSanitizedMarkdownHtml(reasoningMarkdown))}
</div>`
: nothing}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Remove duplicated reasoning block from non-tool message render

renderedTextualContent now includes reasoningMarkdown, but the non-tool branch still renders the same reasoning block again later, so assistant reasoning appears twice for normal (non-tool) messages. This is a user-visible regression in chat rendering and makes reasoning-heavy replies noisier than intended.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

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: 826b2fb13f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/gateway/server-methods/chat.ts Outdated
const resolvedSessionModel = resolveSessionModelRef(cfg, entry, sessionAgentId);
const localMessages =
sessionId && storePath ? readSessionMessages(sessionId, storePath, entry?.sessionFile) : [];
await cleanupManagedOutgoingImageRecords({ sessionKey: canonicalKey });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Avoid running orphan cleanup from chat.history reads

Calling cleanupManagedOutgoingImageRecords on every chat.history request can race with in-flight image creation: createManagedOutgoingImageBlocks writes files into media/outgoing/originals before the JSON record is persisted, and the history-triggered cleanup treats those files as orphaned and deletes them. Under concurrent sends/history refreshes, this can intermittently remove newly created attachments and cause finalization failures or missing images.

Useful? React with 👍 / 👎.

Comment thread ui/src/ui/chat/grouped-render.ts Outdated
Comment on lines +219 to +223
images.push({ url: mediaPath });
}
const mediaPaths = m.MediaPaths;
const mediaTypes = Array.isArray(m.MediaTypes) ? m.MediaTypes : [];
if (Array.isArray(mediaPaths)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Deduplicate legacy MediaPath and MediaPaths image entries

extractImages now pushes MediaPath and then iterates MediaPaths separately without deduplication, so the first image is rendered twice when both fields are present. Gateway transcript writes commonly include both fields for the same attachment (MediaPath plus MediaPaths[0]), so history/image cards will show duplicate previews and duplicate open/copy actions for a single media item.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

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: 7a9b8f88f0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +682 to +686
const localMediaPath = resolveLocalMediaPath(mediaUrl);
if (localMediaPath) {
await assertLocalMediaAllowed(localMediaPath, params.localRoots);
}
return await saveMediaSource(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Enforce local-root checks for relative media paths

assertLocalMediaAllowed is only reached when resolveLocalMediaPath(mediaUrl) returns a value, but that helper skips relative paths, so relative sources (for example ../foo.png) bypass the local-root allowlist and are passed directly to saveMediaSource for local file reads. In the chat.send reply-payload path where mediaUrl can be model/tool-controlled, this allows unintended host-file ingestion and later exposure through managed media URLs outside configured roots.

Useful? React with 👍 / 👎.

Comment on lines +446 to +447
} else if (record.messageId) {
shouldDelete = !(await recordMatchesTranscriptMessage(record));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Avoid reparsing transcript for each cleanup record

This cleanup path checks each history record with recordMatchesTranscriptMessage, which reparses transcript messages for every record; because chat.history invokes cleanup on reads, sessions with many managed images pay repeated full transcript scans on the request path. The result is avoidable O(n) repeated file parsing and synchronous I/O amplification that can significantly increase history latency and block the event loop under larger transcripts.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

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: 707a2cac9a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

}
return {
kind: "image-data-url",
buffer: Buffer.from(match[2].replace(/\s+/g, ""), "base64"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Reject oversized data URLs before decoding base64

Decoding match[2] with Buffer.from(..., "base64") happens before any size guard is applied, while the byte limit is only enforced later in createManagedOutgoingImageBlocks via validateManagedImageBuffer. A crafted reply payload containing a very large data:image/...;base64,... URL will force an unbounded allocation during decode and can spike memory or crash the gateway process before the configured managed-image limits are checked.

Useful? React with 👍 / 👎.

@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord channel: imessage Channel integration: imessage channel: matrix Channel integration: matrix channel: mattermost Channel integration: mattermost channel: msteams Channel integration: msteams channel: slack Channel integration: slack channel: telegram Channel integration: telegram channel: tlon Channel integration: tlon channel: whatsapp-web Channel integration: whatsapp-web app: android App: android app: ios App: ios app: macos App: macos extensions: memory-core Extension: memory-core cli CLI command changes scripts Repository scripts commands Command implementations docker Docker and sandbox tooling agents Agent runtime and tooling channel: feishu Channel integration: feishu extensions: anthropic extensions: openai extensions: minimax channel: qqbot extensions: qa-lab labels Apr 22, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing this PR because it looks dirty (too many unrelated or unexpected changes). This usually happens when a branch picks up unrelated commits or a merge went sideways. Please recreate the PR from a clean branch.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

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: a0f9917d68

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +1485 to +1489
if (audioBlocks.length > 0) {
content.push(...audioBlocks);
}
if (params.includeSensitiveMedia === false && payload.sensitiveMedia === true) {
continue;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Skip sensitive audio blocks when persistence is disabled

When includeSensitiveMedia is false, this function still appends local audio blocks before the sensitive-media guard runs. For payloads with sensitiveMedia: true and trustedLocalMedia: true, the transcript path can still persist base64 audio content even though sensitive media is supposed to be live-only. This leaks sensitive media into stored history instead of excluding it.

Useful? React with 👍 / 👎.

Comment on lines +2461 to +2463
hasSensitiveMediaPayload(finalPayloads)
? await buildAssistantDisplayContentFromReplyPayloads({
sessionKey,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Avoid recreating managed images during sensitive-media filtering

In mixed replies (some sensitive media, some non-sensitive media), buildAssistantDisplayContentFromReplyPayloads is called once to build assistantContent and then called again with includeSensitiveMedia: false. The second pass creates a new set of managed-image records/URLs instead of reusing the first pass, so non-sensitive images are duplicated and the URLs sent in the live message can point at transient records that are not the ones attached to transcript history.

Useful? React with 👍 / 👎.

@prtags

prtags Bot commented Apr 23, 2026

Copy link
Copy Markdown

Related work from PRtags group intent-mastiff-ytno

Title: Open PR duplicate: managed media transcript persistence

Number Title
#68821 fix(gateway,ui): restore managed media transcript persistence in webchat
#69500* fix(gateway,ui): restore managed media transcript persistence in webchat
#70383 fix(gateway,ui): restore managed media transcript persistence in webchat

* This PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: android App: android app: ios App: ios app: macos App: macos app: web-ui App: web-ui channel: bluebubbles Channel integration: bluebubbles channel: discord Channel integration: discord channel: feishu Channel integration: feishu channel: imessage Channel integration: imessage channel: matrix Channel integration: matrix channel: mattermost Channel integration: mattermost channel: msteams Channel integration: msteams channel: qqbot channel: slack Channel integration: slack channel: telegram Channel integration: telegram channel: tlon Channel integration: tlon channel: whatsapp-web Channel integration: whatsapp-web cli CLI command changes commands Command implementations docker Docker and sandbox tooling docs Improvements or additions to documentation extensions: anthropic extensions: memory-core Extension: memory-core extensions: minimax extensions: openai extensions: qa-lab gateway Gateway runtime scripts Repository scripts size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Webchat/Control UI does not render images generated by image_generate tool