{"record":{"id":"ec11f7803e62ab6e","repo":"charmbracelet/crush","slug":"failed-to-create-workspace-v","errorCode":null,"errorMessage":"failed to create workspace: %v","messagePattern":"failed to create workspace: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/root.go","lineNumber":473,"sourceCode":"// createWorkspaceOnLiveServer creates the workspace, retrying against a\n// replacement when the server it reached has already committed to shutting\n// itself down for being idle.\n//\n// That race is unavoidable: the server decides to exit while no client is\n// talking to it, and a client can arrive between that decision and the\n// socket going away. The decision is final on the server's side, so the\n// only correct response is to bring up a fresh server and ask again\n// instead of failing the command.\nfunc createWorkspaceOnLiveServer(\n\tctx context.Context, c *client.Client, req proto.Workspace, replace func() error,\n) (*proto.Workspace, error) {\n\tfor attempt := range maxStaleServerRetries {\n\t\tws, err := c.CreateWorkspace(ctx, req)\n\t\tif err == nil {\n\t\t\treturn ws, nil\n\t\t}\n\t\tif !errors.Is(err, client.ErrServerShuttingDown) || attempt == maxStaleServerRetries-1 {\n\t\t\treturn nil, fmt.Errorf(\"failed to create workspace: %v\", err)\n\t\t}\n\t\tslog.Warn(\"Server is shutting down; retrying against a replacement\",\n\t\t\t\"attempt\", attempt+1, \"error\", err)\n\t\tif err := replace(); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\treturn nil, fmt.Errorf(\"failed to create workspace: server kept shutting down\")\n}\n\n// replaceExitingServer waits out the socket of a server that has committed\n// to exiting, then brings up a fresh one.\nfunc replaceExitingServer(cmd *cobra.Command, hostURL *url.URL) error {\n\tif hostURL.Scheme == \"unix\" {\n\t\tif err := awaitSocketGone(cmd.Context(), hostURL); err != nil {\n\t\t\treturn err\n\t\t}\n\t}","sourceCodeStart":455,"sourceCodeEnd":491,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/cmd/root.go#L455-L491","documentation":"createWorkspaceOnLiveServer in internal/cmd/root.go retries client.CreateWorkspace up to maxStaleServerRetries when the server reports it is shutting down (client.ErrServerShuttingDown). Any non-shutdown error, or exhausting the final retry, returns 'failed to create workspace: %v' wrapping the underlying cause.","triggerScenarios":"The remote server rejects CreateWorkspace — workspace limit reached, auth failure, server-side DB error, or the server is mid-shutdown on the last allowed attempt so the error is surfaced instead of retried.","commonSituations":"A stale crush server process is terminating while the CLI connects; server crashed mid-request; connecting to a server owned by another user/instance that refuses the request; network drop between CLI and HTTP server.","solutions":["Re-run the command — a fresh server may start via ensureServer","Check server health/logs (`crush logs`) for the underlying CreateWorkspace error","Kill stale servers: pkill crush; wait for the socket to disappear, then retry","If using a remote host, verify connectivity and server-side capacity/auth"],"exampleFix":"// before\nc.ConnectAndUse() // hits a dying server once and fails\n// after\n// retry loop already built in; on failure:\n// pkill -f 'crush serve' && crush  # lets ensureServer spawn a fresh server","handlingStrategy":"retry","validationCode":"if _, err := c.HealthCheck(ctx); err != nil {\n    return fmt.Errorf(\"server unhealthy before workspace creation: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"ws, err := c.CreateWorkspace(ctx, req)\nif err != nil {\n    if errors.Is(err, client.ErrServerShuttingDown) {\n        // wait for replacement server, then retry\n    }\n    return fmt.Errorf(\"failed to create workspace: %w\", err)\n}","preventionTips":["Health-check the server before creating workspaces","Avoid connecting during known shutdown windows (deploys, reboots)","Keep a supervisor that only ever runs one server per socket"],"tags":["server","workspace","retry","client"],"backgroundTag":"workspace-creation-failed","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}