{"record":{"id":"b8bc1cf1a858cd71","repo":"charmbracelet/crush","slug":"failed-to-set-compact-mode-w","errorCode":null,"errorMessage":"failed to set compact mode: %w","messagePattern":"failed to set compact mode: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/config.go","lineNumber":71,"sourceCode":"\t}{Scope: scope, ModelType: modelType, Model: model}), http.Header{\"Content-Type\": []string{\"application/json\"}})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to update preferred model: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"failed to update preferred model: status code %d\", rsp.StatusCode)\n\t}\n\treturn nil\n}\n\n// SetCompactMode sets compact mode on the server.\nfunc (c *Client) SetCompactMode(ctx context.Context, id string, scope config.Scope, enabled bool) error {\n\trsp, err := c.post(ctx, fmt.Sprintf(\"/workspaces/%s/config/compact\", id), nil, jsonBody(struct {\n\t\tScope   config.Scope `json:\"scope\"`\n\t\tEnabled bool         `json:\"enabled\"`\n\t}{Scope: scope, Enabled: enabled}), http.Header{\"Content-Type\": []string{\"application/json\"}})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to set compact mode: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"failed to set compact mode: status code %d\", rsp.StatusCode)\n\t}\n\treturn nil\n}\n\n// SetProviderAPIKey sets a provider API key on the server. The wire\n// format tags the credential with an explicit Kind so the server can\n// decode it back into the right Go type — JSON's `any` loses that\n// information across the socket.\nfunc (c *Client) SetProviderAPIKey(ctx context.Context, id string, scope config.Scope, providerID string, apiKey any) error {\n\tvar (\n\t\tkind proto.APIKeyKind\n\t\traw  json.RawMessage\n\t)\n\tswitch v := apiKey.(type) {","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/client/config.go#L53-L89","documentation":"SetCompactMode wraps a transport-level failure of the POST to /workspaces/{id}/config/compact. The compact-mode toggle never reached the server.","triggerScenarios":"c.post fails (connection refused, context canceled) while enabling or disabling compact mode.","commonSituations":"Toggling compact mode right as the server shuts down; stale socket after a server crash.","solutions":["Verify server connectivity and retry the toggle","Check the wrapped cause; on context expiry, retry with a fresh context","Re-apply the desired compact-mode state after reconnection"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Ensure the server is reachable before toggling\nif err := ctx.Err(); err != nil {\n    return err\n}\nif _, err := os.Stat(socketPath); err != nil {\n    return fmt.Errorf(\"server socket missing: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := c.SetCompactMode(ctx, id, scope, enabled); err != nil {\n    if isTransient(err) {\n        // retry with backoff, then re-apply desired state\n    }\n    return err\n}","preventionTips":["Re-apply UI state like compact mode after reconnection","Use contexts with adequate deadlines","Treat compact-mode sync failures as non-fatal UI issues"],"tags":["http","network","config"],"backgroundTag":"http-request-failed","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}