{"record":{"id":"9aacb5c752715c8c","repo":"github/copilot-sdk","slug":"no-session-found-for-sessionid-sessionid","errorCode":null,"errorMessage":"No session found for sessionId: ${sessionId}","messagePattern":"No session found for sessionId: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nodejs/src/client.ts","lineNumber":3044,"sourceCode":"                params: AutoModeSwitchRequest & { sessionId: string }\n            ): Promise<{ response: AutoModeSwitchResponse }> =>\n                await this.handleAutoModeSwitchRequest(params)\n        );\n\n        this.connection.onRequest(\n            \"systemMessage.transform\",\n            async (params: {\n                sessionId: string;\n                sections: Record<string, { content: string }>;\n            }): Promise<{ sections: Record<string, { content: string }> }> =>\n                await this.handleSystemMessageTransform(params)\n        );\n\n        // Register client session API handlers.\n        const sessions = this.sessions;\n        registerClientSessionApiHandlers(this.connection, (sessionId) => {\n            const session = sessions.get(sessionId);\n            if (!session) throw new Error(`No session found for sessionId: ${sessionId}`);\n            return session.clientSessionApis;\n        });\n\n        // Register client *global* API handlers (e.g. LLM inference) on the\n        // same connection. These methods carry no implicit sessionId dispatch\n        // — the runtime calls into a single handler for the whole connection.\n        registerClientGlobalApiHandlers(this.connection, this.clientGlobalHandlers);\n\n        // `hooks.invoke` is an internal RPC method: the runtime calls it to\n        // invoke a hook callback on the client. Route each call to the matching\n        // session's dispatcher. Not part of the public ClientGlobalApiHandlers\n        // interface because HookInvokeRequest/HookType are internal types.\n        this.connection.onRequest(\n            \"hooks.invoke\",\n            async (params: { sessionId: string; hookType: string; input: unknown }) => {\n                return await this.handleHooksInvoke(params);\n            }\n        );","sourceCodeStart":3026,"sourceCodeEnd":3062,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/nodejs/src/client.ts#L3026-L3062","documentation":"When the runtime calls back into the client for a session-scoped API, the client looks up the sessionId in its sessions map and throws if the id is unknown. This means the runtime referenced a session this client instance never registered, or the session was already removed. It is a server-to-client callback dispatch failure.","triggerScenarios":"A runtime callback arrives with a sessionId that was never created via this client (e.g. resume/attach to a session owned by another process), or the session was deleted/expired and later callbacks still reference its id.","commonSituations":"Client restarted and lost in-memory session state while the runtime still holds old session ids; calling session APIs after the session was deleted; sessionId typos or ids from a previous connection being replayed; multiple client instances where the callback lands on the wrong one.","solutions":["Recreate or re-register the session before issuing calls that reference its sessionId.","After a client restart, re-establish sessions with the runtime instead of reusing stale session ids.","Verify you are talking to the same client instance that created the session (check for multiple client instances).","Handle session-expired callbacks by deleting downstream references when a session ends so no stale ids are sent."],"exampleFix":"// before\nconst session = await createSession(client);\nawait client.stop();\n// ... later, with stale sessionId from `session`\nawait resumeSession(client, session.id); // throws: session map lost\n\n// after\nawait client.stop();\nclient = new CopilotClient({ ... });\nawait client.start();\nconst session = await createSession(client); // fresh session id\nawait resumeSession(client, session.id);","handlingStrategy":"try-catch","validationCode":"if (!client.hasSession?.(sessionId)) {\n  const session = await createSession(client); // re-register before use\n  sessionId = session.id;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await useSession(client, sessionId);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('No session found')) {\n    const fresh = await createSession(client);\n    sessionId = fresh.id;\n    await useSession(client, sessionId);\n  } else {\n    throw err;\n  }\n}","preventionTips":["Recreate sessions after any client restart; never reuse persisted session ids.","Drop cached session ids as soon as a session is deleted or expires.","Ensure only one client instance owns a given session.","Wrap session-scoped calls in a create-if-missing retry helper."],"tags":["session","rpc","state","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"}