The House speaker gathered together a group of Republican thought leaders on immigration and border security and gave them a mission: agree on something.

They couldn't.

Almost exactly eight months later, on Friday, he stood in the back of the House floor, resting his chin on his hand and leaning against a rail as he watched an unrelated farm bill -- which would have achieved one of his legacy goals of welfare reform -- go down in flames, a casualty of the still-unresolved immigration debate.

Now, still staring down the barrel of a rebellion from his typically staid, centrist colleagues, Ryan and leadership is tasked with trying to find a way forward for his members, ahead of the looming midterm elections and following the public airing of dirty laundry that has been dividing the GOP conference for months.

The dramatic implosion of an agriculture policy legislation nicknamed the "farm bill" on Friday came after days of tense negotiations regarding immigration -- unrelated to the bill but an issue that has become so fraught for Republicans that the fight over it has now consumed all matters. The bill failed after a group of conservatives withheld their support as they demanded a vote on a hardline immigration bill that does not have the votes to pass.

Leadership had promised such a vote , but the group tanked the bill anyway, thinking as one Freedom Caucus member Rep. Scott Perry of Pennsylvania put it, "too many of our members have been left standing at the altar too many times with those kind of promises."

Conservatives' actions were prompted by the momentum of a rare rebellion from the other side of the ideological spectrum within the party -- a group of moderates who will continue their efforts to bypass leadership this week.

Monday marks the return of lawmakers to the House and the next chance for at least five Republicans to sign on to an effort that would force an immigration floor vote despite repeated pleas from GOP leadership to not resort to the rarely-used, and rarely-successful, procedural step.

As of Monday morning, 20 Republicans and 176 Democrats have signed the so-called discharge petition. If a minimum of 25 Republicans and all 193 Democrats sign it, it will automatically trigger a vote on four competing bills to save the Deferred Action for Childhood Arrivals program, which protected young undocumented immigrants who came to the US as children, including one to-be-determined bill of Ryan's own choosing.

The move spearheaded by a group of Republican moderates was not taken lightly, though. It was spurred by months of growing frustration with a lack of movement by GOP leadership and efforts by conservatives to push the hardline measure they are backing even as it was clear it could not pass the House.

"People are touching the third rail and it's taking everything else down with it," said one Republican source who has been close to the process. "The farm bill would not have gone down if somehow we had figured out immigration reform before."

What comes next could result in a consequential vote on the policy that affects hundreds of thousands of young immigrants who have largely only known the US as home -- and could mean a series of politically perilous votes for Republicans months from Election Day.

This story is based on conversations with more than a dozen people who have been close to the process for the last eight months as it unfolded.

Meetings without results

In mid-September, President Donald Trump had just announced the DACA policy would end in six months and urged Congress to act to save it.

Ryan's theory was simple. The group of Republicans included those at the far right end of the spectrum on immigration, like Virginia Rep. Bob Goodlatte and Idaho Rep. Raul Labrador, as well as moderates who have sought solutions across the aisle, like Florida Rep. Mario Diaz-Balart and Texas Rep. Will Hurd. If they could agree on a path forward, it would be virtually guaranteed to have enough GOP votes to pass the House.

But while the group was earnest in trying to reach a solution, multiple sources familiar with the talks say, the parties could never reconcile the differences within the Republican conference on immigration, let alone something that might pick up Democrats to pass the Senate.

"We were never close," said the Republican source. "it was just like we were talking two different languages. ... People couldn't agree on what they were giving as equal to what they were getting. No one could agree what that calculus was."

Instead, the talks slowly fizzled out, with extenuating circumstances hitting the group, like the retirement of Arizona Sen. Jeff Flake and the subsequent run to replace him by Rep. Martha McSally, a member who was part of the internal immigration discussion but whose politics moved negotiations to the right.

"That group shows you that there is not 218 (votes)," the source said, referring to the number required to pass a bill in the House. "It's a microcosm of the conference and it showed you -- if those guys could agree, then you have 218. "

By January, four of the group members, including Goodlatte, Labrador, McSally and Texas Rep. Mike McCaul, put out their own bill -- the most conservative and aggressive bill proposed on the issue, which would not include a path to citizenship for DACA eligible immigrants and is paired with a host of cuts to legal immigration and anti-illegal immigration measures. That bill has become the one demanded by conservatives who tanked the farm bill.

Meanwhile, others stayed off that bill or pursued other options. Hurd worked with California Democrat Pete Aguilar, the whip of the Congressional Hispanic Caucus, to put out a bipartisan bill with a pathway to citizenship and a mandate to get control of the border -- the bill that with some modifications is expected to prevail if moderates have their way.

"I think it was a good-faith effort to reach a solution, for sure," said another source close to the process. "It was not an exercise for show. ... Now I think you're seeing a lot of the conversations that have been happening for the last eight months playing out in public."

Building frustrations

In order to pass a government funding bill in January, GOP leadership promised the Freedom Caucus that it would whip the Goodlatte bill and bring it to the floor if it had the votes. The Freedom Caucus insists the promise was to bring it to the floor no matter what, though.

That essentially froze everything in the House. Despite some tweaks, the bill's authors would not make major changes to it, and it still remains well short of votes to pass, according to leadership and members familiar with the whip count.

In the meantime, multiple federal courts put Trump's plan to end DACA on indefinite hold, and the Senate tried and failed to pass any DACA measure.

While leadership remained stuck on Goodlatte, moderate frustration grew. Thirty-four Republicans signed a letter to Ryan pushing him for a solution -- the first sign there was a majority-making number of moderates growing frustrated with the process. Hurd and Aguilar's bill got nearly 30 Republican sponsors, and California Rep. Jeff Denham's proposed floor procedure that now underlies the discharge petition has 245 sponsors, with more than 50 Republicans. Another ringleader of the discharge petition, Florida Republican Rep. Carlos Curbelo, began voting no on government funding measures until DACA was resolved, encouraging colleagues to join him.

On the other side of the Republican party, conservatives remained convinced that leadership was not doing enough to push the Goodlatte bill forward. They felt that leadership wanted the bill to fail, and thus was not doing enough arm twisting to get it to 218.

Leadership, meanwhile, consisted of members with different perspectives on how to move forward. That was only exacerbated when Ryan announced he would retire at the end of his term, with his two deputies Majority Leader Kevin McCarthy and Whip Steve Scalise hoping to replace him. Scalise and McCarthy trended more to the right than Ryan, who spent years working on immigration reform before becoming speaker.

"There were always different ideas on how to move forward," said one of the sources. "That's not the reason it didn't move forward, but you could say it was not helpful."

Things boil over

The fight spilled into public view when Denham and Curbelo, joined by Hurd, Diaz-Balart and other moderates, filed the discharge petition earlier this month, officially starting the process to bypass leadership.

As that gained momentum, the Freedom Caucus grew concerned that they had been out-maneuvered and searched for a way to regain leverage for their Goodlatte bill.

"It's all about timing, unfortunately, and leverage, and I think the farm bill was just a casualty," Perry said moments after the farm bill was dramatically defeated Friday. He added that Freedom Caucus members felt they had been promised a vote on the Goodlatte bill for months and weren't willing to take a promise from leadership to vote on it in June. "Too many of our members have been left standing at the altar too many times with those kind of promises."

Leadership had called both moderates and conservatives to their offices for late-night meetings in the days leading up to Friday's vote, including one with both sides together. Members left calling the meetings "productive," but far from producing a detailed plan forward.

Conservatives are still demanding a vote on the Goodlatte bill -- even if it fails -- before they will consider the farm bill again.

According to Denham, the moderates are asking leadership for a clear "timeline" for a full floor debate on immigration or an agreement on what can be brought to the floor. Denham also said the group is asking for either a vote on all four bills that would be brought in the discharge petition — which includes the Goodlatte bill, Hurd-Aguilar bill, a Democratic bill and the bill of Ryan's choosing — or a vote on a compromise bill that meets "negotiating parties'" needs.

But he said the discharge petition efforts can continue in tandem even as they ask for those details, and may pick up steam after the Freedom Caucus move Friday.

"I would say, given, the breaking of the agreement that was made (Friday), you are going to see more Republicans that are frustrated and angry enough to sign onto something that they've never signed onto before," Denham said.

This story has been updated to include additional information.