Let's all take a quick primer in early nuclear weapons first okay? It seems necessary because you, the OP, and few others weren't even aware that Fat Man and Little Boy were completely different weapons.
Fat Man or, more accurately, a Fat Man-type was detonated first at Trinity and then dropped at Nagasaki. It used plutonium produced in breeder reactors. It used a very technically advanced implosion-type ignition, the design and construction took up most of Los Alamos' time and effort.
Here's the part which you and too many other people don't quite understand: The Trinity test wasn't a test to see if the nuclear physics behind the Bomb worked because the physics was a "no-brainer". Instead, Trinity was a test to see if the implosion-style ignition system worked.
Little Boy was used on Hiroshima. It used an uranium isotope and something like 98% of the available amount of that isotope in 1945 so additional Little Boys bombs would be almost impossible to build. Little Boy used a gun-type ignition system that was not tested because, like the physics behind the bomb, it was considered a "no-brainer".
Returning to your original questions...
If the Trinity test failed, the Fat Man design would be re-examined, re-designed, and re-tested. How long that effort would take would depend on why the Fat Man design was faulty. In addition, if Trinity failed, Little Boy wouldn't be used in August and would instead be kept for use during Downfall.
If Little Boy failed at Hiroshima, nuclear physics somehow doesn't work the way all the experimental evidence says it should. This is an ASB level event. Apart from a grossly incompetent arming process during the flight to Hiroshima, something Los Alamos spent years in examining and preventing, Little Boy simply cannot fail absent ASB intervention.
If Fat Man failed at Nagasaki, the project still had a successful Fat Man test at Trinity. An investigation into why Fat Man worked in New Mexico and not over Japan would begin. As with a Trinity failure I mentioned above, the recover after a Nagasaki would depend on what sort of failure occurred.
The bombs alone did not make Japan surrender, they were only part of a complicated surrender equation. In the minds of Japan's war cabinet, the declaration of war by the USSR and rapid loss of Manchuria held equal weight with the bombs and those two events are still going to occur.
If the bombings do not occur in August, one or more atomic bombings are still going to occur that fall. Little Boy, the uranium/gun-type bomb, is going to work absent ASB intervention and will be used during an invasion by the US. The Fat Man type could possibly be used too if it's problems are worked out in time.
The ramifications of a Japanese surrender in the fall of '45 or spring of '46 come down to "little" more than many more dead Japanese, Americans, Russians, Brits, Chinese, Australians, New Zealanders, and others. The Home Islands are already starving, the war is going to continue being fought from Burma to the Philippines, to China, and something on the order of 250,000 civilians per month in the regions of Asia Japan occupies are going to die.
The result of Fat Man's failure is simply more death, more devastation, and a poorer post-war world.