fix(cli): guard gateway abort during turn cancellation - #1506
Open
lihongguang0014 wants to merge 1 commit into
Open
fix(cli): guard gateway abort during turn cancellation#1506lihongguang0014 wants to merge 1 commit into
lihongguang0014 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1505
Problem
Pressing Ctrl+C to interrupt an in-flight gateway turn while the connection is already lost let the
ConnectionErrorraised byabort_sessionescape theKeyboardInterrupt/CancelledErrorhandler and crash the turn instead of returningTurnResult(cancelled=True), so the REPL could not re-prompt.Root cause
src/opensquilla/cli/chat/turn_stream.pyawaitsclient.abort_session(session_key)inside theexcept (KeyboardInterrupt, asyncio.CancelledError)block.GatewayClient._call()raisesConnectionErrorwhen the connection is gone (src/opensquilla/cli/gateway_client.py). An exception raised inside anexceptblock 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_failureintests/test_cli/test_chat_cmd.py:send_messageraisesKeyboardInterruptandabort_sessionraisesConnectionError; assertsTurnResult.cancelled is True. Verified the test fails on unfixed code and passes with the fix; all 63 tests in the file pass.