(sessionId: string)
| 657 | |
| 658 | // Stop a session by sessionId or PID fallback |
| 659 | const stopSession = (sessionId: string): boolean => { |
| 660 | logger.debug(`[RUNNER RUN] Attempting to stop session ${sessionId}`); |
| 661 | |
| 662 | // Try to find by sessionId first |
| 663 | for (const [pid, session] of pidToTrackedSession.entries()) { |
| 664 | if (session.happySessionId === sessionId || |
| 665 | (sessionId.startsWith('PID-') && pid === parseInt(sessionId.replace('PID-', '')))) { |
| 666 | |
| 667 | if (session.startedBy === 'runner' && session.childProcess) { |
| 668 | try { |
| 669 | void killProcessByChildProcess(session.childProcess); |
| 670 | logger.debug(`[RUNNER RUN] Requested termination for runner-spawned session ${sessionId}`); |
| 671 | } catch (error) { |
| 672 | logger.debug(`[RUNNER RUN] Failed to kill session ${sessionId}:`, error); |
| 673 | } |
| 674 | } else { |
| 675 | // For externally started sessions, try to kill by PID |
| 676 | try { |
| 677 | void killProcess(pid); |
| 678 | logger.debug(`[RUNNER RUN] Requested termination for external session PID ${pid}`); |
| 679 | } catch (error) { |
| 680 | logger.debug(`[RUNNER RUN] Failed to kill external session PID ${pid}:`, error); |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | pidToTrackedSession.delete(pid); |
| 685 | logger.debug(`[RUNNER RUN] Removed session ${sessionId} from tracking`); |
| 686 | return true; |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | logger.debug(`[RUNNER RUN] Session ${sessionId} not found`); |
| 691 | return false; |
| 692 | }; |
| 693 | |
| 694 | // Handle child process exit |
| 695 | const onChildExited = (pid: number) => { |
no test coverage detected