{"record":{"id":"5d95bd3439180cf8","repo":"charmbracelet/crush","slug":"failed-to-clear-session-agent-queued-prompts-stat","errorCode":null,"errorMessage":"failed to clear session agent queued prompts: status code %d","messagePattern":"failed to clear session agent queued prompts: status code (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/proto.go","lineNumber":451,"sourceCode":"\tif rsp.StatusCode != http.StatusOK {\n\t\treturn 0, fmt.Errorf(\"failed to get session agent queued prompts: status code %d\", rsp.StatusCode)\n\t}\n\tvar count int\n\tif err := json.NewDecoder(rsp.Body).Decode(&count); err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to decode session agent queued prompts: %w\", err)\n\t}\n\treturn count, nil\n}\n\n// ClearAgentSessionQueuedPrompts clears the queued prompts for a session.\nfunc (c *Client) ClearAgentSessionQueuedPrompts(ctx context.Context, id string, sessionID string) error {\n\trsp, err := c.post(ctx, fmt.Sprintf(\"/workspaces/%s/agent/sessions/%s/prompts/clear\", id, sessionID), nil, nil, nil)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to clear session agent queued prompts: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"failed to clear session agent queued prompts: status code %d\", rsp.StatusCode)\n\t}\n\treturn nil\n}\n\n// GetAgentInfo retrieves the agent status for a workspace.\nfunc (c *Client) GetAgentInfo(ctx context.Context, id string) (*proto.AgentInfo, error) {\n\trsp, err := c.get(ctx, fmt.Sprintf(\"/workspaces/%s/agent\", id), nil, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get agent status: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif err := checkStatus(rsp); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get agent status: %w\", err)\n\t}\n\tvar info proto.AgentInfo\n\tif err := json.NewDecoder(rsp.Body).Decode(&info); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to decode agent status: %w\", err)\n\t}","sourceCodeStart":433,"sourceCodeEnd":469,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/client/proto.go#L433-L469","documentation":"ClearAgentSessionQueuedPrompts expects HTTP 200; any other status becomes this error with the code embedded. The server received the clear request but did not succeed.","triggerScenarios":"POST returns 404 for an unknown/finished session, 401/403 on auth failure, or 500 if the server cannot reset the agent queue.","commonSituations":"Clearing the queue of a session that already completed; expired credentials; server-side agent in a broken state.","solutions":["Treat 404 as 'session gone' and skip clearing","Re-authenticate on 401/403","Check server logs for the 5xx cause","Retry transient failures with backoff"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if sessionID == \"\" { return errors.New(\"session ID required to clear queue\") }","typeGuard":"func clearStatusCode(err error) int {\n\tvar code int\n\tpattern := \"failed to clear session agent queued prompts: status code %d\"\n\tif _, e := fmt.Sscanf(err.Error(), pattern, &code); e == nil { return code }\n\treturn 0\n}","tryCatchPattern":"err := client.ClearAgentSessionQueuedPrompts(ctx, wsID, sid)\nif err != nil {\n\tswitch clearStatusCode(err) {\n\tcase http.StatusNotFound: // session gone, ignore\n\tcase http.StatusUnauthorized: reauthAndRetry()\n\tdefault: return err\n\t}\n}","preventionTips":["Skip clearing sessions that already completed","Refresh auth tokens during long runs","Check server logs for 5xx","Distinguish status errors from transport errors"],"tags":["http","status-code","agent"],"backgroundTag":"http-non-200-response","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}