Skip to content

fix(cli): preserve buffered media output on write failure - #117934

Merged
steipete merged 1 commit into
mainfrom
codex/autoqa-cli-media-buffer-atomic-20260802
Aug 2, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/autoqa-cli-media-buffer-atomic-20260802

Conversation

@steipete

@steipete steipete commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Closes #117926

What Problem This Solves

Fixes an issue where users replacing an existing buffered image or video --output could lose the original file when the filesystem write failed after truncation. The command exited nonzero, but partial generated bytes had already replaced the destination.

Why This Change Was Made

Buffered image and video publication now share the same sibling-temp atomic owner already used by streamed video output. A producer writes beside the destination, and OpenClaw renames that complete file into place only after success. The shared helper also centralizes existing-mode preservation and removes the duplicated streamed-video temp/mode path.

This stays at the CLI output publication boundary. Provider-specific guards would not protect every buffered media provider, and changing provider runtimes is unnecessary because they correctly return complete in-memory assets.

User Impact

Failed buffered image and video writes no longer destroy an existing output file. Successful generation keeps the same command, JSON result, output naming, complete bytes, and destination mode.

Evidence

  • Built current-main baseline a0d4aa34661f55804b5cc68f9b04e69081069574 on Blacksmith Testbox tbx_01kz0vqh64cm8zjr9sazmgfxtf / run 30741184034: deterministic fault injection made both real built-CLI commands exit 1 after replacing the existing destination with 17 generated bytes.
  • Exact head 826052eb9421511db690c27daf4c86d80271e0b0 on Blacksmith Testbox tbx_01kz0y0kmsr5wfrmvfy29ehhzn / run 30742503532: 136/136 focused capability-CLI assertions passed.
  • The exact-head complete unscoped check:changed gate passed, including formatting, production/test typechecks, lint, boundaries, dead-code scans, database/state guards, and import-cycle checks.
  • Exact-head full build passed and verified all 149 public Plugin SDK subpaths.
  • Exact-head source-blind built-CLI contract passed 4/4 cases through a temporary local provider plugin: image and video controls each published the complete 2,048-byte buffer with mode 0640; injected partial-write failures exited 1 while preserving the original image/video bytes and mode; no sibling temp remained.
Redacted exact-head built-CLI output
{
  "head": "826052eb9421511db690c27daf4c86d80271e0b0",
  "summary": { "pass": 4, "fail": 0, "blocked": 0 },
  "imageValid": { "exit": 0, "size": 2048, "mode": "0640", "tempFiles": 0 },
  "imageFault": { "exit": 1, "preserved": "existing-image-fault", "mode": "0640", "tempFiles": 0 },
  "videoValid": { "exit": 0, "size": 2048, "mode": "0640", "tempFiles": 0 },
  "videoFault": { "exit": 1, "preserved": "existing-video-fault", "mode": "0640", "tempFiles": 0 }
}

Production delta: +42/-25 (net +17, primarily the shared atomic owner). Tests: +70/-0. Docs: +1/-0. No config, protocol, storage, migration, dependency, provider-runtime, or Gateway change.

AI-assisted: yes.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes size: S maintainer Maintainer-authored PR labels Aug 2, 2026
@steipete
steipete marked this pull request as ready for review August 2, 2026 09:35
@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. P2 Normal backlog priority with limited blast radius. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 2, 2026, 6:06 AM ET / 10:06 UTC.

ClawSweeper review

What this changes

The PR stages buffered image and video CLI output in a sibling temporary file and atomically replaces --output only after a complete write succeeds.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open for explicit maintainer review: the patch is a focused, source-backed data-integrity repair with strong real CLI proof, but the protected maintainer label and currently failed hosted gate require human handling before merge.

Priority: P2
Reviewed head: 826052eb9421511db690c27daf4c86d80271e0b0
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Strong real CLI evidence and a focused shared-owner repair support a high-confidence patch assessment; hosted gate resolution remains a merge workflow requirement.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body includes redacted exact-head built-CLI terminal results covering successful image/video publication and injected partial-write failures that preserve existing bytes, mode, and cleanup behavior.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body includes redacted exact-head built-CLI terminal results covering successful image/video publication and injected partial-write failures that preserve existing bytes, mode, and cleanup behavior.
Evidence reviewed 6 items Current main still has the defect: Current main writes buffered assets directly to the final destination, so a partial fs.writeFile failure can truncate an existing output before the command reports failure.
Patch repairs the owning boundary: The branch adds one publication helper that creates a sibling temporary file, preserves an existing mode, and delegates final replacement to the established sibling-temp abstraction; buffered output now calls that helper.
Shared-path regression coverage: The branch injects a partial write failure for both buffered image and buffered video output, then asserts the original bytes, mode, and directory contents remain intact.
Findings None None.
Security None None.

How this fits together

OpenClaw's local infer CLI receives generated image/video assets from provider runtimes and publishes them to an operator-selected output path. This change sits at that publication boundary, preserving an existing destination when a producer or filesystem write fails.

flowchart LR
  A[Media provider result] --> B[Infer image or video command]
  B --> C[CLI output publication]
  C --> D[Sibling temporary file]
  D -->|complete write| E[Atomic replacement]
  D -->|write failure| F[Existing destination preserved]
Loading

Decision needed

Question Recommendation
Should this protected-label CLI data-integrity repair be approved once the failed exact-head hosted gates are resolved and the PR remains cleanly mergeable? Approve after green gates: Confirm the failed build/CI gate is resolved on the reviewed head, then approve the focused atomic-output repair.

Why: The code and real behavior proof support the repair, but repository policy requires explicit maintainer handling for protected-label items and the remaining hosted-gate state cannot be resolved from source inspection alone.

Before merge

  • Resolve merge risk (P1) - GitHub currently records build-artifacts and openclaw/ci-gate as failed for this PR state; the exact-head required-gate result must be resolved or rerun successfully before merge.
Agent review details

Security

None.

PR surface

Source +17, Tests +70, Docs +1. Total +88 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 42 25 +17
Tests 1 70 0 +70
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 113 25 +88

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: src/cli/capability-cli.test.ts, serialized state: src/cli/capability-cli/media-output.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #117926
Summary: This PR is the concrete candidate fix for the canonical buffered media output corruption report.

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 canonical atomic publication helper at the CLI output boundary, retain the focused failure coverage for buffered image/video and streamed video, and merge after the exact-head hosted gates are green and a maintainer approves the protected repair.
  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 canonical atomic publication helper at the CLI output boundary, retain the focused failure coverage for buffered image/video and streamed video, and merge after the exact-head hosted gates are green and a maintainer approves the protected repair.

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

Yes. The linked report and PR body provide a source-blind built-CLI fault-injection run on the relevant current-main lineage, and current main still directly writes buffered output to the final path.

Is this the best way to solve the issue?

Yes. Centralizing same-directory atomic publication at the shared CLI output boundary covers both buffered media paths without provider-specific policy or a new configuration surface.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 0bc32f0f5cf5.

Labels

Label justifications:

  • P2: This is a bounded CLI data-integrity bug affecting failed replacement of generated media output, with strong focused evidence but no demonstrated widespread outage.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes redacted exact-head built-CLI terminal results covering successful image/video publication and injected partial-write failures that preserve existing bytes, mode, and cleanup behavior.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes redacted exact-head built-CLI terminal results covering successful image/video publication and injected partial-write failures that preserve existing bytes, mode, and cleanup behavior.

Evidence

What I checked:

  • Current main still has the defect: Current main writes buffered assets directly to the final destination, so a partial fs.writeFile failure can truncate an existing output before the command reports failure. (src/cli/capability-cli/media-output.ts:45, 0bc32f0f5cf5)
  • Patch repairs the owning boundary: The branch adds one publication helper that creates a sibling temporary file, preserves an existing mode, and delegates final replacement to the established sibling-temp abstraction; buffered output now calls that helper. (src/cli/capability-cli/media-output.ts:20, 826052eb9421)
  • Shared-path regression coverage: The branch injects a partial write failure for both buffered image and buffered video output, then asserts the original bytes, mode, and directory contents remain intact. (src/cli/capability-cli.test.ts:2031, 826052eb9421)
  • Existing sibling path already follows this invariant: Current main already stages URL-streamed video output with the sibling-temp helper, and its focused test verifies that a stream failure preserves the previous destination; moving the duplicate owner into media output aligns buffered and streamed paths. (src/cli/capability-cli/video.ts:179, 0bc32f0f5cf5)
  • History and ownership provenance: Blame attributes the new atomic publication owner to the PR head, while the surrounding media-output implementation dates to the prior capability-command refactor by the same current-main contributor. (src/cli/capability-cli/media-output.ts:20, 826052eb9421)
  • Three-way merge remains coherent: A local merge-tree against current main produced a merged result without a conflict in the changed CLI output code. (src/cli/capability-cli/video.ts:163, 826052eb9421)

Likely related people:

  • steipete: Current-main history attributes the capability CLI split and the subsequent streamed-video output hardening to Peter Steinberger; the same history owns the adjacent publication paths this PR consolidates. (role: recent area contributor and feature-history owner; confidence: high; commits: 9c065c895e78, 83fa625fb63a, 826052eb9421; files: src/cli/capability-cli/media-output.ts, src/cli/capability-cli/video.ts, src/cli/capability-cli.test.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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-02T09:41:04.166Z sha 579a9689fc0263d9aa26e45d467d7a1fb3362d16 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-02T09:53:23.960Z sha 826052e :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the codex/autoqa-cli-media-buffer-atomic-20260802 branch from 579a968 to 826052e Compare August 2, 2026 09:47
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 2, 2026
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready proof for exact head 826052eb9421511db690c27daf4c86d80271e0b0.

Root cause: buffered image/video generation called fs.writeFile on the final --output path. A filesystem failure after open/truncate could therefore destroy the existing file before the command reported failure.

Provenance (clear): the direct buffered output writer originated in #62129, authored and merged by @Takhoffman on April 7, 2026. The capability-command split in #108419, authored and merged by @steipete, carried the same behavior into src/cli/capability-cli/media-output.ts.

Canonical repair: buffered image/video output now uses one shared atomic publication helper backed by @openclaw/fs-safe sibling-temp writes. The existing streamed-video caller uses the same owner, removing its duplicate directory, mode, temp, and rename policy. Provider runtimes and no---output media storage remain unchanged.

Proof:

Scope: 4 files; production +42/-25 (net +17), tests +70/-0, docs +1/-0. No config, protocol, storage, migration, dependency, provider-runtime, or Gateway change. Residual risk is low and confined to CLI media-output publication. No known proof gaps.

@steipete
steipete merged commit 610ca42 into main Aug 2, 2026
210 of 214 checks passed
@steipete
steipete deleted the codex/autoqa-cli-media-buffer-atomic-20260802 branch August 2, 2026 10:15
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S 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.

[Bug]: buffered infer output corrupts existing files on write failure

1 participant