Skip to content

fix(gateway): give prepared chat.send media one abandonment-discard owner - #124100

Merged
steipete merged 1 commit into
mainfrom
codex/autoqa-media-orphan-exits
Aug 15, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/autoqa-media-orphan-exits

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

#123983 fixed two of six pre-persistence exits in chat.send that orphan staged inbound media. Prepared attachments live in ~/.openclaw/media/inbound with no transcript reference until the user turn persists, and the inbound sweep is disabled unless attachments.ttlHours is set — so on default installs every leaked file is orphaned permanently. Four sibling exits still leaked:

  • the post-reply-context abort check (chat-send-handler.ts steer window),
  • the post-reply-context routing-change check,
  • the pre-ACK injection settle's onAborted / onActiveLeafChanged outcomes,
  • any setup throw routed to handleChatSendSetupError (e.g. restart-safe admission failing "chat turn was not durably admitted" — by construction the media is unreferenced at that moment).

Why This Change Was Made

Instead of adding four more inline discards (and leaving the next new exit to leak again), custody moves to the lifecycle 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 abort/routing exits, and steer injections carry the same recorder, so the hasPersisted() gate is correct on every path. The ACK disarms the owner because dispatch's error lifecycle persists the referencing transcript on all post-ACK paths. The two inline discards #123983 added are deleted — one owner instead of six call sites, and future exits are covered by construction.

User Impact

Default-install operators no longer accumulate permanently orphaned media files when a send with attachments is aborted, steered into a changed leaf, hit by a hot config reload, or killed by a setup error.

Evidence

  • New regression test drives the setup-error exit with an offloaded attachment (addChatRun throws pre-ACK) and asserts the inbound dir returns to baseline — fails pre-fix (verified via stash), passes post-fix.
  • The original fix(gateway,ui): discard prepared attachment media on pre-persist exits and release catalog-open payloads #123983 abort-during-preparation test still passes through the new owner (its inline discards were replaced, not duplicated).
  • node scripts/run-vitest.mjs run src/gateway/server.chat.gateway-server-chat-b.test.ts — 101/101; src/gateway/server-chat.agent-events.test.ts — 145/145.
  • pnpm tsgo, pnpm check:test-types, oxfmt/oxlint clean; autoreview clean (0.93).

Production LOC +27/−2 (≈+11 code, remainder custody-invariant comments required by repo comment policy); tests +62.

…wner

#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.
@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 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 08:01
@steipete
steipete merged commit 3ec4089 into main Aug 15, 2026
251 checks passed
@steipete
steipete deleted the codex/autoqa-media-orphan-exits branch August 15, 2026 08:20
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Aug 16, 2026
…4353)

#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.
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.
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 size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant