feat(marmot): add Reset Marmot State safety valve in settings

Gives users a last-resort "nuclear" option when Marmot local state is
corrupted or otherwise unrecoverable — wipes every MLS group, retained
epoch secret, persisted KeyPackage bundle, subscription and in-memory
chatroom for the current account. Does not broadcast leave/SelfRemove
commits, since a graceful teardown may be impossible in exactly the
scenarios where users reach for this option. The KeyPackage is
republished lazily on the next sync so the account stays reachable.

Adds clearAllState() helpers on MlsGroupManager and
KeyPackageRotationManager, a resetAllState() orchestrator on
MarmotManager, an Account.resetMarmotState() entry point, and a
destructive row + confirm dialog in the AllSettingsScreen Danger Zone
that mirrors the existing Request-to-Vanish pattern.

https://claude.ai/code/session_01Unm6uLHGLj9UcBY7hWfJVW
This commit is contained in:
Claude
2026-04-23 20:08:26 +00:00
parent 647d6f9841
commit 61c01981cc
7 changed files with 206 additions and 0 deletions
@@ -295,6 +295,36 @@ class MarmotManager(
return nostrGroupId
}
/**
* Nuke all local Marmot state — every MLS group, every retained epoch
* secret, every persisted KeyPackage bundle, and every relay
* subscription. Does NOT publish any leave/SelfRemove commits: the
* reset path is specifically for recovering from corrupted or
* unrecoverable local state where graceful teardown may be impossible.
*
* The caller is responsible for wiping any higher-level in-memory
* structures (e.g. `MarmotGroupList`) and for re-publishing a fresh
* KeyPackage once the reset completes, if the account is still active.
*/
suspend fun resetAllState() {
Log.w("MarmotManager") { "resetAllState(): wiping all Marmot local state for ${signer.pubKey.take(8)}" }
try {
groupManager.clearAllState()
} catch (e: Exception) {
Log.w("MarmotManager", "resetAllState(): groupManager.clearAllState failed: ${e.message}")
}
try {
keyPackageRotationManager.clearAllState()
} catch (e: Exception) {
Log.w("MarmotManager", "resetAllState(): keyPackageRotationManager.clearAllState failed: ${e.message}")
}
try {
subscriptionManager.clear()
} catch (e: Exception) {
Log.w("MarmotManager", "resetAllState(): subscriptionManager.clear failed: ${e.message}")
}
}
/**
* Leave a group.
* Returns proposal bytes to publish (as a GroupEvent).