Skip to content

fix(gateway): discard prepared media when a hook blocks the turn - #124353

Merged
steipete merged 1 commit into
mainfrom
codex/autoqa-blocked-media
Aug 16, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/autoqa-blocked-media

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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_run hook block. The blocked path persists only the redacted block reason — no [media attached: …] markers, no media facts (persistBlocked with the redacted message) — so the offloaded inbound refs in ~/.openclaw/media/inbound stay unreferenced forever. The inbound sweep is off unless attachments.ttlHours is set, so default installs orphan the files permanently — the exact #123983/#124100 bug class.

Why This Change Was Made

Dispatch settle (the finally that already owns dispatchErrorLifecycle.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 recorder markBlocked/persistBlocked semantics) 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

Production LOC +11/−1 (the settle-point discard + custody comment); tests +54.

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

clawsweeper Bot commented Aug 16, 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 gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Aug 16, 2026
@steipete
steipete marked this pull request as ready for review August 16, 2026 02:21
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 16, 2026
@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 15, 2026, 10:28 PM ET / August 16, 2026, 02:28 UTC.

ClawSweeper review

What this changes

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

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch is focused and has a relevant regression test, but the demonstrated P1 deletion path prevents it from being quality-ready.
Proof confidence 🌊 off-meta tidepool Not applicable: This is maintainer-authored gateway work, so the external-contributor real-behavior-proof gate does not apply; the stated focused regression remains useful supplemental evidence.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is maintainer-authored gateway work, so the external-contributor real-behavior-proof gate does not apply; the stated focused regression remains useful supplemental evidence.
Evidence reviewed 6 items Current main lacks the proposed cleanup: Current main ends detached dispatch by finalizing lifecycle work and scheduling the title; it has no blocked-media discard at this terminal point.
Proposed predicate conflates two states: The supplied PR patch adds cleanup whenever the recorder reports isBlocked(), without checking why that state was set.
Persisted turns can deliberately become blocked: Plugin-bound delivery returns transcriptWriteBlocked specifically when recorder.hasPersisted() is already true.
Findings 1 actionable finding [P1] Preserve media referenced by already-persisted turns
Security None None.

How this fits together

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

Before merge

  • Preserve media referenced by already-persisted turns (P1) - isBlocked() is not an unreferenced-media signal: plugin-bound delivery sets it for transcriptWriteBlocked after hasPersisted() is already true. In that path this cleanup deletes inbound files still referenced by the persisted user turn. Record or carry a distinct redacted-unreferenced fact, and add coverage for this persisted blocked state.
  • Resolve merge risk (P1) - The new isBlocked() predicate treats plugin-bound transcript-write blocking as equivalent to a redacted pre-agent block, despite the former occurring after the recorder reports a persisted turn; merging can delete media still referenced by that turn.
  • Resolve merge risk (P1) - Production growth adds a second terminal cleanup owner beside the existing admission owner, making custody depend on an overloaded recorder flag.
  • Complete next step (P2) - A narrow owner-boundary repair is clear: distinguish redacted unreferenced blocked turns from generic blocked transcript states before deleting staged media.
  • Improve patch quality - Use a precise unreferenced-blocked-media signal rather than isBlocked().
  • Improve patch quality - Add a boundary regression where transcriptWriteBlocked follows a persisted attachment turn and verify the inbound media remains present.

Findings

  • [P1] Preserve media referenced by already-persisted turns — src/gateway/server-methods/chat-send-agent-dispatch.ts:510
Agent review details

Security

None.

PR surface

Source +10, Tests +54. Total +64 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 11 1 +10
Tests 1 54 0 +54
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 65 1 +64

Review metrics

Metric Value Why it matters
Production versus test delta production +11/-1, tests +54/-0 The positive production delta introduces a second attachment-cleanup path, so it needs a precise ownership invariant rather than an overloaded terminal flag.

Merge-risk options

Maintainer options:

  1. Separate unreferenced blocking from generic blocking (recommended)
    Replace the broad recorder-state check with a precise redacted-unreferenced-media fact and add coverage proving persisted attachment media survives transcript-write blocking.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Separate redacted unreferenced blocking from generic transcript-write blocking, preserve one cleanup owner, and add regression coverage that a persisted attachment remains readable.

Technical review

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

  • [P1] Preserve media referenced by already-persisted turns — src/gateway/server-methods/chat-send-agent-dispatch.ts:510
    isBlocked() is not an unreferenced-media signal: plugin-bound delivery sets it for transcriptWriteBlocked after hasPersisted() is already true. In that path this cleanup deletes inbound files still referenced by the persisted user turn. Record or carry a distinct redacted-unreferenced fact, and add coverage for this persisted blocked state.
    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 e2e070c927a6.

Labels

Label changes:

  • add P1: As written, the PR can delete attachment media retained by an existing user turn in a live gateway workflow.
  • add merge-risk: 🚨 session-state: The changed terminal cleanup can invalidate media references stored with persisted chat-session state.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This is maintainer-authored gateway work, so the external-contributor real-behavior-proof gate does not apply; the stated focused regression remains useful supplemental evidence.

Label justifications:

  • P1: As written, the PR can delete attachment media retained by an existing user turn in a live gateway workflow.
  • merge-risk: 🚨 session-state: The changed terminal cleanup can invalidate media references stored with persisted chat-session state.
  • 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 is maintainer-authored gateway work, so the external-contributor real-behavior-proof gate does not apply; the stated focused regression remains useful supplemental evidence.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs run src/gateway/server.chat.gateway-server-chat-b.test.ts.
  • [P1] node scripts/run-vitest.mjs run src/gateway/server-methods/chat-send-reply-dispatch.test.ts.
  • [P1] git diff --check.

What I checked:

Likely related people:

  • steipete: Authored the merged prepared-media custody repair that established the ACK handoff now being corrected. (role: feature owner; confidence: high; commits: 3ec408935026, 617b045887d9; files: src/gateway/server-methods/chat-send-handler.ts, src/gateway/server-methods/chat-send-attachments.ts)
  • Shakker: Current-line blame attributes the plugin-bound transcript-write blocking and gateway reply-dispatch marker path to this contributor. (role: recent area contributor; confidence: medium; commits: 8f807ae912d4; files: src/auto-reply/reply/dispatch-from-config.prepare-context.ts, src/gateway/server-methods/chat-send-reply-dispatch.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.

@steipete
steipete merged commit 8d262b9 into main Aug 16, 2026
257 checks passed
@steipete
steipete deleted the codex/autoqa-blocked-media branch August 16, 2026 02:39
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 16, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. 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