diff --git a/.agents/features/client-state.md b/.agents/features/client-state.md index 573ca56..4155ddc 100644 --- a/.agents/features/client-state.md +++ b/.agents/features/client-state.md @@ -86,7 +86,10 @@ The F21 calls stay, for apps and tests without persistence: `send` = `compose` + 8. **The relay fails:** `finish` acknowledges nothing when delivering fails (an app without an outbox depends on that). A `receive` whose relay fails part-way returns what it processed, because the client's state already includes it. -9. **A used welcome mailbox is no longer fetched**, even after a restart. +9. **A used welcome mailbox is no longer fetched**, even after a restart. Neither is a forgotten + invite's: `forget_invite(id)`, which the app calls when an invite is cancelled or older than the + relay's 7 days (the library has no clock). Without it an unclaimed invite's mailbox is fetched + for ever. Planted bugs, for the review: `receive` acknowledges inside the call; `compose` posts; `restore` skips the storage map; `finish` acknowledges before it delivers; a restored client starts diff --git a/crates/client/src/lib.rs b/crates/client/src/lib.rs index c68c5ef..e7b0b1b 100644 --- a/crates/client/src/lib.rs +++ b/crates/client/src/lib.rs @@ -294,6 +294,13 @@ impl Client { Ok(invite) } + /// Stops fetching an invite's welcome mailbox: the invite was cancelled, or is older than the + /// relay keeps unclaimed invites (7 days; the app has the clock, the library has none). + /// Otherwise an unclaimed invite's mailbox is fetched for ever. Save the snapshot after it. + pub fn forget_invite(&mut self, invite: &InviteId) { + self.welcome_boxes.retain(|w| w.invite != *invite); + } + /// Step 2, on the other device, staged: claims the KeyPackage (which uses the link up) and /// creates our mailbox, then makes the group. The Welcome and our `hello` come back for the /// app to deliver after saving. diff --git a/crates/client/tests/state.rs b/crates/client/tests/state.rs index c802c34..9e00a88 100644 --- a/crates/client/tests/state.rs +++ b/crates/client/tests/state.rs @@ -410,3 +410,21 @@ fn a_used_welcome_mailbox_is_no_longer_fetched() { assert!(eva.poll().expect("poll").is_empty()); assert_eq!(relay.waiting_blobs(), 1, "the junk was never fetched"); } + +/// A forgotten invite's mailbox is no longer fetched, even if someone uses the link afterwards. +#[test] +fn a_forgotten_invite_is_no_longer_fetched() { + let relay = MemoryTransport::default(); + let mut eva = Client::new("Eva", relay.clone()).expect("eva"); + let mut jan = Client::new("Jan", relay.clone()).expect("jan"); + let invite = eva.create_invite().expect("invite"); + eva.forget_invite(&invite.id); + let mut eva = restart(&eva, &relay); + jan.accept_invite(&invite).expect("the relay still has it"); + assert!(eva.poll().expect("poll").is_empty()); + assert_eq!( + relay.waiting_blobs(), + 2, + "the Welcome and hello wait, never fetched" + ); +}