Distribution of a random variable exercise I was reading section 1.1 of Terence Tao's book on random matrices, which is a review of probability theory, and I couldn't prove the following exercise, which I copied almost verbatim here:

Independence. When studying the behaviour of a single
random variable X, the distribution of X captures all the probabilistic
information one wants to know about X. The following exercise is
one way of making this statement rigorous: 
Exercise 1.1.10. Let $X$, $X'$ be random variables (on sample spaces $\Omega, \Omega'$ respectively) taking values in a measurable space R (e.g. the real numbers equipped with Borel sigma-algebra), such that they have the same distribution.
Show that after extending the spaces $\Omega, \Omega'$, the two random variables are isomorphic, in the sense that there exists a probability
space isomorphism $\phi: \Omega \to \Omega'$ (i.e. an invertible extension map
whose inverse is also an extension map) such that $X = X' \circ \phi$.

By "extending" and "extension map" Tao means the following:
we say that one probability space $(\Omega', \mathcal{B'}, P')$ extends another probability space $(\Omega, \mathcal{B}, P)$ if there is a surjective map $\pi: \Omega' \to \Omega$ which is measurable and probability preserving (i.e. $P'(\pi^{-1}(E)) = P(E)$ for every $E \in \mathcal{B}$). Every event $E$ in the original probability space
is canonically identified with an event $\pi^{-1}(E)$ of the same probability in the extension. We also think of a random variable X on the original sample space as the "same" as the random variable $X \circ \pi$ on the extended sample space. This identification enables us to add in new random variables that are independent of the existing events and random variables.
So far, I know that WLOG, I can assume that $\Omega$ equals $\Omega'$ by extending them to the product space $\Omega \times \Omega'$. Then I am stuck.
 A: As in my comment above, this looks impossible unless we assume $R$ is the image set:
$$ R = X(\Omega) = X'(\Omega')$$
So let us assume this. Here are some thoughts in that direction...

Incomplete idea: What if we define
\begin{align}
S &= \{(w,z) : w\in \Omega, z \in \Omega', X(w)=X'(z)\}
\end{align}
Since $X$ and $X'$ have the same image, for each $w \in \Omega$ there is a $(w,z) \in S$, and for each $z \in \Omega'$ there is a $(w,z) \in S$. Then define extended spaces:
$(\Omega_e, B_e, P_e)$ and $(\Omega'_e, B'_e, P'_e)$ by
$$ S = \Omega_e = \Omega'_e$$
with $B_e$ and $B'_e$ appropriately defined sigma algebras. Then define $\pi(w,z)=(w,z)$ as the identity function on $S$.  Then the extended random variables are
\begin{align}
X_e(w,z) &=X(w)\\
X'_e(w,z) &=X'(z)
\end{align}
and if we fix $(w,z) \in S$ we get
$$X_e'(\pi(w,z)) = X_e'(w,z) = X'(z)=X(w)=X_e(w,z)$$
where we have used the fact that $(w,z)\in S \implies X(w)=X'(z)$.
Now this answer has absolutely nothing to do with the fact that $X$ and $X'$ have the same distribution, it only uses that they have the same image.
Problem: In comments below I gave the sigma algebras I was initially considering for $B_e$ and $B_e'$.  As Justt points out, the answer above lacks the measurability property for  $\pi$. The identity function can only be measurable if $B_e=B_e'$. Now I wonder if another (single) sigma algebra $F=B_e=B_e'$ can be formed on $S$ with the property that for any $A \in F$, the projection of $A$ onto $\Omega$ is a set in $B$ and the projection of $A$ onto $\Omega'$ is a set in $B'$. Perhaps take a sigma algebra generated by sets of the type $A_1 \times A_2 \subseteq S$ with $A_1 \in B$ and $A_2 \in B'$. I'm not sure if this will work...[Rough draft proof, likely buggy: Let $C$ be the collection of all subsets $A\subseteq S$ with the property that the projection of $A$ onto $\Omega$ is in $B$ and the projection of $A$ onto $\Omega'$ is in $B'$. We want to show $C$ is itself a sigma algebra on $S$. Now $S$ is in $C$.  Also I believe countable unions of sets in $C$ is also in $C$, perhaps even complements...?]
Higher level question: Even if this exercise can be solved, it is not clear to me how it relates to Tao's statement "the distribution of X captures all the probabilistic information one wants to know about X. The following exercise is one way of making this statement rigorous." That statement seems to relate more to the idea that if $P[X\leq x]$ is known for all $x \in \mathbb{R}$, then that uniquely fixes $P[X \in B]$ for all Borel subsets $B\subseteq\mathbb{R}$.
A: So you want to show that if $X: \Omega \to R$ is and $X' \Omega \to R$ are measurable, then there exists two measurable spaces $\widetilde \Omega$, $\widetilde \Omega'$ and four measure preserving surjective maps $\pi : \widetilde \Omega \to \Omega$, $\pi' : \widetilde \Omega' \to \Omega'$,  $\widetilde \pi  : \widetilde \Omega \to \widetilde \Omega'$ $\widetilde \pi^{-1} :  \widetilde \Omega \to \widetilde \Omega'$ such that $\widetilde \pi^{-1} \circ \widetilde \pi = Id_{\widetilde \Omega}$ and $$X \circ \pi = X' \circ \pi' \circ \widetilde \pi.$$
But, as Michael said, if $X$ is surjective and $X'$ is not (which does not prevent them to have the same distribution, see his comment), then the latter equality states that a surjective random variable is equal to a non-surjective one, which is impossible.
I think that the exercise is stated the wrong way around and that the correct statement could be that $\Omega$ and $\Omega'$ are extensions of the same probability space (namely $R$, trivially, the extension maps being $X$ and $X'$ themselves).
Edit : Tao fixed the exercise, the updated statement is exactly what I suggested above.
Edit 2 : as pointed out by OP and Michael Neely, the fixed exercise works only if you forget about the "surjectivity" assumption of the extension maps. This is indeed a silly assumption if you ask me, because otherwise the two good points Tao makes, namely

Probabilistic statements are statements that are stable under extension maps

and

the distribution of X captures all the probabilistic information one wants to know about X

can't be simultaneously true.
A: As mentioned in the comments of Michael's and Justt's answers, the statement of the exercise needs to be modified. If the statement is "show that there exists a random variable Y such that X is equal almost surely to an extension of Y (to a subset of the sample space \Omega), and X' is equal almost surely to an extension of Y (to a subset of the sample space \Omega')", then I can summarize the comments into a proof as follows:
Let $I = X[\Omega] \cap X'[\Omega']$. As a subset of $R$, equip it with the sigma-algebra inherited from R. Equip $I$ with the measure $P_I$ defined by $P_I(E) = P(X \in E) = P'(X' \in E)$. Note that $X$ restricted to $X^{-1}[I]$ is then an extension map, and so is $X'$ restricted to its preimage of $I$ (in particular, they are surjective). Denote $X$ restricted to $X^{-1}[I]$ as $\pi$ and the restricted $X'$ as $\pi'$.
Let $Y$ be the identity map on $I$. Then $Y \circ \pi$, an extension of $Y$, is simply $X$ restricted to $X^{-1}[I]$. $X^{-1}[I]$ is almost all of $\Omega$ by the fact that $X$ and $X'$ are equal in distribution:
$$P(X^{-1}[I]) = P(X \in X'[\Omega']) = P'(X' \in X'[\Omega']) = 1,$$
so $Y \circ \pi$ equals $X$ almost surely. Similarly for $Y \circ \pi'$.
