charmbracelet/crush · error

failed to set compact mode: %w

Error message

failed to set compact mode: %w

What it means

SetCompactMode wraps a transport-level failure of the POST to /workspaces/{id}/config/compact. The compact-mode toggle never reached the server.

Source

Thrown at internal/client/config.go:71

	}{Scope: scope, ModelType: modelType, Model: model}), http.Header{"Content-Type": []string{"application/json"}})
	if err != nil {
		return fmt.Errorf("failed to update preferred model: %w", err)
	}
	defer rsp.Body.Close()
	if rsp.StatusCode != http.StatusOK {
		return fmt.Errorf("failed to update preferred model: status code %d", rsp.StatusCode)
	}
	return nil
}

// SetCompactMode sets compact mode on the server.
func (c *Client) SetCompactMode(ctx context.Context, id string, scope config.Scope, enabled bool) error {
	rsp, err := c.post(ctx, fmt.Sprintf("/workspaces/%s/config/compact", id), nil, jsonBody(struct {
		Scope   config.Scope `json:"scope"`
		Enabled bool         `json:"enabled"`
	}{Scope: scope, Enabled: enabled}), http.Header{"Content-Type": []string{"application/json"}})
	if err != nil {
		return fmt.Errorf("failed to set compact mode: %w", err)
	}
	defer rsp.Body.Close()
	if rsp.StatusCode != http.StatusOK {
		return fmt.Errorf("failed to set compact mode: status code %d", rsp.StatusCode)
	}
	return nil
}

// SetProviderAPIKey sets a provider API key on the server. The wire
// format tags the credential with an explicit Kind so the server can
// decode it back into the right Go type — JSON's `any` loses that
// information across the socket.
func (c *Client) SetProviderAPIKey(ctx context.Context, id string, scope config.Scope, providerID string, apiKey any) error {
	var (
		kind proto.APIKeyKind
		raw  json.RawMessage
	)
	switch v := apiKey.(type) {

View on GitHub (pinned to 7944b8e522)

Solutions

  1. Verify server connectivity and retry the toggle
  2. Check the wrapped cause; on context expiry, retry with a fresh context
  3. Re-apply the desired compact-mode state after reconnection
Defensive patterns

Strategy: retry

Validate before calling

// Ensure the server is reachable before toggling
if err := ctx.Err(); err != nil {
    return err
}
if _, err := os.Stat(socketPath); err != nil {
    return fmt.Errorf("server socket missing: %w", err)
}

Try / catch

if err := c.SetCompactMode(ctx, id, scope, enabled); err != nil {
    if isTransient(err) {
        // retry with backoff, then re-apply desired state
    }
    return err
}

Prevention

When it happens

Trigger: c.post fails (connection refused, context canceled) while enabling or disabling compact mode.

Common situations: Toggling compact mode right as the server shuts down; stale socket after a server crash.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29). Data as JSON: /api/errors/b8bc1cf1a858cd71. Report an issue: GitHub.