Well for one, the bolt doesn't actually have to close the ejection port for the rifle to function, it just helps keep crap out of the action. Additionally, it does not need to be the bolt that closes the ejection port, I believe that the VEPRs in 7.62x54R use a small dust cover attached to the bolt and recoil spring in such a manner that it "telescopes" over the larger ejection port. Another solution would be to use a forward ejection system a la RFB or F2000. Also, pistol caliber carbines can cycle in much less space than rifle calibers. And finally, a blow-forward action (yes that is a thing that exists) were the barrel cycles forwards instead of the bolt cycling backwards, would allow the barrel to seat almost all the way into the stock of the weapon. And, as others have mentioned, the recoil spring need not be placed behind the bolt, one example of such a design being the M14.
None if this is particularly practical, and no-one in a position to buy or sell large quantities of such things considers it worth the extra mechanical complexity in order to fit a couple more inches of barrel into such a small rifle.