github/copilot-sdk · error
failed to unmarshal delete response
Error message
failed to unmarshal delete response: %w
What it means
DeleteSession returns this error when the 'session.delete' result cannot be unmarshalled into deleteSessionResponse. The backend acknowledged the call but its response body was not the expected {success, error} object.
Solutions
- Capture the raw result bytes and validate the expected {success, error} shape
- Update client library and backend to the same version
- Retry the delete; if it recurs, inspect backend logs for the failing session delete
- Check whether a proxy/IPC layer is corrupting the response
Example fix
// before
err := client.DeleteSession(ctx, sessionID)
// after
err := client.DeleteSession(ctx, sessionID)
if err != nil && strings.Contains(err.Error(), "unmarshal delete response") {
// fall back: verify via ListSessions whether the session is gone
} Defensive patterns
Strategy: try-catch
Validate before calling
if sessionID == "" {
return fmt.Errorf("DeleteSession: empty sessionID")
} Type guard
func isDeleteUnmarshalError(err error) bool {
return strings.Contains(err.Error(), "unmarshal delete response")
} Try / catch
if err := client.DeleteSession(ctx, id); err != nil {
if isDeleteUnmarshalError(err) {
// verify deletion via ListSessions before retrying
return fmt.Errorf("delete ack undecodable: %w", err)
}
return err
} Prevention
- Keep client/backend versions aligned
- Confirm deletion independently (ListSessions) rather than trusting a single response
- Log raw delete responses during upgrades
When it happens
Trigger: Calling DeleteSession when the backend returns a malformed or unexpected delete confirmation payload.
Common situations: Version mismatch between client and backend; backend crashed mid-response leaving a truncated payload; middleware rewriting the response.
Understand the failure class
Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.
Related errors
- failed to unmarshal response
- failed to unmarshal sessions response
- failed to unmarshal session metadata response
- failed to unmarshal getLastId response
- failed to unmarshal getForeground response
AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09).
Data as JSON: /api/errors/d79ba3b20c08a0e8.
Report an issue: GitHub.
Appendix: source
Thrown at go/client.go:1618
// if err := client.DeleteSession(context.Background(), "session-123"); err != nil {
// log.Fatal(err)
// }
func (c *Client) DeleteSession(ctx context.Context, sessionID string) error {
unlockSession := c.lockSessionOperation(sessionID)
defer unlockSession()
if err := c.ensureConnected(ctx); err != nil {
return err
}
result, err := c.client.Request(ctx, "session.delete", deleteSessionRequest{SessionID: sessionID})
if err != nil {
return err
}
var response deleteSessionResponse
if err := json.Unmarshal(result, &response); err != nil {
return fmt.Errorf("failed to unmarshal delete response: %w", err)
}
if !response.Success {
errorMsg := "unknown error"
if response.Error != nil {
errorMsg = *response.Error
}
return fmt.Errorf("failed to delete session %s: %s", sessionID, errorMsg)
}
// Remove from local sessions map if present
c.sessionsMux.Lock()
session := c.sessions[sessionID]
delete(c.sessions, sessionID)
c.sessionsMux.Unlock()
if session != nil {
session.releaseGitHubTokenProviderRegistration()
}View on GitHub (pinned to cd8cf15dc3)