Repository navigation
fix(gateway): discard prepared media when a hook blocks the turn - #124353
Conversation
#124100's disarm-at-ACK custody rests on dispatch persisting the referencing transcript on every post-ACK path. The blocked-turn path breaks that: a before_agent_run block persists only the redacted block reason — no media markers, no media facts — so the offloaded inbound refs stay unreferenced forever (the inbound sweep is off unless attachments.ttlHours is set). Dispatch settle now discards the prepared refs when the recorder ended blocked, applying the same custody rule as the pre-ACK owner. Regression test drives a blocked dispatch with an offloaded attachment and asserts the inbound dir returns to baseline; fails pre-fix.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs changes before merge. Reviewed August 15, 2026, 10:28 PM ET / August 16, 2026, 02:28 UTC. ClawSweeper reviewWhat this changesThe branch discards staged inbound attachments when a gateway chat turn is blocked so redacted blocked turns do not leave orphaned media files. Merge readiness⛔ Blocked by patch quality or review findings - 6 items remain Keep open: the new cleanup predicate can delete attachments already referenced by a persisted user turn, so the patch is not safe to merge as written. Priority: P1 Review scores
Verification
How this fits togetherGateway chat stages inbound media before dispatch and records whether the user turn reached the transcript. Blocked turns may record only a redacted reason, so cleanup must distinguish unreferenced media from media already retained by a persisted turn. flowchart LR
A[Chat attachment] --> B[Gateway stages inbound media]
B --> C[User-turn recorder]
C --> D{Transcript contains media?}
D -- Yes --> E[Retain referenced media]
D -- No, redacted block --> F[Discard staged media]
C --> G[Reply delivery metadata]
G --> H[Generic blocked state]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +10, Tests +54. Total +64 across 2 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Keep one terminal custody owner and record a distinct fact for a redacted, unreferenced blocked turn; discard only from that fact and retain media for generic blocked states after persistence. Do we have a high-confidence way to reproduce the issue? Yes—source-reproducible: a persisted plugin-bound user turn returns transcriptWriteBlocked, gateway delivery marks the shared recorder blocked, and the proposed predicate then discards its staged media. Is this the best way to solve the issue? No. The branch uses the aggregate isBlocked() state, but current source uses that state for both redacted unreferenced turns and already-persisted transcript-write blocking; cleanup needs a narrower recorded fact. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against e2e070c927a6. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
…nclaw#124353) openclaw#124100's disarm-at-ACK custody rests on dispatch persisting the referencing transcript on every post-ACK path. The blocked-turn path breaks that: a before_agent_run block persists only the redacted block reason — no media markers, no media facts — so the offloaded inbound refs stay unreferenced forever (the inbound sweep is off unless attachments.ttlHours is set). Dispatch settle now discards the prepared refs when the recorder ended blocked, applying the same custody rule as the pre-ACK owner. Regression test drives a blocked dispatch with an offloaded attachment and asserts the inbound dir returns to baseline; fails pre-fix.
What Problem This Solves
#124100 moved prepared-media abandonment custody to the admission cleanup owner, disarmed at the ACK on the invariant that dispatch persists the referencing transcript on every post-ACK path. The round-6 media lane found the path that breaks that invariant: a
before_agent_runhook block. The blocked path persists only the redacted block reason — no[media attached: …]markers, no media facts (persistBlockedwith the redacted message) — so the offloaded inbound refs in~/.openclaw/media/inboundstay unreferenced forever. The inbound sweep is off unlessattachments.ttlHoursis set, so default installs orphan the files permanently — the exact #123983/#124100 bug class.Why This Change Was Made
Dispatch settle (the
finallythat already ownsdispatchErrorLifecycle.finalize()) now discards the prepared refs when the recorder ended blocked, applying the same custody rule as the pre-ACK owner: unreferenced staged media is discarded. This is the gateway-side owner point — it covers every block source (embedded and CLI runners both funnel through the same recordermarkBlocked/persistBlockedsemantics) without touching the redaction policy, which intentionally strips everything but the block reason.User Impact
Operators running content-blocking hooks no longer accumulate permanently orphaned media files for every blocked send that carried attachments.
Evidence
markBlockedvia the recorder handed todispatchInboundMessage) with an offloaded attachment and asserts the inbound dir returns to baseline — fails pre-fix (stash proof), passes post-fix.node scripts/run-vitest.mjs run src/gateway/server.chat.gateway-server-chat-b.test.ts— 102/102 (includes the fix(gateway): give prepared chat.send media one abandonment-discard owner #124100 and fix(gateway,ui): discard prepared attachment media on pre-persist exits and release catalog-open payloads #123983 custody regressions, proving no double-discard or referenced-media deletion).pnpm tsgo,pnpm check:test-types, oxfmt/oxlint clean; autoreview clean (0.98).Production LOC +11/−1 (the settle-point discard + custody comment); tests +54.