github/copilot-sdk · error
failed to log message
Error message
failed to log message: %w
What it means
Session's logging path builds a log request from LogOptions (including optional ephemeral flag) and calls s.RPC.Log. This error wraps any failure of that RPC — the runtime rejected the log level/options or the transport failed.
Solutions
- Check the wrapped error for the runtime's specific rejection
- Verify the session is still connected before logging
- Validate LogOptions (level, ephemeral) against the runtime version
- Make logging non-fatal: log-and-continue instead of propagating
Example fix
// before
if err := session.Log(ctx, LevelInfo, msg, opts); err != nil { return err }
// after
if err := session.Log(ctx, LevelInfo, msg, opts); err != nil {
log.Printf("session log dropped: %v", err) // keep app running
} Defensive patterns
Strategy: try-catch
Validate before calling
if session == nil || session.SessionID == "" {
return errors.New("cannot log: session not connected")
} Try / catch
if err := session.Log(ctx, level, msg, opts); err != nil {
log.Printf("session log failed (dropped): %v", err)
// do not propagate; logging must not break the app
} Prevention
- Never let session-logging errors crash the application
- Verify LogOptions (level, ephemeral) match the runtime's capabilities
- Avoid logging from goroutines that outlive Disconnect
When it happens
Trigger: Calling the session Log API (with LogOptions) when the `Log` RPC fails: invalid level/options for the runtime, dead connection, or unknown session.
Common situations: Emitting logs after the session/runtime was torn down; using a log option not supported by the running runtime; logging from a goroutine racing session disconnect.
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 abort session
- No session found for sessionId
AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09).
Data as JSON: /api/errors/ebc9a8757b801504.
Report an issue: GitHub.
Appendix: source
Thrown at go/session.go:2087
// session.Log(ctx, "Rate limit approaching", &copilot.LogOptions{Level: rpc.SessionLogLevelWarning})
//
// // Ephemeral message (not persisted)
// session.Log(ctx, "Working...", &copilot.LogOptions{Ephemeral: copilot.Bool(true)})
func (s *Session) Log(ctx context.Context, message string, opts *LogOptions) error {
params := &rpc.LogRequest{Message: message}
if opts != nil {
if opts.Level != "" {
params.Level = &opts.Level
}
if opts.Ephemeral != nil {
params.Ephemeral = opts.Ephemeral
}
}
_, err := s.RPC.Log(ctx, params)
if err != nil {
return fmt.Errorf("failed to log message: %w", err)
}
return nil
}
View on GitHub (pinned to cd8cf15dc3)