# w1 — wave 1.5 (round 2): ID-48's three findings, closed Branch `p5/w1`, range **`ce53553c..bb6ba282`** (three commits, one per finding). Base: `git merge --no-edit feat/disaggregated` was a **fast-forward** to `ce53553c` — wave 1's `79b78665` is already an ancestor of the integration head, so the merge added no commit of its own and the range above is exactly this round's work. Identity checked before the first commit (ID-40's standing rule): `git var GIT_COMMITTER_IDENT` = `Swung0x48 `; all three commits are that name as author **and** committer, single-line messages, no trailer of any kind. Files touched: `MobileGL/MG_Remote/Wire/PipeWireCodec.{h,cpp}` and `MobileGL/MG_Test/Wire/PipeWireCodecTest.cpp` — +290 / −1, nothing else. `PipeWireCodecTest.NoReplyIsWrittenForARowTheCatalogueGivesNoReplySlot` was not touched (c1's). | commit | finding | |---|---| | `1a06b40a` | 1 — an empty `SEG_STAGE` rejects a blob that fits | | `ba6dc4f7` | 3 — blob validation accepts any mapped segment | | `bb6ba282` | 4 — the codec's `MapPersistent` arm never consults the adoption tier | Each intermediate commit was **built and smoke-tested before it was made** (`~/w7/p5-w1-commits.py`), so all three are bisect points, not just the last one. --- ## 1. Finding 1 — an empty `SEG_STAGE` now takes a blob that fits (`1a06b40a`) **What was wrong.** `m_stageHead` / `m_stageTail` are monotonic byte counts, so "every staged byte has retired" reads `head == tail`, **not** `head == tail == 0`, and `head % capacity` is left wherever the last run ended. `StageAllocate` then charged a wrap skip against that offset: with `head == tail == 64` in a 256 KiB stage the test became `2*capacity − 64 <= capacity`, false at **every** occupancy, and `ReclaimStagedBytes()` cannot move an already-empty tail — so the second attempt failed identically and the request aborted on `Fatal{RingOverrun, "SEG_STAGE"}`, whose own message then printed `0 bytes still in flight`. **What changed.** A new private `PipeWireEncoder::RebaseEmptyStage()`, called at the top of each of `StageAllocate`'s two attempts — so it also runs *after* `ReclaimStagedBytes()`, which is the review's scenario (8 MiB allocated, retired, then a 28 MiB request). When `head == tail != 0` it resets both cursors to zero. **The general statement, as the verifier asked: the wrap skip may only be charged against bytes that are actually still in flight, and when there are none the allocator restarts at offset 0.** **One thing the fix shape did not mention and the code needs.** The mark queue has to be rebased with the cursors. A `StageMark` holds the **absolute** head cursor it was pushed at, and `ReclaimStagedBytes` assigns that value straight to `m_stageTail`. Every mark not yet consumed has `StageCursor <= head == tail` (the head is monotonic and marks are pushed in order), so each one names a region that is already reclaimed and zero is the truthful rebasing of it. Without that, one reclaim after a rebase would put the tail **ahead of** the head and `StagedBytesInFlight()` would underflow to ≈2⁶⁴. `RebaseEmptyStage` rewrites them. **Control.** The verifier's extension of `PipeWireCodecTest.StagedBytesAreReclaimedOnlyBehindRetiredSeq`, kept: after the 64-byte allocation retires and in-flight is zero, `StageBytes` of exactly `Wire2::kStageBytes` must land at `Offset == 0`, in `kSegStage`, resolve back to `StageBase()`, and leave `StagedBytesInFlight() == kStageBytes`. > **I made it red once, by doing X: X = deleting the `RebaseEmptyStage();` call at the top of > `StageAllocate`'s attempt loop.** Executed (`~/w7/p5-w1-redcheck2.log`): > `1946 - PipeWireCodecTest.StagedBytesAreReclaimedOnlyBehindRetiredSeq (Subprocess aborted)`, > `0% tests passed, 1 tests failed out of 1` — the verifier's exact outcome. Green again on > restore. ### The exact maximum blob an empty stage takes — and the correction to `w1-v1.md:341` `need = Align8(size)` and the first bound is `need > m_stageCapacity`, so **an empty stage takes a blob of exactly `m_stageCapacity` bytes** (more precisely `floor(capacity / 8) * 8`; every canonical capacity is 8-aligned, so the two are the same number). `m_stageCapacity` is the stage `RingProducer`'s `Capacity()` when one is installed and the whole `SEG_STAGE` view size otherwise. **In a real session there is no stage ring at all** — `SessionRings.h:83-88`: `SEG_STAGE` is "an encoder-local LINEAR ALLOCATOR … a plain byte count: no control page, and no rounding down to a power of two either" — so `m_stageCapacity == SessionSegmentSizes::StageBytes == MOBILEGL_IPC_STAGE_MB`, i.e. **33,554,432 bytes at the default 32**. In the unit fixture it is `Wire2::kStageBytes` = 262,144, which is what the new assertion pins. **`w1-v1.md:341` said "The archive's bound is `MOBILEGL_IPC_STAGE_MB` (32 MiB)". The verifier falsified it, and it was false: before this fix, the bound on an empty stage was** ``` max( head mod capacity , capacity − (head mod capacity) ) ``` — i.e. anywhere from **half** the segment to all of it, equal to the full 32 MiB only on a *fresh* encoder whose head is still 0. (The verifier's discriminator, `FINDING1B: fresh encoder ALLOCATED offset=0 size=262144`, is exactly that boundary case.) **After this fix the sentence is true as written**: the bound is `MOBILEGL_IPC_STAGE_MB`, 32 MiB by default, at every occupancy at which the stage is empty. ### Does R-10's max-record counter see it? **No — and that is now pinned.** `m_maxRecordBytes` is fed from `layout.TotalBytes` in `EncodeRecord` — header + payload + tails, all of it `SEG_CMD` — while a staged blob leaves only `{Seg, Offset, Size}` (24 bytes) in the record. The same control asserts `MaxRecordBytesSeen()` is **unchanged** across a quarter-megabyte `StageBytes`. So `MaxRecordBytesSeen()` is **not** the staging bound and must not be read as one: `SEG_STAGE` has its own bound and its own named `Fatal{RingOverrun, "SEG_STAGE"}` (the message cites `MOBILEGL_IPC_STAGE_MB`), and `SEG_CMD`'s `RingProducer::MaxRecordBytes()` is what R-10's counter is measured against. Both numbers are printed live by their own Fatal; neither is a compile-time constant in this file. --- ## 2. Finding 3 — a content blob must declare `SEG_STAGE` (`ba6dc4f7`) **What was wrong.** The only test was that the run resolved *inside some* segment, so `CreateSamplerState.Parameters={Seg=SEG_REPLY, Offset=0, Size=sizeof(SamplerParameters)}` was accepted by the encoder **and** the decoder, and the sampler applier received those bytes out of a **server-owned** pool whose reuse has nothing to do with stage retirement. The audit's half was worse: `NoteResolvedRun` opened with `if (blob.Size == 0 || blob.Seg != kSegStage) return;`, so the run was never recorded, `PoisonedStageBytes()` stayed zero, and rule C's only mechanical control was dark on exactly the record it exists to catch — the verifier's probe printed `seg=3 accepted=1 poisoned=0` with the audit **on**. **What changed, and where — this is stronger than the fix shape.** The verifier named `RequireDeclaredBlob`. The arm went one level down, into **`CheckBlobIsHonest`**, because `RequireDeclaredBlob` is only the "this record says it carries content" path: the **optional** arms (`CreateRenderState`/`SetDynamicState` with `ChunkMask == 0`, `ResourceSubData` with no content, `BufferSubDataResident`, `CreateShaderState.Spirv[i]`) and the **encoder's** per-slot honesty loop call `CheckBlobIsHonest` directly, and a fix in `RequireDeclaredBlob` alone would have left every one of them accepting `SEG_REPLY`. `RequireDeclaredBlob` calls `CheckBlobIsHonest`, so it is covered too. The arm runs **before** the resolve, deliberately: a forged `SEG_REPLY` run that happens to lie inside a mapped reply pool must be refused for naming the wrong carrier, not left to pass or fail on whether that pool is mapped at all. **Which Fatal family, and why.** `Fatal{ProtocolCorruption, ".blob"}`, **not** a new `BlobNotStaged`. The families are the vocabulary the operator and the CI greps share — `ProtocolCorruption`, `AbiMismatch`, `UnmigratedVerb`, `UnmigratedPipeInput`, `UnsetCallMask`, `RingOverrun`, and no other appears anywhere in `MG_Remote` — and a one-off seventh name would be a token nothing else in the tree recognises. The **segment** is in the message, which is the part that has to be greppable: `seg=%u offset=%llu size=%llu is not SEG_STAGE(%u)`, plus the citation of contract table 1 groups A/B/C and R-10. **The audit's bookkeeping is now unreachable rather than load-bearing.** `NoteResolvedRun`'s `blob.Seg != kSegStage` case was a silent `return`; it is now a named Fatal of its own, matching the run-count overflow Fatal immediately below it, and its single caller (`ResolveOrFatal`) runs `RequireDeclaredBlob` first — so it cannot be reached and says so if it ever is. The verifier's "either cover the carrier or be unreachable for anything but `SEG_STAGE`" is satisfied by the second branch. **Controls.** Two new forked cases, both in the file's own Fatal-arm idiom (`RunInChild` + `DiedOfAbort` + a **required diagnostic substring**, never `EXPECT_DEATH`): - `AContentBlobCarriedOutsideSegStageIsFatalAtTheDecoder` — the verifier's perturbed sampler fixture kept as its own case, **with `SetAuditPoison(true)` armed**, so the second half of the finding is nailed too: with the poison on, the record must *die* rather than be applied with `PoisonedStageBytes()` at zero. Requires `is not SEG_STAGE`, `CreateSamplerState.blob` and `seg=3` in the child's log. - `TheEncoderRefusesTheNonStageCarrierTheDecoderCallsFatal` — the symmetry this file already states one arm over: under `inproc` a `SEG_REPLY` pointer resolves, so an emitter that staged into the reply pool would get a valid seq locally and a Fatal on a peer. > **I made them red once, by doing X: X = removing the `kSegStage` requirement.** Executed > twice, both recorded in `~/w7/p5-w1-redcheck2.log`: > **(a)** deleting only the `blob.Seg != kSegStage` arm — both cases red > (`0% tests passed, 2 tests failed out of 2`); > **(b)** the full wave-1 revert, that arm **and** `NoteResolvedRun`'s silent `return` — both > cases red again, this time with the decoder child exiting 0, i.e. the verifier's exact > `accepted=1 poisoned=0` state. Green again on restore. --- ## 3. Finding 4 — the codec's `MapPersistent` arm goes through the tier gate (`bb6ba282`) **What was wrong.** `AdoptTier` had **zero** references anywhere on the codec path; the arm was an unconditional `PostReply(..., kStatusDeclined, nullptr, 0); return true;`. `ConfigLoader.cpp` accepts 0, 1 and 2, so `MOBILEGL_IPC_ADOPT_TIER=0` and `=1` — which contract §5 promises "parse and are `Fatal` at use, naming P11" — decoded as an ordinary DECLINED on both forbidden tiers, and an operator got a run that looked like a working T0. **What changed.** The arm now asks `MG_Remote::Client::AdoptTierIsEmulate()` (b1's file, unchanged) behind **the same conjunction the monolith applier uses**, `MG_Config::Transport != MG_Config::TransportMode::Monolith` — `PipeApply.cpp`'s guard, verbatim, so the two paths cannot drift. The return value is deliberately not a branch: the helper returns `true` at T2 and **aborts** at T0/T1 on its own named diagnostic, and R-6 says P5 declines at every tier it survives. **Controls** — three, and the third is what keeps the first two honest: - `AdoptTierZeroIsFatalOnTheWirePathAndNamesP11` and `AdoptTierOneIsFatalOnTheWirePathAndNamesP11`. Forked, not `EXPECT_DEATH` (the file's header forbids it: `EXPECT_DEATH` re-runs the whole binary and re-enters the applier's globals). **The diagnostic is required, not optional** — `ID-46` finding 10 is an empty death regex, and these are its opposite: each case requires the literal `MOBILEGL_IPC_ADOPT_TIER=0 names adoption tier T0, which P11 implements` (and `=1 … T1 …`) in the child's log, and prints that log when it fails, so a crash for any other reason fails the case. - `TierTwoUnderSplitTransportStillDeclinesRatherThanRefusing` — the positive half. Without it the two death cases could be satisfied by an arm that aborted on *every* tier, which is the opposite mistake. T2 under `InProcess` transport still answers `kStatusDeclined` with an empty payload (R-6), RAII-restored. > **I made both death cases red once, by doing X: X = restoring the unconditional decline > (deleting the `AdoptTierIsEmulate` call).** Executed: `33% tests passed, 2 tests failed out of > 3` — both `AdoptTier*IsFatalOnTheWirePathAndNamesP11` red, and > `TierTwoUnderSplitTransportStillDeclinesRatherThanRefusing` **still green**, which is exactly > the discrimination the positive control exists for. Green again on restore. --- ## 4. The four self-tests, on `bb6ba282` Gate script `~/w7/p5-w1-gate2.sh`, log `~/w7/p5-w1-gate2.log`. Every configure is checked for `CMAKE_GENERATOR` + `CMAKE_CXX_COMPILER` + `CTestTestfile.cmake` out of the cache (the verifier's C-10 trap: `CTestTestfile.cmake` alone did not catch a GCC/Makefiles tree), and **no test runs after a failed build** — all four were `rc=0`, `Ninja`, `clang++`. **(1) G1 — clean, as required.** ``` G1-split nm MG_Remote pull=0 (must be 0) split=346 (must be > 0) symbol-report: .text 10806611 -> 10806611 (+0, +0.000%) symbol-report: 27814 -> 27814 defined symbols: 0 added, 0 removed, 0 resized, 0 renamed ``` Against `~/w7/p5-before-libMobileGL.so`, `--threshold 0`, marker `.READY` = `4595163c7c439641ddb94f8a936eb2ccd5fb8b19` (ID-44's re-taken baseline) confirmed present before the run. Report `~/w7/p5-w1g-symbols.md`. This was never in doubt: everything this round touches is under `MG_Remote`, which the pull build does not compile. **(2) `ctest -L unit`, four lanes.** | lane | result | |---|---| | `build-linux` (pull) | **1814 / 1814** | | `build-push` | **1814 / 1814** | | `build-verify` | **1814 / 1814** | | `build-split` | **1980**, 1 failed — `PipeWireCodecTest.NoReplyIsWrittenForARowTheCatalogueGivesNoReplySlot` | 1975 → 1980 is **+5**, all of them mine and all in `build-split` only (the `MG_Test/Wire` directory is not configured in the other three, which is why the pull/push name lists do not move): `TierTwoUnderSplitTransportStillDeclinesRatherThanRefusing`, `AContentBlobCarriedOutsideSegStageIsFatalAtTheDecoder`, `TheEncoderRefusesTheNonStageCarrierTheDecoderCallsFatal`, `AdoptTierZeroIsFatalOnTheWirePathAndNamesP11`, `AdoptTierOneIsFatalOnTheWirePathAndNamesP11`. The one red is **the known one and is not mine** — c1's catalogue-flag conflict at `PipeWireCodecTest.cpp:1203`, ID-48's carve-out; that case was not edited. **(3) `ctest -L integration-gpu`.** ``` push integration-gpu: 100% tests passed, 0 tests failed out of 1128 split integration-gpu (MOBILEGL_TRANSPORT=monolith): 100% tests passed, 0 tests failed out of 1149 ``` Name-for-name against `~/w7/p5-before-ctest-names.txt` with `comm`, the way `wsl_p5_gate.sh:118-122` does, over `ctest -N` for every label: ``` pull removed: 0 added: 40 push removed: 0 added: 40 added by this package (pull): 0 ``` **Removed = 0 in both**, which is the G14 assertion. The 40 additions are the merged integration head's (b1 round 2 and `dev`), not this package's — none of them is a `PipeWireCodecTest` entry, because that suite exists only in `build-split`. **(4) Generators** — I touched no `.def` and no generator; run anyway. ``` gen_pipe: generated files are up to date gen_pipe: self-test: 9 negative-control trip(s), positive control OK gen_pipe_field_ownership: generated file is up to date gen_pipe_dirty_surface: --check green (its long under-firing summary in the log) ``` **G5, both scripts** (run with the submodule links **off**, since they drive git): ``` bash scripts/p3a_untouched_regions.sh ff2994d9 HEAD rc=0 172b022273db01b1… FlushPendingRangesFrom [p3a-untouched] the 11 pool / deferred-release / ring / flush-drain functions are [p3a-untouched] byte-identical between ff2994d9 and HEAD bash scripts/p4a_untouched_regions.sh ff2994d9 HEAD rc=0 [p4a-untouched] the 17 … regions are byte-identical between ff2994d9 and HEAD ``` b1's eleventh-row pin (`172b0222…`, ID-41 as amended) matches. --- ## 5. What needs an integrator ruling, or at least a decision recorded **5.1 `GetCaps`'s two blobrefs are now held to `SEG_STAGE` as well, and they are the one server→client row that owns an `MGPBlobRef`.** Contract §2 row 18 puts `MGPCaps`'s `FormatCapabilities` and `RendererInfo` in the **server → client** direction, but they are enumerated by `BlobSlotsFor(GetCaps)` and therefore walked by the encoder's honesty loop and by the decoder's `GetCaps` arm, both of which call `CheckBlobIsHonest`. **This is inert in P5**: the caps snapshot travels as a flatbuffer `CtrlEnvelope` out of `ServerSession::PublishCapsSnapshot` (`ServerSession.cpp:380`), never as record blobrefs, so nothing declares those two and the whole split unit lane is unaffected — verified, not assumed. But the phase that does carry caps in a **record** will hit this arm, and at that point either `GetCaps` is exempted by name or the catalogue grows the per-op *legal segment* column the verifier flagged as the ruling-worthy version of this fix. **Filed, not taken** — the minimal fix needed no ruling and I did not want a generated column landing in a rework round. **5.2 The tier gate carries the applier's `Transport != Monolith` conjunct, including its hole.** I mirrored `PipeApply.cpp` verbatim so the two cannot drift, which means that a decoder driven directly under **monolith** transport still skips the tier check. In production that is unreachable — a record only arrives at the decoder over a wire — and it is exactly ID-42's finding that a split build under monolith transport mints like push. Only a unit test can be in that state, and mine sets `InProcess`. If the integrator would rather the forbidden tiers die at **parse**, that is `ConfigLoader.cpp` = **c0's** file, and `PersistentMapTracker.cpp:118`'s own comment has already filed it; nothing in this round depends on the answer. **5.3 No new Fatal family.** I used `ProtocolCorruption` rather than the review's suggested `BlobNotStaged` (reasoning in §2). If the integrator wants a seventh family it is a one-line change here plus whatever in CI greps the family names — say so and I will take it. **5.4 No overlap with s1, ID-47 or the reply geometry.** Worth stating explicitly because finding 3's fix mentions `SEG_REPLY`: my refusal names `kSegReply` only as an **illegal client→server blob carrier**, and it lives in `CheckBlobIsHonest`. s1's reply-slot work writes `SEG_REPLY` through `ReplySlot` / `ReplySink::PostReply`, which carries no `MGPBlobRef` and never reaches any of these arms; ID-47 moves `SessionSegmentSizes::ReplyBytes` and `ReplySlotCount`, which none of my files reads. **No shared line, no shared symbol.** The one file s1 and w1 both have an interest in — `PipeWireCodecTest.cpp` — I touched only in my own cases. **5.5 The pre-existing red is still there and still not a package's.** `PipeWireCodecTest.NoReplyIsWrittenForARowTheCatalogueGivesNoReplySlot:1203` vs `PipeCalls.def:100`'s `kReplySlot` on `ResourceCreate`. Unchanged from the verifier's §"Pre-existing red"; ID-48 assigns the case to c1 and I left it alone. Every count above is stated with it included. --- ## 6. Corrections to `w1-v1.md` - **`:341`** — "The archive's bound is `MOBILEGL_IPC_STAGE_MB` (32 MiB)". **Was false when written** (the effective bound was `max(head mod capacity, capacity − head mod capacity)`, i.e. between half the segment and all of it, and equal to 32 MiB only on a fresh encoder). **It is true as of `1a06b40a`**, at every occupancy at which the stage is empty. §1 above carries the arithmetic, the exact number (33,554,432 bytes at the default knob) and the separate answer on R-10's max-record counter, which does **not** see staged bytes. - No other claim in `w1-v1.md` was falsified by the verifier; §10's reversal note and the var-tail table are unaffected by this round. --- ## 7. Provenance — scripts and logs, all `~/w7/p5-w1-` prefixed | file | what | |---|---| | `p5-w1-gate2.sh` / `p5-w1-gate2.log` | the gate of §4 (configure + generator/compiler proof, build, generators, G1, four unit lanes, G14 name lists, integration-gpu both arms) | | `p5-w1-redcheck2.py` / `p5-w1-redcheck2.log` | the R-16 driver: four perturbations, each rebuilt and run, each restored and re-run green. Ends `P5_W1_REDCHECK2_ALL_WENT_RED` | | `p5-w1-bt.sh` | build-one-target-then-test; **refuses to run any test when the build failed** (the verifier's stale-binary trap) | | `p5-w1-commits.py` | the three-commit split; every anchor asserted unique, every intermediate state built and smoke-tested before it was committed | | `p5-w1g-symbols.md` | the G1 symbol report | | `p5-w1g-unit-{linux,push,verify,split}.log`, `p5-w1g-igpu-{push,split-mono}.log` | the lane logs | | `p5-w1g-names-{linux,push}.txt` | the `ctest -N` name lists compared with `comm` | | `p5-w1-p3a.log` / `p5-w1-p4a.log` | G5, both untouched-region scripts, `rc=0` | | `p5-w1-final-build.log` / `p5-w1-final-unit-split.log` | the re-run on the committed tree: `1980`, the one known red | One note on the harness, since it cost a round trip: **a `<<"EOF"` heredoc does not survive `wsl.exe -- bash -lc '…'`** — the quoting is lost somewhere in the Windows argument path and the body is expanded before the file is written, so the first version of the build script wrote `cmake --build ""` and printed four empty `build rc=` lines. Every script above was written as a **file**, never as an inline command string, which is the same conclusion the verifier reached from the other direction. No LFS fetch. No adb. Nothing outside `MG_Remote/Wire` and my own cases in `MG_Test/Wire/PipeWireCodecTest.cpp`.