I am trying to plan a system which validates the compability of different components by comparing their semantic versioning number, especially the major release number (since it indicates API changes and backwards compability). I came across the following scenario where I could not find an exact answer:

Let's say the code is on version `2.3.5` and I add a new major API change, therefore updating the version to `3.0.0`. However, a few days after releasing I find that this change does not suit the users' needs, and I revert this change so that everything that was compatible with the versions `2.x.x` will be compatible again (note that I'm not doing a version control revert, but rather put the old version of the code back in a regular commit). Now I can't figure out if the new version should be `4.0.0` because I again did a major API change and the numbers should always be incremented, or, because it will be backwards compatible again, use `2.4.0`.

I see advantages and problems with both solutions. Are there ground rules or best practices for such cases?