github/copilot-sdk · error

session.create response did not include a sessionId

Error message

session.create response did not include a sessionId

What it means

In the inline (first) session-creation path, the client unmarshals the session.create response into a struct with a SessionID field. If the JSON parses but the sessionId field is empty or absent, this error is thrown. The server acknowledged the request but did not return an identifier the client needs to register the session.

Solutions

  1. Check the server response actually contains a sessionId field (log/capture the raw payload)
  2. Upgrade the server to a version compatible with this SDK's session.create contract
  3. If using a mock server, add sessionId to its canned response
  4. Check for server-side partial-failure handling that returns 200 with an empty body

Example fix

// mock server before
{"ok": true}
// after
{"ok": true, "sessionId": "sess_123"}
Defensive patterns

Strategy: validation

Validate before calling

var probe struct{ SessionID string `json:"sessionId"` }
if err := json.Unmarshal(raw, &probe); err != nil || probe.SessionID == "" {
    return errors.New("server response lacks sessionId")
}

Try / catch

s, err := client.CreateSession(ctx, opts)
if err != nil && strings.Contains(err.Error(), "did not include a sessionId") {
    log.Printf("session.create payload: %s", rawBody)
    return upgradeServerError(err)
}

Prevention

When it happens

Trigger: CreateSession (inline path, session == nil) where the session.create response is valid JSON but lacks a non-empty "sessionId" field — e.g. server returns {} or {"sessionId": ""}.

Common situations: Running against an older server that names the field differently (e.g. "id"); mock/test servers returning incomplete payloads; server-side errors swallowed into an empty 200 response.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09). Data as JSON: /api/errors/88e00792107fcc3b. Report an issue: GitHub.

Appendix: source

Thrown at go/client.go:1127

	// For the server-assigned (cloud) path, register the session
	// synchronously from the read loop the instant the response arrives,
	// before the read loop dispatches the next message. Without this hook
	// the awaiter goroutine may not run until after the read loop has
	// dispatched the first session.event notification, which would be
	// silently dropped because the session id isn't yet in the lookup
	// table. Non-cloud sessions are already registered above.
	var inlineCb func(raw json.RawMessage) error
	if session == nil {
		inlineCb = func(raw json.RawMessage) error {
			var early struct {
				SessionID string `json:"sessionId"`
			}
			if err := json.Unmarshal(raw, &early); err != nil {
				return fmt.Errorf("failed to parse sessionId from response: %w", err)
			}
			if early.SessionID == "" {
				return fmt.Errorf("session.create response did not include a sessionId")
			}
			s, err := initializeSession(early.SessionID)
			if err != nil {
				return err
			}
			session = s
			registeredSessionID = early.SessionID
			return nil
		}
	}

	result, err := c.client.RequestWithInlineResponse(ctx, "session.create", req, inlineCb)
	if err != nil {
		if registeredSessionID != "" {
			unregisterSession(registeredSessionID, session)
		}
		return nil, fmt.Errorf("failed to create session: %w", err)
	}

View on GitHub (pinned to cd8cf15dc3)