Files
giza-kmp/composeApp
Kgothatso NgakoandClaude Opus 5 8e1037dff1 feat(marmot): the library's engine over Room, for current-profile rooms (v2 Phase 5)
A current-profile room is now read and written by quartz's own managers:
MlsGroupManager holds its live group and persists through a store over the
app's tables, MarmotInboundProcessor reads its kind:445s -- settling same-epoch
commits through the convergence engine and recognising redelivery by the
Marmot message id -- and MarmotOutboundProcessor builds the ones this device
sends. Everything in docs/marmot-v2.md's "v2 says" column that is not a wire
shape lives in those three, and the app no longer carries its own copy of
their logic for these rooms.

Where the build chose differently from the plan: **a room's profile picks its
pipeline**. The plan had one engine for every room. Two things stood against
that once the code was open. The library's processor has no carve-out for the
bare gift wrap a legacy room carries a direct message in -- it would refuse
every legacy DM as an author that is not the sender -- and the manager's
installState declines a state whose group context matches the live one, so a
legacy path that mutates the manager's instance and then asks it to persist
would persist nothing, while its own retained-epoch list would drift from the
manager's. So legacy rooms keep MarmotInboundManager over MlsGroupCache,
unchanged, and retire with it; current-profile rooms go through MarmotEngine.
A room is on one profile for life, so the two never hold the same group, which
is what keeps the manager's live instance the single writer of a
current-profile room's state. For the same reason the library's KeyPackage
rotation manager is constructed but not fed: Welcomes are matched to this
device's bundles by the app's own profile-aware table, by reference, and the
processor reads the rotation manager only on its own Welcome path. The
vendored CommitOrdering therefore stays, for legacy rooms.

RoomMlsGroupStateStore resolves the library's key -- the routing address --
through MarmotRouting to the room, keeps the state in ChatRoom.mlsGroupState
as before, and keeps the retained epochs as MarmotRetainedEpochSecret rows,
which until now were written by the outbound path and read back by nothing:
every epoch the inbound path retained was a map in an object, gone at the next
launch. The engine is owned by the database (CurareDatabase.marmotEngine),
because the DAOs that need it are made by Room from that instance and can be
handed nothing else; it restores every group once, seeds convergence with each,
and loads a room made or joined later from its row on first ask.

Inbound, NostrDao.indexMarmotGroupEvent branches on ChatRoom.marmotProfile()
-- read off the stored state's group context without rebuilding the group --
and the result handling every kind:445 shares (membership changes, the chat
line, the signing and ceremony dispatch) is one function for both pipelines.
The processor names the group by its address; the result is re-addressed to
the room once. A pass a commit opened is driven to its cutoff by a ticking
coroutine, since a quiet group has nothing else to drive it. Outbound, an
application message in a current-profile room is built by the outbound
processor over the engine's group, and an invite or batched add is staged on a
clone by the manager and installed at once -- retained, persisted -- with the
callers' own state writes skipped for these rooms; installing on a relay's OK
rather than at once is what Phase 6 changes. A reindex closes the room's open
convergence pass before replaying.

Tests: CurrentProfileInteropJvmTest puts two implementations in one group --
the app's engine over a CurareDatabase and a bare library stand-in playing
Amethyst -- and has the stand-in invite the app through a gift-wrapped Welcome,
messages cross in both directions (the app's read by the stand-in as a
canonical payload), a commit from the other side move the room's membership
and epoch, and a second engine over the same database read a message from the
epoch before that commit -- the case the old pipeline could not pass.
RoomMlsGroupStateStoreJvmTest pins the store's contract. Full JVM suite: 1,175
tests pass.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-13 23:20:02 +02:00
..