Assuming that McClellan is immediately relieved in the aftermath of Malvern Hill, the Army of the Potomac would still withdraw to Harrison Landing. Afterall, Malvern Hill, with a little effort, could easily be flanked to McClellan's right. If McClellan wasn't going to counterattack, withdrawing was the most pragmatic move.
Now there is the question of who replaces McClellan. John Pope was already in charge of the Army of Virginia (I, XI, XII Corps) on June 26, 1862 and the Battle of Malvern Hill occured on July 1, 1862.
The two most likely candidates are Edwin V. Sumner and Fitz-John Porter. Both Sumner and Fitz-John Porter felt that the army was perfectly secure and their commands in excellent conditions, and they opposed any suggestion to remove the army from the bank of the James River.
Honestly speaking, Fitz-John Porter was the best corps commander in the Army of the Potomac at the time and thus he had the best potential for army command. Though he never got to demonstrate whether he could succeed in an offensive role, he did deliver the most punishing attack on Jackson's corps at Second Manassas and was a very able soldier. However, Fitz-John Porter was close friend of McClellan and would likely refuse command if McClellan was sacked. This results in Sumner taking command of the Army of the Potomac.
Edwin V. Sumner is a mixed bag as a commander. His poor performance at Williams led McClellan to assess Sumner as "a greater fool than I supposed." However, over the course of the Peninsular Campaign he earned a more favorable reputation, leading energetically and being wounded twice. However, I don't believe that Sumner could be a good army commander. His performance at Antietam was horrible at best. Sumner led the II Corps at the head of the column, this was a very bad decision as he was unable to direct the troops at the rear. Sumner's habit of leading from the front resulted in his failure to correct French's division from straying away from Sedgwick's column. This resulted in the disaster at West Woods in which Sedgwick's Division was conpletely shattered. Meanwhile, Sumner assumed that French was right next to Sedwick and sent his son, an aide, to instruct French to attack the enemy in front of him. Due to his mistaken assumptions and the fact that he was in the frontlines rather than the rear, Sumner failed to use his staff to correct French which led him to strike the Sunken Lane instead. Overall, Sumner's performance as corps commander was quite poor and I can't see he would make a good army commander. The only positives I can list for Sumner are: his willingness to obey orders and his aggressiveness.
Sumner could decide to attack Lee in support of Pope's offensive. This could potentially pin Lee down while Pope invades central Virginia. However, Lee's Army of Northern Virginia was still a very potent force after the Seven Days Campaign. Combine this with Sumner's potentially poor performance as an army commander, Sumner may get a bloody nose from Lee. This may even serve as evidence for Lincoln to evacuate the Army of the Potomac early.
However, given what I have read on Henry Halleck and the Second Bull Run campaign, it is likely that the Army of the Potomac would still be pulled out from the banks of the James. Halleck felt that the situation in Virginia violated the precepts of war. Halleck viewed McClellan's position on the James as incompatible with the classic concept of "concentration of force." If Halleck still decides to evacuate the Army of the Potomac from the banks of the James to reinforce Pope, Sumner would be more willing to respond to the orders than McClellan. Though Sumner would be, like McClellan IOTL, constrained by limited shipping abilities, I think Sumner would not drag his feet on complying with orders to send VI Corps to reinforce Pope. This would probably prevent the Battle of Second Bull Run from being a total Union failure at the very least.