The best known of the conflicts occurring in eusocial Hymenoptera is queen-worker conflict over sex ratio. So far, sex ratio theory has mostly focused on optimal investment in the production of male versus female sexuals, neglecting the investment in workers. Increased investment in workers decreases immediate sexual productivity but increases expected future colony productivity. Thus, an important issue is to determine the queen's and workers' optimal investment in each of the three castes (workers, female sexuals, and male sexuals), taking into account a possible trade-off between production of female sexuals and workers (both castes developing from diploid female eggs). Here, we construct a simple and general kin selection model that allows us to calculate the evolutionarily stable investments in the three castes, while varying the identity of the party controlling resource allocation (relative investment in workers, female sexuals, and male sexuals). Our model shows that queens and workers favor the investment in workers that maximizes lifetime colony productivity of sexual males and females, whatever the colony kin structure. However, worker production is predicted to be at this optimum only if one of the two parties has complete control over resource allocation, a situation that is evolutionarily unstable because it strongly selects the other party to manipulate sex allocation in its favor. Queens are selected to force workers to raise all the males by limiting the number of eggs they lay, whereas workers should respond to egg limitation by raising a greater proportion of the female eggs into sexual females rather than workers as a means to attain a more female-biased sex allocation. This tug-of-war between queens and workers leads to a stable equilibrium where sex allocation is between the queen and worker optima and the investment in workers is below both parties' optimum. Our model further shows that, under most conditions, female larvae are in strong conflict with queens and workers over their developmental fate because they value their own reproduction more than that of siblings. With the help of our model, we also investigate how variation in queen number and number of matings per queen affect the level of conflict between queens, workers, and larvae and ultimately the allocation of resource in the three castes. Finally, we make predictions that allow us to test which party is in control of sex allocation and caste determination.