Skip to content

fix(media): roll back partial generated batches - #119292

Merged
steipete merged 2 commits into
mainfrom
codex/qa-media-batch-rollback
Aug 4, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/qa-media-batch-rollback

Conversation

@steipete

@steipete steipete commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Closes #119284

What Problem This Solves

When one generated item in an image, music, or video batch failed to persist, files already saved by the same batch were left in the managed media store even though the tool returned an error and no result referenced them. Concurrent image/music saves could be worse: Promise.all returned the first rejection while another filesystem write was still running, allowing a late orphan to appear after failure was already reported.

Root Cause

Each tool owned its own save loop but none owned batch commit/rollback semantics:

  • image and music used Promise.all, which rejects before sibling writes settle;
  • video saved sequentially but threw without compensating earlier successful writes;
  • cleanup existed only in the media store as a guarded single-file operation, not at the generated-batch owner.

Current-main reproduction at 1cf1af4aed3dedb010a885fcc9dc652f6d6d93d2 added one boundary case per tool. All three failed while the other 125 tests passed.

What Changed

  • Added one agent-tool batch persistence owner with concurrent and sequential modes.
  • Concurrent image/music batches drain every already-started write before deciding rollback, so late successes cannot escape.
  • Sequential video batches stop at the first terminal failure and roll back earlier saved files without changing large-buffer write ordering.
  • Rollback uses the canonical path-guarded deleteMediaBuffer, best-effort cleanup cannot mask the original persistence error, and successful result ordering is preserved.
  • Video's existing over-limit buffer → provider URL fallback remains a successful non-persisted item rather than a batch failure.
  • Added filesystem-backed proof against an isolated real managed media store for both sequential and concurrent rollback orderings.

No protocol, configuration, provider, storage schema, background-task, delivery, or successful-result contract changes.

Observed Behavior

The fixed tests prove:

  1. image/music execution does not settle while a sibling save is still running after another save fails;
  2. every late or already-successful file from the failed batch is deleted;
  3. sequential video rollback deletes files saved before a later failure;
  4. cleanup failures are contained and the original persistence error is rethrown;
  5. real saveMediaBuffer writes resolve and contain the expected bytes before failure, then resolveMediaBufferPath rejects after rollback;
  6. all existing successful, background, metadata, and URL-fallback cases remain green.

Evidence

Exact head: 4140df297a113d167e3cdbe74d5db1954d74fa63.

Repair Doctrine Summary

  • Architectural owner: the generated-media tool layer, which turns a provider batch into one tool result.
  • Canonical fix: one all-or-nothing persistence helper shared by image, music, and video.
  • Removed/avoided paths: no retry, TTL-only workaround, duplicate per-tool cleanup, fallback store, or weakened error.
  • Production delta: +125/-34 (net +91), paying for the shared batch transaction and compensating cleanup boundary.
  • Test delta: +254/-0 across the shared owner and all three sibling tools.
  • Risk: low-medium. Failure behavior gains bounded local cleanup; successful persistence ordering, video memory behavior, and output shapes are unchanged.

Release-note context: generated image, music, and video batches no longer leave managed-media files behind when a later item fails to save.

AI-assisted: yes.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Aug 4, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Aug 4, 2026
@clawsweeper

clawsweeper Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 4, 2026, 2:11 PM ET / 18:11 UTC.

ClawSweeper review

What this changes

The PR makes generated image, music, and video batches delete files already persisted by the batch if a later save fails.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open for explicit maintainer handling: the rollback design is correct and sufficiently proven, but this protected PR remains behind main with an unfinished and a failed normal CI check in the supplied exact-head status.

Priority: P2
Reviewed head: 4140df297a113d167e3cdbe74d5db1954d74fa63
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-backed repair with strong real-store proof; current branch and required-check state remain merge gates rather than patch defects.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR documents exact-head filesystem-backed proof against an isolated real managed-media store, including bytes observed before failure and canonical-path absence after rollback.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR documents exact-head filesystem-backed proof against an isolated real managed-media store, including bytes observed before failure and canonical-path absence after rollback.
Evidence reviewed 6 items Current-main failure path: Image and music use Promise.all for managed-media writes, so a first rejected save can return before sibling writes settle; video rethrows a later sequential failure without compensating earlier writes.
Canonical cleanup contract: The media store persists bytes before returning SavedMedia and provides path-guarded deletion; its contract explicitly leaves best-effort suppression to the batch owner.
Shared owner preserves failure semantics: The proposed helper drains concurrent saves with Promise.allSettled, rolls back every recorded SavedMedia through the canonical delete API, and rethrows the first persistence error.
Findings None None.
Security None None.

How this fits together

Generated-media tools convert provider buffers into managed media files before returning tool results to an agent. The new batch owner decides whether those writes become a complete result or are removed after a terminal persistence failure.

flowchart LR
  Provider[Generated media provider] --> Tools[Image music and video tools]
  Tools --> Batch[Batch persistence owner]
  Batch --> Store[Managed media store]
  Store --> Decision{All saves succeed?}
  Decision -->|Yes| Result[Tool media result]
  Decision -->|No| Rollback[Delete batch files]
  Rollback --> Error[Original persistence error]
Loading

Decision needed

Question Recommendation
Should this protected maintainer PR be accepted once its exact resulting head has green required checks? Accept after exact-head validation: Keep the shared rollback owner and merge after the required checks pass on the head that will be merged.

Why: The patch is technically sound, but the protected maintainer label requires an explicit human merge decision after the branch and CI state are current.

Before merge

  • Resolve merge risk (P1) - The supplied GitHub state shows the branch behind main, one failed compact check, and one in-progress compact check; merge must wait for green required gates on the exact resulting head.
Agent review details

Security

None.

PR surface

Source +91, Tests +254. Total +345 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 4 125 34 +91
Tests 4 254 0 +254
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 379 34 +345

Review metrics

Metric Value Why it matters
Production versus test delta production +91 net; tests +254 The production growth is justified by one shared persistence owner that replaces three incomplete per-tool failure paths, with focused sibling and real-store regression coverage.

Stored data model

Persistent data-model change detected: serialized state: src/agents/tools/generated-media-batch-persistence.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #119284
Summary: This PR is the focused candidate fix for the linked generated-media partial-persistence bug.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep one shared generated-media batch transaction at the tool layer, retain the media store’s guarded delete primitive, and merge only after the refreshed exact head is fully validated.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep one shared generated-media batch transaction at the tool layer, retain the media store’s guarded delete primitive, and merge only after the refreshed exact head is fully validated.

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

Yes. Current main directly exposes the failure path through concurrent image/music writes and uncompensated sequential video writes; the PR supplies focused boundary cases, though this read-only review did not execute them.

Is this the best way to solve the issue?

Yes. A single generated-media batch owner is the narrowest maintainable fix because it owns the provider-batch-to-tool-result boundary while reusing the media store’s existing guarded cleanup contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 7a0a4c5f2a3b.

Labels

Label justifications:

  • P2: A failed generated-media batch can leave orphaned managed files, a bounded defect affecting image, music, and video generation.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR documents exact-head filesystem-backed proof against an isolated real managed-media store, including bytes observed before failure and canonical-path absence after rollback.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR documents exact-head filesystem-backed proof against an isolated real managed-media store, including bytes observed before failure and canonical-path absence after rollback.

Evidence

What I checked:

Likely related people:

  • steipete: Peter Steinberger introduced all three generated-media tools and the atomic media-store write path, then authored this focused repair. (role: feature owner and recent media contributor; confidence: high; commits: 3a456678ee35, 579043597564, dc0ee2e178dc; files: src/agents/tools/image-generate-tool.ts, src/agents/tools/music-generate-tool.ts, src/agents/tools/video-generate-tool.ts)
  • vincentkoc: Current-main blame for the affected paths and recent media-store work identify Vincent Koc as a relevant adjacent owner, though the shallow history cannot establish an exact introducing change. (role: recent adjacent contributor; confidence: medium; commits: 52954a1fa8f4; files: src/agents/tools/image-generate-tool.ts, src/agents/tools/music-generate-tool.ts, src/agents/tools/video-generate-tool.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Obtain green required checks on the exact head that will be merged; request one exact-head re-review if that refresh changes code.

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 (2 earlier review cycles)
  • reviewed 2026-08-04T17:19:19.456Z sha 598d15c :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-04T18:02:32.608Z sha 4140df2 :: needs maintainer review before merge. :: none

@steipete

steipete commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 4, 2026
@steipete

steipete commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready proof for 4140df297a113d167e3cdbe74d5db1954d74fa63.

Production delta is +125/-34 for the shared ownership boundary; tests are +254/-0. No protocol, config, provider, schema, delivery, or successful-result contract changed. No proof gap remains.

@steipete
steipete merged commit 941e18d into main Aug 4, 2026
208 of 218 checks passed
@steipete
steipete deleted the codex/qa-media-batch-rollback branch August 4, 2026 18:23
@steipete

steipete commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 4, 2026
…fecycle-20260804

* origin/main:
  perf(agents): reuse provider policy manifest registry (#119305)
  fix(media): roll back partial generated batches (#119292)
vincentkoc added a commit that referenced this pull request Aug 4, 2026
Punchcard-Session: crisp-lantern-orchard-nv

* origin/main: (46 commits)
  perf(agents): reuse provider policy manifest registry (#119305)
  fix(media): roll back partial generated batches (#119292)
  fix(gateway): steer matching embedded turns (#119287)
  fix(telegram): correlate deliveries to explicit topics
  fix(plugins): preserve install index state across failures (#119228)
  test: trim redundant control ui coverage (#119286)
  test: cover missing config method in memory settings
  fix: gate curated config controls by method
  test: cover read-only admin method gates
  fix: keep config drafts on their gateway
  fix: reset agent skill filters with config patch
  refactor: reuse chat error state helper
  test: avoid unbound identity request assertion
  refactor: isolate clawhub skill search
  fix: guard delayed config actions across reconnects
  fix: preserve workshop revisions across session navigation
  refactor: isolate workshop revision handoff
  test: advertise skill action methods in ui e2e
  fix: fail stale workshop revision sends
  fix: bind revision handoffs to gateway snapshots
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 5, 2026
* fix(media): roll back partial generated batches

* test(media): prove generated batch rollback on disk
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 6, 2026
…fecycle-20260804

* origin/main:
  perf(agents): reuse provider policy manifest registry (openclaw#119305)
  fix(media): roll back partial generated batches (openclaw#119292)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

Generated-media batch persistence leaves orphaned files on partial failure

1 participant