Skip to content

fix(gateway,ui): discard prepared attachment media on pre-persist exits and release catalog-open payloads - #123983

Merged
steipete merged 2 commits into
mainfrom
codex/autoqa-attachment-leaks
Aug 15, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/autoqa-attachment-leaks

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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.

  1. Gateway inbound-media orphans on abort/routing-change. chat.send stages 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 the media://inbound/<id> URI never persists), and the inbound sweep (cleanOldMedia) is disabled unless attachments.ttlHours is 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.
  2. UI catalog-open payload strand. Opening a terminal-catalog session cleared state.chatAttachments = [] without releaseChatAttachmentPayloads, stranding payload-store File entries 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 discardPreparedChatSendAttachments helper using the same deleteMediaBuffer path 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

  • Extended the existing chat.abort cancels chat.send during attachment preparation before ACK e2e test with an offloaded non-image attachment and an inbound-directory baseline assertion: fails pre-fix (2 orphaned files remain), passes post-fix. Full server.chat.gateway-server-chat-b.test.ts suite green (100 tests).
  • New chat-pane-session.catalog-attachments.test.ts proves the payload-store entry is released on catalog open: fails pre-fix (dataUrl still resolvable), passes post-fix.
  • src/gateway/chat-attachments.test.ts green; pnpm tsgo, pnpm tsgo:ui, pnpm check:test-types clean; oxlint/oxfmt clean.
  • Autoreview (Codex, high): clean, no accepted findings, "patch is correct (0.95)".
  • Production LOC: +14 −1 (helper with invariant comment + two discard calls + one release call). Justified: closes a permanent disk leak at its lifecycle owner; the alternative — enabling the sweep by default — changes a shipped retention contract.

…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.
@clawsweeper

clawsweeper Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Aug 15, 2026
@steipete
steipete marked this pull request as ready for review August 15, 2026 03:42
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 15, 2026
@clawsweeper

clawsweeper Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 15, 2026, 12:19 AM ET / 04:19 UTC.

ClawSweeper review

What this changes

The 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
Reviewed head: b1d3b704ae88da434edeecc47d097a89c431679c

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch has focused lifecycle intent and tests, but two previously reported ownership blockers remain.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor real-behavior-proof gate.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor real-behavior-proof gate.
Evidence reviewed 6 items Catalog cleanup releases fallback-owned payloads: The PR releases every visible attachment ID, but leaves composer fallback entries intact; payload release removes the data URL/object URL by ID, so a fallback sharing that ID becomes unrecoverable.
Fallbacks intentionally retain attachment metadata: The current UI stores copies of composer attachments in storage-failure fallbacks, while the payload store deletes payload data by attachment ID.
Later Gateway exits remain unowned: The added discard calls cover only the first post-preparation abort/reroute checks. Later reply-context and pre-ACK injection terminal exits still return before detached dispatch takes ownership.
Findings 2 actionable findings [P1] Preserve payloads owned by composer fallbacks
[P2] Reclaim media on every later pre-persist exit
Security None None.

How this fits together

Gateway 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]
Loading

Before merge

  • Preserve payloads owned by composer fallbacks (P1) - chatComposerFallbackByScope can retain these same attachment IDs after a storage failure, but this call deletes their payload-map entries while leaving the fallback intact. Returning to that fallback can no longer resolve the data URL or object URL. Exclude fallback-owned IDs, or atomically discard the corresponding fallback, and cover the shared-owner case.
  • Reclaim media on every later pre-persist exit (P2) - This only covers the two checks immediately after preparation. The reply-context and pre-ACK injection waits can later terminate through the same abort/routing handlers before startChatDispatch owns the refs, leaving staged inbound media behind. Keep one handler-owned, once-only cleanup guard until persistence or dispatch handoff and test a later terminal exit.
  • Resolve merge risk (P2) - Merging the catalog cleanup now can leave a retained composer fallback with attachment metadata whose payload data has already been deleted.
  • Resolve merge risk (P1) - Aborts, routing changes, and active-leaf changes after attachment preparation can still orphan inbound media before dispatch takes ownership.
  • Improve patch quality - Preserve payloads held by composer fallbacks and test the shared-ID case.
  • Improve patch quality - Cover a post-preparation, pre-dispatch Gateway abort, routing change, or active-leaf exit with an offloaded attachment.

Findings

  • [P1] Preserve payloads owned by composer fallbacks — ui/src/pages/chat/chat-pane-session.ts:292
  • [P2] Reclaim media on every later pre-persist exit — src/gateway/server-methods/chat-send-handler.ts:77-85
Agent review details

Security

None.

PR surface

Source +16, Tests +54. Total +70 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 17 1 +16
Tests 2 54 0 +54
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 71 1 +70

Review metrics

Metric Value Why it matters
Production versus test delta production +17/-1; tests +54/-0 The production additions attempt lifecycle cleanup, but the tests presently cover only the earliest Gateway exit and an unshared UI payload.

Merge-risk options

Maintainer options:

  1. Repair lifecycle ownership before merge (recommended)
    Extend the handler-owned cleanup through every pre-handoff terminal path and exclude fallback-owned IDs from catalog payload release, with focused regressions for both cases.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Retain composer-fallback attachment payloads during catalog open and use one once-only Gateway cleanup owner for every terminal path before persistence or dispatch handoff; add focused regressions.

Technical review

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

  • [P1] Preserve payloads owned by composer fallbacks — ui/src/pages/chat/chat-pane-session.ts:292
    chatComposerFallbackByScope can retain these same attachment IDs after a storage failure, but this call deletes their payload-map entries while leaving the fallback intact. Returning to that fallback can no longer resolve the data URL or object URL. Exclude fallback-owned IDs, or atomically discard the corresponding fallback, and cover the shared-owner case.
    Confidence: 0.99
  • [P2] Reclaim media on every later pre-persist exit — src/gateway/server-methods/chat-send-handler.ts:77-85
    This only covers the two checks immediately after preparation. The reply-context and pre-ACK injection waits can later terminate through the same abort/routing handlers before startChatDispatch owns the refs, leaving staged inbound media behind. Keep one handler-owned, once-only cleanup guard until persistence or dispatch handoff and test a later terminal exit.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 622eec9c364f.

Labels

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool and patch quality is 🦪 silver shellfish.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.

Label justifications:

  • P2: The PR addresses bounded attachment leaks, but the remaining failure paths have limited blast radius rather than a core-runtime outage.
  • merge-risk: 🚨 session-state: The catalog path can invalidate data still retained by composer fallback state, breaking later attachment recovery.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR is exempt from the external-contributor real-behavior-proof gate.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/gateway/server.chat.gateway-server-chat-b.test.ts.
  • [P1] node scripts/run-vitest.mjs ui/src/pages/chat/chat-pane-session.catalog-attachments.test.ts.
  • [P1] pnpm tsgo.
  • [P1] pnpm tsgo:ui.
  • [P1] pnpm check:test-types.

What I checked:

Likely related people:

  • steipete: Current-main blame attributes the catalog-session and fallback ownership surface to Peter Steinberger, matching the PR author identity; the available shallow history is otherwise limited. (role: recent area contributor; confidence: high; commits: d7d059c7e646, 8630f82d44f2; files: ui/src/pages/chat/chat-pane-session.ts, ui/src/pages/chat/chat-composer-memory-fallback.ts, src/gateway/server-methods/chat-send-handler.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-15T03:49:33.646Z sha 8630f82 :: needs changes before merge. :: [P1] Preserve payloads owned by composer fallbacks | [P2] Reclaim media on all later pre-persist exits | [P1] Remove unused baseline setup from the duplicate-send test

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 15, 2026
@steipete
steipete merged commit 617b045 into main Aug 15, 2026
200 checks passed
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@steipete
steipete deleted the codex/autoqa-attachment-leaks branch August 15, 2026 04:30
steipete added a commit that referenced this pull request Aug 15, 2026
…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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 16, 2026
…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
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 16, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant