github/copilot-sdk · error
Session not found
Error message
Session not found: ${params.sessionId} What it means
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.
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.
Example fix
// before
await client.handleUserInputRequest({ sessionId: staleId, question: q });
// after
if (!client.hasSession(staleId)) {
console.warn("dropping stale user-input for", staleId);
return;
}
await client.handleUserInputRequest({ sessionId: staleId, question: q }); Defensive patterns
Strategy: try-catch
Validate before calling
if (client.hasSession(params.sessionId)) {
await client.handleUserInputRequest(params);
} Type guard
null
Try / catch
try {
await client.handleUserInputRequest({ sessionId, question });
} catch (e) {
if (e instanceof Error && e.message.startsWith("Session not found:")) {
// stale session: drop or recreate
} else throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- No session found for sessionId
- CLI process not started
- CLI child process was unexpectedly started in parent…
- FfiRuntimeHost is already closed.
- Unknown session
AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09).
Data as JSON: /api/errors/cba6bb8bf0f9e96b.
Report an issue: GitHub.
Appendix: source
Thrown at nodejs/src/client.ts:3174
}
private async handleUserInputRequest(params: {
sessionId: string;
question: string;
choices?: string[];
allowFreeform?: boolean;
}): Promise<{ answer: string; wasFreeform: boolean }> {
if (
!params ||
typeof params.sessionId !== "string" ||
typeof params.question !== "string"
) {
throw new Error("Invalid user input request payload");
}
const session = this.sessions.get(params.sessionId);
if (!session) {
throw new Error(`Session not found: ${params.sessionId}`);
}
const result = await session._handleUserInputRequest({
question: params.question,
choices: params.choices,
allowFreeform: params.allowFreeform,
});
return result;
}
private async handleExitPlanModeRequest(
params: ExitPlanModeRequest & { sessionId: string }
): Promise<ExitPlanModeResult> {
if (
!params ||
typeof params.sessionId !== "string" ||
typeof params.summary !== "string" ||
!Array.isArray(params.actions) ||View on GitHub (pinned to cd8cf15dc3)