Skip to content

fix(cli): guard gateway abort during turn cancellation - #1506

Open
lihongguang0014 wants to merge 1 commit into
mainfrom
fix/turn-stream-cancel-abort-escape
Open

fix(cli): guard gateway abort during turn cancellation#1506
lihongguang0014 wants to merge 1 commit into
mainfrom
fix/turn-stream-cancel-abort-escape

Conversation

@lihongguang0014

Copy link
Copy Markdown
Collaborator

Fixes #1505

Problem

Pressing Ctrl+C to interrupt an in-flight gateway turn while the connection is already lost let the ConnectionError raised by abort_session escape the KeyboardInterrupt/CancelledError handler and crash the turn instead of returning TurnResult(cancelled=True), so the REPL could not re-prompt.

Root cause

src/opensquilla/cli/chat/turn_stream.py awaits client.abort_session(session_key) inside the except (KeyboardInterrupt, asyncio.CancelledError) block. GatewayClient._call() raises ConnectionError when the connection is gone (src/opensquilla/cli/gateway_client.py). An exception raised inside an except block escapes it, so the turn never reaches the graceful cancel path — and connection loss is exactly when users press Ctrl+C.

Fix

Wrap the abort call in try/except Exception (minimal change, 7 lines). The turn is already cancelled locally; the abort RPC is best-effort.

Test

Adds regression test test_gateway_stream_interrupt_tolerates_abort_failure in tests/test_cli/test_chat_cmd.py: send_message raises KeyboardInterrupt and abort_session raises ConnectionError; asserts TurnResult.cancelled is True. Verified the test fails on unfixed code and passes with the fix; all 63 tests in the file pass.

Interrupting a gateway turn while the connection is already lost let
the ConnectionError raised by abort_session escape the
KeyboardInterrupt/CancelledError handler and crash the turn instead of
returning TurnResult(cancelled=True). Wrap the abort call so the turn
still cancels locally and the REPL can re-prompt.

Adds a regression test where send_message raises KeyboardInterrupt and
abort_session raises ConnectionError.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Interrupting a gateway turn crashes with ConnectionError when the connection is already lost

1 participant