Files
giza-kmp/composeApp/schemas/to.curare.compose.database.CurareDatabase
Kgothatso NgakoandClaude Opus 5 f617560cf9 feat(marmot): publish before apply (v2 Phase 6)
A commit this device makes into an established current-profile room is no
longer applied and then broadcast. It is prepared on a clone by the manager,
recorded as a durable obligation before anything is broadcast, sent, and
installed only when a relay in its scope accepts it. docs/marmot-v2.md, Phase 6.

The library's gate explains why apply-and-roll-back is not the same thing:
between applying a local commit and undoing it on failure there is a window in
which this client's canonical state is an epoch no peer has, and a crash inside
it makes the fork permanent. Recording the obligation before the broadcast
closes the mirror-image window -- a commit peers accepted that this device has
no memory of preparing, and would mint a replacement for at the next start.

Two new tables (schema 22 -> 23), MarmotPublishObligation and MarmotOutboundGate,
back RoomPublishObligationStore; MarmotEngine holds a MarmotPublishGate over it
and restores it after the groups. MarmotCommitResult -- the row that already
held a commit's Welcome until the relay's OK -- carries the obligation id, and
DatabaseNostrRepository.broadcastProcessed resolves it on "published" through
MarmotEngine.confirmPublished, which installs the pending state, tells
convergence of the commit we authored (without which a peer's competing commit
would look like an orphan rather than a fork we are half of), and only then
lets the Welcome go out: the MIP-02 ordering enforced by sequence rather than by
hope. A second OK for the same event from another relay finds no obligation
and changes nothing.

The founding Add keeps its exception. A group that is only its creator has no
peer a failure to publish could fork, so it installs at once -- the library's
satisfyEmptyObligation draws the same line, "creation and its immediately
following founding Add, never a later commit". While an obligation is pending
the room cannot prepare another commit: a second invite is refused with
MarmotCommitPendingException, shown as itself on the confirmation screen, rather
than forked; the membership note's batching closed the race inside one invite,
and this closes it between invites. The broadcast queue's requeue re-sends the
same signed event, which is the byte-identical retry the rule demands, and a
"failed" from the pump -- a timeout or a relay's refusal, which the pump does
not tell apart -- leaves the obligation pending rather than discarding a state
some relay may have taken. Legacy rooms are unchanged.

Tests: PublishBeforeApplyJvmTest pins the founding Add installing at once, a
later commit prepared and queued but not applied, the second Welcome held back,
a concurrent invite refused, the OK installing the state and queueing the
Welcome, a second OK changing nothing, and an obligation restored by an engine
rebuilt over the same database and installed by a late OK. Full JVM suite:
1,177 tests pass.

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