Skip to content

fix(chat): progress images break after task cleanup for runs not started by a chat send - #165275

Merged
steipete merged 2 commits into
mainfrom
fix/agent-run-commentary-media-custody
Oct 5, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/agent-run-commentary-media-custody

Conversation

@steipete

@steipete steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: images an agent shows mid-task in Control UI chat turn into "File not found" cards when the run was not started by a chat send (for example a run resumed by Gateway restart recovery) and the referenced files are later cleaned up.

User Impact

User impact: progress attachments stay visible after reload and after the task deletes its scratch files, no matter which Gateway owner started the run. No change for final replies or message-tool attachments, which were already durable.

Why This Change Was Made

Chat sends already record delivery intent for MEDIA: references in mid-turn (commentary) text and copy those files into managed outgoing media, rewriting the transcript row's display content (#148795). Runs that enter through the agent method had none of that, so a commentary row kept raw workspace paths that the UI fetched live from disk. On the Team Gateway a restart-recovery run posted before/after screenshots from its task worktree; once the task removed .openclaw/tmp, every render failed.

The custody (prepare hook plus the observer's lifetime) is now one factory in the commentary media module. chat.send consumes it unchanged, and session-bound agent runs load it inside dispatch ownership and wrap the agent command in it. The prepare hook travels through a Gateway-only command option (stripped from public ingress). Sessionless runs skip custody; loader failures settle through the dispatcher's normal terminal path.

Evidence

  • Regression src/gateway/agent-turn/agent-run-commentary-media.test.ts: an agent run whose commentary block contains a local MEDIA: PNG persists openclawDelivery.mediaUrls and a managed display attachment (/api/chat/media/outgoing/... + artifactId), rejects hook-added references, and still resolves identical bytes after the source PNG is deleted. It fails on the original dispatcher.
  • agent-run-dispatch.owner.test.ts covers custody-loader failure cleanup (24 passed); agent-command-execution-identity.test.ts asserts the option is excluded from public ingress and stripped by the sanitizer.
  • Remote Linux runs: 36 sibling/importer files 1,673 passed; 13 affected files 692 passed after the final correction; node scripts/check-changed.mjs and the runtime build green; Codex autoreview scoped-clean.
  • docs/web/control-ui/chat.md now states that progress attachments are preserved for runs started by any Gateway owner.

Share chat.send's authored commentary media custody with session-bound
agent runs, including restart recovery and internal dispatch, so progress
attachments survive cleanup of their original workspace files.

Carry transcript preparation through Gateway-only command options and
attempt execution. Load custody inside dispatch ownership so startup stays
lazy and loader failures settle before the run owner is released.

Keep pre-hook delivery intent, sessionless behavior, and final-reply media
ownership intact. Cover durable artifact reads after source deletion and
custody-loader failure cleanup.
@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling labels Oct 5, 2026
@steipete
steipete marked this pull request as ready for review October 5, 2026 02:22
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 5, 2026
@clawsweeper

clawsweeper Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 10:28 PM ET / October 5, 2026, 02:28 UTC.

ClawSweeper review

What this changes

The branch shares progress-attachment preservation between chat sends and session-bound agent runs so attachments survive cleanup of their original files.

Merge readiness

✅ Ready for maintainer review

This PR addresses a source-confirmed gap that remains on current main. The shared custody implementation preserves existing media policy and dispatch cleanup; no concrete introduced defect was found.

Priority: P2
Reviewed head: 9df3f73b9f66222e2c0c57cf2792b70595909ca5

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused ownership repair with meaningful regression coverage and no supported blocking finding.
Proof confidence 🌊 off-meta tidepool Not applicable: Repository State identifies the author as MEMBER, so the ordinary external-contributor proof gate is exempt. The added regression exercises dispatch-to-storage durability with mocked admission/model execution; inspected screenshots belong to the earlier merged PR. Existing transcript fields and managed-media formats are reused without a stored-data contract change.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository State identifies the author as MEMBER, so the ordinary external-contributor proof gate is exempt. The added regression exercises dispatch-to-storage durability with mocked admission/model execution; inspected screenshots belong to the earlier merged PR. Existing transcript fields and managed-media formats are reused without a stored-data contract change.
Evidence reviewed 9 items Verified review scope: The checkout is the pinned PR head and remained clean. Review used the merge-base-to-head introduced delta, rather than endpoint drift.
Remaining current-main gap: Current-main dispatch invokes the agent command without loading commentary media custody or supplying its transcript preparer. Its execution phase still calls that dispatcher directly.
Run-bound custody: Sessionless runs retain their existing path. Session-bound runs lazily load the existing media owner and require the admitted registration, matching controller, current dispatch authority, and an unaborted run.
Findings None None.
Security None None.

How this fits together

Gateway agent dispatch runs tasks and records their conversation transcripts. Commentary media custody copies authored progress attachments into managed storage and updates transcript display content for Control UI history.

flowchart TD
A[Chat send or agent run] --> B[Admitted session execution]
B --> C[Authored progress attachment]
C --> D[Current run and media policy checks]
D --> E[Managed attachment storage]
E --> F[Transcript display update]
F --> G[Control UI history]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +108, Tests +223, Docs 0. Total +331 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 8 161 53 +108
Tests 4 258 35 +223
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 13 420 89 +331

Review metrics

Metric Value Why it matters
Production versus regression coverage production +108 LOC; tests +222 LOC Production growth supplies the missing agent-run adapter and shared custody factory, with focused durability and startup-failure coverage.

Technical review

Best possible solution:

Use one run-bound commentary media owner across Gateway entrypoints while preserving authored transcript bytes and existing attachment access policy.

Do we have a high-confidence way to reproduce the issue?

Yes, source establishes a clear path: a session-bound agent run records commentary MEDIA references without chat-send custody, then source-file deletion leaves history pointing at missing files. No runtime reproduction was executed in this review.

Is this the best way to solve the issue?

Yes, sharing the existing custody owner is a narrow repair that avoids parallel media policy and keeps completion within dispatch ownership.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 0db00eabfef9.

Labels

Label changes:

  • add P2: This repairs progress attachments becoming unreadable after scratch-file cleanup, with limited impact on conversation history.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Repository State identifies the author as MEMBER, so the ordinary external-contributor proof gate is exempt. The added regression exercises dispatch-to-storage durability with mocked admission/model execution; inspected screenshots belong to the earlier merged PR. Existing transcript fields and managed-media formats are reused without a stored-data contract change.

Label justifications:

  • P2: This repairs progress attachments becoming unreadable after scratch-file cleanup, with limited impact on conversation history.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Repository State identifies the author as MEMBER, so the ordinary external-contributor proof gate is exempt. The added regression exercises dispatch-to-storage durability with mocked admission/model execution; inspected screenshots belong to the earlier merged PR. Existing transcript fields and managed-media formats are reused without a stored-data contract change.

Evidence

What I checked:

  • Verified review scope: The checkout is the pinned PR head and remained clean. Review used the merge-base-to-head introduced delta, rather than endpoint drift. (9df3f73b9f66)
  • Remaining current-main gap: Current-main dispatch invokes the agent command without loading commentary media custody or supplying its transcript preparer. Its execution phase still calls that dispatcher directly. (src/gateway/agent-turn/agent-run-dispatch.ts:196, 0db00eabfef9)
  • Run-bound custody: Sessionless runs retain their existing path. Session-bound runs lazily load the existing media owner and require the admitted registration, matching controller, current dispatch authority, and an unaborted run. (src/gateway/agent-turn/agent-run-commentary-media.ts:21, 9df3f73b9f66)
  • Shared preservation and security contract: The factory records references from pre-hook source text and joins observer completion. The existing observer retains session/run matching, local media policy, live checks after awaits, exact-row rewriting, and cleanup of uncommitted artifacts. (src/gateway/server-methods/chat-send-commentary-media.ts:57, 9df3f73b9f66)
  • Focused regression coverage: The added test uses real dispatch, attempt forwarding, transcript persistence, managed attachment preparation, and artifact reads while mocking command admission and model execution. It checks original bytes after source deletion and excludes hook-added references. Tests were inspected, not executed during this read-only review. (src/gateway/agent-turn/agent-run-commentary-media.test.ts:133, 9df3f73b9f66)
  • Public ingress remains restricted: The transcript preparer is Gateway-only in the command types and is explicitly removed by the public ingress sanitizer; it is forwarded through the existing common attempt parameters. (src/agents/agent-command-execution-identity.ts:249, 9df3f73b9f66)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

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 cd29ad5 into main Oct 5, 2026
211 of 213 checks passed
@steipete
steipete deleted the fix/agent-run-commentary-media-custody branch October 5, 2026 02:57
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 5, 2026
…ted by a chat send (openclaw#165275)

* fix(gateway): keep progress attachments durable for agent-run turns

Share chat.send's authored commentary media custody with session-bound
agent runs, including restart recovery and internal dispatch, so progress
attachments survive cleanup of their original workspace files.

Carry transcript preparation through Gateway-only command options and
attempt execution. Load custody inside dispatch ownership so startup stays
lazy and loader failures settle before the run owner is released.

Keep pre-hook delivery intent, sessionless behavior, and final-reply media
ownership intact. Cover durable artifact reads after source deletion and
custody-loader failure cleanup.

* refactor(gateway): compact agent-run commentary media wiring
RomneyDa pushed a commit that referenced this pull request Oct 9, 2026
…ted by a chat send (#165275)

* fix(gateway): keep progress attachments durable for agent-run turns

Share chat.send's authored commentary media custody with session-bound
agent runs, including restart recovery and internal dispatch, so progress
attachments survive cleanup of their original workspace files.

Carry transcript preparation through Gateway-only command options and
attempt execution. Load custody inside dispatch ownership so startup stays
lazy and loader failures settle before the run owner is released.

Keep pre-hook delivery intent, sessionless behavior, and final-reply media
ownership intact. Cover durable artifact reads after source deletion and
custody-loader failure cleanup.

* refactor(gateway): compact agent-run commentary media wiring

(cherry picked from commit cd29ad5)
(cherry picked from commit f624ae99746b5ae36aa78072070f78fb4165b45b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant