[MG_Remote] (P6/hs): the build stamp that was silently empty, and two asymmetries the handshake never checked

CONTRACT-P6 4.2 and 4.3. Three defects, all of them things the handshake
believed it was checking and was not.

1. THE BUILD STAMP WAS "" AND NOTHING SAID SO. CMakeLists took the git hash
   through an execute_process with NO RESULT_VARIABLE, so a failed
   `git rev-parse` yielded the empty string. Verified live rather than
   inferred: this worktree's `.git` is a file holding a WINDOWS path, WSL's
   git answers `fatal: not a git repository`, result 128 - and every WSL build
   mixed "" into its ABI fingerprint. Two builds from different commits then
   agreed exactly, which is the one thing the stamp exists to prevent. The
   already-failing SessionHandshakeTest was reporting this the whole time.

   The fix may NOT touch GIT_COMMIT_HASH_SHORT: it is baked into
   glGetString(GL_VERSION), so redefining it changes an application-visible GL
   string and the pull build's .rodata - a behaviour leak and a G1 break at
   once. MGGitHash.h.in gains a SECOND pair instead, consumed only by the
   fingerprint, plus -DMOBILEGL_BUILD_STAMP for trees git cannot read (CI has
   ${GITHUB_SHA} in hand). A stampless build is now a configure-time WARNING
   naming the consequence, not silence.

   MOBILEGL_BUILD_STAMP_PRESENT IS MIXED AS ITS OWN FIELD. "this build cannot
   name its commit" and "this build's commit is the empty string" are different
   claims, and collapsing them is how every stampless build in the world agreed
   with every other. The test asserts the flag moves the fingerprint in EITHER
   build state, and the `BuildStamp = ""` perturbation is now guarded - in a
   stampless build production's value already IS "", so that assertion was
   passing while proving nothing.

2. THE CLIENT NEVER READ abiMajor/abiMinor. Hello has carried them since P5
   and the SERVER checks them; the client compared only the fingerprint. The
   fingerprint mixes AbiVersion so a mismatch would fire anyway - but as
   "struct shapes", which sends the reader looking for a layout change that is
   not there. Under spawn the peer is a SEPARATE IMAGE the operator chose with
   MOBILEGL_IPC_SERVER_PATH, so this is exactly the failure that needs its own
   sentence. Both handshake sites call one helper; there are two sites, and
   only one of them was reachable before `sm`, which is how the gap survived.

3. Hello::pid WAS 0 AND Welcome::serverPid ECHOED IT. So both were always 0 and
   neither named anything, while §9.5's arm-proof gate wants exactly the child
   pid. Both now carry real ids, and the pair is the cheapest arm proof in the
   protocol: under spawn they MUST differ, and a same-process session cannot
   produce two different values. The client keeps what the server STATED -
   local launcher knowledge is a different fact from one that crossed the wire,
   and only the second can be asserted from the server's own mouth.

R-16 both ways: revert serverPid to echoing hello->pid() and the new test reds
on both halves, naming 4.3. G1 re-measured after the CMake and header changes:
0 symbol diff, .text unchanged at 0xa52203.

Unit suite goes from two long-standing failures to one - the remaining
PipeCatalogue.FrontendNeverTakesAnApplierAddress is an environmental path
problem in this tree, unrelated. All six OpenRA arms still green.
This commit is contained in:
swung0x48 committed 2026-09-21 19:21:43 -04:00
1 parent 8b13d8a84c
commit 90f9a79058
10 files changed
+249 -9

No files matched your search

+31
View File
@@ -193,6 +193,37 @@ TEST(ServerSpawnTest, AnEglControlOpCrossesToTheOtherProcessAndAnswers) {
ASSERT_EQ(Server::ReapServer(session.server, 5000, &exitCode), MOBILEGL_OK);
}
TEST(ServerSpawnTest, TheHandshakeCarriesTwoDifferentProcessIdsAndNotTwoZeroes) {
// CONTRACT-P6 4.3. Hello::pid was hard-coded 0 and Welcome::serverPid ECHOED it back, so the
// handshake carried 0 and 0 and named nothing at all. Both now carry real ids, which makes
// the pair the cheapest arm proof in the protocol: under spawn they MUST differ, and a
// same-process session cannot produce two different values.
//
// ServerSession records the pid it welcomed; ClientSession knows the child it launched. The
// assertion is that those two agree AND that neither is this process.
Session session;
ASSERT_TRUE(Bring("pids", &session));
ASSERT_EQ(Handshake(session), MOBILEGL_OK);
const std::uint32_t self = static_cast<std::uint32_t>(::getpid());
const std::uint32_t server = static_cast<std::uint32_t>(session.server.pid);
EXPECT_NE(server, 0u) << "the launcher did not record a child pid";
EXPECT_NE(server, self) << "that is this process, so there is nothing to prove";
// THE VALUE THAT CROSSED THE WIRE, not the one the launcher happens to remember. Welcome
// carries the server's own getpid(), so this equality says the handshake reached the process
// we started - rather than some other listener that answered on the name - and it says it
// from the server's own mouth.
EXPECT_EQ(Client::ClientSessionInstance().PeerServerPid(), server)
<< "Welcome::serverPid does not name the process we launched";
EXPECT_NE(Client::ClientSessionInstance().PeerServerPid(), self)
<< "the peer stated OUR pid; serverPid is echoing the client again (4.3)";
Client::ClientSessionInstance().Stop();
int exitCode = -1;
ASSERT_EQ(Server::ReapServer(session.server, 5000, &exitCode), MOBILEGL_OK);
}
TEST(ServerSpawnTest, AKilledServerLatchesDeviceLostFromTheHangupAndNotFromADeadline) {
// `dl`, and exit gate S2: kill -9 the server mid-session and the client must find out FROM A
// DESCRIPTOR. This is the red-once for CONTRACT-P6 D5c, whose whole content is that the
+28 -2
View File
@@ -136,10 +136,25 @@ TEST(SessionHandshakeTest, TheAbiFingerprintChangesWhenAnyOfItsInputsDoes) {
EXPECT_EQ(inputs.OpCount, static_cast<Uint64>(MG_Pipe::MGPWireOp::kOpCount));
EXPECT_EQ(inputs.AbiVersion, static_cast<Uint32>(MOBILEGL_ABI_VERSION(
MOBILEGL_PROTOCOL_ABI_MAJOR, MOBILEGL_PROTOCOL_ABI_MINOR)));
// CONTRACT-P6 4.2. THE ASSERTION SPLITS WITH THE MACRO PAIR, and it has to: this used to
// demand a non-empty stamp unconditionally and was RED in every build whose git could not be
// read - a real signal, but one that told the reader nothing about WHICH of the two states
// the build was in. Now the build system states it, and both states are asserted.
ASSERT_NE(inputs.BuildStamp, nullptr);
EXPECT_NE(inputs.BuildStamp[0], '\0');
EXPECT_EQ(inputs.BuildStampPresent, static_cast<Uint32>(MOBILEGL_BUILD_STAMP_PRESENT))
<< "the fingerprint disagrees with the build system about whether this build has a stamp";
#if MGL_HANDSHAKE_TEST_HAS_GIT_HASH
EXPECT_STREQ(inputs.BuildStamp, GIT_COMMIT_HASH_SHORT);
EXPECT_STREQ(inputs.BuildStamp, MOBILEGL_BUILD_STAMP_VALUE);
#endif
#if MOBILEGL_BUILD_STAMP_PRESENT
EXPECT_NE(inputs.BuildStamp[0], '\0')
<< "the build claims a stamp and the fingerprint mixed an empty one";
#else
// A stampless build is a KNOWN, DECLARED state - CMake warns at configure time - but it must
// not be a silent one here either. What still has to hold is that the ABSENCE is mixed, which
// the BuildStampPresent perturbation below proves.
EXPECT_STREQ(inputs.BuildStamp, "")
<< "PRESENT is 0 but a value came through; the two halves of the pair disagree";
#endif
// Every input moves the answer. Each lambda changes exactly one field of a copy of the
@@ -176,8 +191,19 @@ TEST(SessionHandshakeTest, TheAbiFingerprintChangesWhenAnyOfItsInputsDoes) {
perturbed([](Transport::AbiFingerprintInputs& i) { i.BuildStamp = "not-this-build"; }))
<< "the git stamp is not mixed";
// A missing stamp is not the same as an empty one, and neither is the same as a real build.
// THE PRESENCE FLAG IS ITSELF AN INPUT (4.2), and this is the assertion that makes a
// stampless build safe to reason about: a peer that says "I could not name my commit" must
// not produce the same fingerprint as one whose commit genuinely is "". It has to move the
// answer in EITHER build state, which is why it sits outside the #if below.
EXPECT_NE(production, perturbed([](Transport::AbiFingerprintInputs& i) { ++i.BuildStampPresent; }))
<< "BuildStampPresent is not mixed; 'no stamp' and 'empty stamp' are one input again";
EXPECT_NE(production, perturbed([](Transport::AbiFingerprintInputs& i) { i.BuildStamp = nullptr; }));
#if MOBILEGL_BUILD_STAMP_PRESENT
// Vacuous without a stamp: production's value already IS "", so this perturbation would be
// the identity and the assertion would pass while proving nothing.
EXPECT_NE(production, perturbed([](Transport::AbiFingerprintInputs& i) { i.BuildStamp = ""; }));
#endif
EXPECT_NE(perturbed([](Transport::AbiFingerprintInputs& i) { i.BuildStamp = nullptr; }),
perturbed([](Transport::AbiFingerprintInputs& i) { i.BuildStamp = ""; }))
<< "\"no stamp\" and \"an empty stamp\" collapsed into one input";