{"record":{"id":"912bf476764660b8","repo":"github/copilot-sdk","slug":"failed-to-send-message-w","errorCode":null,"errorMessage":"failed to send message: %w","messagePattern":"failed to send message: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/session.go","lineNumber":447,"sourceCode":"//\t}\nfunc (s *Session) Send(ctx context.Context, options MessageOptions) (string, error) {\n\ttraceparent, tracestate := getTraceContext(ctx)\n\treq := sessionSendRequest{\n\t\tSessionID:      s.SessionID,\n\t\tPrompt:         options.Prompt,\n\t\tSource:         options.Source,\n\t\tDisplayPrompt:  options.DisplayPrompt,\n\t\tAttachments:    options.Attachments,\n\t\tMode:           options.Mode,\n\t\tAgentMode:      options.AgentMode,\n\t\tTraceparent:    traceparent,\n\t\tTracestate:     tracestate,\n\t\tRequestHeaders: options.RequestHeaders,\n\t}\n\n\tresult, err := s.client.Request(ctx, \"session.send\", req)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to send message: %w\", err)\n\t}\n\n\tvar response sessionSendResponse\n\tif err := json.Unmarshal(result, &response); err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to unmarshal send response: %w\", err)\n\t}\n\treturn response.MessageID, nil\n}\n\n// SendPrompt is a convenience wrapper for [Session.Send] that takes a plain\n// prompt string instead of a [MessageOptions] struct. Equivalent to:\n//\n//\tsession.Send(ctx, copilot.MessageOptions{Prompt: prompt})\nfunc (s *Session) SendPrompt(ctx context.Context, prompt string) (string, error) {\n\treturn s.Send(ctx, MessageOptions{Prompt: prompt})\n}\n\n// SendAndWait sends a message to this session and waits until the session becomes idle.","sourceCodeStart":429,"sourceCodeEnd":465,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/session.go#L429-L465","documentation":"Session.Send issues a \"session.send\" request over the client's transport. If that request fails (transport error, non-success response, timeout), the error is wrapped as \"failed to send message\". The empty string message ID is returned since no response arrived.","triggerScenarios":"s.client.Request(ctx, \"session/send\", req) returns an error during Send (directly or via SendPrompt/SendAndWait) — connection drop, server unavailable, context deadline exceeded, or authentication failure.","commonSituations":"Server process stopped or crashed; network interruption mid-session; context deadline too short for large prompts; session already closed on the server.","solutions":["Inspect the wrapped inner error to distinguish transport failure vs server rejection.","Check that the agent server is running and the session is still connected (session.Disconnect/Reconnect as needed).","Increase the context timeout for large prompts or slow networks.","Retry the send with backoff if the inner error is transient (connection reset, timeout)."],"exampleFix":"// before\nctx := context.Background()\nid, err := session.Send(ctx, msg) // hangs/fails on slow networks\n// after\nctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)\ndefer cancel()\nid, err := session.Send(ctx, msg)","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"var id string\nvar err error\nfor i := 0; i < 3; i++ {\n    id, err = session.Send(ctx, msg, opts)\n    if err == nil || !isTransient(err) {\n        break\n    }\n    time.Sleep(time.Duration(1<<i) * 100 * time.Millisecond)\n}","preventionTips":["Set generous context timeouts for sends","Health-check the server before sending","Handle session disconnections with reconnect logic"],"tags":["rpc","session","network"],"backgroundTag":"api-request-failed","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}