charmbracelet/crush · error

failed to get session history files: %w

Error message

failed to get session history files: %w

What it means

ListSessionHistoryFiles failed inside c.get, the low-level HTTP helper, before any response was available. The client wraps the transport-level error with this message. This fires when the request could not be completed at all: DNS failure, connection refused/reset, TLS error, context cancellation, or request-construction failure.

Source

Thrown at internal/client/proto.go:628

	if err != nil {
		return nil, fmt.Errorf("failed to get session: %w", err)
	}
	defer rsp.Body.Close()
	if rsp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("failed to get session: status code %d", rsp.StatusCode)
	}
	var sess proto.Session
	if err := json.NewDecoder(rsp.Body).Decode(&sess); err != nil {
		return nil, fmt.Errorf("failed to decode session: %w", err)
	}
	return &sess, nil
}

// ListSessionHistoryFiles retrieves history files for a session as proto types.
func (c *Client) ListSessionHistoryFiles(ctx context.Context, id string, sessionID string) ([]proto.File, error) {
	rsp, err := c.get(ctx, fmt.Sprintf("/workspaces/%s/sessions/%s/history", id, sessionID), nil, nil)
	if err != nil {
		return nil, fmt.Errorf("failed to get session history files: %w", err)
	}
	defer rsp.Body.Close()
	if rsp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("failed to get session history files: status code %d", rsp.StatusCode)
	}
	var files []proto.File
	if err := json.NewDecoder(rsp.Body).Decode(&files); err != nil {
		return nil, fmt.Errorf("failed to decode session history files: %w", err)
	}
	return files, nil
}

// CreateSession creates a new session in a workspace as a proto type.
func (c *Client) CreateSession(ctx context.Context, id string, title string) (*proto.Session, error) {
	rsp, err := c.post(ctx, fmt.Sprintf("/workspaces/%s/sessions", id), nil, jsonBody(proto.Session{Title: title}), http.Header{"Content-Type": []string{"application/json"}})
	if err != nil {
		return nil, fmt.Errorf("failed to create session: %w", err)
	}

View on GitHub (pinned to 7944b8e522)

Solutions

  1. Inspect the wrapped error for the root cause (connection refused, no such host, context deadline exceeded).
  2. Verify the server address/base URL and that the workspace ID and session ID are correct.
  3. Retry with backoff if the error is transient (connection reset, timeout).
  4. Check network connectivity, VPN, and TLS configuration.
  5. URL-escape ids: ensure they contain no raw slashes or invalid characters.

Example fix

// before
files, err := client.ListSessionHistoryFiles(ctx, wsID, sessID)
if err != nil { return err }
// after
files, err := client.ListSessionHistoryFiles(ctx, wsID, sessID)
if err != nil {
    var netErr net.Error
    if errors.As(err, &netErr) && netErr.Timeout() {
        // retry with backoff
    }
    return err
}
Defensive patterns

Strategy: retry

Validate before calling

// Pre-flight: ensure the server is reachable
req, _ := http.NewRequestWithContext(ctx, http.MethodGet, baseURL+"/health", nil)
if _, err := http.DefaultClient.Do(req); err != nil {
    return fmt.Errorf("server unreachable: %w", err)
}

Type guard

func isTransportError(err error) bool {
    var netErr net.Error
    return err != nil && errors.As(err, &netErr)
}

Try / catch

files, err := client.ListSessionHistoryFiles(ctx, wsID, sessID)
if err != nil {
    if isTransportError(err) {
        // retry with exponential backoff
    }
    return err
}

Prevention

When it happens

Trigger: GET /workspaces/{id}/sessions/{sessionID}/history fails at the transport layer: server unreachable, connection dropped mid-request, ctx cancelled/deadline exceeded, or invalid URL characters in id/sessionID causing request creation failure.

Common situations: Server not running or wrong base URL; network outage or VPN drop; context timeout on slow history endpoints; workspace or session IDs containing characters needing escaping.

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/fc2fbfe0c787cee5. Report an issue: GitHub.