{"record":{"id":"36a9aa0339b65612","repo":"can1357/oh-my-pi","slug":"no-active-debug-session-launch-or-attach-first","errorCode":null,"errorMessage":"No active debug session. Launch or attach first.","messagePattern":"No active debug session\\. Launch or attach first\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/dap/session.ts","lineNumber":1784,"sourceCode":"\t\t\treturn null;\n\t\t}\n\t\tconst session = this.#sessions.get(this.#activeSessionId) ?? null;\n\t\tif (!session) {\n\t\t\tthis.#activeSessionId = null;\n\t\t}\n\t\treturn session;\n\t}\n\n\t/** True when the current active session is live and paused at a stop. */\n\t#hasLiveStoppedActiveSession(): boolean {\n\t\tconst active = this.#getActiveSessionOrNull();\n\t\treturn active !== null && active.status === \"stopped\" && active.client.isAlive();\n\t}\n\n\t#getActiveSessionOrThrow(): DapSession {\n\t\tconst session = this.#getActiveSessionOrNull();\n\t\tif (!session) {\n\t\t\tthrow new Error(\"No active debug session. Launch or attach first.\");\n\t\t}\n\t\treturn session;\n\t}\n\n\t#getRootSession(session: DapSession): DapSession {\n\t\tlet root = session;\n\t\twhile (root.parentSessionId) {\n\t\t\tconst parent = this.#sessions.get(root.parentSessionId);\n\t\t\tif (!parent) break;\n\t\t\troot = parent;\n\t\t}\n\t\treturn root;\n\t}\n\n\t#getTreeSessions(session: DapSession): DapSession[] {\n\t\tconst sessions: DapSession[] = [];\n\t\tconst pending = [this.#getRootSession(session)];\n\t\twhile (pending.length > 0) {","sourceCodeStart":1766,"sourceCodeEnd":1802,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/dap/session.ts#L1766-L1802","documentation":"DapSessionManager.#getActiveSessionOrThrow guards every public operation that requires a live debug session. It throws when there is no session at all, or the current session is not in 'stopped' status with a live client. In short: you asked the debugger to do something while no debugger was running.","triggerScenarios":"Calling methods like setBreakpoint, stackTrace, evaluate, continue, or step on a DapSessionManager instance before calling launch/attach, or after the session was terminated/disposed.","commonSituations":"Running debug commands from an automation/agent tool without first launching the debugger; the debuggee exited and the session was cleaned up; attaching failed earlier and the error was swallowed; managing multiple sessions and the active one was closed.","solutions":["Launch or attach a debug session before issuing commands","Check session status (e.g. a status/isAlive accessor) before calling operations, and surface 'start a debug session first' guidance to the user","Handle the case where the debuggee terminated normally — treat subsequent commands as no-ops","If a session unexpectedly disappeared, re-launch/attach it"],"exampleFix":"// before\nawait sessionManager.setBreakpoint('/a.ts', 10); // throws: no active session\n// after\nif (await sessionManager.hasActiveSession()) {\n\tawait sessionManager.setBreakpoint('/a.ts', 10);\n} else {\n\tawait sessionManager.launch({ type: 'node', program: '/a.js' });\n}","handlingStrategy":"validation","validationCode":"const active = manager.getActiveSession?.();\nif (!active || active.status !== 'stopped' || !active.client?.isAlive?.()) {\n\tthrow new SkipOperation('no active debug session');\n}","typeGuard":"function hasActiveSession(s) { return s !== null && s.status === 'stopped' && s.client.isAlive(); }","tryCatchPattern":"try {\n\tawait manager.setBreakpoint(file, line);\n} catch (err) {\n\tif (err.message.includes('No active debug session')) {\n\t\tawait manager.launch(config); // start session then retry\n\t}\n}","preventionTips":["Always launch/attach before debug commands","Track session lifecycle and clear dependent UI state on termination","Guard agent tools with an explicit session-required precondition"],"tags":["dap","debugger","session-state","invalid-state"],"backgroundTag":"no-active-debug-session","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}