{"record":{"id":"f2b47cf13d01fc39","repo":"charmbracelet/crush","slug":"failed-to-initiate-session-agent-processing-statu","errorCode":null,"errorMessage":"failed to initiate session agent processing: status code %d","messagePattern":"failed to initiate session agent processing: status code (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/proto.go","lineNumber":585,"sourceCode":"\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\n// ListMessages retrieves all messages for a session as proto types.\nfunc (c *Client) ListMessages(ctx context.Context, id string, sessionID string) ([]proto.Message, error) {\n\trsp, err := c.get(ctx, fmt.Sprintf(\"/workspaces/%s/sessions/%s/messages\", id, sessionID), nil, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get messages: %w\", err)\n\t}\n\tdefer rsp.Body.Close()\n\tif rsp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"failed to get messages: status code %d\", rsp.StatusCode)\n\t}\n\tvar msgs []proto.Message\n\tif err := json.NewDecoder(rsp.Body).Decode(&msgs); err != nil && !errors.Is(err, io.EOF) {\n\t\treturn nil, fmt.Errorf(\"failed to decode messages: %w\", err)\n\t}","sourceCodeStart":567,"sourceCodeEnd":603,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/client/proto.go#L567-L603","documentation":"Thrown by Client.InitiateAgentProcessing when the server responded to POST /workspaces/{id}/agent/init with a non-200 status code. The body is discarded, so the caller only knows the numeric status. This means the server received and rejected the init request. Called by InitCoderAgent and InitCoderAgentNonInteractive.","triggerScenarios":"Calling InitiateAgentProcessing with an unknown workspace id (404), when the agent is already initialized or in a bad state (409/500), with auth failures (401/403), or when the server's agent setup fails internally (500) such as missing provider credentials.","commonSituations":"Re-running init against a stale/deleted workspace; provider API keys not configured on the server so agent startup fails with 500; route mismatch after a client/server version skew (404); expired auth token (401).","solutions":["Re-produce the request with curl to capture the response body and exact status code.","Verify the workspace id exists and the client/server versions match (route compatibility).","Check server logs for the agent-init failure cause (e.g. missing provider credentials).","Fix authentication (refresh token / re-login) if the status is 401 or 403."],"exampleFix":"// before\nerr := client.InitiateAgentProcessing(ctx, wsID, false)\nif err != nil {\n    return err\n}\n// after: fail fast with a contextual message including the status\nif err := client.InitiateAgentProcessing(ctx, wsID, false); err != nil {\n    if strings.Contains(err.Error(), \"status code 401\") {\n        return fmt.Errorf(\"agent init rejected: re-authenticate and retry: %w\", err)\n    }\n    return fmt.Errorf(\"agent init failed for workspace %s: %w\", wsID, err)\n}","handlingStrategy":"try-catch","validationCode":"// Confirm workspace exists before init\n_, err := client.GetSession(ctx, wsID, anyKnownSessionID)\nif err != nil {\n    return fmt.Errorf(\"workspace %s unreachable or invalid — fix before agent init\", wsID)\n}\n// Ensure provider credentials are configured server-side\nif os.Getenv(\"ANTHROPIC_API_KEY\") == \"\" && os.Getenv(\"OPENAI_API_KEY\") == \"\" {\n    return errors.New(\"no provider credentials configured for agent init\")\n}","typeGuard":"func statusOf(err error) int {\n    var code int\n    if _, scanErr := fmt.Sscanf(err.Error(), \"failed to initiate session agent processing: status code %d\", &code); scanErr == nil {\n        return code\n    }\n    return 0\n}","tryCatchPattern":"err := client.InitiateAgentProcessing(ctx, wsID, interactive)\nif err != nil {\n    switch statusOf(err) {\n    case 404:\n        return fmt.Errorf(\"workspace %q not found: check client/server route compatibility\", wsID)\n    case 401, 403:\n        return ErrAuthenticationRequired\n    case 500:\n        return fmt.Errorf(\"agent init failed server-side: check server logs (credentials?)\"): %w\", err)\n    }\n    return err\n}","preventionTips":["Match client and server versions to avoid route mismatches (404)","Configure provider API keys before attempting agent init","Reproduce failed inits with curl to read the response body the client discards","Treat 401/403 as re-auth prompts, not retryable faults"],"tags":["http","server-error","status-code","agent-init"],"backgroundTag":"unexpected-http-status","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}