fix(frost): resume a session whose own turn was cut short

Every step a session takes is driven by a message arriving, and a device
killed part way through its own pass is waiting on one that has already
been delivered. The signer set is recorded, so it will never be processed
again; the partial signature it would have produced was never made. The
coordinator asking again cannot reach past it either -- what a resend
asks a member for is the message this device believes it already sent --
so the session is a dead end on both sides, and in a room with several
open proposals it is the one that was mid-pass that stops.

So one sweep that no message drives: on opening a room, every session in
it that is not settled and whose owner has answered is handed to
`advance`, which does what it always does. It publishes nothing new --
each step asks whether its output exists rather than whether a stage says
it ran -- and only answered sessions are passed in, so the approval gate
is not approached, let alone reached past. A refusal counts as an answer
for the same reason: a device killed between deciding and publishing says
it on the next open rather than never.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Kgothatso NgakoandClaude Opus 5 committed 2026-10-08 14:33:13 -05:00
1 parent 1e59fd2334
commit a9532ff115
5 files changed
+229 -1

No files matched your search

@@ -138,6 +138,17 @@ class DatabaseFrostSigningRepository(
emptySet()
}
override suspend fun resumeAnswered(localChatRoom: LocalChatRoom) {
try {
FrostSigningManager.resumeAnswered(database = database, localChatRoom = localChatRoom)
} catch (e: Throwable) {
// Each session already settles its own failure inside `advance`, so
// anything reaching here is the sweep itself, and a repair that
// takes the room down with it is worse than one that did not happen.
logger.e("Error resuming signing sessions in ${localChatRoom.chatRoom.id}", e)
}
}
override suspend fun approve(localChatRoom: LocalChatRoom, sessionId: String) {
try {
FrostSigningManager.approve(
@@ -2119,6 +2119,52 @@ object FrostSigningManager {
return asked - answered - session.userPublicKey
}
/**
* Takes every answered session in a room as far as its stored messages now
* allow. The one thing here that no message drives.
*
* Being message-driven is this manager's whole shape, and it is not quite
* enough on its own. A pass of [advance] is where a device publishes its
* nonce and its partial signature, and a device killed part way through one
* -- the coordinator's signer set recorded, the signature not yet made --
* has nothing left to wake it. The message that would have is already filed,
* so it is never processed again; and the coordinator's [resend] cannot
* reach past that either, because what it asks a quiet member for is a
* message this device believes it has already sent.
*
* **It publishes nothing new.** [advance]'s own gates decide what goes out,
* and each asks whether a message exists rather than whether a stage says it
* ran, so a session with nothing outstanding takes no steps at all. Only
* sessions whose owner has answered are passed in, so this cannot put this
* device's material behind events nobody agreed to: the approval gate is the
* one thing a resume must not reach past, and this does not come near it.
*
* A refusal is an answer too, and resumes for the same reason: a device
* killed between deciding and publishing says it on the next pass rather
* than leaving the group waiting on a member who has already made up their
* mind.
*/
suspend fun resumeAnswered(database: CurareDatabase, localChatRoom: LocalChatRoom) {
val answered = database.frostSigningSessionDao()
.getSessionsForChatRoom(localChatRoom.chatRoom.id)
.filter { session ->
session.stage != FrostSigningStage.COMPLETE &&
session.stage != FrostSigningStage.FAILED &&
(session.signApprovedAt != null || session.signDeclinedAt != null)
}
if (answered.isEmpty()) return
logger.i(
"Resuming ${answered.size} answered signing session(s) in " +
localChatRoom.chatRoom.id
)
// One at a time, and one failing does not stop the rest: [advance]
// settles its own session's failure and returns.
answered.forEach { session -> advance(database, localChatRoom, session.id) }
}
/**
* Re-publishes the messages *this* device authored for a session, because
* the coordinator says it never received them.
@@ -162,6 +162,18 @@ interface FrostSigningRepository {
*/
suspend fun membersOwing(session: FrostSigningSession): Set<HexKey>
/**
* Takes every session in a room whose owner has answered as far as its
* stored messages allow, for the steps no arriving message will drive.
*
* A device killed part way through a session's turn -- the signer set
* recorded, its own partial signature not yet published -- is waiting on a
* message that has already been delivered and will not arrive twice. This is
* what gets it moving again, and it publishes nothing its owner has not
* already agreed to.
*/
suspend fun resumeAnswered(localChatRoom: LocalChatRoom)
/** Agrees to sign, letting the session publish this device's part and run on. */
suspend fun approve(localChatRoom: LocalChatRoom, sessionId: String)
@@ -232,6 +244,8 @@ interface FrostSigningRepository {
override suspend fun membersOwing(session: FrostSigningSession): Set<HexKey> = emptySet()
override suspend fun resumeAnswered(localChatRoom: LocalChatRoom) = Unit
override suspend fun approve(localChatRoom: LocalChatRoom, sessionId: String) = Unit
override suspend fun decline(localChatRoom: LocalChatRoom, sessionId: String) = Unit
@@ -202,6 +202,7 @@ class ChatMessageListViewModel(
observeProposalsAwaitingYou()
observeCeremoniesAwaitingYou()
askForGroupHistory()
resumeSigningSessions()
}
/**
@@ -301,6 +302,28 @@ class ChatMessageListViewModel(
}
}
/**
* Lets this room's answered signing sessions take any step they are able to.
*
* Everything else in a session moves on a message arriving, and a device
* killed part way through its own turn is waiting on one that has already
* been delivered: the signer set is filed, so it will not be processed
* twice, and the coordinator asking again cannot help, because what it asks
* a quiet member for is the partial signature this device believes it sent.
* Opening the room is the next moment the app has.
*
* Cheap to call every time, and safe to: the manager publishes nothing that
* is already on file and touches no session whose owner has yet to answer.
* See `FrostSigningRepository.resumeAnswered`.
*/
private fun resumeSigningSessions() {
viewModelScope.launch(Dispatchers.IO) {
runCatching {
frostSigningRepository.resumeAnswered(localChatRoom)
}.onFailure { logger.w(throwable = it) { "Could not resume this room's signing sessions" } }
}
}
fun observeChatRoomFeed() {
logger.d("observeChatRoomFeed")
viewModelScope.launch(Dispatchers.IO) {