Skip to content

fix(cli): allow /cancel during an active coding-agent run - #7

Merged
steipete merged 2 commits into
openclaw:mainfrom
SebTardif:fix/f001-cancel-during-run
Sep 5, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
SebTardif:fix/f001-cancel-during-run

Conversation

@SebTardif

@SebTardif SebTardif commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

The interactive Coding Agent CLI awaited each run before reading the next command, so the advertised /cancel could never reach active work. This PR keeps input available while streaming, retains cancellation requested during run creation, reports abort failures without terminating the terminal, and closes readline/the SDK client on idle Ctrl+C or EOF.

The maintainer follow-up uses readline's line iterator to settle shutdown, deduplicates concurrent cancellation attempts, preserves retry after failure, and resolves the executable path before the direct-run check so symlinked invocations work. One-shot mode is preserved. The contributor's original commit remains in the branch, with thanks @SebTardif in Unreleased.

Validation on macOS / Node 24.20.0:

  • pnpm check passed: formatting, lint, types, all 17 tests, docs, four starter builds, and both compiled CLI smokes.
  • A scripted real PTY launched node .../sdk/coding-agent-cli/dist/index.js through the macOS /tmp symlink. Baseline ignored /cancel during the stream and later printed No active run. The patched CLI invoked cancellation while streaming, printed aborted, then run.cancelled / status: cancelled, and exited 0.
  • The same PTY drive verified active Ctrl+C cancellation and idle Ctrl+C shutdown, both exit 0. The active-stream cases use a synthetic SDK shim fixture that keeps events open until cancellation; the idle case runs the compiled CLI without a fixture. No live Gateway/provider or network-abort claim is made.
  • Regression coverage includes cancellation/exit during delayed creation, rejected abort retry, EOF cleanup, Ctrl+C failure recovery, and symlinked entrypoints. Independent autoreview through P2 is clean.

Prepared for maintainer approval; not merged. CLI JSON redaction remains a separate concern in #8.

The interactive coding-agent-cli advertised /cancel, but the REPL
awaited sendPrompt before the next question, so /cancel always ran
after currentRun was cleared.

Keep reading slash commands while events stream, cancel on SIGINT,
and cover the path with a hanging-run REPL drive.

Signed-off-by: Sebastien Tardif <[email protected]>
@clawsweeper

clawsweeper Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

🦞👀
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.

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. 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 29, 2026
@clawsweeper

clawsweeper Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed September 5, 2026, 4:15 PM ET / 20:15 UTC.

ClawSweeper review

What this changes

The branch keeps the coding-agent CLI responsive during runs, handles cancellation and terminal shutdown, adds regression coverage and documentation, and includes dependency updates already present on main.

Merge readiness

✅ Ready for maintainer review

This PR remains necessary: current main still blocks command input during runs. The revised implementation resolves the three prior findings, and the new terminal evidence supports the changed CLI behavior. No blocking defect remains.

Priority: P2
Reviewed head: 6ced5233b1af489a829590658a39d35fd9c23e08

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A sound lifecycle repair with relevant terminal evidence, focused regression coverage, and all prior findings addressed.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The exact-head macOS PTY trace exercises the compiled CLI’s /cancel dispatch, active Ctrl+C, and idle shutdown with observed cancellation and clean exit. Synthetic SDK activity supplies the active-run condition; live Gateway abortion is neither changed nor claimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The exact-head macOS PTY trace exercises the compiled CLI’s /cancel dispatch, active Ctrl+C, and idle shutdown with observed cancellation and clean exit. Synthetic SDK activity supplies the active-run condition; live Gateway abortion is neither changed nor claimed.
Evidence reviewed 8 items Current main still contains the defect: The default-branch CLI awaits sendPrompt before reading another command, and sendPrompt clears currentRun before returning. The advertised cancellation command therefore cannot interrupt that run.
Prior findings resolved: The current implementation retains the run-creation promise, catches cancellation errors and resets failed attempts for retry, and uses readline iteration that settles on close. The new tests cover delayed creation, rejected cancellation, EOF, terminal signals, and symlinked invocation.
Compiled CLI terminal proof: The supplied comment #7 (comment) identifies the exact reviewed head and reports macOS/Node 24.20.0 PTY traces: baseline cancellation arrived too late; patched /cancel and active Ctrl+C produced aborted/cancelled results; idle Ctrl+C exited cleanly. Active scenarios used a synthetic SDK fixture; idle shutdown used the unmodified shim. This exercises the changed terminal boundary without claiming provider or network cancellation.
Findings None None.
Security None None.

How this fits together

The coding-agent CLI is a copyable terminal example that sends prompts through the cookbook’s workspace SDK shim. It streams run events and accepts commands to cancel work or close the client.

flowchart TD
  A[Terminal input] --> B[CLI command loop]
  B --> C[Create agent run]
  C --> D[Stream events and result]
  B --> E[Cancel active or starting run]
  E --> C
  B --> F[Close terminal and client]
  D --> G[Terminal output]
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test growth Production +168/-97 (net +71); tests +271 The growth supports explicit cancellation lifecycle handling and focused regression coverage.
Prior findings 3 resolved, 0 remaining The revised head addresses delayed creation, cancellation failures, and idle Ctrl+C shutdown.

Technical review

Best possible solution:

Keep cancellation within the existing CLI and SDK run API, preserving responsive input, retryable abort errors, and orderly client shutdown.

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

Yes. Current main’s input loop cannot read /cancel until the active run finishes; the supplied baseline PTY trace confirms that sequence. This review did not execute the CLI.

Is this the best way to solve the issue?

Yes. Decoupling prompt execution from terminal input fixes the owning layer, and the follow-up handles creation races, abort failures, and shutdown without adding a competing cancellation API.

AGENTS.md: not found in the target repository.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The exact-head macOS PTY trace exercises the compiled CLI’s /cancel dispatch, active Ctrl+C, and idle shutdown with observed cancellation and clean exit. Synthetic SDK activity supplies the active-run condition; live Gateway abortion is neither changed nor claimed.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The exact-head macOS PTY trace exercises the compiled CLI’s /cancel dispatch, active Ctrl+C, and idle shutdown with observed cancellation and clean exit. Synthetic SDK activity supplies the active-run condition; live Gateway abortion is neither changed nor claimed.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.
  • remove merge-risk: 🚨 availability: Current PR review selected no merge-risk labels.

Label justifications:

  • P2: This repairs an advertised command in a standalone cookbook example with limited product blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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 exact-head macOS PTY trace exercises the compiled CLI’s /cancel dispatch, active Ctrl+C, and idle shutdown with observed cancellation and clean exit. Synthetic SDK activity supplies the active-run condition; live Gateway abortion is neither changed nor claimed.
  • proof: sufficient: Contributor real behavior proof is sufficient. The exact-head macOS PTY trace exercises the compiled CLI’s /cancel dispatch, active Ctrl+C, and idle shutdown with observed cancellation and clean exit. Synthetic SDK activity supplies the active-run condition; live Gateway abortion is neither changed nor claimed.

Evidence

What I checked:

  • Current main still contains the defect: The default-branch CLI awaits sendPrompt before reading another command, and sendPrompt clears currentRun before returning. The advertised cancellation command therefore cannot interrupt that run. (sdk/coding-agent-cli/src/index.ts:128, afff52646498)
  • Prior findings resolved: The current implementation retains the run-creation promise, catches cancellation errors and resets failed attempts for retry, and uses readline iteration that settles on close. The new tests cover delayed creation, rejected cancellation, EOF, terminal signals, and symlinked invocation. (sdk/coding-agent-cli/src/index.ts:60, 6ced5233b1af)
  • Compiled CLI terminal proof: The supplied comment fix(cli): allow /cancel during an active coding-agent run #7 (comment) identifies the exact reviewed head and reports macOS/Node 24.20.0 PTY traces: baseline cancellation arrived too late; patched /cancel and active Ctrl+C produced aborted/cancelled results; idle Ctrl+C exited cleanly. Active scenarios used a synthetic SDK fixture; idle shutdown used the unmodified shim. This exercises the changed terminal boundary without claiming provider or network cancellation. (sdk/coding-agent-cli/src/index.ts:154, 6ced5233b1af)
  • SDK and proof boundary: README Status documents the private workspace SDK shim, and the CLI package resolves @openclaw/sdk to that workspace package. Its cancellation method returns a local response. The prior request for live Gateway abortion exceeds the behavior changed and claimed here; real PTY dispatch and shutdown evidence is relevant. (README.md:19, 6ced5233b1af)
  • Dependency and workflow comparison: All eight introduced workflow/dependency files exactly match fetched main. Inspection found no added permission scope, lifecycle hook, alternate dependency source, or authority change specific to the remaining CLI work. (pnpm-workspace.yaml:6, 6ced5233b1af)
  • Feature-history routing: Available main history connects Peter Steinberger to the standalone SDK examples and later shim maintenance. The CLI blob at the standalone-example commit matches current main, and its raw recorded parent has no CLI path. Some deeper follow/blame reads failed on unavailable objects; no broader introduction claim relies on those failures. (sdk/coding-agent-cli/src/index.ts:5, 233792e097de)

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.

History

Review history (15 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-01T12:07:59.842Z sha 978f3f4 :: needs real behavior proof before merge. :: [P2] Handle rejected SIGINT cancellations
  • reviewed 2026-09-02T11:55:13.522Z sha 978f3f4 :: needs real behavior proof before merge. :: [P2] Handle rejected SIGINT cancellations
  • reviewed 2026-09-02T18:10:26.276Z sha 978f3f4 :: needs real behavior proof before merge. :: [P2] Handle rejected SIGINT cancellations
  • reviewed 2026-09-02T21:50:26.606Z sha 978f3f4 :: needs real behavior proof before merge. :: [P2] Handle rejected SIGINT cancellations
  • reviewed 2026-09-02T23:24:22.115Z sha 978f3f4 :: needs real behavior proof before merge. :: [P1] Preserve cancellation requested during run creation | [P2] Handle rejected cancellation requests
  • reviewed 2026-09-03T15:54:16.769Z sha 978f3f4 :: needs real behavior proof before merge. :: [P1] Preserve cancellation requested during run creation | [P2] Handle rejected cancellation requests
  • reviewed 2026-09-04T11:53:45.303Z sha 978f3f4 :: needs real behavior proof before merge. :: [P1] Preserve cancellation requested during run creation | [P2] Handle cancellation errors without terminating the REPL
  • reviewed 2026-09-05T05:00:07.563Z sha 978f3f4 :: needs real behavior proof before merge. :: [P1] Preserve cancellation requested during run creation | [P2] Handle cancellation errors without terminating the CLI | [P2] Settle the pending question when Ctrl+C closes readline

@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. P1 Urgent regression or broken agent/channel workflow affecting real users now. P2 Normal priority bug or improvement with limited blast radius. and removed P2 Normal priority bug or improvement with limited blast radius. P1 Urgent regression or broken agent/channel workflow affecting real users now. labels Aug 30, 2026
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Live proof for 6ced5233b1af489a829590658a39d35fd9c23e08 on macOS / Node 24.20.0:

baseline: /cancel during active stream -> run.completed; next /cancel -> No active run.
patched:  /cancel during active stream -> aborted, run.cancelled, status cancelled; exit 0
patched:  Ctrl+C during active stream -> aborted, run.cancelled, status cancelled; exit 0
patched:  idle Ctrl+C -> clean exit 0

This drove the actual compiled sdk/coding-agent-cli/dist/index.js in a real PTY, including an absolute path through macOS's /tmp symlink. For the active cases, an imported synthetic fixture keeps the workspace SDK shim's event stream open and makes its cancellation observable; idle shutdown uses the unmodified shim. This proves CLI input dispatch, terminal signals, result handling, and shutdown. It does not claim live Gateway/provider or network abort verification.

pnpm check passed (17 tests plus formatting, lint, types, docs, all starter builds, and both compiled CLI smokes). New regression cases cover delayed creation, failed abort retry, EOF cleanup, Ctrl+C failure recovery, and symlinked entrypoints. Independent autoreview through P2 is clean.

Maintainer fixes preserve the original contributor commit and add an Unreleased thank-you to @SebTardif. No merge or release performed.

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. 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. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. labels Sep 5, 2026
@steipete
steipete merged commit 6deea84 into openclaw:main Sep 5, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants