Skip to content

The agent that turns websites into APIs!

fix(cli): distinguish task cancellation from user interruption

kalil0321d77dbdfce35e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bc7783b..7c157d8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Click now requires version 8.3.3 or newer to fix [PYSEC-2026-2132](https://osv.dev/vulnerability/PYSEC-2026-2132). LiteLLM releases that pin `click==8.1.8` (including 1.83.7) cannot share an environment with this release. Use RAE's built-in pricing, run such LiteLLM releases in a separate environment, or select a LiteLLM release whose requirements allow the patched Click version. Optional LiteLLM pricing detection remains available only when its dependencies are compatible; do not downgrade Click to enable it.
### Fixed
-- Report agent provider runs that produce no result as failures: JSON/NDJSON emits an error result, and plain output prints the error to stderr; all exit with code 1. Preserve Claude/Cursor cancellation as `interrupted` in non-interactive mode. Interactive cancellation keeps exit code 0 and any completed partial result, including when a real Ctrl+C cancels an asyncio task, rather than reporting a provider failure.
+- Report agent provider runs that produce no result as failures: JSON/NDJSON emits an error result, and plain output prints the error to stderr; all exit with code 1. Preserve Claude/Cursor Ctrl+C as `interrupted` in non-interactive mode. Interactive Ctrl+C keeps exit code 0 and any completed partial result, including when the signal cancels an asyncio task. Programmatic cancellations propagate to asyncio callers and produce a CLI failure with exit code 1, while preserving partial results.
- Raise security minimums to Click >=8.3.3, aiohttp >=3.14.3, cryptography >=50.0.0, AnyIO >=4.14.2, PyJWT >=2.13.0, python-multipart >=0.0.30, Starlette >=1.3.1, and SoupSieve >=2.9.0 (collector extra). Export these floors in package metadata so upgrades cannot retain vulnerable versions that only the repository lockfile excluded.
- Refresh the locked Claude Agent SDK and MCP dependencies so the development environment also uses MCP 2.x and `httpx2`, without the legacy `httpx`, `httpx-sse`, and `httpcore` packages. Add subprocess smoke tests for CLI startup with legacy HTTP client imports blocked.
diff --git a/src/reverse_api/auto_engineer.py b/src/reverse_api/auto_engineer.py
index 5f45469..11a1468 100644
--- a/src/reverse_api/auto_engineer.py
+++ b/src/reverse_api/auto_engineer.py
@@ -278,7 +278,12 @@ class ClaudeAutoEngineer(ClaudeEngineer):
# follow-up loop instead of offering another turn.
return last_result
- except (KeyboardInterrupt, asyncio.CancelledError):
+ except asyncio.CancelledError as exc:
+ # Keep cancellation semantics for asyncio callers while retaining
+ # the partial result for the CLI, including SIGINT via Runner.
+ exc.partial_result = last_result # type: ignore[attr-defined]
+ raise
+ except KeyboardInterrupt:
self.ui.console.print("\n [dim]run aborted[/dim]")
if not self.interactive:
raise
diff --git a/src/reverse_api/cli.py b/src/reverse_api/cli.py
index 252af52..3c96848 100644
--- a/src/reverse_api/cli.py
+++ b/src/reverse_api/cli.py
@@ -2186,12 +2186,17 @@ def run_auto_capture(
engineer.start_sync()
interrupted = False
+ cancelled = False
try:
result = asyncio.run(engineer.analyze_and_generate())
interrupted = isinstance(result, dict) and result.get("error") == "interrupted"
- except (KeyboardInterrupt, asyncio.CancelledError):
- result = None
+ except KeyboardInterrupt as exc:
+ result = getattr(exc.__context__, "partial_result", None)
interrupted = True
+ console.print("\n [dim]run aborted[/dim]")
+ except asyncio.CancelledError as exc:
+ result = getattr(exc, "partial_result", None)
+ cancelled = True
finally:
# Always stop sync when done
engineer.stop_sync()
@@ -2212,6 +2217,8 @@ def run_auto_capture(
**(
{"error": "interrupted"}
if interrupted
+ else {"error": "Agent analysis cancelled."}
+ if cancelled
else {"error": "Agent analysis produced no result."}
if result is None
else {}
diff --git a/src/reverse_api/cursor_engineer.py b/src/reverse_api/cursor_engineer.py
index 4634066..a381d5a 100644
--- a/src/reverse_api/cursor_engineer.py
+++ b/src/reverse_api/cursor_engineer.py
@@ -606,7 +606,12 @@ class CursorAutoEngineer(CursorEngineer):
return last_result
turn_prompt = fu
self.message_store.save_prompt(turn_prompt)
- except (KeyboardInterrupt, asyncio.CancelledError):
+ except asyncio.CancelledError as exc:
+ # Keep cancellation semantics for asyncio callers while retaining
+ # the partial result for the CLI, including SIGINT via Runner.
+ exc.partial_result = last_result # type: ignore[attr-defined]
+ raise
+ except KeyboardInterrupt:
self.ui.console.print("\n [dim]run aborted[/dim]")
if not self.interactive:
raise
diff --git a/tests/test_cli_agent_json.py b/tests/test_cli_agent_json.py
index 8a8e31f..58ddfb8 100644
--- a/tests/test_cli_agent_json.py
+++ b/tests/test_cli_agent_json.py
@@ -595,7 +595,15 @@ def test_provider_interrupt_output_modes(tmp_path, monkeypatch, sdk, output_flag
if output_flag:
args.append(output_flag)
result = CliRunner().invoke(main, args)
- if output_flag is None:
+ if interrupt_type is asyncio.CancelledError:
+ assert result.exit_code == 1, result.output
+ if output_flag in ("--json", "--json-stream"):
+ payload = json.loads(result.stdout.strip().splitlines()[-1])
+ assert payload["status"] == "error"
+ assert payload["error"] == "Agent analysis cancelled."
+ else:
+ assert "Agent analysis cancelled." in result.stderr
+ elif output_flag is None:
assert result.exit_code == 0, result.output
assert "run aborted" in result.output
assert "produced no result" not in result.output