Skip to content

docs: update ProtocolAddress and session locking for inline-SSO refactor (whatsapp-rust#1131) - #447

Merged
jlucaso1 merged 2 commits into
mainfrom
claude/nifty-bohr-t3r5pj
Jul 27, 2026
Merged

docs: update ProtocolAddress and session locking for inline-SSO refactor (whatsapp-rust#1131)#447
jlucaso1 merged 2 commits into
mainfrom
claude/nifty-bohr-t3r5pj

Conversation

@jlucaso1

@jlucaso1 jlucaso1 commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

Reflects whatsapp-rust#1131 ("perf: five cuts to the per-message allocation count"), which made two internal changes that the docs described inaccurately:

  • ProtocolAddress went from a single-String buffer to AddressBuf, a small-buffer optimization that keeps addresses up to 47 bytes inline with zero heap allocation, spilling to a String beyond that. ProtocolAddress::new() now takes &str instead of an owned String, with_capacity(capacity, device_id) was removed in favor of empty(device_id) (no capacity hint needed), and reset_with()'s closure now receives &mut AddressBuf instead of &mut String.
  • session_mutexes_for() (resolve every mutex, then lock each in a second pass) is now #[cfg(test)]-only. Production code uses the new session_guards_for(), which locks each mutex as it is resolved.

Changes

  • advanced/signal-protocol.mdx: rewrote the "Single-buffer ProtocolAddress" section for the inline/spill design (including the Debug-leak safety note the PR fixed), updated the "Reusable hot-loop address construction" and "Single-allocation session lock keys" sections and code samples for empty() / session_guards_for(), and corrected two now-stale allocation-count claims.
  • api/signal.mdx, concepts/architecture.mdx: updated references to session_mutexes_for()session_guards_for().
  • concepts/storage.mdx: corrected the "two-allocation overhead" claim, since ProtocolAddress construction is now allocation-free for inline-sized addresses.

Changelog entries are intentionally left untouched per project convention (human-authored only).

Test plan

  • Verified new API shapes against wacore/libsignal/src/core/address.rs and wacore/src/types/jid.rs on whatsapp-rust@main
  • Searched the docs tree for remaining stale references to session_mutexes_for() / with_capacity outside test-only context — none found
  • mint broken-links (not run — Mintlify CLI unavailable in this environment; no new headings were added, only existing anchors reused)

Generated by Claude Code


Summary by cubic

Updates Signal Protocol docs to match whatsapp-rust PR #1131: ProtocolAddress now uses an inline-first buffer and the send path uses session_guards_for() instead of session_mutexes_for(). Also corrects the reused-buffer allocation note for spilled addresses (saves up to 99 allocations, not 100).

  • Migration
    • Use ProtocolAddress::new(name: &str, device_id) (was String).
    • Replace with_capacity(...) with empty(device_id).
    • reset_with() closure now takes &mut AddressBuf (was &mut String).
    • Switch to session_guards_for(&jids); session_mutexes_for() is test-only.

Written for commit 19d7d76. Summary will update on new commits.

…tor (whatsapp-rust#1131)

whatsapp-rust PR #1131 replaced ProtocolAddress's single-String buffer with
an inline-up-to-47-bytes small-buffer optimization, changed `new()` to take
`&str`, removed `with_capacity()` in favor of `empty()`, and replaced the
resolve-then-lock `session_mutexes_for()` pattern with `session_guards_for()`,
which locks each mutex as it is resolved. Update the affected reference docs
to match the new APIs and drop the now-inaccurate allocation-count claims.
@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@jlucaso1, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 30 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d3890658-7671-44d3-a4fe-79b82a9d5bc1

📥 Commits

Reviewing files that changed from the base of the PR and between 4aa1f11 and 19d7d76.

📒 Files selected for processing (4)
  • advanced/signal-protocol.mdx
  • api/signal.mdx
  • concepts/architecture.mdx
  • concepts/storage.mdx

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mintlify

mintlify Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
whatsapp-rust 🟢 Ready View Preview Jul 26, 2026, 11:59 PM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@greptile-apps

greptile-apps Bot commented Jul 27, 2026

Copy link
Copy Markdown

Greptile Summary

Updates Signal Protocol documentation to match the inline-first AddressBuf and revised session-locking APIs.

  • Replaces ProtocolAddress::with_capacity() examples with empty() and documents inline-versus-spilled storage.
  • Replaces production references to session_mutexes_for() with session_guards_for().
  • Corrects allocation guidance across advanced, API, architecture, and storage documentation.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
advanced/signal-protocol.mdx Documents the new address-buffer representation and session guard flow; the previous allocation-savings overstatement is corrected to at most 99 avoided allocations.
api/signal.mdx Updates the documented group participant encryption lock helper to session_guards_for().
concepts/architecture.mdx Aligns the concurrency overview with immediate, ordered lock acquisition through session_guards_for().
concepts/storage.mdx Corrects the session-key allocation explanation for inline ProtocolAddress storage.

Reviews (2): Last reviewed commit: "docs: correct reused-buffer allocation s..." | Re-trigger Greptile

Comment thread advanced/signal-protocol.mdx Outdated
The first spill on a reused ProtocolAddress still allocates its backing
String; only subsequent resets avoid a new allocation. Addressed via
review feedback on #447.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 04be73d33f

ℹ️ 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".

```

`to_protocol_address_string()` is used on hot paths (message encryption and decryption) as the key for `session_locks`. It pre-sizes the output buffer and builds the string in a single allocation, avoiding the two-allocation overhead of constructing a `ProtocolAddress` and then calling `.to_string()`.
`to_protocol_address_string()` is used on hot paths (message encryption and decryption) as the key for `session_locks`. It pre-sizes the output buffer and builds the `String` in a single allocation. Constructing a `ProtocolAddress` itself no longer allocates for addresses that fit inline (see [Single-buffer ProtocolAddress](#single-buffer-protocoladdress) below), but `.to_string()` on top of it still does, so `to_protocol_address_string()` remains the cheaper path when only the string is needed.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Document the new ProtocolAddress lock keys

This still says the hot-path session_locks key is produced by to_protocol_address_string(), but the inline-SSO refactor uses reusable ProtocolAddress values as the lock-cache keys; otherwise session_guards_for() could not avoid constructing a string key. The same stale model remains in concepts/architecture.mdx, which declares Cache<String, ...>, and in concepts/storage.mdx. Update these descriptions and snippets to the new key type so readers are not given the pre-#1131 allocation and cache behavior.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This premise doesn't hold — I checked against whatsapp-rust@main:

session_locks is still Cache<String, Arc<Mutex<()>>> (src/client.rs:1000), unchanged by #1131. session_lock_for(signal_addr_str: &str) (src/client/adapters.rs:38) calls self.session_locks.get_with_by_ref(signal_addr_str, ...)get_with_by_ref only allocates an owned String key on a cache miss; on a hit it takes &str and allocates nothing. That's what lets session_guards_for() pass addr.as_str() (from a reused ProtocolAddress) without constructing a string key, with no need for the cache itself to be keyed by ProtocolAddress.

This isn't new either — get_with_by_ref already existed at #1131's base commit (1118084), so it predates the inline-SSO refactor entirely. The docs' Cache<String, ...> declaration in concepts/architecture.mdx and the to_protocol_address_string() description in advanced/signal-protocol.mdx are accurate as written. No change needed here.


Generated by Claude Code

@jlucaso1
jlucaso1 merged commit c97f538 into main Jul 27, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants