@@ -1962,8 +1962,12 @@ public async ValueTask DisposeAsync()
19621962
19631963 try
19641964 {
1965- await InvokeRpcAsync < object > (
1966- "session.destroy" , [ new SessionDestroyRequest ( ) { SessionId = SessionId } ] , CancellationToken . None ) ;
1965+ var response = await InvokeRpcAsync < SessionDetachResponse > (
1966+ "session.detach" , [ new SessionDetachRequest ( ) { SessionId = SessionId } ] , CancellationToken . None ) ;
1967+ if ( ! response . Success )
1968+ {
1969+ LogSessionDetachFailed ( SessionId , response . Error ?? "unknown error" ) ;
1970+ }
19671971 }
19681972 catch ( ObjectDisposedException )
19691973 {
@@ -2000,6 +2004,9 @@ await InvokeRpcAsync<object>(
20002004 [ LoggerMessage ( Level = LogLevel . Debug , Message = "Failed to fetch tool metadata for {toolName}" ) ]
20012005 private partial void LogToolMetadataFetchFailed ( Exception exception , string toolName ) ;
20022006
2007+ [ LoggerMessage ( Level = LogLevel . Warning , Message = "Failed to detach session {sessionId}: {error}" ) ]
2008+ private partial void LogSessionDetachFailed ( string sessionId , string error ) ;
2009+
20032010 [ LoggerMessage ( Level = LogLevel . Error , Message = "Permission handler or response delivery failed. SessionId={SessionId}, RequestId={RequestId}" ) ]
20042011 private partial void LogPermissionHandlerOrDeliveryFailed ( Exception exception , string sessionId , string requestId ) ;
20052012
@@ -2037,11 +2044,17 @@ internal record SessionAbortRequest
20372044 public string SessionId { get ; init ; } = string . Empty ;
20382045 }
20392046
2040- internal record SessionDestroyRequest
2047+ internal record SessionDetachRequest
20412048 {
20422049 public string SessionId { get ; init ; } = string . Empty ;
20432050 }
20442051
2052+ internal record SessionDetachResponse
2053+ {
2054+ public bool Success { get ; init ; }
2055+ public string ? Error { get ; init ; }
2056+ }
2057+
20452058 internal void ThrowIfDisposed ( )
20462059 {
20472060 ObjectDisposedException . ThrowIf ( Volatile . Read ( ref _isDisposed ) != 0 , this ) ;
@@ -2074,7 +2087,8 @@ internal void ThrowIfDisposed()
20742087 [ JsonSerializable ( typeof ( SendMessageRequest ) ) ]
20752088 [ JsonSerializable ( typeof ( SendMessageResponse ) ) ]
20762089 [ JsonSerializable ( typeof ( SessionAbortRequest ) ) ]
2077- [ JsonSerializable ( typeof ( SessionDestroyRequest ) ) ]
2090+ [ JsonSerializable ( typeof ( SessionDetachRequest ) ) ]
2091+ [ JsonSerializable ( typeof ( SessionDetachResponse ) ) ]
20782092 [ JsonSerializable ( typeof ( SessionEndHookInput ) ) ]
20792093 [ JsonSerializable ( typeof ( SessionEndHookOutput ) ) ]
20802094 [ JsonSerializable ( typeof ( SessionStartHookInput ) ) ]
0 commit comments