@@ -2109,8 +2109,12 @@ public async ValueTask DisposeAsync()
21092109
21102110 try
21112111 {
2112- await InvokeRpcAsync < object > (
2113- "session.destroy" , [ new SessionDestroyRequest ( ) { SessionId = SessionId } ] , CancellationToken . None ) ;
2112+ var response = await InvokeRpcAsync < SessionDetachResponse > (
2113+ "session.detach" , [ new SessionDetachRequest ( ) { SessionId = SessionId } ] , CancellationToken . None ) ;
2114+ if ( ! response . Success )
2115+ {
2116+ LogSessionDetachFailed ( SessionId , response . Error ?? "unknown error" ) ;
2117+ }
21142118 }
21152119 catch ( ObjectDisposedException )
21162120 {
@@ -2147,6 +2151,9 @@ await InvokeRpcAsync<object>(
21472151 [ LoggerMessage ( Level = LogLevel . Debug , Message = "Failed to fetch tool metadata for {toolName}" ) ]
21482152 private partial void LogToolMetadataFetchFailed ( Exception exception , string toolName ) ;
21492153
2154+ [ LoggerMessage ( Level = LogLevel . Warning , Message = "Failed to detach session {sessionId}: {error}" ) ]
2155+ private partial void LogSessionDetachFailed ( string sessionId , string error ) ;
2156+
21502157 [ LoggerMessage ( Level = LogLevel . Error , Message = "Permission handler or response delivery failed. SessionId={SessionId}, RequestId={RequestId}" ) ]
21512158 private partial void LogPermissionHandlerOrDeliveryFailed ( Exception exception , string sessionId , string requestId ) ;
21522159
@@ -2184,11 +2191,17 @@ internal record SessionAbortRequest
21842191 public string SessionId { get ; init ; } = string . Empty ;
21852192 }
21862193
2187- internal record SessionDestroyRequest
2194+ internal record SessionDetachRequest
21882195 {
21892196 public string SessionId { get ; init ; } = string . Empty ;
21902197 }
21912198
2199+ internal record SessionDetachResponse
2200+ {
2201+ public bool Success { get ; init ; }
2202+ public string ? Error { get ; init ; }
2203+ }
2204+
21922205 internal void ThrowIfDisposed ( )
21932206 {
21942207 ObjectDisposedException . ThrowIf ( Volatile . Read ( ref _isDisposed ) != 0 , this ) ;
@@ -2221,7 +2234,8 @@ internal void ThrowIfDisposed()
22212234 [ JsonSerializable ( typeof ( SendMessageRequest ) ) ]
22222235 [ JsonSerializable ( typeof ( SendMessageResponse ) ) ]
22232236 [ JsonSerializable ( typeof ( SessionAbortRequest ) ) ]
2224- [ JsonSerializable ( typeof ( SessionDestroyRequest ) ) ]
2237+ [ JsonSerializable ( typeof ( SessionDetachRequest ) ) ]
2238+ [ JsonSerializable ( typeof ( SessionDetachResponse ) ) ]
22252239 [ JsonSerializable ( typeof ( SessionEndHookInput ) ) ]
22262240 [ JsonSerializable ( typeof ( SessionEndHookOutput ) ) ]
22272241 [ JsonSerializable ( typeof ( SessionStartHookInput ) ) ]
0 commit comments