Still I think it is pretty obvious that OTL Mexico had pretty deep, systemic problems stemming from having been an exploited and underdeveloped Spanish colony, with a huge culture gap between the only somewhat Hispanicized native peoples and a more or less Castillian elite that could neither make common cause with the mestizo majority nor settle its own internal bickering. Bottom line was that Mexico was simply not a modern nation.
Perhaps there is no need to wank Mexico into complete equivalence on a per capita basis with el Norte (since Mexico I believe had quite a high total population even then, this would mean Mexico dwarfs the USA in national product and military capability). Nor even necessarily to make Mexico's overall industrial product such that the two federal republics were comparable in gross product. But somewhere there is probably a minimum level of productivity and national coherence such that Mexico could field a border defense force of sufficient competence and well enough equipped and of reasonable loyalty to its government such that the USA would think twice and thrice before striking, at least not without a very good
causus belli, one better than "they're brown and we want their land!" as OTL
!
Now the question is--given Mexico's systemic legacy of underdevelopment and social antagonism between the Castillian overlords and the vast majority of the population, could there have been any social evolution there that would give the Mexican government deep enough force to hold Texas from secession in the 1820s and hold off any land-grabbing in the 1840s?
It seems that actually, despite the infamous idiocy of Santa Anna (and why and how did such a clown take power in Mexico City--and did so again at least once and maybe more often than that after his defeat by the Texans?) the Mexicans OTL had a shot at holding as things were, and would have needed not much more to secure the place once and for all.
Still, I do think that even if the Texan adventure had ended ingloriously for the Anglos there, Americans would not stop trying to pry something off and eventually there would have been a showdown. How much more solid and developed would the Mexican regime have to be to have enough to draw on to hold all of the territory that OTL the USA took?
Actually aside from Texas, by 1849 they had already lost control of the territories known as Deseret, to Brigham Young's Mormon exodus. And OTL California was already teetering on the edge of secession before Kit Carson ever showed up.
I think that a more solidly developing Mexico could at least have held on to California better, by having better relations with the Mexicans who did settle there OTL and by sending more to join them in holding it.
Deseret OTOH had taken control of land that the Mexicans, and Spanish before them, claimed on European conference tables and had some small outpost garrisons to try to guard at best, but basically had done nothing with, for good or ill. I think that they would perforce have to negotiate some deal with Salt Lake City, either recognition of independence (which at least might give Mexico a useful distraction for Washington to have to consider) or winning over their allegiance to the Mexican Republic as a highly autonomous province. Since there was little love lost between the Mormons and the Anglo-Americans who had driven them from their homes into the western wilderness, this might have been very viable.
Actually I think that Deseret overlapped the legally agreed-upon borders between the Louisiana Purchase and the last days of the Spanish empire in New Spain, so if Brigham Young did agree to come under the Mexican flag, this would amount to taking at least a piece of US territory with him.
Again I just don't know enough detail of early Mexican history to suggest any PODs that might plausibly result in such a Mexico. But if Mexico were stronger in the ways I indicate--better social integration between native mestizos and Castillian-oriented dons, more of an industrial core, a central culture of government that wasn't a comic-opera revolving door of coups but had some stability, better opportunity for middle classes deriving from both ethnic strands to grow and rely on better business conditions--then I think California would have been hard to take without a very bitter fight, and perhaps not even then. A strong enough Mexican government could after all call on the British to become allies and offer them port facilities in San Francisco and San Diego, perhaps without fear that the British would try to carve the hinterland off as protectorates.
With the RN based in California and in Puget Sound as well how much provocation could any US President risk, with Oregon caught in the vise like that? He'd risk losing the USA's only outlet onto the Pacific!