github/copilot-sdk · error
failed to abort session
Error message
failed to abort session: %w
What it means
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.
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
Example fix
// before
abortCtx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
_ = session.Abort(abortCtx)
// after
abortCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := session.Abort(abortCtx); err != nil {
log.Printf("abort failed: %v", err)
} Defensive patterns
Strategy: try-catch
Validate before calling
select {
case <-ctx.Done():
return ctx.Err()
default:
// ctx alive, safe to Abort
} Try / catch
if err := session.Abort(ctx); err != nil {
var cause error
errors.As(err, &cause)
log.Printf("abort failed (cause: %v)", cause)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Aborting after the session already finished or was detached; runtime process crashed mid-run; using an Abort context that is itself canceled/deadline-exceeded.
Understand the failure class
Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.
Related errors
- unknown error
- failed to get events
- failed to disconnect session
- failed to log message
- No session found for sessionId
AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09).
Data as JSON: /api/errors/5c1014f7b320a95f.
Report an issue: GitHub.
Appendix: source
Thrown at go/session.go:1933
//
// Example:
//
// // Start a long-running request in a goroutine
// go func() {
// session.Send(context.Background(), copilot.MessageOptions{
// Prompt: "Write a very long story...",
// })
// }()
//
// // Abort after 5 seconds
// time.Sleep(5 * time.Second)
// if err := session.Abort(context.Background()); err != nil {
// log.Printf("Failed to abort: %v", err)
// }
func (s *Session) Abort(ctx context.Context) error {
_, err := s.client.Request(ctx, "session.abort", sessionAbortRequest{SessionID: s.SessionID})
if err != nil {
return fmt.Errorf("failed to abort session: %w", err)
}
return nil
}
// SetModelOptions configures optional parameters for SetModel.
type SetModelOptions struct {
// ReasoningEffort sets the reasoning effort level for the new model (e.g., "low", "medium", "high", "xhigh", "max").
ReasoningEffort *string
// ReasoningSummary sets the reasoning summary mode for the new model.
// Use ReasoningSummaryNone to suppress summary output regardless of whether reasoning is enabled.
ReasoningSummary *ReasoningSummary
// ContextTier explicitly selects a context window tier for models that support it.
// Leave nil to use normal model behavior with no explicit tier.
ContextTier *ContextTier
// ModelCapabilities overrides individual model capabilities resolved by the runtime.
// Only non-nil fields are applied over the runtime-resolved capabilities.
ModelCapabilities *rpc.ModelCapabilitiesOverrideView on GitHub (pinned to cd8cf15dc3)