Skip to content

fix(cli): stop image output after accepted interrupts - #191176

Merged
obviyus merged 2 commits into
openclaw:mainfrom
zhangguiping-xydt:fix/infer-image-interrupt
Nov 2, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
zhangguiping-xydt:fix/infer-image-interrupt

Conversation

@zhangguiping-xydt

@zhangguiping-xydt zhangguiping-xydt commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

openclaw infer image generate and image edit can create or overwrite an output file after the CLI has accepted Ctrl+C.

User Impact

Cancelling image generation/editing now discards late provider results before output writes begin. Already-started writes retain their existing atomic publication behavior. Normal output, model selection and image bytes are unchanged.

Why This Change Was Made

Pass the existing CLI work-scope signal to image generation and check it before dispatch and after the provider returns, before publishing outputs. No new lifecycle owner, configuration or API. Original fix by @zhangguiping-xydt; their commits are retained.

Evidence

Independent built-CLI before/after proof and hashes.

Built main f33f9c1c53f911816103cb6e04b67d52be4369a2 and candidate production in secretless Linux/Node 24.22.1 isolation. A local LiteLLM-compatible HTTP fixture receives a real generation/edit request, holds its response until the CLI acknowledges SIGINT, then releases the image. Both commands start with an existing destination.

  • Main twice: generate and edit overwrite the destination despite exit 130 and acknowledged cancellation.
  • Candidate twice: generate and edit exit 130 and preserve the destination byte-for-byte.
  • All uninterrupted controls write the same PNG and exit 0.
  • 109 focused tests passed; the consolidated late-result regression fails on main's destination-byte preservation. Targeted Oxlint/Oxfmt passed.
  • Simplification reused the existing edit-options fixture, removed duplicate cancellation setup and its allocation: production +6/-0, tests +56/-56 (net zero), docs +1/-1 against the merge base.

The runtime proof uses the actual built CLI and HTTP adapter, not a private helper or paid provider. The focused test separately returns a result after its work scope closes, protecting the noncooperating-provider boundary.

Merge Danger

Two-way door: a revert fully restores previous behavior; no persisted-state migration or public contract changes. Blast radius is local image generation/editing cancellation before output publication. This does not roll back a write already underway.

@clawsweeper

clawsweeper Bot commented Nov 2, 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 cli CLI command changes size: S labels Nov 2, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. 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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 2, 2026
@clawsweeper

clawsweeper Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR forwards CLI cancellation to image providers and discards late results before output writes begin.

Example: Run image edit with --output portrait.png, then press Ctrl+C while the provider is responding.

  • Before: A late provider result can overwrite portrait.png despite acknowledged cancellation and exit 130.
  • After: The command exits 130 and preserves the existing destination bytes.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A narrow, useful repair with shipped-CLI before/after evidence, a baseline-failing late-result regression, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The exact-head proof comment records real built image generate/edit commands on isolated Linux arm64 with Node 24.22.1 and a real LiteLLM HTTP adapter: responses released after acknowledged SIGINT overwrite baseline destinations but preserve candidate bytes, while uninterrupted controls succeed.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An image command can overwrite a destination after the CLI has acknowledged the user's cancellation.
Reason: Preserving destination bytes after accepted cancellation has clear user value, follows the existing video precedent, and needs no new option, public API, or lifecycle owner.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current image CLI cancellation defect with a focused change and no actionable findings; normal CI gates remain pending.

Priority: P2
Reviewed head: 8d12010ba7d97ea13a68db69b28c34d474dd36e5

Before merge

None.

Findings

None.

Agent review details

How this fits together

The inference CLI resolves image options and agent configuration, calls the shared generation runtime, and publishes returned image buffers through the existing atomic file writer.

flowchart LR
  A[Image CLI command] --> B[Image generation runtime]
  C[CLI work scope] --> B
  B --> D[Provider adapter]
  D --> E[Cancellation check]
  C --> E
  E --> F[Atomic output writer]
Loading

Technical review

Best possible solution:

Merge the focused cancellation fix once the normal exact-head CI gates pass, retaining the existing atomic writer and already-started-write behavior.

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

The supplied built-CLI comparison reproduces overwrites after acknowledged SIGINT, and current-main source retains the same missing cancellation boundary; no target code was executed during this review.

Is this the best way to solve the issue?

This is the smallest complete fix: reuse the CLI-owned signal for cooperative provider cancellation and reject noncooperating late results before entering the existing output writer.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 35b1636f135b.

Provenance checked

  • Image command dispatch and output publication changes intended behavior with a stated reason (6938f6e: The cited refactor inlined single-use adapters while preserving existing behavior; it does not establish when the cancellation defect originated.)
  • Image edit fixture and input-loading assertions keeps the original intent (71b0fe5: The earlier refactor consolidated input loading and protected ordered paths, duplicate inputs, bytes, basenames, MIME inference, and forwarded options; those cases remain in the normal variant.)
  • Documented interruption and atomic-output behavior keeps the original intent (c54e9a1: The video repair stopped interrupted downloads while preserving already-started buffered writes; this PR extends the same boundary to image results.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Exact introduced change: The introduced production diff captures the existing work-scope signal, checks it before dispatch, forwards it to generateImage, and checks it before starting output publication. (src/cli/capability-cli/image.ts:127, 8d12010ba7d9)
  • Current main still needs the fix: Current main calls generateImage without the CLI cancellation signal and proceeds directly to writeOutputAsset after the provider resolves. (src/cli/capability-cli/image.ts:125, 35b1636f135b)
  • Shipped CLI before and after evidence: obviyus supplied exact-head built-CLI results at fix(cli): stop image output after accepted interrupts #191176 (comment): real LiteLLM HTTP requests were held until acknowledged SIGINT; baseline generate/edit overwrote existing destinations, candidate preserved their hashes, and uninterrupted controls wrote the expected PNG. (8d12010ba7d9)
  • Late-result regression: The consolidated edit fixture returns an image after closing its real AsyncWorkScope and asserts destination-byte preservation and suppressed success/error output; the supplied proof records its intended baseline failure and 109 passing focused tests. (src/cli/capability-cli.image-options.test.ts:79, 8d12010ba7d9)
  • Existing cancellation precedent: Merged fix(cli): stop capability video downloads on interrupt #187563 uses the same cancellation-before-buffered-publication boundary for video and explicitly preserves already-started writes; it does not repair the image command. (src/cli/capability-cli/video.ts:201, c54e9a19fb73)
  • Feature history and ownership: History across image.ts and the earlier capability-cli.ts shows repeated domain and CLI ownership work by Peter Steinberger and recent image-input consolidation by Vincent Koc; checkout blame confirms retained lines from both. Blob-dependent git log -S searches encountered an unavailable historical object, so the original defect's introduction remains unassigned. (src/cli/capability-cli/image.ts:115, 71b0fe58ccf4)

Likely related people:

  • Peter Steinberger: Raw commit 6938f6e adds src/cli/capability-cli/image.ts:104 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 6938f6e782a9; files: src/cli/capability-cli/image.ts)
  • Vincent Koc: Raw commit 71b0fe5 adds src/cli/capability-cli/image.ts:113 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 71b0fe58ccf4; files: src/cli/capability-cli/image.ts)

PR surface

Source +6, Tests 0, Docs 0. Total +6 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 6 0 +6
Tests 1 56 56 0
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 63 57 +6

Review metrics

Metric Value Why it matters
Production versus test growth Production +6/-0; tests +56/-56, net zero The fix reuses existing lifecycle ownership and extends the existing edit fixture without increasing test-file size.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Accepted cancellation can still overwrite an image destination, with impact limited to local image inference commands.
  • 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.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-02T15:27:40.264Z sha d4dc476 :: needs maintainer review before merge. :: none

Reviewed November 2, 2026, 11:00 AM ET / 16:00 UTC (Revision 2).

@obviyus

obviyus commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Independent built-CLI proof

Candidate: 8d12010ba7d97ea13a68db69b28c34d474dd36e5 (production is contributor's d4dc476feec65780cdc45feea963dbfea999107f, unchanged). Baseline main: f33f9c1c53f911816103cb6e04b67d52be4369a2.

Linux arm64, secretless node:24.22.1 Docker, independently built runtime artifacts. Each invocation uses its own home, profile, state, configuration, workspace and loopback HTTP fixture. No real provider credentials or paid requests.

Real commands: node openclaw.mjs --profile <isolated-profile> infer image generate|edit --model litellm/gpt-image-2 --agent main --prompt "synthetic one pixel fixture" --output <existing-file> --json; edit also passes --file <valid-png>.

The local LiteLLM-compatible HTTP fixture fully receives the actual image-generation or multipart edit request, then holds its response. The driver sends SIGINT to the CLI foreground process group and waits for the CLI's own acknowledgement, "Command interrupted by SIGINT. Waiting for cleanup before exiting." Only after that acknowledgement does the fixture release its successful image response. This is a request/acknowledgement barrier, not a cancellation timer or a private lifecycle injection.

Built artifact Runs Generate after accepted SIGINT Edit after accepted SIGINT Uninterrupted generate/edit
main 2 Existing destination overwritten with returned PNG Existing destination overwritten with returned PNG PNG written, exit 0
candidate 2 Original destination byte-identical Original destination byte-identical Same PNG written, exit 0

All cancelled commands exit 130. Both main repeats nevertheless overwrite the file after accepting cancellation. Both candidate repeats preserve the original bytes, even though the fixture releases its response after the acknowledgement. The cooperative HTTP cancellation and the late-result publication guard are both exercised: the runtime proof checks the real HTTP path; the focused regression returns a successful image from a provider after its work scope has begun closing.

SHA-256:

original 26 bytes: 924ee01183acbe50fc35c0b3a68652b42ae4806241d037f78ece7a2ec23b84d6
returned 68-byte PNG: 7091aaabb3c9d27a4cd4ca8254fe60af3b0a14618e223c13f7d6785f6fb8565a
main cancel generate/edit, both repeats: original -> PNG
candidate cancel generate/edit, both repeats: original -> original
all 8 uninterrupted controls: original -> PNG

Focused checks: 109 tests passed in capability-cli.image-options.test.ts and capability-cli.test.ts; targeted Oxlint and Oxfmt passed. The consolidated cancellation regression on main fails exactly at destination-byte preservation (PNG received instead of original GIF); its other six cases pass. No hosted CI rerun requested.

Simplification: reused the existing edit-options fixture for its normal/cancelled variants, removed duplicated cancellation setup and the test-line allocation. Production +6/-0, tests +56/-56 (net 0), docs +1/-1 against the merge base. No new configuration, API, SDK surface or compatibility reader. Original fix and contributor credit retained: @zhangguiping-xydt.

Scope: interrupts accepted before output publication begins; this does not roll back an output write already underway. Normal generation/editing and the returned image bytes are unchanged.

@obviyus

obviyus commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 2, 2026
@obviyus
obviyus merged commit 1dc0ebf into openclaw:main Nov 2, 2026
121 of 124 checks passed
@obviyus

obviyus commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Landed in 1dc0ebf. Thanks @zhangguiping-xydt. Cancelling image generation with Ctrl-C no longer overwrites the existing file.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 3, 2026
fix(cli): keep the existing image file when generation is cancelled with Ctrl-C



When an image generation or edit was cancelled with Ctrl-C (SIGINT), the CLI acknowledged the cancel but still wrote the late response over the existing output file. The output is no longer written after an accepted cancel, so the original file is kept. Uninterrupted runs write as before.

Evidence: built CLI in secretless Node 24.22.1 Docker with a delayed local image endpoint. Main overwrote existing generation and edit outputs twice after acknowledging SIGINT; with this change the original file hashes were kept twice. Uninterrupted controls wrote the expected PNG. Details: openclaw#191176 (comment).

Thanks @zhangguiping-xydt.

Co-authored-by: Ayaan Zaidi <[email protected]>
maplel pushed a commit to maplel/openclaw that referenced this pull request Nov 24, 2026
(cherry picked from commit 1dc0ebf)

Co-authored-by: Ayaan Zaidi <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit cf6b1de3f68c8778acd13ca68c74d67da56a0a38)
(cherry picked from commit d52c35543570add20491bebaf3598cdcc2ef09dd)
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 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.

2 participants