{"record":{"id":"58682c253f54b6ed","repo":"github/copilot-sdk","slug":"session-create-response-did-not-include-a-sessioni-58682c","errorCode":null,"errorMessage":"session.create response did not include a sessionId.","messagePattern":"session\\.create response did not include a sessionId\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Client.cs","lineNumber":1342,"sourceCode":"                        sessionId,\n                        connection.Rpc,\n                        config,\n                        transformCallbacks,\n                        hasHooks,\n                        \"CopilotClient.CreateSessionAsync\");\n                }\n            };\n\n            var response = await InvokeRpcAsync<CreateSessionResponse>(\n                connection.Rpc, \"session.create\", [request], null, cancellationToken, onResponseInline);\n            LoggingHelpers.LogTiming(_logger, LogLevel.Debug, null,\n                \"CopilotClient.CreateSessionAsync session creation request completed successfully. Elapsed={Elapsed}, SessionId={SessionId}\",\n                rpcTimestamp,\n                response.SessionId);\n\n            if (session is null)\n            {\n                throw new InvalidOperationException(\"session.create response did not include a sessionId.\");\n            }\n\n            if (localSessionId != null && !string.Equals(localSessionId, response.SessionId, StringComparison.Ordinal))\n            {\n                throw new InvalidOperationException(\n                    $\"session.create returned sessionId {response.SessionId} but the caller requested {localSessionId}.\");\n            }\n\n            if (config.OnMcpAuthRequest is not null)\n            {\n                await session.Rpc.EventLog.RegisterInterestAsync(\"mcp.oauth_required\", cancellationToken);\n            }\n\n            session.WorkspacePath = response.WorkspacePath;\n            session.SetCapabilities(response.Capabilities);\n            session.SetOpenCanvases(response.OpenCanvases);\n\n            await UpdateSessionOptionsForModeAsync(session, config, cancellationToken).ConfigureAwait(false);","sourceCodeStart":1324,"sourceCodeEnd":1360,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/dotnet/src/Client.cs#L1324-L1360","documentation":"CreateSessionAsync throws this InvalidOperationException when the session.create RPC response completes successfully but the decoded session object (sessionId) is null. This indicates the server replied without the required sessionId field, i.e. a malformed or unexpected response payload.","triggerScenarios":"Calling CreateSessionAsync when the runtime returns a session.create response missing sessionId - e.g. server/runtime version mismatch, a proxy or mock returning an empty payload, or a protocol deserialization gap.","commonSituations":"Pointing the SDK at an incompatible or very old runtime/CLI version; custom or mocked JSON-RPC servers in tests; network middleware stripping or truncating response fields.","solutions":["Verify the Copilot CLI/runtime version matches the SDK's supported protocol version and update it.","Log the raw session.create response to inspect what the server actually returned.","Retry CreateSessionAsync in case of a transient malformed response.","If using a mock or proxy server, fix it to include sessionId in the session.create result."],"exampleFix":"// before (custom mock server)\nresult = new { }; // session.create response without sessionId\n// after\nresult = new { sessionId = Guid.NewGuid().ToString() };","handlingStrategy":"retry","validationCode":"// can only be checked after the RPC; validate response server-side in mocks:\n// mock must return { sessionId: \"...\" } for session.create","typeGuard":"static bool HasSessionId(SessionResponse? response) => response?.Session is not null && !string.IsNullOrEmpty(response.Session.SessionId);","tryCatchPattern":"try { session = await client.CreateSessionAsync(config); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"did not include a sessionId\"))\n{\n    logger.LogWarning(\"Malformed session.create response; retrying\");\n    session = await client.CreateSessionAsync(config); // bounded retry recommended\n}","preventionTips":["Keep CLI/runtime and SDK versions aligned","Test against real runtime responses, not hand-rolled mocks missing sessionId","Log raw JSON-RPC traffic to catch malformed replies early"],"tags":["dotnet","rpc","protocol","response-validation","session"],"backgroundTag":"unexpected-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"}