fix(signal): persist retry advances before wire - #1041
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI (base), Organization UI (inherited) Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughRetry resend handling now persists Signal state before sending through a shared helper. Related tests use shared mock socket and leased-session setup helpers to validate pre-wire flushing and durable-lease behavior. ChangesRetry resend durability
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant RetryReceiptHandler
participant SignalState
participant Transport
RetryReceiptHandler->>SignalState: persist_signal_state_pre_wire()
SignalState-->>RetryReceiptHandler: persistence result
RetryReceiptHandler->>Transport: send retry stanza
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📦 Binary size report
.text per crate
Baseline: |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/retry.rs`:
- Around line 1321-1340: Update the test helpers attach_mock_noise_socket and
seed_retry_lease to accept &Client instead of &Arc<Client>. Keep their existing
behavior unchanged and rely on deref coercion at current call sites.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI (base), Organization UI (inherited)
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: e3d03abb-a2ea-43c9-8bfc-3182d5cf4d17
📒 Files selected for processing (1)
src/retry.rs
Dismissed because a newer commit was pushed; Greptile will re-review the current head.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f62988997f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
|
|
||
| async fn send_retry_stanza(&self, stanza: Node) -> Result<(), anyhow::Error> { | ||
| self.persist_signal_state_pre_wire().await?; |
There was a problem hiding this comment.
Keep retry leases gated until they are actually persisted
When another retry/send for the same device starts after the branch drops _session_guard but before this pre-wire flush takes the sessions-cache lock, it can check out the just-advanced session. flush_signal_cache_batch_safe() then skips that CheckedOut session and returns Ok with reservation_pending still set, so this line can proceed to send_node even though the raised counter lease was not written; a crash before the other operation checks the session back in and flushes can reload the pre-lease counter and reuse outbound key material. The retry path needs to fail/retry if the gate leaves a pending reservation, or otherwise prevent the session from being checked out across the gate.
Useful? React with 👍 / 👎.
Summary
Why
Retry encryption advances a pairwise Signal session. The previous order sent the retry stanza before persisting that advance, so a crash or persistence failure could reload the old chain state after ciphertext had already reached the wire. A send failure also skipped the post-send flush entirely.
The retry path now follows the same durability rule as regular sends: release the session lock, persist only when crossing a lease boundary, then write the stanza. This also removes the unconditional synchronous full flush after every retry.
Closes #1035
Validation
cargo fmt --allcargo clippy -p whatsapp-rust --tests -- -D warningscargo test -p whatsapp-rust retry_(52 passed)cargo test -p whatsapp-rust --quiet(997 unit tests passed, 1 ignored; integration and doc tests passed)