charmbracelet/crush · error
failed to get session history files: status code %d
Error message
failed to get session history files: status code %d
What it means
ListSessionHistoryFiles reached the history endpoint but the server responded with a non-200 status code. The client returns this error with the status code embedded. The body is not parsed, so the actual server-side error detail is discarded unless you inspect the exchange manually.
Source
Thrown at internal/client/proto.go:632
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)
}
defer rsp.Body.Close()
if rsp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("failed to create session: status code %d", rsp.StatusCode)
}View on GitHub (pinned to 7944b8e522)
Solutions
- Check the status code in the error message and handle it (404: verify workspace/session IDs exist; 401/403: refresh credentials; 5xx: retry later).
- Verify the session belongs to the given workspace ID.
- Refresh or re-issue authentication credentials.
- Capture the response body for diagnostics (may require a modified client or proxy).
- Retry with backoff for 429/5xx responses.
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 {
if strings.Contains(err.Error(), "status code 404") {
return fmt.Errorf("session %q not found in workspace %q", sessID, wsID)
}
return err
} Defensive patterns
Strategy: try-catch
Validate before calling
// Confirm the session exists first
_, err := client.GetSession(ctx, wsID, sessID)
if err != nil {
return fmt.Errorf("session %s not accessible in workspace %s: %w", sessID, wsID, err)
} Type guard
func isStatusCodeError(err error, code int) bool {
return err != nil && strings.Contains(err.Error(), fmt.Sprintf("status code %d", code))
} Try / catch
files, err := client.ListSessionHistoryFiles(ctx, wsID, sessID)
if err != nil {
switch {
case isStatusCodeError(err, 404):
return fmt.Errorf("session %q not found", sessID)
case isStatusCodeError(err, 401), isStatusCodeError(err, 403):
return fmt.Errorf("refresh credentials: %w", err)
}
return err
} Prevention
- Validate workspace/session IDs before calling.
- Refresh auth tokens before expiry.
- Check workspace permissions.
- Retry only 429/5xx statuses.
When it happens
Trigger: GET /workspaces/{id}/sessions/{sessionID}/history returns 404 (workspace or session not found), 401/403 (bad credentials/permissions), 500 (server error), etc.
Common situations: Deleted or mistyped session ID; expired API credentials; missing permission on the workspace; server-side failure while reading history files.
Related errors
- status code %d: %s
- status code %d
- failed to list workspaces: status code %d
- failed to get MCP pending auth: status code %d
- failed to get MCP auth URL: status code %d
AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29).
Data as JSON: /api/errors/7571e34b1bbfc373.
Report an issue: GitHub.