MCPcopy Create free account
hub / github.com/tiann/hapi / stopSession

Function stopSession

cli/src/runner/run.ts:659–692  ·  view source on GitHub ↗
(sessionId: string)

Source from the content-addressed store, hash-verified

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) => {

Callers 2

startRunnerControlServerFunction · 0.85
setRPCHandlersMethod · 0.85

Calls 3

killProcessFunction · 0.90
debugMethod · 0.80

Tested by

no test coverage detected