SAN FRANCISCO — WHEN audiences watch the movie “Spare Parts” in theaters this month, they will see the kind of Hollywood ending that has eluded the immigration debate in Congress.

The film is based on my reporting about four young immigrants who built an underwater robot. In the movie, which closely reflects the true story, the students enter the nation’s pre-eminent robotics competition, an event sponsored by NASA and the Navy. They win widespread recognition for their accomplishments and, when the movie ends in 2004, their future is bright.

Unfortunately, that’s not how the story really ends.

All four students were born in Mexico and were brought across the border illegally as children. Though they grew up in Arizona and viewed themselves as Americans, the law did not. They lived with the daily threat of deportation. Oscar Vazquez dreamed of joining the Army — he was officer of the year in his J.R.O.T.C. program — but discovered he couldn’t enlist because he didn’t have legal residency. Cristian Arcega was a geeky brainiac who found few outlets for his smarts in gang-torn West Phoenix. Lorenzo Santillan was a former gang member himself looking to stay clean. And Luis Aranda, the only one who had gotten a work permit, just the year before, was a hulking giant of a kid who rarely spoke.

This ragtag group from Carl Hayden Community High School in West Phoenix constructed the robot out of cheap plastic tubing and garbage. It smelled so bad, they called the machine Stinky. The other entrants — almost all college students — had corporate sponsors and serious budgets. This was an underwater robotics contest, but Carl Hayden didn’t even have a swimming pool. Nonetheless, Stinky came in first place.