In the days running up to the Labour party conference one of Keir Starmer’s most senior aides took him aside and told him he had to get a grip of his No 10 operation after weeks of damaging headlines over tensions within his top team. The aide was not alone. A handful of other advisers and friends had made a similar plea to the prime minister. Downing Street was dysfunctional, they told him, and the whole government was at risk of being undermined. At the heart of the problem appeared to be tensions over Sue Gray, the former senior civil servant who became his chief of staff. She had become an increasingly divisive figure. While some cabinet ministers stood by her, grateful for ensuring they got a hearing and for her sharing how government operated, there were also mis-steps, for which perhaps inevitably she became the lightning rod. Gray was accused of alienating some of her political colleagues, who accused her of “control freakery”, and creating a bottle neck in No 10 that delayed policy decisions and appointments. She provoked further anger when it emerged that she was paid £170,000 – more than the prime minister – while at the same time special advisers had their pay cut and their contracts stalled. She was also criticised over her work on preparations for government. Some on the political side were frustrated that her office controlled the grid of announcements so that even when the pace of activity was frenetic, it did not have a proportionate public impact. Many in government will hope that her departure will draw a line under a difficult period for the government and give Starmer an opportunity for a reset before a busy autumn and the run up to a difficult budget. But there are still concerns, particularly among cabinet ministers, over a lack of clear political direction at the top. Some fear the No 10 political operation still feels like it is in opposition mode, rather than running the country. Several ministers think it is unfair to lay the blame at Gray for the way government decisions were rolled out to the media, or for the donors row which Starmer’s own office had handled and she was given little access to. Yet Gray was aware that she had become the story and – like many senior No 10 figures before her – it would mean she had to go. Her friends say that she had struggled with the media attention ever since she had been asked by Boris Johnson to carry out the Partygate investigation. “In recent weeks it has become clear to me that intense commentary around my position risked becoming a distraction to the government’s vital work of change,” she said in her resignation statement. “It is for that reason I have chosen to stand aside, and I look forward to continuing to support the prime minister in my new role.” In the end, Starmer told Gray that it wasn’t working out at a meeting on Friday. They agreed her new role as envoy for the nations and regions. Starmer promised the briefing against her would stop, sources said. Early whispers of an elegant solution, in which Gray would move to a role overseeing devolution, had emerged while the party gathered in Liverpool, but it had taken the prime minister a couple of weeks to get a plan in place. Her new job is, in many ways, a good fit, given her previous experience on devolution and the fact she is well liked by mayors. Several have told the Guardian their relationship with Starmer’s office had been terrible until she came along last September. Gray will be at the prime minister’s side as he hosts his first council of nations and regions on Friday in Scotland. She is expected to be given a peerage, meaning she can carry out the role from the House of Lords. It comes as little surprise that Gray has been the one to go. While some senior No 10 figures claim that reports of rivalry between her and Morgan McSweeney – Starmer’s most senior political aide and the architect of Labour’s election victory – were overblown, deep tensions clearly did exist. One cabinet minister, foreshadowing her departure weeks ago said: “One or both of them will have to go. It’s not going to be Morgan.” Gray, however, was said to have been blind-sided by the decision to give McSweeney her job, and only found out shortly before it was announced. Starmer had been exasperated at the in-fighting, sources said, and resolved to deal with problems before parliament returned from recess so he could focus on the government’s primary purpose. “It’s difficult to know which way Keir will go,” one insider said at the time. “He can be ruthless as hell if he needs to, but he also won’t want to act rashly and look weak. But he knows he has to act.” In the subsequent days, Starmer did indeed act. The issue of the cabinet secretary, Simon Case, which represented another personnel headache, was resolved as he formally confirmed he was stepping down. Nin Pandit, a former director of the Downing Street policy unit, has now been appointed as Starmer’s principal private secretary, the most senior civil servant in his own office, after she impressed McSweeney. Vidhya Alakeson, the political director at No 10, and Jill Cuthbertson, the director of government relations, were promoted to deputy chiefs of staff, addressing criticism that the Downing Street operation was underpowered. James Lyons, a former political journalist and communications expert, has been brought in to head up a new strategic communications team, in recognition that No 10 needed to sharpen up its political operation. Starmer’s allies had predicted that he would come to the conclusion himself that Gray would have to go. “It was a matter of when, not if,” said one friend. “Keir got there. He always does”. But his first 100 days in power have been rocky and it may take more than just a new chief of staff, or even bolstering his Downing Street operation, to turn that around. There remain fears inside Labour that Starmer lacks the political acumen needed to avoid further pitfalls. He still has a big job ahead to reassure his party, and the country, that he has done enough to steady the ship.