The only way to guarantee sustained Ukrainian grain production is for the Russians to withdraw or for Ukrainians to surrender. I don't think the Ukrainians are obliged to surrender to stop people in other countries from starving. This is on Russia.
Would the Ukrainian agricultural sectors continue to operate effectively if Russia fully occupied the country, knowing that their wealth might be stolen? Would Russia move to bring their own oligarchs in to colonise and control production? Either way the restoration of production would take much longer than if Russia simply retreated.