{"record":{"id":"21f092ea0cf3f557","repo":"charmbracelet/crush","slug":"failed-to-summarize-session-status-code-d","errorCode":null,"errorMessage":"failed to summarize session: status code %d","messagePattern":"failed to summarize session: status code (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/proto.go","lineNumber":571,"sourceCode":"\tif rsp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"failed to get session agent info: status code %d\", rsp.StatusCode)\n\t}\n\tvar info proto.AgentSession\n\tif err := json.NewDecoder(rsp.Body).Decode(&info); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to decode session agent info: %w\", err)\n\t}\n\treturn &info, nil\n}\n\n// AgentSummarizeSession requests a session summarization.\nfunc (c *Client) AgentSummarizeSession(ctx context.Context, id string, sessionID string) error {\n\trsp, err := c.post(ctx, fmt.Sprintf(\"/workspaces/%s/agent/sessions/%s/summarize\", id, sessionID), nil, nil, nil)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to summarize session: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"failed to summarize session: status code %d\", rsp.StatusCode)\n\t}\n\treturn nil\n}\n\n// InitiateAgentProcessing triggers agent initialization on the server.\nfunc (c *Client) InitiateAgentProcessing(ctx context.Context, id string, interactive bool) error {\n\tbody := jsonBody(proto.AgentInitRequest{Interactive: interactive})\n\trsp, err := c.post(ctx, fmt.Sprintf(\"/workspaces/%s/agent/init\", id), nil, body, http.Header{\"Content-Type\": []string{\"application/json\"}})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to initiate session agent processing: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"failed to initiate session agent processing: status code %d\", rsp.StatusCode)\n\t}\n\treturn nil\n}\n","sourceCodeStart":553,"sourceCodeEnd":589,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/client/proto.go#L553-L589","documentation":"Thrown by Client.AgentSummarizeSession when the server responded to POST /workspaces/{id}/agent/sessions/{sessionID}/summarize with a status code other than 200. The response body is not inspected, so any server-side failure (bad session id, agent not initialized, internal error, auth rejection) surfaces as this status-code error. Reached via AgentSummarize.","triggerScenarios":"Calling AgentSummarizeSession with a sessionID that no longer exists (404), before the agent has been initialized (4xx/5xx), with an invalid workspace id, when the server lacks permission/auth for the operation (401/403), or when the server's summarization backend errors out (500).","commonSituations":"Client and server out of sync after the session was deleted elsewhere; API base URL misconfigured so the request hits the wrong route (404); auth token expired (401); server bug or overloaded LLM provider causing 500 during summarization.","solutions":["Log the actual rsp status on the server side or re-issue the request with curl to see the response body and identify the exact status.","Verify the workspace id and sessionID are valid and the session still exists.","Ensure the agent was initialized (InitiateAgentProcessing) before requesting summarization.","Check authentication/token validity if the status is 401/403; check server logs if 500."],"exampleFix":"// before: only the numeric status is known\nif err := client.AgentSummarize(ctx, wsID, sessionID); err != nil {\n    return err\n}\n// after: validate session exists first and surface the status\nsess, err := client.GetSession(ctx, wsID, sessionID)\nif err != nil {\n    return fmt.Errorf(\"cannot summarize missing session: %w\", err)\n}\nif err := client.AgentSummarize(ctx, wsID, sessionID); err != nil {\n    return fmt.Errorf(\"summarize failed for session %s (status in error): %w\", sessionID, err)\n}","handlingStrategy":"validation","validationCode":"// Validate ids before requesting summarization\nif wsID == \"\" || sessionID == \"\" {\n    return errors.New(\"workspace and session ids are required\")\n}\nif _, err := client.GetSession(ctx, wsID, sessionID); err != nil {\n    return fmt.Errorf(\"session %s not summarizable: %w\", sessionID, err)\n}","typeGuard":"func isStatusCodeError(err error) bool {\n    return strings.Contains(err.Error(), \"status code \")\n}\n\nfunc statusCodeOf(err error) int {\n    var code int\n    fmt.Sscanf(err.Error(), \"failed to summarize session: status code %d\", &code)\n    return code\n}","tryCatchPattern":"err := client.AgentSummarize(ctx, wsID, sessionID)\nif err != nil {\n    switch statusCodeOf(err) {\n    case 401, 403:\n        return reauthAndRetry(ctx, wsID, sessionID)\n    case 404:\n        return ErrSessionNotFound\n    default:\n        return fmt.Errorf(\"summarize rejected by server: %w\", err)\n    }\n}","preventionTips":["Verify the session exists (GetSession) before summarizing","Initialize the agent first (InitiateAgentProcessing) — summarization depends on agent state","Refresh auth tokens proactively to avoid 401/403","Capture server-side logs to map non-200 statuses to root causes"],"tags":["http","http-client","server-error","status-code"],"backgroundTag":"unexpected-http-status","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}