This depends on the complexity of the environment being learned, and the purpose for learning it. There is no general answer.
For the simple environments used to teach reinforcement learning (RL), often the optimal solution is obvious, or can be calculated and proven optimal. For instance, any environment that can be solved using policy iteration will have a known optimal policy and optimal value function. The goals of these environments are to teach, or to check correctness of agents - it helps in these cases to have a well known correct answer.
At the next level up in terms of complexity are well-studied environments which can have achievable targets set for learning agents. The goals of these environments include getting useful metrics for learning agents, such as how many episodes it takes a particular implementation to learn it well enough. Defining "well enough" is a matter of experience with existing agents.
Getting more complex still, in general it is not possible to know whether an agent has fully optimised against its environment. The subject area of sequential decision making that includes RL agents can cover scenarios such as driving a car or playing a computer game. We don't know when any agent, whether they are based on RL or some other approach, has fully learning an environment, and instead must construct tests of behaviour - e.g. make an agent simulate driving in a set of scenarios, and expect at least safe behaviour in each of them, essentially a driving test similar to one a person might take. In these environments, often the tests are based on "good enough to use" goals. We can say an agent has learned to drive if it drives more safely than an average human.
In the special case of competitive games, we can score agents against each other or against human players. You might say that an agent has learned its environment if it beats some standard player, but also you can rank agents against each other and declare a particular agent as the current best.
It is possible to mix and match these ideas. The Atari games learning suite has benchmark scores to reach that count as "standard human", and recently agents have been published that beat all of those scores.
What happens if you continue training after the agent has learnt the environment? Will it perform by reaching its goal every time or will there be failed episodes?
If you include training episodes, then RL learns mainly by "trial and error". So you should expect an agent to make deliberate mistakes as it tests to see what happens. In some environments these could be critical mistakes leading to failed episodes.
If you ignore the training episodes and are interested only in performance without exploration - e.g. testing every few hundred episodes - then you can expect performance to vary depending on the type of agent and environment. Some agents even exhibit "catastrophic forgetting", which as the name implies causes performance to drop significantly - this can be caused by a successful agent over-fitting to all the recent successful episodes without errors it just experienced, and losing the ability to predict the true lower value of incorrect actions.
Neither failed episodes during training nor catastrophic forgetting are inevitable. It depends on the environment and type of agent.