{"record":{"id":"e9cbb397d564524a","repo":"charmbracelet/crush","slug":"failed-to-initiate-session-agent-processing-w","errorCode":null,"errorMessage":"failed to initiate session agent processing: %w","messagePattern":"failed to initiate session agent processing: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/client/proto.go","lineNumber":581,"sourceCode":"// 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\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}","sourceCodeStart":563,"sourceCodeEnd":599,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/client/proto.go#L563-L599","documentation":"Thrown by Client.InitiateAgentProcessing in internal/client/proto.go when the HTTP POST to /workspaces/{id}/agent/init fails at the transport layer before a response is received. The wrapped error from c.post is returned, so it is always a connection, DNS, timeout, or context-cancellation problem. Called by InitCoderAgent and InitCoderAgentNonInteractive.","triggerScenarios":"Calling InitCoderAgent/InitCoderAgentNonInteractive when the server is unreachable, the workspace id is invalid at the URL level (though that would typically 404), the context is canceled, the connection is refused, or a TLS handshake fails.","commonSituations":"Crush server not started yet when the client boots; wrong host/port in client configuration; container network not up in dev environments; VPN or corporate proxy blocking the connection; very short context timeout expiring on a slow network.","solutions":["Check the wrapped error: context.DeadlineExceeded means retry with a longer timeout; connection-refused means start/check the server.","Confirm the server address configured for the client matches the running crush server.","Retry initialization after the server has fully started (add startup wait/health check).","If the context was canceled, ensure nothing aborts the parent context prematurely."],"exampleFix":"// before\nerr := client.InitiateAgentProcessing(ctx, wsID, true)\nif err != nil {\n    return err\n}\n// after: wait for the server then init with a deadline\nif err := waitForServer(ctx, client); err != nil {\n    return fmt.Errorf(\"server not ready: %w\", err)\n}\ninitCtx, cancel := context.WithTimeout(ctx, 15*time.Second)\ndefer cancel()\nif err := client.InitiateAgentProcessing(initCtx, wsID, true); err != nil {\n    return fmt.Errorf(\"agent init: %w\", err)\n}","handlingStrategy":"retry","validationCode":"// Wait for the server before initializing the agent\nreq, _ := http.NewRequestWithContext(ctx, http.MethodGet, serverURL+\"/healthz\", nil)\nrsp, err := http.DefaultClient.Do(req)\nif err != nil || rsp.StatusCode != http.StatusOK {\n    return errors.New(\"crush server not ready for agent init\")\n}","typeGuard":"func isInitTransportError(err error) bool {\n    return errors.Is(err, context.DeadlineExceeded) ||\n        errors.Is(err, context.Canceled) ||\n        strings.Contains(err.Error(), \"connection refused\") ||\n        strings.Contains(err.Error(), \"no such host\")\n}","tryCatchPattern":"err := client.InitiateAgentProcessing(ctx, wsID, interactive)\nif err != nil && isInitTransportError(err) {\n    select {\n    case <-time.After(2 * time.Second):\n        return client.InitiateAgentProcessing(ctx, wsID, interactive)\n    case <-ctx.Done():\n        return ctx.Err()\n    }\n}","preventionTips":["Gate agent init behind a server readiness check at startup","Use bounded-exponential-backoff retries for the init call","Never reuse a canceled context for retries","Log the wrapped cause (%w chain) to separate startup ordering from config bugs"],"tags":["network","http-client","connection","agent-init"],"backgroundTag":"http-request-failed","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}