fix(recv): retry (not NACK) InvalidSignedPreKeyId on the 1:1 decrypt path - #987
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
Next review available in: 30 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI (base), Organization UI (inherited) Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe InvalidPreKeyId retry-handling call in receive.rs is reformatted for multiline style without behavior change. In tests.rs, the prekey bundle helper is parameterized to accept a signed prekey id, and a new test verifies that an unprovisioned signed prekey id triggers a retry receipt with RetryReason::InvalidKeyId. ChangesRetry Path and Test Coverage
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: Look, this needs to be airtight — key mismatch handling is the kind of thing that breaks trust at scale, and trust is everything. The test coverage here is a good start, but I want to make sure this pattern gets extended everywhere it matters. Ship it once it's clean. 🚥 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 |
There was a problem hiding this comment.
No issues found across 2 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Not reviewed (too large): src/message/tests.rs (~77 lines) - if these are generated or fixture files, add them to ignored paths to exclude them from future reviews.
Auto-approved: Adds retry handling for InvalidSignedPreKeyId, mirroring existing InvalidPreKeyId handling. Isolated change with tests.
Re-trigger cubic
📦 Binary size report
.text per crate
Baseline: |
A PreKeySignalMessage naming a signed prekey we've rotated past SIGNED_PRE_KEY_RETENTION makes get_signed_pre_key return InvalidSignedPreKeyId. That error was unhandled by the session-decrypt match arms and fell to the catch-all, which spawns a 500 NACK and clears the stanza from the offline queue -> permanent, silent 1:1 message loss. WA Web classifies it as SignalRetryable and answers with a retry receipt carrying our live bundle, so the peer rebuilds against the current signed prekey. The sibling InvalidPreKeyId arm already retries; add the same for InvalidSignedPreKeyId (RetryReason::InvalidKeyId). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L1geaAZffSxDhP7dpNrbbt
a8ba6fd to
78ea9a1
Compare
…w feedback) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L1geaAZffSxDhP7dpNrbbt
There was a problem hiding this comment.
0 issues found across 2 files (changes from recent commits).
Not reviewed (too large): src/message/tests.rs (~8 lines) - if these are generated or fixture files, add them to ignored paths to exclude them from future reviews.
Auto-approved: Bug fix: adds missing handling for InvalidSignedPreKeyId decrypt error to send retry receipt instead of terminal NACK, plus test coverage. Low risk, isolated change.
Re-trigger cubic
What
Handle
SignalProtocolError::InvalidSignedPreKeyIdon the session (pkmsg/msg) decrypt path by sending a retry receipt (RetryReason::InvalidKeyId) instead of letting it fall to the catch-all500NACK.Why (bug)
When a
PreKeySignalMessagenames a signed prekey we've rotated pastSIGNED_PRE_KEY_RETENTION(src/features/rotate_key.rs),SignedPreKeyAdapter::get_signed_pre_keyreturnsInvalidSignedPreKeyId. The session-decrypt match insrc/message/receive.rshandledSessionNotFound,BadMac/InvalidMessage,InvalidPreKeyId,UntrustedIdentity,DuplicatedMessage— but notInvalidSignedPreKeyId, so it hit theelsecatch-all →spawn_nack(UnhandledError). A500NACK clears the stanza from the offline queue → permanent, silent 1:1 message loss.WhatsApp Web classifies this as a
SignalDecryptionError→SignalRetryable→ retry receipt (WAWeb/Msg/ProcessingDecryptionHandler.js); the receipt carries our live bundle so the peer rebuilds against the current signed prekey. The siblingInvalidPreKeyIdarm already retries — this was an inconsistent drop for the signed-prekey case.How
else if matches!(e, InvalidSignedPreKeyId)arm before the catch-all that routes to the existinghandle_decrypt_failure(RetryReason::InvalidKeyId, …), mirroring the adjacentInvalidPreKeyIdarm. The catch-all500NACK is preserved for genuinely non-Signal errors.Tests
test_invalid_signed_prekey_id_sends_retry_receipt— builds a bundle whose signed-prekey id the client never provisioned (the id is not signed, so the bundle is still accepted), so decrypt hitsInvalidSignedPreKeyId; asserts a retry receipt withRetryReason::InvalidKeyIdis emitted (pre-fix this took the terminal NACK path, which never bumps the retry caches).bobs_prekey_bundletest helper intobobs_prekey_bundle_with_spk_id(client, spk_id); the original delegates withspk_id = 1(no behavior change for existing callers).cargo fmt,cargo clippy -p whatsapp-rust --lib --testsclean; new test passes.🤖 Generated with Claude Code
Generated by Claude Code