After a ton of testing and creating .esp files I figured out why this bug fix works and why the official patch does not. The order the factions are listed within the .esp file decides which faction wins conflicts between the faction records! The rule for breaking conflicts is the opposite of that for mods, with the faction listed first having the highest priority. Unfortunately, TES5EDIT will always list the factions in the order they appear within the Skyrim.esm file regardless of the order they appear within an individual .esp file. Even worse, the Creation Kit always displays and writes the factions in alphabetical order. Therefore, neither TES5EDIT nor CK can see the difference between the records for Mirella Godshand in Skyrim.esm and Mirella Godshand Bugfix.esp. The ONLY way I was able to see and modify the faction order and therefore the priority order of the factions was to use a Hex Editor and the zlib library to manually change the .esp files.
As a proof of concept, I created two .esp files. I removed Mirella from the ArkMirellasAlchemyFaction (which isn't needed for her to have the correct inventory) and instead added her to the _00E_FL_Traveller_01_Vender faction for both files. In the first .esp file (TravelFirst.esp), the faction order is:
1. _00E_FL_Traveller_01_Vender
2. ArkMechantMirellaFaction
3. MerchantFaction
4. ArkDefaultMerchantFaction
5. A_CrimeFaction “Ark”
In the second (TravelSecond.esp), the faction order is:
1. ArkMechantMirellaFaction
2. _00E_FL_Traveller_01_Vender
3. MerchantFaction
4. ArkDefaultMerchantFaction
5. A_CrimeFaction “Ark”
Even though both .esp files appear to be exactly the same in both TES5EDIT and CK, they produce completely different results! Mirella has only food for sale using TravelFirst.esp and her correct inventory with TravelSecond.esp.
The faction order for Mirella Godshand in the Skyrim.esm file that came with patch 1.1.7.3 is:
1. MerchantFaction
2. A_CrimeFaction
3. ArkMirellasAlchemyFaction
4. ArkDefaultMerchantFaction
5. ArkMerchantMirellaFaction
and the faction order in Mirella Godshand Bugfix.esp is in alphabetical order due to the Creation Kit:
1. A_CrimeFaction
2. ArkDefaultMerchantFaction
3. ArkMerchantMirellaFaction
4. ArkMirellasAlchemyFaction
5. MerchantFaction
From trial and error, I discovered that if ArkMerchantMirellaFaction has a higher priority than ArkMirellasAlchemyFaction, Mirella will always have the correct inventory no matter what the rest of the order is. I suspect this is because the PLVD field in the ArkMirellasAlchemyFaction faction is not working as expected although I can't prove it. Taking this into account and placing the factions in order of decreasing specificity, I suggest the following faction order which is implemented in MMMAMFDMCF.esp:
1. ArkMerchantMirellaFaction (MM)
2. ArkMirellasAlchemyFaction (MA)
3. MerchantFaction (MF)
4. ArkDefaultMerchantFaction (DM)
5. A_CrimeFaction (CF)
As an interesting side note, it seems that Mirella does not actually need to have the MerchantFaction in order to have her correct inventory. I removed her from the MerchantFaction and added her to 'ArkFaction "Ark"' faction and she still functioned perfectly as far as I could tell. I'm sure some scripts would not be able to recognize her as a vendor though.
Finally, the librarian does not have the same issue as Mirella. He does not have any faction that attaches him to a Vender Buy/Sell List. The only way to fix him would be to add him to one of the existing factions but I'm not sure which one would be correct. However, I suspect there are many minor bugs caused by faction order scattered among the other NPCs.
NOTE: The data size difference between the Skyrim.esm record and the record within Mirella Godshand Bugfix.esp is due do a format difference in the FULL field. Mirella Godshand Bugfix.esp uses a null-terminated zstring which is 17 bytes long while Skyrim.esm uses an lstring (FormID) that is 4 bytes long to reference a string stored outside of the record. The 13 byte difference turns into a 4 byte difference after the data is compressed. This red herring ate up a lot of time :/
NOTE 2: I noticed two very minor issues with Mirella's AI Packages. First, from 3-4AM, Mirella is running the scripts for both gambling (CapitalCityMirella_Gamble01) and sleeping (CapitalCityMirellaSleep0x7) at the same time. I'm not sure if this can cause issues or not. Second, she never locks her door at night because the CapitalCityMirellaTrade13x8 script does not include that function. This does not seem intentional based on other NPC behavior but I could be wrong.