It sounds like you did everything right:
- You checked before the “three and a half years” point.[1]
- The mezuzah was not in a vulnerable place, such as in direct sunlight or exposed to the rain. In such cases, you would have had to check it at least once a year[2] or more, depending on the circumstances.[3]
As such, not only can you not be faulted for this unfortunate discovery, but you will receive reward as well. Our Sages assure:
If a person plans to do a mitzvah but is prevented from completing due to circumstances beyond his control, Scripture credits him as if he had performed it.[4]
Although there is no halachic requirement to check indoor mezuzahs yearly, some authorities record the meritorious custom of checking mezuzot every Elul.[5]
[1] Kuntres HaMezuzah, citing Yosef Ometz 479 and Parashah Sedurah 70.
[2] Aruch HaShulchan Y.D. 291:1.
[3] Mishnah Berurah 39:26, in reference to tefillin.
[4] Berachot 6a, cited in Agur B’ohalecha 39:6.
[5] Kitzur Shulchan Aruch 128:3; See Mateh Efraim 581:10.