{"record":{"id":"520804ca7b626a0c","repo":"charmbracelet/crush","slug":"failed-to-decode-session-agent-queued-prompts-w","errorCode":null,"errorMessage":"failed to decode session agent queued prompts: %w","messagePattern":"failed to decode session agent queued prompts: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/proto.go","lineNumber":438,"sourceCode":"\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}\n\treturn nil\n}\n\n// GetAgentInfo retrieves the agent status for a workspace.","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/client/proto.go#L420-L456","documentation":"After a 200 response, GetAgentSessionQueuedPrompts decodes the body as a bare JSON integer. If the body is not a valid JSON number (HTML error page, empty body, object wrapper, truncated response), json.Decode fails and this error wraps the decode failure.","triggerScenarios":"Server returns 200 with an unexpected body: a proxy injecting HTML, an empty body, or an API version returning {\"count\": N} instead of a plain int.","commonSituations":"API version mismatch between client and server; misconfigured reverse proxy returning a login page with 200; server bug changing the response shape.","solutions":["Verify client and server versions match (plain int response expected)","Dump the raw response body to see what was actually returned","Check for proxies/middleware rewriting the response","Update the client to match the server's current response schema"],"exampleFix":"// before\nvar count int\nif err := json.NewDecoder(rsp.Body).Decode(&count); err != nil {\n\treturn 0, fmt.Errorf(\"failed to decode session agent queued prompts: %w\", err)\n}\n// after\nbody, _ := io.ReadAll(rsp.Body)\nvar count int\nif err := json.Unmarshal(body, &count); err != nil {\n\treturn 0, fmt.Errorf(\"decode queued prompts %q: %w\", body, err)\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func decodeQueuedCount(body io.Reader) (int, error) {\n\tdec := json.NewDecoder(body)\n\tvar n int\n\tif err := dec.Decode(&n); err != nil {\n\t\treturn 0, fmt.Errorf(\"expected JSON int, got: %w\", err)\n\t}\n\treturn n, nil\n}","tryCatchPattern":"n, err := client.GetAgentSessionQueuedPrompts(ctx, wsID, sid)\nif err != nil && strings.Contains(err.Error(), \"failed to decode session agent queued prompts\") {\n\t// log raw body / check version mismatch instead of retrying blindly\n}","preventionTips":["Pin client and server to matching versions","Snapshot the response body when decoding fails","Ensure proxies do not rewrite API responses","Add an integration test asserting the plain-int response shape"],"tags":["json","decode","api-mismatch"],"backgroundTag":"json-decode-failed","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}