{"record":{"id":"d8629932b86909f8","repo":"charmbracelet/crush","slug":"failed-to-create-session-w","errorCode":null,"errorMessage":"failed to create session: %w","messagePattern":"failed to create session: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/proto.go","lineNumber":645,"sourceCode":"\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get session history files: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"failed to get session history files: status code %d\", rsp.StatusCode)\n\t}\n\tvar files []proto.File\n\tif err := json.NewDecoder(rsp.Body).Decode(&files); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to decode session history files: %w\", err)\n\t}\n\treturn files, nil\n}\n\n// CreateSession creates a new session in a workspace as a proto type.\nfunc (c *Client) CreateSession(ctx context.Context, id string, title string) (*proto.Session, error) {\n\trsp, err := c.post(ctx, fmt.Sprintf(\"/workspaces/%s/sessions\", id), nil, jsonBody(proto.Session{Title: title}), http.Header{\"Content-Type\": []string{\"application/json\"}})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create session: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"failed to create session: status code %d\", rsp.StatusCode)\n\t}\n\tvar sess proto.Session\n\tif err := json.NewDecoder(rsp.Body).Decode(&sess); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to decode session: %w\", err)\n\t}\n\treturn &sess, nil\n}\n\n// ListSessions lists all sessions in a workspace as proto types.\nfunc (c *Client) ListSessions(ctx context.Context, id string) ([]proto.Session, error) {\n\trsp, err := c.get(ctx, fmt.Sprintf(\"/workspaces/%s/sessions\", id), nil, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get sessions: %w\", err)\n\t}","sourceCodeStart":627,"sourceCodeEnd":663,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/client/proto.go#L627-L663","documentation":"CreateSession failed inside c.post, the low-level HTTP helper, before a response was returned. The transport error is wrapped with this message. The POST to /workspaces/{id}/sessions never completed: connection failure, TLS error, or context cancellation.","triggerScenarios":"POST /workspaces/{id}/sessions fails at transport level: server down, connection refused/reset, ctx deadline exceeded, or URL-escaping issues with the workspace id.","commonSituations":"Server unreachable (wrong host/port); network interruption during the POST; caller's context cancelled while creating the session; oversized or invalid title causing early connection teardown (rare).","solutions":["Inspect the wrapped error for the root cause.","Verify server availability and the workspace ID.","Retry with backoff for transient network failures; note the session may or may not have been created, so check via ListSessions/GetSession before retrying blindly.","Check context deadlines — allow enough time for session creation.","Confirm network/VPN/TLS setup."],"exampleFix":"// before\nsess, err := client.CreateSession(ctx, wsID, title)\nif err != nil { return err }\n// after\nsess, err := client.CreateSession(ctx, wsID, title)\nif err != nil {\n    if ctx.Err() != nil { return ctx.Err() }\n    // transient? retry idempotently: look up by title first\n    return err\n}","handlingStrategy":"retry","validationCode":"// Validate inputs and connectivity first\nif wsID == \"\" { return errors.New(\"workspace id required\") }\nif err := ctx.Err(); err != nil { return err }","typeGuard":"func isCreateTransportError(err error) bool {\n    var netErr net.Error\n    return err != nil && strings.Contains(err.Error(), \"failed to create session\") && errors.As(err, &netErr)\n}","tryCatchPattern":"sess, err := client.CreateSession(ctx, wsID, title)\nif err != nil {\n    if ctx.Err() != nil { return ctx.Err() }\n    // transport-level: safe to retry after checking whether the session was created\n    return retryWithBackoff(func() error {\n        s, e := client.CreateSession(ctx, wsID, title)\n        if e == nil { sess = s; return nil }\n        return e\n    })\n}","preventionTips":["Use contexts with adequate deadlines.","Verify server availability before writes.","Treat create retries carefully — list sessions to avoid duplicates.","Escape IDs used in URL paths."],"tags":["http","network","client"],"backgroundTag":"http-request-failed","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}