File tree Expand file tree Collapse file tree 2 files changed +38
-9
lines changed
Expand file tree Collapse file tree 2 files changed +38
-9
lines changed Original file line number Diff line number Diff line change @@ -622,21 +622,19 @@ export class CopilotSession {
622622 }
623623 try {
624624 const result = await this . elicitationHandler ( request , { sessionId : this . sessionId } ) ;
625- await this . connection . sendRequest ( "session.ui.handlePendingElicitation" , {
626- sessionId : this . sessionId ,
627- requestId,
628- result,
629- } ) ;
625+ await this . rpc . ui . handlePendingElicitation ( { requestId, result } ) ;
630626 } catch {
631627 // Handler failed — attempt to cancel so the request doesn't hang
632628 try {
633- await this . connection . sendRequest ( "session.ui.handlePendingElicitation" , {
634- sessionId : this . sessionId ,
629+ await this . rpc . ui . handlePendingElicitation ( {
635630 requestId,
636631 result : { action : "cancel" } ,
637632 } ) ;
638- } catch {
639- // Best effort — another client may have already responded
633+ } catch ( rpcError ) {
634+ if ( ! ( rpcError instanceof ConnectionError || rpcError instanceof ResponseError ) ) {
635+ throw rpcError ;
636+ }
637+ // Connection lost or RPC error — nothing we can do
640638 }
641639 }
642640 }
Original file line number Diff line number Diff line change @@ -945,5 +945,36 @@ describe("CopilotClient", () => {
945945 ) ;
946946 rpcSpy . mockRestore ( ) ;
947947 } ) ;
948+
949+ it ( "sends cancel when elicitation handler throws" , async ( ) => {
950+ const client = new CopilotClient ( ) ;
951+ await client . start ( ) ;
952+ onTestFinished ( ( ) => client . forceStop ( ) ) ;
953+
954+ const session = await client . createSession ( {
955+ onPermissionRequest : approveAll ,
956+ onElicitationRequest : async ( ) => {
957+ throw new Error ( "handler exploded" ) ;
958+ } ,
959+ } ) ;
960+
961+ const rpcSpy = vi . spyOn ( ( client as any ) . connection ! , "sendRequest" ) ;
962+
963+ await session . _handleElicitationRequest ( { message : "Pick a color" } , "req-123" ) ;
964+
965+ const cancelCall = rpcSpy . mock . calls . find (
966+ ( c ) =>
967+ c [ 0 ] === "session.ui.handlePendingElicitation" &&
968+ ( c [ 1 ] as any ) ?. result ?. action === "cancel"
969+ ) ;
970+ expect ( cancelCall ) . toBeDefined ( ) ;
971+ expect ( cancelCall ! [ 1 ] ) . toEqual (
972+ expect . objectContaining ( {
973+ requestId : "req-123" ,
974+ result : { action : "cancel" } ,
975+ } )
976+ ) ;
977+ rpcSpy . mockRestore ( ) ;
978+ } ) ;
948979 } ) ;
949980} ) ;
You can’t perform that action at this time.
0 commit comments