Hello everyone, I am having quite a frustrating issue.

I've managed to develop a little system using AJAX to implement an AJAX shipping estimator tab on the product page, as well as an AJAX add to cart for the product page.

In themselves, these modules work fine. Here is the general skeleton of how the loading flows:
1) The product page finishes loading in a second, and then you are allowed to execute the jQuery operations, such as using AJAX add to cart.
2) At the same time it finishes loading, it then sends an AJAX request to the shipping estimator to load it into the appropriate tab. This is done so that the product page can completely load quickly without being tied down with the cURL requests.
3) After 4-5 seconds the shipping estimator finishes execution and is loaded into the appropriate tab.

So understand that, here is the issue:
1) When the page finishes loading, I can add products to the cart by pressing the add to cart button, the sidebox then reflects the appropriate changes.
2) 4-5 seconds after the page finishes loading, the shipping estimator loads in. Now if I press add to cart, the ones that I added during the load time are gone. So, if my starting quantity in the cart was 0, and I added 2 during the loading time, now if I add 2 more to the cart, my final quantity will be 2 again.
3) If I change the address in the AJAX shipping estimator, it then takes another 4-5 seconds to load in the new results. During that time, if I add the product to the cart, it will then be reset after the loading completes, like above.

I have tried numerous methods of debugging this, and the only thing that I've managed to find out with certainty is that the server-side script being called by AJAX basically reverts the cart just by calling application_top.php, not by any of my own code.

Does anyone have any idea where I could look in order to solve this problem?

My current hypothesis is that the PHP $_SESSION variable is inherently not live, that is to say that if you change a session variable in Page B while Page A is loading, and after that change Page A calls that variable, it will still hold the same value as when the session was started on Page A.
The thing is though, even though that's true, I cannot find anywhere in application_top where the $_SESSION['cart'] is being set to anything. Even though the AJAX estimator uses the cart for the cURL requests, it only accesses the object and doesn't really modify it. So after it loads, it shouldn't have modified the cart at all, right? Well, obviously it's doing that somewhere, but I haven't been able to figure out where. The autoload_func isn't doing it, so I've run out of ideas for now.

Any ideas?

Thank you all in advance!