Skip to content

fix(cli): preserve TTS output on copy failure - #117962

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

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

Conversation

@steipete

@steipete steipete commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Closes #117953

What Problem This Solves

Fixes an issue where users replacing an existing local or loopback-Gateway TTS --output could lose the original audio when the final copy failed after truncation. The command exited nonzero, but partial synthesized bytes had already replaced the destination.

Why This Change Was Made

Both TTS copy paths now use the atomic sibling-temp publication owner introduced for generated image/video output. The source audio copies beside the destination, then replaces it only after a complete copy succeeds. This completes the same CLI publication invariant without adding TTS-specific temp or mode policy.

Remote-Gateway --output remains explicitly unsupported; provider synthesis, Gateway RPC, and OpenClaw's no---output TTS persistence are unchanged.

User Impact

Failed TTS output copies no longer destroy an existing audio file. Successful local and loopback-Gateway conversion keeps the same command, JSON result, complete audio bytes, path, and destination mode.

Evidence

  • Built current-main baseline 9045484aea506c14aa2419b181a348d93a3d24ef on Blacksmith Testbox tbx_01kz0zv3wsd6d9c6zby2r9tvj8 / run 30743562486: the real built CLI exited 1 after replacing existing-speech with 17 synthesized bytes.
  • Exact head e93bc7ddd610776bb1191a64b7c20bd195e72cd5 on Blacksmith Testbox tbx_01kz114ga3nsjfq9aq4y50b5bk / run 30744299295: 138/138 focused capability-CLI assertions passed, including local and loopback-Gateway partial-copy failure coverage.
  • The exact-head full unscoped check:changed gate passed, including formatting, production/test typechecks, lint, boundaries, dead-code scans, database/media 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 2/2 through a temporary local speech provider: the valid control published all 2,048 bytes with mode 0640; injected copy failure exited 1 while preserving existing-speech-fault, mode 0640, and no sibling temp.
Redacted exact-head built-CLI output
{
  "head": "e93bc7ddd610776bb1191a64b7c20bd195e72cd5",
  "summary": { "pass": 2, "fail": 0, "blocked": 0 },
  "valid": { "exit": 0, "size": 2048, "mode": "0640", "tempFiles": 0 },
  "fault": { "exit": 1, "preserved": "existing-speech-fault", "mode": "0640", "tempFiles": 0 }
}
  • Final exact-head autoreview: clean, no accepted/actionable findings, correctness confidence 0.98.
  • Public model identifier gate: PASS; the diff adds no model identifier.
  • Hosted exact-head CI run 30744274755 completed successfully; node scripts/watch-pr-ci.mjs 117962 e93bc7ddd610776bb1191a64b7c20bd195e72cd5 returned GREEN.

Production delta: +12/-4 (net +8). Tests: +68/-0. Docs: +1/-0. No config, protocol, storage, migration, dependency, provider-runtime, Gateway RPC, or remote-Gateway behavior 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 10:42
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. 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, 7:02 AM ET / 11:02 UTC.

ClawSweeper review

What this changes

The PR routes local and loopback-Gateway TTS --output copies through the shared sibling-temp publisher so failed copies preserve an existing audio file.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

This is a focused, evidence-backed data-integrity repair: the branch correctly applies the existing atomic publication owner to both TTS --output paths, has strong built-CLI proof, and merges cleanly with current main. The protected maintainer label and linked open issue mean it should remain open for an explicit merge decision. Likely related people: steipete (high confidence) and Dallin Romney (medium confidence).

Priority: P0
Reviewed head: e93bc7ddd610776bb1191a64b7c20bd195e72cd5
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Strong real CLI proof, focused regression coverage, and reuse of the existing publication owner make this a high-confidence repair pending protected-label maintainer review.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR includes redacted exact-head built-CLI before/after evidence for both successful publication and injected partial-copy failure, showing preserved prior bytes, mode, and temp-file cleanup.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR includes redacted exact-head built-CLI before/after evidence for both successful publication and injected partial-copy failure, showing preserved prior bytes, mode, and temp-file cleanup.
Evidence reviewed 7 items Current-main defect remains in the owner path: Current main directly creates the destination directory and copies generated audio to the final path in the loopback-Gateway branch; the local branch uses the same direct final-destination copy pattern. A partial copy failure can therefore replace existing user bytes before throwing.
Branch uses the canonical publisher in both TTS branches: The proposed helper delegates its temporary copy to publishOutputFileAtomically, and both local and loopback-Gateway --output paths call it instead of copying straight to the destination.
Shared helper protects the required invariant: The existing publisher creates the parent directory, captures the existing destination mode, writes in the destination directory, and resolves the final path only through the sibling-temp-file contract.
Findings None None.
Security None None.

How this fits together

The capability CLI invokes either local TTS synthesis or a loopback Gateway, then optionally publishes the generated audio to an operator-selected --output path. That publication step determines both the reported output path and whether a failed filesystem copy can overwrite prior user audio.

flowchart LR
  A[CLI TTS convert command] --> B{Local or loopback Gateway}
  B --> C[Generated audio path]
  C --> D[Optional output path]
  D --> E[Sibling temporary copy]
  E --> F{Copy completed?}
  F -->|Yes| G[Atomically replace destination]
  F -->|No| H[Keep prior audio unchanged]
Loading

Decision needed

Question Recommendation
Should this protected, proof-positive data-integrity repair be refreshed against current main and merged now? Refresh and merge: Rebase or otherwise refresh the clean merge result on current main, retain the focused two-transport regression coverage, and merge the repair.

Why: The code and supplied real behavior proof support the fix, but the maintainer label requires an explicit maintainer merge decision rather than automated cleanup.

Before merge

  • Resolve merge risk (P1) - The branch is behind current main; although the inspected three-way merge is clean, a maintainer should refresh the candidate against the current base or confirm GitHub’s final merge result before landing.
  • Complete next step (P2) - The patch is ready for explicit maintainer merge handling, but the protected maintainer label and linked open issue rule out automated close or repair dispatch.
Agent review details

Security

None.

PR surface

Source +8, Tests +68, Docs +1. Total +77 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 12 4 +8
Tests 1 68 0 +68
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 81 4 +77

Review metrics

None.

Stored data model

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

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #117953
Summary: This PR is the concrete candidate fix for the linked TTS output data-loss report and should stay open until it is merged or otherwise resolved.

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 atomic output-publication path and merge this focused repair after a current-base refresh confirms the same built-CLI preservation behavior.
  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 atomic output-publication path and merge this focused repair after a current-base refresh confirms the same built-CLI preservation behavior.

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

Yes, at source level with high confidence: the linked report supplies a built-CLI partial-copy reproduction, and current main still directly copies to the final destination in both affected TTS paths.

Is this the best way to solve the issue?

Yes. Reusing the established sibling-temp publication helper is the narrowest maintainable repair because it centralizes directory creation, destination-mode preservation, cleanup, and atomic replacement policy.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 92c7400a54a3.

Labels

Label justifications:

  • P0: The repaired path can silently destroy an existing operator-selected audio file after reporting a failed command, making it a data-loss-class regression.
  • 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 includes redacted exact-head built-CLI before/after evidence for both successful publication and injected partial-copy failure, showing preserved prior bytes, mode, and temp-file cleanup.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR includes redacted exact-head built-CLI before/after evidence for both successful publication and injected partial-copy failure, showing preserved prior bytes, mode, and temp-file cleanup.

Evidence

What I checked:

  • Current-main defect remains in the owner path: Current main directly creates the destination directory and copies generated audio to the final path in the loopback-Gateway branch; the local branch uses the same direct final-destination copy pattern. A partial copy failure can therefore replace existing user bytes before throwing. (src/cli/capability-cli/tts-runtime.ts:75, 92c7400a54a3)
  • Branch uses the canonical publisher in both TTS branches: The proposed helper delegates its temporary copy to publishOutputFileAtomically, and both local and loopback-Gateway --output paths call it instead of copying straight to the destination. (src/cli/capability-cli/tts-runtime.ts:37, e93bc7ddd610)
  • Shared helper protects the required invariant: The existing publisher creates the parent directory, captures the existing destination mode, writes in the destination directory, and resolves the final path only through the sibling-temp-file contract. (src/cli/capability-cli/media-output.ts:24, 92c7400a54a3)
  • Regression coverage spans both affected transports: The added parameterized capability-CLI test injects a partial copy failure for local and loopback-Gateway conversion, then asserts preserved bytes, mode, absent JSON success output, and no leftover sibling temp file. (src/cli/capability-cli.test.ts:2907, e93bc7ddd610)
  • Real built-CLI proof is supplied: The PR body records a source-blind built-CLI control and injected-copy-failure run: the successful command published 2,048 bytes with mode 0640, while the failure exited 1, retained the prior destination contents and mode, and left no sibling temp file. (e93bc7ddd610)
  • Canonical helper provenance: The shared atomic media publication helper was introduced by the recent current-main fix that established this CLI output invariant, so reusing it avoids a parallel TTS-specific policy. (src/cli/capability-cli/media-output.ts:20, 610ca42ce3d2)

Likely related people:

  • steipete: Current-main history attributes the shared atomic media-output repair to Peter Steinberger, and this PR reuses that exact owner boundary rather than introducing a separate TTS mechanism. (role: shared publication invariant owner and recent CLI contributor; confidence: high; commits: 610ca42ce3d2; files: src/cli/capability-cli/media-output.ts, src/cli/capability-cli/tts-runtime.ts)
  • Dallin Romney: Recent file history and line provenance connect this contributor to the current TTS CLI runtime surface that contains the direct-copy behavior. (role: recent TTS runtime contributor; confidence: medium; commits: 44dc286ce7c7; files: src/cli/capability-cli/tts-runtime.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 (1 earlier review cycle)
  • reviewed 2026-08-02T10:48:00.238Z sha e93bc7d :: needs maintainer review before merge. :: none

@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready proof for exact head e93bc7ddd610776bb1191a64b7c20bd195e72cd5.

Root cause: both local and loopback-Gateway TTS branches copied synthesized audio directly into the final --output, allowing a partial copyFile failure to destroy prior user bytes before reporting failure.

Provenance (clear): the direct TTS output copies originated in #62129, authored and merged by @Takhoffman on April 7, 2026. The capability-command split in #108419, authored and merged by @steipete, carried them into src/cli/capability-cli/tts-runtime.ts.

Canonical repair: both TTS callers now copy through the shared atomic publication owner landed in #117934. This removes final-path writes without introducing TTS-specific temp/mode/cleanup policy. Remote-Gateway rejection, synthesis, RPC, and no---output persistence are unchanged.

Proof:

  • Baseline main-at-9045484aea506c14aa2419b181a348d93a3d24ef Testbox tbx_01kz0zv3wsd6d9c6zby2r9tvj8, run 30743562486: the real built CLI exited 1 after replacing existing-speech with 17 synthesized bytes.
  • Exact-head Testbox tbx_01kz114ga3nsjfq9aq4y50b5bk, run 30744299295: remote HEAD and clean tree verified as e93bc7ddd610776bb1191a64b7c20bd195e72cd5; 138/138 focused assertions, full unscoped check:changed, and full build passed, including all 149 public Plugin SDK subpaths.
  • Exact-head source-blind built-CLI contract passed 2/2 through a temporary local speech provider. The control copied all 2,048 bytes with mode 0640; injected failure exited 1 while preserving existing-speech-fault, mode, and directory contents with no temp. Redacted output is in the PR body.
  • Hosted CI https://github.com/openclaw/openclaw/actions/runs/30744274755 completed successfully; the repo watcher returned GREEN.
  • Final exact-head autoreview: clean, no accepted/actionable findings, correctness confidence 0.98.
  • ClawSweeper reviewed this head at 5/6 for readiness, proof, and patch quality with no finding. After fetching origin/main at 55816c47d133d00bf0b6306881589975505338a9, GitHub still reports the PR MERGEABLE; this comment records the explicit maintainer landing decision.
  • Repo-native review artifacts validate READY FOR /prepare-pr with zero findings. OPENCLAW_TESTBOX=1 scripts/pr prepare-run 117962 completed without changing the head.
  • Public model identifier gate: PASS; the diff adds no model identifier.

Scope: 3 files; production +12/-4 (net +8), tests +68/-0, docs +1/-0. No config, protocol, storage, migration, dependency, provider-runtime, Gateway RPC, or remote-Gateway behavior change. Residual risk is low and confined to final TTS file publication. No known proof gaps.

@steipete
steipete merged commit 85e4094 into main Aug 2, 2026
201 of 210 checks passed
@steipete
steipete deleted the codex/autoqa-cli-tts-atomic-20260802 branch August 2, 2026 11:08
@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 P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. 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]: TTS output corrupts existing file when copy fails

1 participant