{"record":{"id":"5c1014f7b320a95f","repo":"github/copilot-sdk","slug":"failed-to-abort-session-w","errorCode":null,"errorMessage":"failed to abort session: %w","messagePattern":"failed to abort session: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/session.go","lineNumber":1933,"sourceCode":"//\n// Example:\n//\n//\t// Start a long-running request in a goroutine\n//\tgo func() {\n//\t    session.Send(context.Background(), copilot.MessageOptions{\n//\t        Prompt: \"Write a very long story...\",\n//\t    })\n//\t}()\n//\n//\t// Abort after 5 seconds\n//\ttime.Sleep(5 * time.Second)\n//\tif err := session.Abort(context.Background()); err != nil {\n//\t    log.Printf(\"Failed to abort: %v\", err)\n//\t}\nfunc (s *Session) Abort(ctx context.Context) error {\n\t_, err := s.client.Request(ctx, \"session.abort\", sessionAbortRequest{SessionID: s.SessionID})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to abort session: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// SetModelOptions configures optional parameters for SetModel.\ntype SetModelOptions struct {\n\t// ReasoningEffort sets the reasoning effort level for the new model (e.g., \"low\", \"medium\", \"high\", \"xhigh\", \"max\").\n\tReasoningEffort *string\n\t// ReasoningSummary sets the reasoning summary mode for the new model.\n\t// Use ReasoningSummaryNone to suppress summary output regardless of whether reasoning is enabled.\n\tReasoningSummary *ReasoningSummary\n\t// ContextTier explicitly selects a context window tier for models that support it.\n\t// Leave nil to use normal model behavior with no explicit tier.\n\tContextTier *ContextTier\n\t// ModelCapabilities overrides individual model capabilities resolved by the runtime.\n\t// Only non-nil fields are applied over the runtime-resolved capabilities.\n\tModelCapabilities *rpc.ModelCapabilitiesOverride","sourceCodeStart":1915,"sourceCodeEnd":1951,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/session.go#L1915-L1951","documentation":"Session.Abort sends the `session.abort` RPC to stop an in-flight run for this session. This error wraps any failure of that request — transport error, invalid/expired session, or a server-side refusal — with the root cause available via the %w chain.","triggerScenarios":"Calling Session.Abort(ctx) when the `session.abort` request fails: connection to the runtime is broken, the session ID is unknown server-side, or the runtime returns an error for the abort.","commonSituations":"Aborting after the session already finished or was detached; runtime process crashed mid-run; using an Abort context that is itself canceled/deadline-exceeded.","solutions":["Check the wrapped error to identify transport vs server cause","Ensure ctx is alive (not canceled) when calling Abort","Verify the session is still active before aborting; an already-finished session may be re-created instead","Reconnect and retry the abort, or rely on the run ending when the runtime dies"],"exampleFix":"// before\nabortCtx, cancel := context.WithTimeout(context.Background(), time.Second)\ndefer cancel()\n_ = session.Abort(abortCtx)\n// after\nabortCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)\ndefer cancel()\nif err := session.Abort(abortCtx); err != nil {\n    log.Printf(\"abort failed: %v\", err)\n}","handlingStrategy":"try-catch","validationCode":"select {\ncase <-ctx.Done():\n    return ctx.Err()\ndefault:\n    // ctx alive, safe to Abort\n}","typeGuard":null,"tryCatchPattern":"if err := session.Abort(ctx); err != nil {\n    var cause error\n    errors.As(err, &cause)\n    log.Printf(\"abort failed (cause: %v)\", cause)\n}","preventionTips":["Use a fresh, non-canceled context with a sane timeout for Abort","Only abort sessions known to be active","Log the unwrapped cause for diagnosis"],"tags":["go","session","rpc","abort"],"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"}