{"record":{"id":"d2d06cd0b0a12654","repo":"github/copilot-sdk","slug":"session-create-returned-sessionid-s-but-the-calle","errorCode":null,"errorMessage":"session.create returned sessionId %s but the caller requested %s","messagePattern":"session\\.create returned sessionId (.+?) but the caller requested (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/client.go","lineNumber":1161,"sourceCode":"\t\t}\n\t\treturn nil, fmt.Errorf(\"failed to create session: %w\", err)\n\t}\n\n\tvar response createSessionResponse\n\tif err := json.Unmarshal(result, &response); err != nil {\n\t\tif registeredSessionID != \"\" {\n\t\t\tunregisterSession(registeredSessionID, session)\n\t\t}\n\t\treturn nil, fmt.Errorf(\"failed to unmarshal response: %w\", err)\n\t}\n\n\tif session == nil {\n\t\treturn nil, fmt.Errorf(\"session.create response did not include a sessionId\")\n\t}\n\n\tif localSessionID != \"\" && response.SessionID != \"\" && response.SessionID != localSessionID {\n\t\tunregisterSession(registeredSessionID, session)\n\t\treturn nil, fmt.Errorf(\"session.create returned sessionId %s but the caller requested %s\", response.SessionID, localSessionID)\n\t}\n\tif config.OnMCPAuthRequest != nil {\n\t\tif _, err := c.client.Request(ctx, \"session.eventLog.registerInterest\", map[string]any{\n\t\t\t\"sessionId\": session.SessionID,\n\t\t\t\"eventType\": \"mcp.oauth_required\",\n\t\t}); err != nil {\n\t\t\tunregisterSession(registeredSessionID, session)\n\t\t\treturn nil, err\n\t\t}\n\t}\n\n\tsession.workspacePath = response.WorkspacePath\n\tsession.setCapabilities(response.Capabilities)\n\n\tif err := c.updateSessionOptionsForMode(ctx, session, optBackInFields{\n\t\tSkipCustomInstructions: config.SkipCustomInstructions,\n\t\tCustomAgentsLocalOnly:  config.CustomAgentsLocalOnly,\n\t\tCoauthorEnabled:        config.CoauthorEnabled,","sourceCodeStart":1143,"sourceCodeEnd":1179,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/client.go#L1143-L1179","documentation":"When CreateSession is called with a caller-specified local session ID and the server returns a different sessionId, the client unregisters the just-created session and returns this mismatch error. It enforces that the server honored the requested identifier; silently accepting a different ID would break the caller's bookkeeping.","triggerScenarios":"CreateSession with a non-empty localSessionID option while the server's session.create response returns a different non-empty response.SessionID.","commonSituations":"Passing a pre-chosen session ID for resumability while the server generates its own IDs; reusing IDs across server restarts; ID collisions resolved server-side by minting a new ID.","solutions":["Remove the explicit local session ID option and let the server assign one","Verify the server supports caller-supplied session IDs and echoes them back","Use the returned response.SessionID instead of your local ID for subsequent calls","Check for stale state where the requested ID already exists server-side"],"exampleFix":"// before\nopts.LocalSessionID = \"my-fixed-id\"\ns, _ := c.CreateSession(ctx, opts)\n// after\ns, _ := c.CreateSession(ctx, opts) // use s.SessionID downstream","handlingStrategy":"validation","validationCode":"if localID != \"\" {\n    // only pass a local session ID if the server is known to honor caller-supplied IDs\n    if !serverSupportsCallerSessionIDs { localID = \"\" }\n}","typeGuard":null,"tryCatchPattern":"s, err := client.CreateSession(ctx, opts)\nif err != nil && strings.Contains(err.Error(), \"but the caller requested\") {\n    // drop the explicit ID and retry\n    opts.LocalSessionID = \"\"\n    s, err = client.CreateSession(ctx, opts)\n}","preventionTips":["Only set a local session ID when the server contract supports it","Always use the returned SessionID for subsequent calls","Don't reuse IDs across server restarts"],"tags":["session","id-mismatch","rpc","state"],"backgroundTag":"invalid-argument-value","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"}