{"record":{"id":"1236559055608a0c","repo":"github/copilot-sdk","slug":"failed-to-delete-session-s-s","errorCode":null,"errorMessage":"failed to delete session %s: %s","messagePattern":"failed to delete session (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/client.go","lineNumber":1626,"sourceCode":"\t\treturn err\n\t}\n\n\tresult, err := c.client.Request(ctx, \"session.delete\", deleteSessionRequest{SessionID: sessionID})\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tvar response deleteSessionResponse\n\tif err := json.Unmarshal(result, &response); err != nil {\n\t\treturn fmt.Errorf(\"failed to unmarshal delete response: %w\", err)\n\t}\n\n\tif !response.Success {\n\t\terrorMsg := \"unknown error\"\n\t\tif response.Error != nil {\n\t\t\terrorMsg = *response.Error\n\t\t}\n\t\treturn fmt.Errorf(\"failed to delete session %s: %s\", sessionID, errorMsg)\n\t}\n\n\t// Remove from local sessions map if present\n\tc.sessionsMux.Lock()\n\tsession := c.sessions[sessionID]\n\tdelete(c.sessions, sessionID)\n\tc.sessionsMux.Unlock()\n\tif session != nil {\n\t\tsession.releaseGitHubTokenProviderRegistration()\n\t}\n\n\treturn nil\n}\n\n// GetLastSessionID returns the ID of the most recently updated session.\n//\n// This is useful for resuming the last conversation when the session ID\n// was not stored. Returns nil if no sessions exist.","sourceCodeStart":1608,"sourceCodeEnd":1644,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/client.go#L1608-L1644","documentation":"DeleteSession returns this error when the backend explicitly reported the delete failed: deleteSessionResponse.Success was false and the backend supplied an Error string. This is a backend-side failure report, not a transport/decode problem.","triggerScenarios":"Calling DeleteSession and receiving response.Success == false; the wrapped message includes the backend's own error text (or 'unknown error' if none).","commonSituations":"Deleting a session that is still active/open in the TUI; permission problems on the backend's session storage directory; session already deleted concurrently.","solutions":["Read the embedded backend error message after the colon for the root cause","Ensure no running agent process has the session open before deleting","Check filesystem permissions on the backend's session storage directory","Confirm the session still exists (it may already have been deleted)"],"exampleFix":"// before\nerr := client.DeleteSession(ctx, sessionID)\nif err != nil { panic(err) }\n// after\nif err := client.DeleteSession(ctx, sessionID); err != nil {\n    log.Printf(\"could not delete session %s: %v\", sessionID, err)\n    // inspect whether session was active, then retry\n}","handlingStrategy":"try-catch","validationCode":"sessions, _ := client.ListSessions(ctx)\nexists := slices.ContainsFunc(sessions, func(s *SessionInfo) bool { return s.ID == sessionID })\nif !exists { return fmt.Errorf(\"session %s not found\", sessionID) }","typeGuard":null,"tryCatchPattern":"if err := client.DeleteSession(ctx, id); err != nil {\n    if strings.Contains(err.Error(), \"failed to delete session\") {\n        // backend refused: parse reason after the colon, check active/permissions\n        return fmt.Errorf(\"backend refused delete: %w\", err)\n    }\n    return err\n}","preventionTips":["Close or detach the session in the TUI before deleting","Check the backend's session storage directory permissions","Handle double-delete gracefully (session may already be gone)"],"tags":["delete-session","backend-error","session"],"backgroundTag":"api-error-response","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}