Repository navigation
fix(gateway,ui): discard prepared attachment media on pre-persist exits and release catalog-open payloads - #123983
Conversation
…ts and release catalog-open payloads Two attachment-lifecycle leaks with the same shape: state whose owner dropped the reference without reclaiming the resource. - chat.send stages inbound media (~/.openclaw/media/inbound) during attachment preparation; the abort and session-routing-changed exits between preparation success and user-turn persistence returned without deleting the staged files. Nothing references them afterward, and the inbound sweep is disabled unless attachments.ttlHours is set, so default installs orphaned them permanently. Both exits now discard through the same deleteMediaBuffer path the error exits already use. - Opening a terminal-catalog session cleared state.chatAttachments without releasing payload-store entries, stranding Files and object URLs for the tab lifetime; every sibling discard path releases first.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs changes before merge. Reviewed August 15, 2026, 12:19 AM ET / 04:19 UTC. ClawSweeper reviewWhat this changesThe PR deletes inbound media when an early Gateway chat send is aborted or rerouted, and releases web-chat attachment payloads when a catalog session opens. Merge readiness⛔ Blocked by patch quality or review findings - 6 items remain Keep this PR open: both blockers from the prior review remain, so the attachment cleanup is incomplete and can either lose a recoverable fallback attachment or leak later pre-persist media. Priority: P2 Review scores
Verification
How this fits togetherGateway chat preparation creates inbound-media files before a user turn is persisted; the handler must retain cleanup ownership until persistence or dispatch takes over. The Control UI separately holds browser payloads for both the visible composer and recoverable composer fallbacks. flowchart LR
A[Client attachments] --> B[Gateway prepares media]
B --> C{Turn handed off?}
C -->|Terminal before handoff| D[Discard inbound media]
C -->|Persisted or dispatched| E[Agent turn]
F[Web composer attachments] --> G[Catalog session opens]
G --> H[Retain fallback payloads or discard fallback]
H --> I[Release unowned browser payloads]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +16, Tests +54. Total +70 across 5 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Use one handler-owned, once-only media cleanup boundary through persistence or dispatch handoff, and preserve fallback-owned payload IDs when catalog navigation clears only the visible composer. Do we have a high-confidence way to reproduce the issue? Yes—source inspection gives high-confidence paths: a fallback sharing a visible attachment ID loses its payload on catalog open, and later pre-ACK Gateway terminal paths retain prepared inbound media. Is this the best way to solve the issue? No. The proposed cleanup is too narrow: it must cover all pre-handoff Gateway exits and respect existing fallback ownership rather than releasing every visible attachment ID. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 622eec9c364f. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
…wner (#124100) #123983 fixed two of six pre-persistence exits that orphan staged inbound media (~/.openclaw/media/inbound has no transcript reference until the user turn persists, and the inbound sweep is off by default). Four sibling exits still leaked: the post-reply-context abort and routing-change checks, the pre-ACK injection settle (onAborted/onActiveLeafChanged), and any setup throw routed to handleChatSendSetupError. Instead of adding four more inline discards, the custody moves to the admission cleanup owner: every abandonment exit already funnels through cleanupAdmittedRun, which now fires an armed discard gated on the user-turn recorder's persisted fact (the restart-safe path persists durably before its exits; steer injections carry the same recorder). The ACK disarms it because dispatch's error lifecycle persists the referencing transcript on every post-ACK path. The two inline discards #123983 added are deleted. Regression test drives the setup-error exit with an offloaded attachment and fails pre-fix; the original #123983 abort test still passes through the new owner.
…ts and release catalog-open payloads (openclaw#123983) * fix(gateway,ui): discard prepared attachment media on pre-persist exits and release catalog-open payloads Two attachment-lifecycle leaks with the same shape: state whose owner dropped the reference without reclaiming the resource. - chat.send stages inbound media (~/.openclaw/media/inbound) during attachment preparation; the abort and session-routing-changed exits between preparation success and user-turn persistence returned without deleting the staged files. Nothing references them afterward, and the inbound sweep is disabled unless attachments.ttlHours is set, so default installs orphaned them permanently. Both exits now discard through the same deleteMediaBuffer path the error exits already use. - Opening a terminal-catalog session cleared state.chatAttachments without releasing payload-store entries, stranding Files and object URLs for the tab lifetime; every sibling discard path releases first. * test(gateway): drop duplicate unused inbound baseline block
…wner (openclaw#124100) openclaw#123983 fixed two of six pre-persistence exits that orphan staged inbound media (~/.openclaw/media/inbound has no transcript reference until the user turn persists, and the inbound sweep is off by default). Four sibling exits still leaked: the post-reply-context abort and routing-change checks, the pre-ACK injection settle (onAborted/onActiveLeafChanged), and any setup throw routed to handleChatSendSetupError. Instead of adding four more inline discards, the custody moves to the admission cleanup owner: every abandonment exit already funnels through cleanupAdmittedRun, which now fires an armed discard gated on the user-turn recorder's persisted fact (the restart-safe path persists durably before its exits; steer injections carry the same recorder). The ACK disarms it because dispatch's error lifecycle persists the referencing transcript on every post-ACK path. The two inline discards openclaw#123983 added are deleted. Regression test drives the setup-error exit with an offloaded attachment and fails pre-fix; the original openclaw#123983 abort test still passes through the new owner.
What Problem This Solves
Two attachment-lifecycle leaks found by the round-4 attachments/media investigation lane. Both share one shape: an owner dropped its reference to a resource without reclaiming it.
chat.sendstages inbound media into~/.openclaw/media/inbound/during attachment preparation. The two exits between preparation success and user-turn persistence — active-run abort (finishAbortedChatSend) and hot session-routing change (rejectSessionRoutingChanged) — returned without deleting the staged files. Nothing ever references them afterward (the transcript entry that would carry themedia://inbound/<id>URI never persists), and the inbound sweep (cleanOldMedia) is disabled unlessattachments.ttlHoursis set, so on default installs every aborted send with an offloaded attachment leaks its files permanently. The error exits already clean up; these two success-then-bail exits did not.state.chatAttachments = []withoutreleaseChatAttachmentPayloads, stranding payload-storeFileentries and their object URLs for the tab lifetime. Every sibling discard path (pane handoff, queue removal) releases first.Why This Change Was Made
Repair leaked state at its producer: the chat-send handler owns the prepared-attachments lifetime until the turn persists, so the two pre-persist exits now discard through a small
discardPreparedChatSendAttachmentshelper using the samedeleteMediaBufferpath the preparation error exits already use. The UI fix adds the one missing release call before the array clear, matching the established pattern.User Impact
Aborting a send that carried attachments (or racing a config routing change) no longer permanently leaks files into the media directory on default installs. Opening a catalog session with staged attachments no longer pins their memory and blob URLs for the rest of the tab.
Evidence
chat.abort cancels chat.send during attachment preparation before ACKe2e test with an offloaded non-image attachment and an inbound-directory baseline assertion: fails pre-fix (2 orphaned files remain), passes post-fix. Fullserver.chat.gateway-server-chat-b.test.tssuite green (100 tests).chat-pane-session.catalog-attachments.test.tsproves the payload-store entry is released on catalog open: fails pre-fix (dataUrl still resolvable), passes post-fix.src/gateway/chat-attachments.test.tsgreen;pnpm tsgo,pnpm tsgo:ui,pnpm check:test-typesclean; oxlint/oxfmt clean.