fix: a member invited into a keyed room says it follows signed commits on joining

An invited member of a robust group could never be made an admin. Making
one needs the room to require the group's signature, which waits until
every member's device has said it follows signed commits. A device said
so when the room's screen was opened, or back when it heard another say
it -- but the founders said it before the invite, at an epoch the new
member cannot read, so it heard nothing, nobody said it again, and the
room waited on a screen the member had no reason to open.

A device now says it on joining (the Welcome path) and once each start
(GovernanceSupport.announceAll), for members who joined before this.
The waiting notice names who the room waits on and what for, instead of
"X need to update Giza".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kgothatso NgakoandClaude Opus 5.5 committed 2026-11-20 09:01:14 +02:00
1 parent aa4c8eba05
commit 6aae56520b
8 files changed
+125 -5

No files matched your search

@@ -127,7 +127,7 @@
<string name="governance_on">Changes to who is in this group need the group's signature. It always keeps at least %1$d admins.</string>
<string name="require_signatures">Require the group's signature for changes</string>
<string name="require_signatures_explainer">From then on, adding or removing a member, or changing who the admins are, is proposed and has to be signed by the group before it happens.</string>
<string name="governance_waiting">Before changes can need the group's signature, %1$s need to update Giza.</string>
<string name="governance_waiting">Waiting for %1$s to open an up-to-date Giza. Until then, this group can't require its signature on changes, and nobody else can be made an admin.</string>
<string name="make_admin_body_keyed">They'll be asked to accept, then the group signs it, and they'll hold a share of the group's key and be asked to approve its changes.</string>
<string name="remove_as_admin_body_keyed">Once the group signs it, they stay in the group as a member and their share of the group's key is rotated away.</string>
<string name="admin_offer_sent">Asked; they become an admin once they accept and the group signs it</string>
@@ -921,6 +921,15 @@ abstract class NostrDao(
mlsGroup = group,
)
// That this device follows signed commits, said on
// joining. It cannot read the others saying it -- that
// was before its epoch -- so it would never answer, and
// the room would wait on it until its screen was opened.
// docs/remove-convenient-groups.md, "After the build".
if (group.currentGroupState().isCurrentProfile) {
GovernanceSupport.announce(database, nostrGroupId, group, userPublicKey)
}
// Save ChatRoom Relays...
participants.filter { it.participantPublicKey != userPublicKey }.forEach { participant ->
val publicKey = participant.participantPublicKey
@@ -145,6 +145,8 @@ class DatabaseChatRepository(
override suspend fun reconcileAdminFlags(): Int = AdminFlags.reconcileAll(database)
override suspend fun announceGovernanceSupport(): Int = GovernanceSupport.announceAll(database)
override suspend fun followThroughCeremonies(keyPair: KeyPair) = kotlinx.coroutines.coroutineScope {
launch { CeremonyFollowThrough.observe(database = database, chatRepository = this@DatabaseChatRepository, keyPair = keyPair) }
// What a governed room's signed changes need after they land: a rotation
@@ -1,11 +1,13 @@
package mobi.giza.compose.managers
import co.touchlab.kermit.Logger
import com.vitorpamplona.mls.group.MlsGroup
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
import kotlin.time.Clock
import kotlin.time.Instant
import mobi.giza.compose.database.GizaDatabase
import mobi.giza.compose.nostr.MarmotProfile
import mobi.giza.compose.database.model.MarmotInnerEvent
import mobi.giza.compose.nostr.frost.GovernanceSupportEvent
@@ -16,9 +18,15 @@ import mobi.giza.compose.nostr.frost.GovernanceSupportEvent
* The rule cannot be switched on while anybody in the room would be left behind
* by it: a device that does not know it applies the bare commits Giza drops and
* reads none of the envelopes, and is in a different group from the first change.
* So each device says, once per room, that it can follow -- and says it back when
* it hears another say it, which is how a member who never opens the room's screen
* still gets counted.
* So each device says, once per room, that it can follow: when it is welcomed in,
* when it starts, when the room's screen is opened, and back when it hears another
* say it.
*
* Joining has to be one of them. A member invited after the others said it cannot
* read what they said -- it was sent at an epoch before theirs -- so it never hears
* anybody to answer, and nobody says it again. Until it opened the room's screen
* the room waited on it, and nobody could be made an admin. See
* docs/remove-convenient-groups.md, "After the build".
*/
object GovernanceSupport {
@@ -59,4 +67,27 @@ object GovernanceSupport {
)
return true
}
/**
* [announce] for every room this device is in, for the members who joined
* before joining was one of the times it is said. Once per start, and a read
* with no write for a room that has it already. One room that will not open is
* logged and passed over.
*
* @return how many rooms it was said in now.
*/
suspend fun announceAll(database: GizaDatabase): Int =
database.chatRoomDao().getChatRoomIdsWithMlsState().count { chatRoomId ->
runCatching {
val room = database.chatRoomDao().findChatRoomById(chatRoomId) ?: return@runCatching false
if (room.chatRoom.leftGroupAt != null || room.chatRoom.marmotProfile() != MarmotProfile.CURRENT) return@runCatching false
val group = database.marmotEngine.groupFor(room.routingId) ?: return@runCatching false
announce(database, chatRoomId, group, room.chatRoom.userPublicKey)
}.getOrElse {
logger.e("Could not say $chatRoomId follows signed commits", it)
false
}
}
private val logger = Logger.withTag("GovernanceSupport")
}
@@ -256,6 +256,13 @@ interface ChatRepository {
*/
suspend fun reconcileAdminFlags(): Int
/**
* Says, in every keyed room this device is in, that it follows signed commits,
* for the rooms joined before joining said it. Once per start. See
* `GovernanceSupport.announceAll`.
*/
suspend fun announceGovernanceSupport(): Int
/**
* Takes every key ceremony [keyPair] coordinated from a key to a working room,
* until cancelled: asks the group to sign its key state (a subgroup's parent to
@@ -588,6 +595,8 @@ interface ChatRepository {
override suspend fun reconcileAdminFlags(): Int = 0
override suspend fun announceGovernanceSupport(): Int = 0
override suspend fun sendChatMessage(
text: String,
@@ -255,6 +255,12 @@ class SynchronizationViewModel(
// written. docs/robust-group-admins.md, Phase 6.
runCatching { chatRepository.reconcileAdminFlags() }
.onFailure { logger.e("Could not bring admin flags in line", it) }
// A member who joined a keyed room before joining said it
// follows signed commits, and never opened its screen, holds
// the room back from requiring them -- and so from making
// anyone an admin. docs/remove-convenient-groups.md.
runCatching { chatRepository.announceGovernanceSupport() }
.onFailure { logger.e("Could not say which rooms this device follows", it) }
launch(Dispatchers.IO) { observePendingBroadcastNostrEventRequests(keyPair) }
// Runs until cancelled rather than draining a queue, but it
// belongs here for the same reason the pumps do: it needs the
@@ -264,10 +264,38 @@ class GovernanceGateJvmTest {
return event.toGroupEvent(userHex)!!
}
/** Takes back what this device said, as a device that joined before joining said it. */
private suspend fun forgetOurSupport() {
db.marmotInnerEventDao().getByChatRoomAndKinds(roomId, listOf(GovernanceSupportEvent.KIND))
.filter { it.publicKey == userHex }
.forEach { db.marmotInnerEventDao().deleteById(it.id) }
assertFalse(userHex in GovernanceSupport.supporters(db, roomId))
}
@Test
fun `a member welcomed into a keyed room says it on joining`() = runBlocking {
// Nobody else says anything after the Welcome: what the others said before it
// is at an epoch this device cannot read. docs/remove-convenient-groups.md.
governedRoom(governed = false)
assertTrue(userHex in GovernanceSupport.supporters(db, roomId), "joining did not say it")
assertEquals(setOf(dana.hex), GovernanceSupport.missing(db, roomId, appGroup()))
}
@Test
fun `a device that joined before joining said it says it when it starts`() = runBlocking {
governedRoom(governed = false)
forgetOurSupport()
assertEquals(1, chatRepository.announceGovernanceSupport())
assertTrue(userHex in GovernanceSupport.supporters(db, roomId))
assertEquals(0, chatRepository.announceGovernanceSupport(), "said twice")
}
@Test
fun `hearing another member say it, this device says it back`() = runBlocking {
governedRoom(governed = false)
assertFalse(userHex in GovernanceSupport.supporters(db, roomId))
forgetOurSupport()
says(dana)
+35
View File
@@ -389,6 +389,41 @@ detail screen, and a Bennu peer's convenient group still reaches them.
they were written. Add a parenthetical saying it was removed here.
- [README.md](./README.md): the table row, which this commit adds, says "built".
### After the build: an invited member holds the group back
Found on a device, with this plan merged alongside member-admin-promotion. A robust
group's founders were admins holding shares; a member invited afterwards (D7 lets a
keyed room take one) was a plain member, as designed. But nobody could make them an
admin: the ⋮ on their row offered only **Remove from group**, and the room said it was
waiting for them to update Giza when they already had.
Making a member of a keyed room an admin needs the room to require the group's
signature (`AdminGovernance.keyedChangesAllowed`), and that can be switched on only
once every member's device has said it follows signed commits
(`GovernanceSupport.missing`). A device said it when its room's screen was opened, and
back when it heard another member say it. The founders had all said it before the
invite, and an invited member cannot read anything sent at an epoch before its own --
so it never heard one to answer, nobody said it again, and the room waited on a
screen the member had no reason to open.
- **A device says it on joining.** The Welcome path in `NostrDao`, beside
`AdminFlags.reconcile`, for a current-profile room.
- **And once each start** (`GovernanceSupport.announceAll`, from
`SynchronizationViewModel` beside `reconcileAdminFlags`), for the members who joined
before joining said it. A room that has it already is a read and no write.
- **The notice** (`governance_waiting`) names who the room is waiting on and what for --
"Waiting for Alice to open an up-to-date Giza. Until then, this group can't require
its signature on changes, and nobody else can be made an admin." -- instead of
telling them to update, which they often had, with a verb that did not agree with
one name.
Pinned in `GovernanceGateJvmTest`: a welcomed member has said it before anybody else
speaks, and a device whose saying is taken back says it again at start, once.
Once nobody is outstanding an admin still taps **Require the group's signature for
changes**, and the room's share rotation has to be on (a development build). Then the
member's row offers **Make admin**, and the member accepts on their own device.
## Out of scope
- **One-to-one chats** (D1). If they are to become robust, that needs its own plan.