Skip to content

fix(cli): stop interrupted tool usage status reads - #198076

Merged
obviyus merged 2 commits into
openclaw:mainfrom
Alix-007:alix/fix-tool-usage-status-interrupt-20261113
Nov 13, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
Alix-007:alix/fix-tool-usage-status-interrupt-20261113

Conversation

@Alix-007

@Alix-007 Alix-007 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: openclaw tools usage status acknowledges an interrupt while waiting for its Gateway reply but keeps the read alive until the launcher forcibly kills it.

User Impact

User impact: Interrupted usage reports release the connection and exit with the normal SIGINT/SIGTERM code, without printing a late JSON or text report.

Why This Change Was Made

Forward the existing command signal only for the status read, keep its aborted rejection quiet, and guard final output. Import and reset retain their existing mutation settlement path.

Evidence

Product HEAD: 9602fc3d83b44561bf4f4b736e064236329b324a; acceptance-red BASE: 0633f256350b5580a5bdbcd8a6a5782750de03d4.

  • Actual CLI → real Gateway: clean normal QA builds run node openclaw.mjs tools usage status in JSON and human modes in a controlling PTY. A transparent proxy forwards the real handshake/request and holds the successful real toolUsage.status reply before delivering terminal Ctrl-C or SIGTERM. It records the exact held connection and actual terminal/stderr readback.
  • Same frozen red/green scenarios: Both BASE interrupts reach launcher emergency SIGKILL after 2032–2033 ms. HEAD naturally exits 130/143 in 95–103ms, closes the held read connection within 7–8ms, and leaves no owned CLI/Gateway/proxy process. No late status report, JSON or command-failed banner after the normal interruption notice. No collector watchdog fires.
  • Legal controls: Three controls on both revisions: normal JSON and human output exit0 and read the real public tool score persisted through the canonical usage owner; wrong-token authentication still exits1. Configuration bytes stay unchanged and the real Gateway/proxy clean up normally.
  • Focused regression: BASE has one intended public-output regression failure and nine passing controls; HEAD has 10 passing tests in 10.588s: pnpm test src/cli/tools-cli.test.ts --maxWorkers=1. Targeted types, typed lint and formatting pass. Clean exact-HEAD QA build: 269.059s. Independent adversarial review: PASS, no findings.

Reproduce with the unchanged collector: python3 cli-read-proof-v2.py CHECKOUT FRESH_OUTPUT NODE26 EXPECTATION tools. Environment and observations, BASE receipt, HEAD receipt, actual terminal/RPC output, and independent review.

Production +11/−2 lines; tests +15/−0 lines, 2 files. Existing-solutions preflight: reuse the existing AsyncWorkScope/Gateway abort owner; no new signal framework, dependency, configuration/default, public protocol/schema, permission or migration. Siblings: Forward the existing command signal only for the status read, keep its aborted rejection quiet, and guard final output. Import and reset retain their existing mutation settlement path. Upstream CI is checked after publication.

Not tested: Tool execution, live transcript import/reset cancellation or settlement, external providers, Windows/macOS and production load. The proof covers a genuine local Gateway response held before CLI readback. It does not claim a real external tool/hook cancellation.

Maintainer proof on 6320c4c (built CLI, real Gateway, held status reply; unit test dropped to keep net test lines at 0): #198076 (comment)

@clawsweeper

clawsweeper Bot commented Nov 13, 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 cli CLI command changes size: XS labels Nov 13, 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 13, 2026
@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR cancels interrupted tool-usage status requests and suppresses their late output.

Example: Press Ctrl-C while openclaw tools usage status --json awaits a Gateway reply.

  • Before: The read stays open until the launcher forcibly kills the process.
  • After: The connection closes and the CLI exits 130 without printing the report.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused repair with direct shipped-entry-point evidence and no actionable findings; pending CI remains ordinary validation.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Exact-head collaborator output exercises the built CLI against a real Gateway in a secretless Node container, holding or delaying toolUsage.status replies before SIGINT/SIGTERM; the candidate closes the read, exits 130/143, emits no report, and preserves normal read and mutation controls.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Interrupting a pending tool-usage status report leaves its connection alive until forced termination.
Reason: Restoring normal command interruption has clear value, uses existing ownership, and leaves administrative scope and mutation semantics intact.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current cancellation bug with a small, focused change; no actionable correctness or security findings remain, and exact-head CI is still pending.

Priority: P2
Reviewed head: 6320c4ca37828e26e1855e95c8690284fa1fcb11

Before merge

None.

Findings

None.

Agent review details

How this fits together

The tools CLI sends administrative usage requests through the shared Gateway RPC client and renders the response; the existing command scope supplies cancellation.

flowchart TD
  A[Terminal interrupt] --> B[CLI command scope]
  B --> C[Tool usage status command]
  C --> D[Shared Gateway RPC client]
  D --> E[Gateway usage service]
  C --> F[Report output]
Loading

Technical review

Best possible solution:

Use the existing command signal and Gateway teardown owner to cancel status reads while preserving mutation settlement.

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

Current-main source exposes the uncancelled read, and supplied real CLI/Gateway red and green results demonstrate the failure and repair; this review ran no target code.

Is this the best way to solve the issue?

The patch is the smallest complete fix: connect the existing cancellation signal, quiet its rejection, and prevent output after interruption without adding another lifecycle owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Tool-usage CLI request and output keeps the original intent (8a328bf: The usage-ranked tool-index feature added administrative commands to inspect, import, and reset learned usage.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Focused introduced change: The introduced diff forwards the existing signal only for status, preserves ordinary errors, and checks cancellation before output; import and reset retain their settlement behavior. (src/cli/tools-cli.ts:76, 6320c4ca3782)
  • Current main still needs the repair: Fetched main invokes toolUsage.status without a cancellation signal and renders its result without an interruption guard. (src/cli/tools-cli.ts:90, 18872ea508b9)
  • Existing cancellation owner: The CLI RPC runtime forwards the supplied signal; the Gateway call's abort handler stops its client before settling the request. (src/gateway/call.ts:672, 6320c4ca3782)
  • Exact-head shipped-entry-point proof: Collaborator obviyus supplied real built CLI/Gateway output for the reviewed head in fix(cli): stop interrupted tool usage status reads #198076 (comment): held and delayed replies cancel with exits 130/143 and no report, while normal status, import dry-run, and reset controls pass. (6320c4ca3782)
  • Supporting red and green receipts: The linked receipts record the real CLI and Gateway handshake, held successful status responses, base forced termination, and successful cancellation at the earlier production-identical head; normal output and authentication-error controls retain their results. (head-receipt.json, 734f14532cfe)
  • Verified feature provenance: The merged feature feat: add an opt-in usage-ranked tool index #197128 introduced the tools usage commands for administrative inspection, import, and reset; this repair preserves that purpose. (src/cli/tools-cli.ts:74, 8a328bf86189)

Likely related people:

  • Josh Lehman: Raw commit 8a328bf adds src/cli/tools-cli.ts:74 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 8a328bf86189; files: src/cli/tools-cli.ts)

PR surface

Source +9. Total +9 across 1 file. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 11 2 +9
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 11 2 +9

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A bounded administrative status command fails to cancel cleanly, without affecting the core agent or channel workflow.
  • 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-13T04:27:09.206Z sha 9602fc3 :: needs maintainer review before merge. :: none

Reviewed November 13, 2026, 12:15 AM ET / 05:15 UTC (Revision 2).

@obviyus

obviyus commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

Proof for 6320c4c (built openclaw in a secretless node:24.22.1 container).

Setup: a real built gateway run, with a small relay in front that holds the toolUsage.status reply (forever, or released after 4 s for the -late runs). The signal is sent once the relay holds the reply. Main = merge base 0633f25, candidate = this head. Two rounds each.

lane=base round=1 scenario=plain-int        signal=INT  exit=137 ms=3449 stdout_bytes=0
lane=base round=1 scenario=json-term        signal=TERM exit=137 ms=3371 stdout_bytes=0
lane=base round=1 scenario=plain-term-late  signal=TERM exit=137 ms=3552 stdout_bytes=0
lane=base round=1 scenario=json-int-late    signal=INT  exit=137 ms=3392 stdout_bytes=0
lane=base round=2 scenario=plain-int        signal=INT  exit=137 ms=3681 stdout_bytes=0
lane=base round=2 scenario=json-term        signal=TERM exit=137 ms=3690 stdout_bytes=0
lane=base round=2 scenario=plain-term-late  signal=TERM exit=137 ms=3334 stdout_bytes=0
lane=base round=2 scenario=json-int-late    signal=INT  exit=137 ms=3639 stdout_bytes=0
lane=cand round=1 scenario=plain-int        signal=INT  exit=130 ms=1421 stdout_bytes=0
lane=cand round=1 scenario=json-term        signal=TERM exit=143 ms=1423 stdout_bytes=0
lane=cand round=1 scenario=plain-term-late  signal=TERM exit=143 ms=1270 stdout_bytes=0
lane=cand round=1 scenario=json-int-late    signal=INT  exit=130 ms=1553 stdout_bytes=0
lane=cand round=2 scenario=plain-int        signal=INT  exit=130 ms=1413 stdout_bytes=0
lane=cand round=2 scenario=json-term        signal=TERM exit=143 ms=1394 stdout_bytes=0
lane=cand round=2 scenario=plain-term-late  signal=TERM exit=143 ms=1373 stdout_bytes=0
lane=cand round=2 scenario=json-int-late    signal=INT  exit=130 ms=1428 stdout_bytes=0

Both lanes print only the existing line on stderr, e.g. Command interrupted by SIGINT. Waiting for cleanup before exiting. Main keeps the read open and is force-killed (137). The candidate closes the read and exits 130/143 right away.

Controls, both rounds, both lanes, exit 0: tools usage status, tools usage status --json, tools usage import --dry-run --json, tools usage reset --json. Main and candidate stdout are byte-identical apart from timestamps (now, since/before, liveSince).

Tests: dropped the added unit test to keep net test lines at 0; the change is covered by the e2e runs above.

@obviyus

obviyus commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 13, 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 13, 2026
@obviyus
obviyus merged commit 76c319b into openclaw:main Nov 13, 2026
116 of 117 checks passed
@obviyus

obviyus commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

Landed in 76c319b. Thanks @Alix-007.

@Alix-007

Copy link
Copy Markdown
Contributor Author

Thanks @obviyus for checking the late-reply and mutation controls, and landing this!

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 14, 2026
fix(tools): stop the usage status read when tools usage status is interrupted

openclaw tools usage status did not pass the command's abort signal to its Gateway read, so Ctrl-C or SIGTERM while the reply was pending left the read running until the launcher force-killed the command with exit 137. The read now takes the abort signal and the command exits with the existing interrupt code. Uninterrupted status, import and reset are unchanged. No new text.

Evidence: the built CLI in a secretless node:24.22.1 container against a real gateway run behind a relay that holds the usage status reply, plain and --json, SIGINT and SIGTERM, two rounds per lane. On main all 8 interrupted runs were force-killed with exit 137 after about 3.5 s. With this change all 8 exit 130 or 143 within about 1.5 s with only the existing interrupt line. Uninterrupted status, status --json, import --dry-run --json and reset --json give the same output on both. Net 0 test lines. Details: openclaw#198076 (comment).

Thanks @Alix-007.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes 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: XS 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