{"record":{"id":"cba6bb8bf0f9e96b","repo":"github/copilot-sdk","slug":"session-not-found-params-sessionid","errorCode":null,"errorMessage":"Session not found: ${params.sessionId}","messagePattern":"Session not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nodejs/src/client.ts","lineNumber":3174,"sourceCode":"    }\n\n    private async handleUserInputRequest(params: {\n        sessionId: string;\n        question: string;\n        choices?: string[];\n        allowFreeform?: boolean;\n    }): Promise<{ answer: string; wasFreeform: boolean }> {\n        if (\n            !params ||\n            typeof params.sessionId !== \"string\" ||\n            typeof params.question !== \"string\"\n        ) {\n            throw new Error(\"Invalid user input request payload\");\n        }\n\n        const session = this.sessions.get(params.sessionId);\n        if (!session) {\n            throw new Error(`Session not found: ${params.sessionId}`);\n        }\n\n        const result = await session._handleUserInputRequest({\n            question: params.question,\n            choices: params.choices,\n            allowFreeform: params.allowFreeform,\n        });\n        return result;\n    }\n\n    private async handleExitPlanModeRequest(\n        params: ExitPlanModeRequest & { sessionId: string }\n    ): Promise<ExitPlanModeResult> {\n        if (\n            !params ||\n            typeof params.sessionId !== \"string\" ||\n            typeof params.summary !== \"string\" ||\n            !Array.isArray(params.actions) ||","sourceCodeStart":3156,"sourceCodeEnd":3192,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/nodejs/src/client.ts#L3156-L3192","documentation":"After payload validation, the client looks up the session in its internal sessions map. This error means the sessionId supplied does not correspond to any live session managed by this CopilotClient instance. It is thrown before the request is forwarded to session._handleUserInputRequest.","triggerScenarios":"Calling the user-input request method with a sessionId that was never registered, or whose session has since been removed/disposed from the client's sessions map.","commonSituations":"Handling a delayed async callback after the session already ended; using a sessionId from a different CopilotClient instance; typo'd or truncated session id copied from logs; client restart wiping in-memory sessions while a stale message is replayed.","solutions":["Log and confirm the sessionId exists: only pass ids obtained from session creation on this same client instance.","Check session lifecycle: re-create the session if it was stopped/disposed before handling user input.","Verify you are calling the client instance that owns the session, not a second instance.","Guard with client-side existence check or catch the error and skip stale messages."],"exampleFix":"// before\nawait client.handleUserInputRequest({ sessionId: staleId, question: q });\n// after\nif (!client.hasSession(staleId)) {\n  console.warn(\"dropping stale user-input for\", staleId);\n  return;\n}\nawait client.handleUserInputRequest({ sessionId: staleId, question: q });","handlingStrategy":"try-catch","validationCode":"if (client.hasSession(params.sessionId)) {\n  await client.handleUserInputRequest(params);\n}","typeGuard":"null","tryCatchPattern":"try {\n  await client.handleUserInputRequest({ sessionId, question });\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith(\"Session not found:\")) {\n    // stale session: drop or recreate\n  } else throw e;\n}","preventionTips":["Track session lifecycle and cancel pending work on session end.","Only use sessionIds returned by the same client instance.","Log session create/remove events to correlate stale ids."],"tags":["session","state","lifecycle","lookup-failed"],"backgroundTag":"resource-not-found","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}