{"record":{"id":"e369ce755845f596","repo":"github/copilot-sdk","slug":"session-create-returned-sessionid-returnedid-bu","errorCode":null,"errorMessage":"session.create returned sessionId ${returnedId} but the caller requested ${localSessionId}","messagePattern":"session\\.create returned sessionId (.+?) but the caller requested (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"java/sdk/src/main/java/com/github/copilot/CopilotClient.java","lineNumber":1018,"sourceCode":"                request.setGitHubTokenProviderRegistrationId(tokenRegistration.id());\n                if (preRegisteredSessionHolder[0] != null) {\n                    preRegisteredSessionHolder[0].setGitHubTokenProviderRegistration(tokenRegistration);\n                }\n            }\n\n            long rpcNanos = System.nanoTime();\n            return connection.rpc.invoke(\"session.create\", request, CreateSessionResponse.class)\n                    .thenCompose(response -> {\n                        String returnedId = response.sessionId();\n                        LoggingHelpers.logTiming(LOG, Level.FINE,\n                                \"CopilotClient.createSession session creation request completed. Elapsed={Elapsed}, SessionId=\"\n                                        + (returnedId != null ? returnedId : localSessionId),\n                                rpcNanos);\n                        if (returnedId == null || returnedId.isEmpty()) {\n                            throw new RuntimeException(\"session.create response did not include a sessionId\");\n                        }\n                        if (localSessionId != null && !localSessionId.equals(returnedId)) {\n                            throw new RuntimeException(\"session.create returned sessionId \" + returnedId\n                                    + \" but the caller requested \" + localSessionId);\n                        }\n                        CopilotSession session = preRegisteredSessionHolder[0] != null\n                                ? preRegisteredSessionHolder[0]\n                                : initializeSession.apply(returnedId);\n                        preRegisteredSessionHolder[0] = session;\n                        if (tokenRegistration != null) {\n                            session.setGitHubTokenProviderRegistration(tokenRegistration);\n                        }\n                        registeredIdHolder[0] = returnedId;\n                        CompletableFuture<?> interest = config.getOnMcpAuthRequest() != null\n                                ? session.getRpc().eventLog.registerInterest(\n                                        new SessionEventLogRegisterInterestParams(returnedId, \"mcp.oauth_required\"))\n                                : CompletableFuture.completedFuture(null);\n                        session.setWorkspacePath(response.workspacePath());\n                        session.setCapabilities(response.capabilities());\n                        session.setOpenCanvases(response.openCanvases());\n","sourceCodeStart":1000,"sourceCodeEnd":1036,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/java/sdk/src/main/java/com/github/copilot/CopilotClient.java#L1000-L1036","documentation":"When createSession is called with an explicit sessionId, CopilotClient validates that the server echoed the same id back. If the server returned a different sessionId than the caller requested, the client throws to prevent operating on a session the caller cannot address.","triggerScenarios":"Calling createSession(options) with a preset sessionId (localSessionId != null) while the server's session.create handler generates or returns its own distinct sessionId.","commonSituations":"Multiple clients racing to create sessions with the same id; a server that ignores client-supplied session ids; stale id reuse after a server restart; tests seeding ids that the server does not honor.","solutions":["Stop pre-assigning a sessionId and let createSession use the server-generated id","Ensure the component that minted localSessionId is the same one that owns session.create handling","Check for duplicate clients or reconnect logic reusing an old session id after server restart","Enable FINE timing logs to compare requested vs returned ids"],"exampleFix":"// before\nclient.createSession(new CreateSessionOptions().setSessionId(myFixedId));\n// after\nCopilotSession session = client.createSession(new CreateSessionOptions());\nString id = session.getSessionId();","handlingStrategy":"validation","validationCode":"if (requestedSessionId != null && !requestedSessionId.isBlank()) {\n    // be ready for the server to reject or reassign client-supplied ids\n}","typeGuard":null,"tryCatchPattern":"try {\n    client.createSession(optsWithFixedId);\n} catch (RuntimeException e) {\n    if (e.getMessage().startsWith(\"session.create returned sessionId\")) {\n        // fall back to server-assigned id\n    }\n}","preventionTips":["Avoid pre-assigning session ids; let the server mint them","Ensure only one component generates session ids","Re-derive session ids after server restarts instead of reusing cached ones"],"tags":["rpc","session","id-mismatch"],"backgroundTag":"unexpected-api-response-shape","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"}