feat(proposals): ask again about everything the filter is showing

The bulk control I argued against, built -- and the objection turned out to be
solvable rather than fatal, so it is worth recording what happened to it.

Half of it was already handled. Two resends in the same second do not collide
on the outbound row id: `broadcast` hashes that id over the session's own tags
and steps a second forward when it finds a collision rather than overwriting.
Different sessions were never at risk.

The other half was real. A resend publishes two messages, and `resend` keeps to
two deliberately because "publishing in bursts is what the skipped-keys bug
feeds on"; three proposals at once is six, in the same second that "two events
published in the same second race, and exactly one survives" was written about.
So the sessions are spaced rather than the budget quietly raised --
`resendAll` waits `RESEND_SPACING` between them, one second, which is the
resolution the protocol works in because `created_at` is stored to the second.

The pacing lives in the manager and not in the loop that wanted it, because
everything that justifies it does: MLS generations, relay ordering, outbound
ids. A caller that launched `resend` per session would put every burst into one
second, and the call site is the wrong place to know why that matters. There is
a test against the real manager that three sessions take longer than two
spacings and claim three different seconds.

What it acts on is `visible`, not the room: a bulk control reaching rows the
reader cannot see is its one unforgivable move. A cooling-down row is left out
of the count rather than included and skipped, because the count is what the
button says out loud and offering three while able to send two is a lie told
before the tap. Offered from two up: one is what the row's own button is for.

Every covered row goes quiet for the whole run rather than for its own turn --
a paced run means a row whose turn has not come is still about to publish, and
a row button offering to send it meanwhile would send it twice. A session
already in flight on its own is left out of the run for the same reason.

It is offered on any filter showing two it can act on, not only "being signed".
That filter is where it earns its place -- three rows stalled for one reason --
but the rule is about what is on screen, not about which chip put it there.

1419 jvm tests pass, the Android target compiles, all audit budgets met.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Kgothatso NgakoandClaude Opus 5 committed 2026-10-08 16:04:13 -05:00
1 parent 4330d718be
commit 72cfb561c4
11 files changed
+705 -1

No files matched your search

@@ -238,6 +238,7 @@
<string name="shared_key">Shared key</string>
<string name="signed">Signed</string>
<string name="signing_key">Signing key</string>
<string name="some_proposals_had_already_settled">Some had already settled, so not every one was asked again.</string>
<string name="the_key_this_room_signs_as">The key this room signs as, and the ceremony it came from.</string>
<string name="what_the_group_signed">What the group signed</string>
<string name="this_room_signs_as">This room signs as</string>
@@ -348,6 +349,8 @@
<string name="add_chapter_to">Add chapter to %1$s</string>
<string name="add_people_to">Add people to %1$s</string>
<string name="ask_all_again">Ask all %1$s again</string>
<string name="asked_again_about_all">Asked again about all %1$s proposals</string>
<string name="chapter">Chapter %1$s</string>
<string name="chapter_words_characters">Chapter %1$s · %2$s words · %3$s characters</string>
<string name="chunk">Chunk %1$s</string>
@@ -141,6 +141,24 @@ class DatabaseFrostSigningRepository(
false
}
override suspend fun resendAll(
localChatRoom: LocalChatRoom,
sessionIds: List<String>
): Int = try {
FrostSigningManager.resendAll(
database = database,
localChatRoom = localChatRoom,
sessionIds = sessionIds
)
} catch (e: Throwable) {
// Zero rather than rethrown, as a single resend swallows and for the
// same reason. Whatever went out before the throw is already out; what
// this loses is the count, and a repair that takes the screen down with
// it is worse than one that undercounted.
logger.e("Error asking again about ${sessionIds.size} signing session(s)", e)
0
}
override suspend fun membersOwing(session: FrostSigningSession): Set<HexKey> = try {
FrostSigningManager.membersOwing(database = database, session = session)
} catch (e: Throwable) {
@@ -23,7 +23,9 @@ import kotlin.time.Clock
import kotlin.time.Duration
import kotlin.time.Instant
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.delay
import to.curare.compose.database.CurareDatabase
import to.curare.compose.database.model.ChatMessage
import to.curare.compose.database.model.DkgSession
@@ -177,6 +179,24 @@ object FrostSigningManager {
*/
val RESEND_COOLDOWN: Duration = 5.minutes
/**
* How long [resendAll] waits between one session and the next.
*
* A resend publishes two messages, which is a burst the room is known to
* survive -- `MlsGroupCache` covers a burst decrypted in one sync, and
* [resend] keeps to two deliberately for that reason. Asking again about
* three proposals at once is six, outside the budget somebody set with a bug
* attached to it, so the sessions are spaced instead of the budget being
* quietly raised.
*
* One second because that is the resolution the protocol works in.
* `created_at` is stored to the second, relays offer no ordering, and "two
* events published in the same second race, and exactly one survives" is how
* a proposal was lost once already -- see `MlsGroupCache`. A second between
* sessions puts each one's pair in a second of its own.
*/
val RESEND_SPACING: Duration = 1.seconds
/**
* The kinds a member authors for a session, and so the ones [republishOwn]
* may repeat. Everything else on the session is the coordinator's.
@@ -1940,6 +1960,42 @@ object FrostSigningManager {
* have been published against an aggregate already, so the retry is a fresh
* proposal and never this one again -- which is what [fail] tells the group.
*/
/**
* Asks again about several sessions, one after another, and says how many
* actually published.
*
* One at a time and spaced, which is the whole reason this is here rather
* than a loop at the call site: a caller that launched [resend] per session
* would put every one of their two-message bursts into the same second, and
* the room's tolerance for that is the thing `MlsGroupCache` documents the
* limits of. See [RESEND_SPACING].
*
* A session that publishes nothing is stepped over rather than stopping the
* run -- a cooldown that has not expired, or one that turns out to be
* waiting on nobody, is a reason to skip it and not to abandon the others.
* The count returned is of the ones that went out, so a caller can say "two
* of three" rather than claiming all of them.
*/
suspend fun resendAll(
database: CurareDatabase,
localChatRoom: LocalChatRoom,
sessionIds: List<String>
): Int {
var sent = 0
sessionIds.forEachIndexed { index, sessionId ->
// Before, not after, so the last session is not followed by a pause
// nobody is waiting through.
if (index > 0) delay(RESEND_SPACING)
if (resend(database, localChatRoom, sessionId)) sent++
}
logger.i("Asked again about $sent of ${sessionIds.size} session(s)")
return sent
}
suspend fun resend(
database: CurareDatabase,
localChatRoom: LocalChatRoom,
@@ -166,6 +166,19 @@ interface FrostSigningRepository {
*/
suspend fun resend(localChatRoom: LocalChatRoom, sessionId: String): Boolean
/**
* Asks again about several sessions, spaced out, and says how many published.
*
* One call rather than a loop over [resend], because the spacing is the
* point: every resend is a two-message burst, and launching several at once
* would put all of them in one second -- which is how a proposal was lost
* once already. See `FrostSigningManager.RESEND_SPACING`.
*
* A session that publishes nothing is stepped over, not a reason to abandon
* the rest, so the count returned may be less than the list given.
*/
suspend fun resendAll(localChatRoom: LocalChatRoom, sessionIds: List<String>): Int
/**
* The share holders a session is still waiting on, as the manager counts
* them -- who has said nothing while it collects nonces, and which chosen
@@ -262,6 +275,11 @@ interface FrostSigningRepository {
sessionId: String
): Boolean = false
override suspend fun resendAll(
localChatRoom: LocalChatRoom,
sessionIds: List<String>
): Int = 0
override suspend fun membersOwing(session: FrostSigningSession): Set<HexKey> = emptySet()
override suspend fun resumeAnswered(localChatRoom: LocalChatRoom) = Unit
@@ -65,6 +65,9 @@ import to.curare.compose.ui.theme.spacing
import curare.composeapp.generated.resources.Res
import org.jetbrains.compose.resources.stringResource
import curare.composeapp.generated.resources.abandoned
import curare.composeapp.generated.resources.some_proposals_had_already_settled
import curare.composeapp.generated.resources.asked_again_about_all
import curare.composeapp.generated.resources.ask_all_again
import curare.composeapp.generated.resources.everyone_has_signed_this_session
import curare.composeapp.generated.resources.asked_again_to_sign
import curare.composeapp.generated.resources.asked_again_recently
@@ -190,6 +193,23 @@ fun ProposalListScreen(
val askedToSign = stringResource(Res.string.asked_again_to_sign)
val nobodyLeft = stringResource(Res.string.everyone_has_signed_this_session)
// Parameterised only on the count the composition already
// knows -- how many were asked about -- so both are read here
// with the rest. How many of them went out is not known until
// the run finishes, and the one message that would want it is
// for a case rare enough to say in words: a proposal settles
// between the tap and its turn only if somebody else's
// signature lands in that second.
val askedAbout = state.askableVisible.size
val askedAll = stringResource(Res.string.asked_again_about_all, askedAbout)
val someSettled = stringResource(Res.string.some_proposals_had_already_settled)
val onAskAll: () -> Unit = {
proposalListViewModel.askAllAgain { sent, of ->
notify(if (sent == of) askedAll else someSettled)
}
}
val askAgain: (ProposalListUIState.Proposal) -> Unit = { proposal ->
val signing = proposal.state == ProposalState.BEING_SIGNED
@@ -236,6 +256,21 @@ fun ProposalListScreen(
)
}
// Under the chips, because what it acts on is what the
// chips chose. From two up: one is what the row's own
// button is for, and a bulk control over a single
// proposal is a second way to do one thing, further from
// the row it affects.
if (state.canAskAll) {
AskAllAgainButton(
count = askedAbout,
asking = state.askableVisible.any {
proposalListViewModel.isAsking(it.session.id)
},
onAskAll = onAskAll
)
}
ProposalList(
state = state,
onOpen = open,
@@ -603,6 +638,38 @@ private fun ProposalCard(
}
}
/**
* Asks again about every proposal the filter has in front of the reader.
*
* The bulk form of the row's own button, and it earns its place on exactly the
* screen the filters made: "being signed" with three rows in it is three
* proposals stalled for the same reason, and asking about them one at a time is
* three taps to say one thing.
*
* It says how many, because that is how many publishes the tap causes. The run
* itself is paced a second apart -- see `FrostSigningManager.RESEND_SPACING` --
* so what the button starts is not a burst, and the rows it covers go quiet
* together for its duration rather than one at a time.
*/
@Composable
private fun AskAllAgainButton(
count: Int,
asking: Boolean,
onAskAll: () -> Unit,
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = MaterialTheme.spacing.containerPadding),
) {
TextButton(enabled = !asking, onClick = onAskAll) {
Icon(Icons.Default.Campaign, contentDescription = Decorative)
Spacer(modifier = Modifier.width(MaterialTheme.spacing.itemGap))
Text(stringResource(Res.string.ask_all_again, count))
}
}
}
/**
* Asks the members a proposal is still waiting on to take another look.
*
@@ -228,6 +228,50 @@ class ProposalListViewModel(
}
}
/**
* Asks again about every visible proposal that can be, one after another.
*
* The list of sessions comes from the state rather than from the caller, so
* what goes out is what the filter had in front of the reader when they
* tapped -- a bulk control that acted on rows somebody could not see would
* be the one thing it must never do.
*
* Each session is marked pending for the whole run, not just for its own
* turn. The run is paced -- see `FrostSigningManager.RESEND_SPACING` -- so a
* row whose turn has not come yet is still a row that is about to publish,
* and a button offering to send it separately in the meantime would send it
* twice.
*
* [onResult] is told how many went out and how many were tried. They differ
* when a session stopped being askable between the tap and its turn, which a
* paced run leaves room for: somebody else's signature can land in that
* second and settle it.
*/
fun askAllAgain(onResult: (sent: Int, of: Int) -> Unit) {
val state = proposalListUIState as? ProposalListUIState.Loaded ?: return
val sessionIds = state.askableVisible
.map { it.session.id }
.filterNot { it in pending }
if (sessionIds.isEmpty()) return
pending.addAll(sessionIds)
viewModelScope.launch(Dispatchers.IO) {
val sent = frostSigningRepository.resendAll(
localChatRoom = state.localChatRoom,
sessionIds = sessionIds
)
pending.removeAll(sessionIds.toSet())
viewModelScope.launch(Dispatchers.Main) {
onResult.invoke(sent, sessionIds.size)
}
}
}
/** Whether an ask for this session is still in flight. */
fun isAsking(sessionId: String): Boolean = sessionId in pending
@@ -64,6 +64,31 @@ sealed interface ProposalListUIState {
val counts: Map<ProposalState, Int> = ProposalState.entries.associateWith { state ->
proposals.count { it.state == state }
}
/**
* The rows on screen that one tap could ask again about.
*
* Drawn from [visible] and not from [proposals], because the offer is to
* ask again about *these* -- the ones the filter put in front of the
* reader. Asking about proposals they cannot see would be the bulk
* control's one unforgivable move.
*
* A proposal inside its cooldown is left out rather than included and
* skipped. `resend` would decline it harmlessly either way, but the
* count is what the button says out loud, and a button offering three
* when it can only send two is a button that lies before it is pressed.
*/
val askableVisible: List<Proposal> =
visible.filter { it.canAskAgain && it.askAgainAt == null }
/**
* Whether to offer asking about all of them at once.
*
* Two, because one is what the row's own button is for: a bulk control
* over a single proposal is a second way to do the same thing, in a
* place further from the row it affects.
*/
val canAskAll: Boolean = askableVisible.size >= 2
}
/**