[MG_Backend, MG_State, MG_Pipe, MG_Remote, MG_Impl, MG_IntegrationTest, docs] (P7): magma installs a state-object death table, and the inproc arm stops losing every object_death

CONTRACT-P7 §5.5. DirectVulkan had no StateObjectDeathOps at all, so under a Magma
inproc session NotifyStateObjectDestroyed reached nobody and the server was never told
that a frontend object had died. Package L measured the shape: with the WireTables
install condition made backend-agnostic, CtWireScenario's two death cases PASS on Magma
spawn and tcp - the remote client has no local backend, so the client-side emitter
installed there answers the notice - and FAIL on inproc, where the install condition
deliberately stands aside for "the backend's own dispatcher" and Magma had none.

g_magmaStateObjectDeathOps is that dispatcher. It mirrors g_glesStateObjectDeathOps
(DirectGLES/Managers.cpp:335) with ONE arm rather than two: Espryt's other arm destroys
a backend twin keyed by lifetime id, and Magma keeps no such twin - its two
client-minted kinds are keyed on {slot, gen} by MagmaPipeIdentityTables and the other
six are still reached from their frontend objects - so what is left is exactly the emit
of object_death off the apply thread. Installed from
BackendObject_DirectVulkan::Initialize(), i.e. ServerLoop::CreateBackend, step 1 of
InitServerRoleCommon: the one place BOTH Magma server roles pass through, and before any
client session exists. #if MOBILEGL_BUILD_DISAGGREGATED && MOBILEGL_PIPE_PUSH, so the
pull build compiles nothing new.

The two skip guards in CtWireScenario go with it. Every other "Magma installs none" site
the audit found is comment text whose ARGUMENT survives, and each is reworded rather than
deleted: the table emits the wire record and frees no client slot, so P4a's
backend-neutral NotifyAndFree is still the only thing that returns one, HandleRecycle's
C-1 case still measures the only protection the allocator has, and MagmaPipeArms' age
sweep is still the only thing that retires an identity slot.

The framebuffer death case now reads the client's allocator beside the server's tally.
That correction matters: the plan called this a slot leak provable with PipeSlotPeek, and
it is not - it has been backend-neutral since P4a. What leaked was the SERVER's twin, and
a framebuffer has no wire delete opcode at all, so object_death is its only delivery.

Two installers cannot race although the global is last-writer-wins with no stacking:
Magma's runs only in a process that owns a DirectVulkan backend, and
InstallClientWireTables' arm runs only under Transport == Spawn, which is by construction
the process that owns none.

RED-ONCE: `if (false) InstallStateObjectDeathOps();` reds the two Split cases alone
(`Expected: (afterCounters.deaths) > (deathsBefore), actual: 0 vs 0`, CtWireScenario.cpp:264)
and leaves spawn and tcp green - the exact split of responsibility the comment claims.
Restored: 8/8. Recorded in docs/Disaggregated/notes/p7/magma-c.md.
This commit is contained in:
2026-09-22 16:07:13 -04:00
parent 07079c3c0e
commit dce9953d36
12 changed files with 270 additions and 35 deletions
@@ -13,8 +13,19 @@
// the leak it rules out is entirely inside the library, and it is invisible in pixels, in GL
// names and in `glGetError` - so the only honest observable is the allocator's own live count
// and high-water mark. Reading them is what makes the case fail on the backend it actually
// failed on (DirectVulkan, which installs no StateObjectDeathOps) rather than only on the one
// where a backend-owned free happened to exist.
// failed on (DirectVulkan, which at P3a installed no StateObjectDeathOps) rather than only on
// the one where a backend-owned free happened to exist.
//
// P7 wave 2 package C: DirectVulkan now installs a table of its own (CONTRACT-P7 §5.5), and
// the sentence above is history rather than the current state - but the reason this header
// exists is UNCHANGED and is worth spelling out, because the obvious reading of that news is
// wrong. Magma's table does not free a client slot and never could: the free is P4a's, it
// runs from the frontend object's own destructor on the client thread whatever backend is
// live (MG_Impl/Pipe/PipeFill.cpp's NotifyAndFree), and Magma's table is the EMIT arm that
// tells the SERVER to drop its twin. So the allocator is still the only observable of the
// client half, and a case that reads `deaths` alone would be blind to a slot that never came
// back. The two readings belong together, which is what CtWireScenario's framebuffer case now
// does.
//
// A separate translation unit for BackendCapsPeek.h's reason, verbatim: the scenario sources
// include the GL headers with prototypes and MobileGL's umbrella header is not meant to meet
@@ -25,6 +25,7 @@
// half of that control is TheDirectApplierResetCallOnTheGLThreadIsRoleViolation below, and
// the guard's two non-Fatal arms are pinned in PipeWireCodecTest's CtWireFatals suite.
#include "../Harness/PipeSlotPeek.h"
#include "../Harness/PipeStatsWindow.h"
#include "../Harness/ScenarioFixture.h"
#include "../Harness/SplitRuntimePeek.h"
@@ -147,13 +148,16 @@ namespace {
TEST_F(CtWireScenario, TextureDeathCrossesAndTheRecycledSlotAnswersTheNewObject) {
if (!Ready()) return;
// The object_death producer is Espryt-side (OnFrontendStateObjectDestroyed,
// CONTRACT-P5C.md §5.2); Magma installs no StateObjectDeathOps (P7), so under
// DirectVulkan there is no death record to watch and the case has nothing to prove.
if (HeadlessGL::Get().BackendName() != "DirectGLES") {
GTEST_SKIP() << "object_death is produced by the DirectGLES death-notice ops; "
"DirectVulkan has none until P7";
}
// P7 wave 2 package C: THE BACKEND GUARD IS GONE, and both halves of why it was here
// are answered rather than waived. The producer used to be Espryt-side only
// (OnFrontendStateObjectDestroyed, CONTRACT-P5C.md §5.2), so a DirectVulkan run had
// no death record to watch; Magma now installs its own StateObjectDeathOps
// (DirectVulkan.cpp, CONTRACT-P7 §5.5) and emits the same `object_death`. Package L
// measured that the SPAWN arm already passed once the WireTables install condition
// went backend-agnostic and that the INPROC arm failed here with `deaths` 0 vs 0
// (notes/p7/magma-two-process-first-run.md §6); the table is what closes the inproc
// half, and this case is the gate on it. It is also the RED-ONCE for that table: with
// the install site short-circuited, both cases red on the two EXPECT_GT below.
const GLubyte red[4] = {255, 0, 0, 255};
const GLubyte green[4] = {0, 255, 0, 255};
@@ -204,14 +208,13 @@ namespace {
TEST_F(CtWireScenario, FramebufferDeathCrossesAndTheRecycledSlotAnswersTheNewObject) {
if (!Ready()) return;
// Same producer reason as the texture case above: object_death is emitted by the
// DirectGLES death-notice ops; DirectVulkan has none until P7.
if (HeadlessGL::Get().BackendName() != "DirectGLES") {
GTEST_SKIP() << "object_death is produced by the DirectGLES death-notice ops; "
"DirectVulkan has none until P7";
}
// Backend-agnostic for the texture case's reason (P7 wave 2 package C): both
// backends now install a StateObjectDeathOps table and both emit `object_death`.
// Framebuffer is the kind object_death EXISTS for: it has no other wire delete
// opcode (CONTRACT-P5C.md §5.2). The renderbuffer goes along so the FBO has storage.
// opcode (CONTRACT-P5C.md §5.2) - which is exactly why the missing Magma table was
// a SERVER-side twin leak and not merely a missing counter: with no consumer for
// the notice, nothing on the wire ever told the server this framebuffer had died.
// The renderbuffer goes along so the FBO has storage.
GLuint fbo = 0, renderbuffer = 0;
glGenFramebuffers(1, &fbo);
glGenRenderbuffers(1, &renderbuffer);
@@ -234,6 +237,21 @@ namespace {
const auto beforeCounters = ServerCounters();
ASSERT_TRUE(beforeCounters.valid) << "server object-death telemetry missing";
const MobileGL::Uint64 deathsBefore = beforeCounters.deaths;
// THE CLIENT'S OWN ACCOUNTING, read beside the server's (P7 wave 2 package C,
// CONTRACT-P7 §5.5's PipeSlotPeek clause). The two numbers answer DIFFERENT halves of
// one death and neither implies the other, which is exactly why both are read here:
// * `deaths` below says the SERVER was told - the half the missing Magma table
// broke, and the only delivery a framebuffer has (no wire delete opcode at all);
// * this one says the CLIENT returned the slot. That half has been backend-neutral
// since P4a (PipeFill.cpp's NotifyAndFree frees whatever the notice does), so it
// is a CONTROL rather than the subject: if it ever regressed, a green `deaths`
// would be measuring an object that never let go of its handle.
// `false` means the allocator is out of reach (a pull build, or Android's hidden
// symbols), and the peek is then simply not asserted - "could not look" is not
// "did not leak", so nothing is concluded from it either way.
unsigned fboSlotsBefore = 0;
const bool slotsReadable =
PeekPipeSlotLiveCount(PipeSlotKind::Framebuffer, &fboSlotsBefore);
glDeleteFramebuffers(1, &fbo);
// THE FENCE (MOBILEGL_IPC_BATCH_WAITS, default on): object_death is a kCtxObject
// value-class record - published WITHOUT waiting for its own apply (production-safe:
@@ -245,7 +263,16 @@ namespace {
ASSERT_TRUE(afterCounters.valid) << "server object-death telemetry missing";
EXPECT_GT(afterCounters.deaths, deathsBefore)
<< "the framebuffer's death produced no object_death record - and no other "
"opcode can carry it";
"opcode can carry it. Backend "
<< Gl().BackendName();
if (slotsReadable) {
unsigned fboSlotsAfter = 0;
ASSERT_TRUE(PeekPipeSlotLiveCount(PipeSlotKind::Framebuffer, &fboSlotsAfter));
EXPECT_LT(fboSlotsAfter, fboSlotsBefore)
<< "the dead framebuffer kept its client slot: live count " << fboSlotsBefore
<< " -> " << fboSlotsAfter << " across the delete. Backend "
<< Gl().BackendName();
}
glDeleteRenderbuffers(1, &renderbuffer);
// Recycle: a new FBO and a new backing store, cleared to a different colour. A stale
@@ -1394,13 +1394,21 @@ void main() { oColor = texture(uTex, vUv); }
// back? Until C-1 the answer under DirectVulkan was NO. The mint is the client's
// (MGPipeVertexInputEmitter::EmitVertexElements acquires a VertexElementsCso slot at
// every validate point with a VAO bound) and the only free in the tree was Espryt's
// StateObjectDeathOps consumer - so under Magma, which installs none deliberately
// StateObjectDeathOps consumer - so under Magma, which installed none
// (MagmaPipeArms.h: "an allocator here would grow by one SlotState plus one map node
// per object EVER created, for the life of the process, on a platform with an LMK"),
// every VAO ever created held its slot and its ~1.3 KB applier record until the process
// died, on the shipped 0x1ff mask, until create_vertex_elements began tripping
// Fatal{ProtocolCorruption} permanently at kMGPipeMaxVertexElementsSlots.
//
// P7 WAVE 2 PACKAGE C DOES NOT RETIRE THIS CASE, and the reason is the whole point of
// C-1. Magma now installs a StateObjectDeathOps table (CONTRACT-P7 §5.5), but that
// table's one arm EMITS the `object_death` record so the SERVER drops its twin - it
// frees no client slot and could not: the free is the client's own, from the frontend
// destructor, on the client thread. So this case still measures the only thing that
// ever protected the allocator, and it would still be the case that goes red if that
// free were ever moved back behind a backend table.
//
// THE OBSERVABLE IS THE ALLOCATOR, not pixels: this leak produces correct pictures the
// whole way to the fatal, which is exactly why the four cases above ran green over it.
// It runs on BOTH backends' Handles lanes; DirectVulkan is where it was red.