Repository navigation
Conversation
Greptile SummaryThis PR fixes two related persistence gaps in the managed-media webchat path:
All P2 or lower — no blocking issues found. Test coverage for the seam is solid. Confidence Score: 5/5Safe 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 |
There was a problem hiding this comment.
💡 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".
| if (sessionKeyFilter && record.sessionKey !== sessionKeyFilter) { | ||
| retainedCount += 1; | ||
| continue; |
There was a problem hiding this comment.
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 👍 / 👎.
| } | ||
|
|
||
| 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; |
There was a problem hiding this comment.
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 👍 / 👎.
| const blobUrl = URL.createObjectURL(blob); | ||
| managedImageBlobUrlResolvedCache.set(cacheKey, blobUrl); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
💡 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".
| const safeUrl = resolveSafeExternalUrl(rawUrl, opts.basePath ?? window.location.href, { | ||
| allowDataImage: opts.allowDataImage ?? true, |
There was a problem hiding this comment.
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 👍 / 👎.
| if (savedOriginal.size > limits.maxBytes) { | ||
| throw createManagedImageAttachmentError( | ||
| `Managed image attachment ${JSON.stringify(alt)} exceeds the ${formatLimitMiB(limits.maxBytes)} byte limit`, | ||
| ); | ||
| } |
There was a problem hiding this comment.
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 👍 / 👎.
| const mediaPath = m.MediaPath; | ||
| if (typeof mediaPath === "string" && mediaPath.trim()) { | ||
| images.push({ url: mediaPath }); | ||
| } |
There was a problem hiding this comment.
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 👍 / 👎.
|
Addressed the Codex suggestions in 19125e9. What changed:
Validation:
|
There was a problem hiding this comment.
💡 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".
| return resolveSafeExternalUrl(rawUrl, opts.basePath ?? window.location.href, { | ||
| allowDataImage: true, |
There was a problem hiding this comment.
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 👍 / 👎.
| if (!savedOriginal.contentType?.startsWith("image/")) { | ||
| continue; |
There was a problem hiding this comment.
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 👍 / 👎.
|
@codex review |
There was a problem hiding this comment.
💡 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".
| if (!savedOriginal.contentType?.startsWith("image/")) { | ||
| continue; |
There was a problem hiding this comment.
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 👍 / 👎.
| if (!managedUrl) { | ||
| return resolveSafeExternalUrl(rawUrl, opts.basePath ?? window.location.href, { | ||
| allowDataImage: true, |
There was a problem hiding this comment.
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 👍 / 👎.
| const mediaPath = m.MediaPath; | ||
| if (typeof mediaPath === "string" && mediaPath.trim() && isImageLikeLegacyMediaPath(mediaPath)) { | ||
| images.push({ url: mediaPath }); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
💡 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"); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
💡 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".
| localRoots: getAgentScopedMediaLocalRootsForSources({ | ||
| cfg, | ||
| agentId, | ||
| mediaSources, | ||
| }), |
There was a problem hiding this comment.
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 }); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
💡 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); |
There was a problem hiding this comment.
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 👍 / 👎.
| ${reasoningMarkdown | ||
| ? html`<div class="chat-thinking"> | ||
| ${unsafeHTML(toSanitizedMarkdownHtml(reasoningMarkdown))} | ||
| </div>` | ||
| : nothing} |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
💡 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".
| const resolvedSessionModel = resolveSessionModelRef(cfg, entry, sessionAgentId); | ||
| const localMessages = | ||
| sessionId && storePath ? readSessionMessages(sessionId, storePath, entry?.sessionFile) : []; | ||
| await cleanupManagedOutgoingImageRecords({ sessionKey: canonicalKey }); |
There was a problem hiding this comment.
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 👍 / 👎.
| images.push({ url: mediaPath }); | ||
| } | ||
| const mediaPaths = m.MediaPaths; | ||
| const mediaTypes = Array.isArray(m.MediaTypes) ? m.MediaTypes : []; | ||
| if (Array.isArray(mediaPaths)) { |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
💡 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".
| const localMediaPath = resolveLocalMediaPath(mediaUrl); | ||
| if (localMediaPath) { | ||
| await assertLocalMediaAllowed(localMediaPath, params.localRoots); | ||
| } | ||
| return await saveMediaSource( |
There was a problem hiding this comment.
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 👍 / 👎.
| } else if (record.messageId) { | ||
| shouldDelete = !(await recordMatchesTranscriptMessage(record)); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
💡 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"), |
There was a problem hiding this comment.
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 👍 / 👎.
|
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. |
There was a problem hiding this comment.
💡 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".
| if (audioBlocks.length > 0) { | ||
| content.push(...audioBlocks); | ||
| } | ||
| if (params.includeSensitiveMedia === false && payload.sensitiveMedia === true) { | ||
| continue; |
There was a problem hiding this comment.
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 👍 / 👎.
| hasSensitiveMediaPayload(finalPayloads) | ||
| ? await buildAssistantDisplayContentFromReplyPayloads({ | ||
| sessionKey, |
There was a problem hiding this comment.
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 👍 / 👎.
|
Related work from PRtags group Title: Open PR duplicate: managed media transcript persistence
|
Summary
chat.historyor get inconsistent follow-up rendering/auth behavior on reload.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause (if applicable)
Regression Test Plan (if applicable)
src/gateway/server.chat.gateway-server-chat.test.tssrc/gateway/managed-image-attachments.test.tsui/src/ui/views/chat.test.tsui/src/ui/chat/gateway-http-auth.test.tsui/src/ui/views/chat-image-open.browser.test.tsUser-visible / Behavior Changes
Diagram (if applicable)
Security Impact (required)
Repro + Verification
Environment
Steps
Expected
Actual
Evidence
Human Verification (required)
Review Conversations
Compatibility / Migration
Risks and Mitigations