{"record":{"id":"c84ed1b9917b5640","repo":"github/copilot-sdk","slug":"failed-to-set-foreground-session","errorCode":null,"errorMessage":"Failed to set foreground session","messagePattern":"Failed to set foreground session","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nodejs/src/client.ts","lineNumber":2466,"sourceCode":"     * @returns A promise that resolves when the session is switched\n     * @throws Error if the client is not connected or if the operation fails\n     *\n     * @example\n     * ```typescript\n     * // Switch the TUI to display a specific session\n     * await client.setForegroundSessionId(\"session-123\");\n     * ```\n     */\n    async setForegroundSessionId(sessionId: string): Promise<void> {\n        if (!this.connection) {\n            throw new Error(\"Client not connected\");\n        }\n\n        const response = await this.connection.sendRequest(\"session.setForeground\", { sessionId });\n        const result = response as { success: boolean; error?: string };\n\n        if (!result.success) {\n            throw new Error(result.error || \"Failed to set foreground session\");\n        }\n    }\n\n    /**\n     * Subscribes to a specific session lifecycle event type.\n     *\n     * Lifecycle events are emitted when sessions are created, deleted, updated,\n     * or change foreground/background state (in TUI+server mode).\n     *\n     * @param eventType - The specific event type to listen for\n     * @param handler - A callback function that receives events of the specified type\n     * @returns A function that, when called, unsubscribes the handler\n     *\n     * @example\n     * ```typescript\n     * // Listen for when a session becomes foreground in TUI\n     * const unsubscribe = client.onLifecycle(\"session.foreground\", (event) => {\n     *   console.log(`Session ${event.sessionId} is now displayed in TUI`);","sourceCodeStart":2448,"sourceCodeEnd":2484,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/nodejs/src/client.ts#L2448-L2484","documentation":"The session.setForeground RPC returned a falsy success flag — the runtime received the request to make the given session the TUI foreground session but rejected it. Typically the sessionId is unknown, the session is not in a state that can be foregrounded, or the TUI runtime does not support the operation.","triggerScenarios":"Thrown at nodejs/src/client.ts:2466 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Confirm the sessionId was returned by createSession and still exists","Ensure the target session is active before setting it foreground","Check the runtime version supports session.setForeground; if not, update the runtime"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}