fix(agents): improve process termination with multi-layer kill strategy
Resolves #87 and #9 by implementing a robust three-tier process termination approach: 1. ProcessRegistry kill - primary method using run_id tracking 2. ClaudeProcessState kill - fallback via stored process handle 3. System kill command - last resort using PID and OS commands Key improvements: - Enhanced logging throughout termination flow for better debugging - Graceful fallback between termination methods - Proper UI state management even when backend termination fails - Track run_id in AgentExecution component for targeted process killing - Comprehensive error handling with user-friendly feedback - Consistent event emission for UI synchronization This ensures agents can be properly stopped without requiring application restart, addressing the core issue where STOP requests were ignored and processes continued running.
This commit is contained in:
@@ -606,7 +606,25 @@ export const ClaudeCodeSession: React.FC<ClaudeCodeSessionProps> = ({
|
||||
setError(null);
|
||||
} catch (err) {
|
||||
console.error("Failed to cancel execution:", err);
|
||||
setError("Failed to cancel execution");
|
||||
|
||||
// Even if backend fails, we should update UI to reflect stopped state
|
||||
// Add error message but still stop the UI loading state
|
||||
const errorMessage: ClaudeStreamMessage = {
|
||||
type: "system",
|
||||
subtype: "error",
|
||||
result: `Failed to cancel execution: ${err instanceof Error ? err.message : 'Unknown error'}. The process may still be running in the background.`,
|
||||
timestamp: new Date().toISOString()
|
||||
};
|
||||
setMessages(prev => [...prev, errorMessage]);
|
||||
|
||||
// Clean up listeners anyway
|
||||
unlistenRefs.current.forEach(unlisten => unlisten());
|
||||
unlistenRefs.current = [];
|
||||
|
||||
// Reset states to allow user to continue
|
||||
setIsLoading(false);
|
||||
hasActiveSessionRef.current = false;
|
||||
setError(null);
|
||||
} finally {
|
||||
setIsCancelling(false);
|
||||
}
|
||||
|
Reference in New Issue
Block a user