{"record":{"id":"4081ec5de1cf4834","repo":"charmbracelet/crush","slug":"failed-to-get-session-agent-queued-prompts-status","errorCode":null,"errorMessage":"failed to get session agent queued prompts: status code %d","messagePattern":"failed to get session agent queued prompts: status code (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/proto.go","lineNumber":434,"sourceCode":"\t\treturn fmt.Errorf(\"failed to refresh MCP resources: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"failed to refresh MCP resources: status code %d\", rsp.StatusCode)\n\t}\n\treturn nil\n}\n\n// GetAgentSessionQueuedPrompts retrieves the number of queued prompts for a\n// session.\nfunc (c *Client) GetAgentSessionQueuedPrompts(ctx context.Context, id string, sessionID string) (int, error) {\n\trsp, err := c.get(ctx, fmt.Sprintf(\"/workspaces/%s/agent/sessions/%s/prompts/queued\", id, sessionID), nil, nil)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to get session agent queued prompts: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\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}","sourceCodeStart":416,"sourceCodeEnd":452,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/client/proto.go#L416-L452","documentation":"GetAgentSessionQueuedPrompts requires HTTP 200; any other status becomes this error carrying the numeric code. The server was reached but rejected the queued-prompts query.","triggerScenarios":"GET returns 404 because the session ID no longer exists, 401/403 on expired auth, or 5xx from a server-side agent failure.","commonSituations":"Polling a session that was deleted concurrently; token expiry during a long agent run; agent endpoint disabled on the server.","solutions":["Handle 404 by treating the session as gone and stopping polling","Refresh authentication on 401/403","Check server logs for 5xx details","Retry transient 5xx with backoff"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if sessionID == \"\" { return errors.New(\"session ID required\") }\n// optionally check the session still exists via a session list call first","typeGuard":"func statusCodeFrom(err error) int {\n\tvar code int\n\tpattern := \"failed to get 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":"n, err := client.GetAgentSessionQueuedPrompts(ctx, wsID, sid)\nif err != nil {\n\tif statusCodeFrom(err) == http.StatusNotFound {\n\t\treturn 0, nil // session gone; stop polling\n\t}\n\treturn 0, err\n}","preventionTips":["Handle 404 as terminal for the polling loop","Refresh tokens proactively during long agent runs","Retry only 5xx with backoff","Keep client/server versions in sync"],"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"}