Skip to content

docs: Signal-cache flush scheduling and flush_pending_signal_state (PR #1022) - #402

Merged
jlucaso1 merged 10 commits into
mainfrom
claude/nifty-bohr-dfkb90
Jul 14, 2026
Merged

docs: Signal-cache flush scheduling and flush_pending_signal_state (PR #1022)#402
jlucaso1 merged 10 commits into
mainfrom
claude/nifty-bohr-dfkb90

Conversation

@jlucaso1

@jlucaso1 jlucaso1 commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

Documents the durability-model changes from whatsapp-rust#1022 ("perf(signal): coalesce receive flushes and persist outbound state pre-wire"), which changed when the in-memory Signal cache reaches persistent storage:

  • Send path (DM, group, and status sends) now flushes the Signal ratchet advance synchronously, before the stanza reaches the wire, and aborts the send with Err if that persistence write fails (previously this was logged only, not propagated).
  • Receive path (live traffic, outside the offline-drain batcher) now routes through a single-flight coalescing scheduler: a burst of receives folds into one flush per ~25ms window, retried with exponential backoff (up to 5s) on backend failure — instead of flushing per stanza.
  • A new public method, Client::flush_pending_signal_state(), lets callers force a deterministic durability settle (e.g. before reading persisted state directly, or ahead of a non-graceful shutdown), with a documented deadlock precondition (never call from inside an event handler or InboundDurabilityHook).

The offline drain, retry-receipt recovery, identity-change recovery, and teardown all keep their own synchronous flushes and are unaffected — confirmed by inspecting the diff, which does not touch commit_batch.rs (the file governing InboundDurabilityHook batch-commit ordering). advanced/inbound-durability.mdx was therefore left unchanged.

Changes

  • api/client.mdx — adds a flush_pending_signal_state reference entry under Protocol Operations (signature, durability semantics, deadlock warning, example).
  • advanced/signal-protocol.mdx — adds a new "Flush scheduling: send vs. receive" subsection under Storage Integration explaining the synchronous-send / coalesced-receive durability model and the generation-scoped scheduler.
  • api/send.mdx — adds a note under send_message that outbound Signal state is now persisted synchronously pre-wire and that persistence failures now surface as SendError::Internal, plus updates the SendError::Internal variant description.

No changelog entries were added or modified per standing instructions (changelog is human-maintained only).

Test plan

  • Docs build/lint passes (Mintlify)
  • New anchors resolve: /api/client#flush_pending_signal_state, /advanced/signal-protocol#flush-scheduling-send-vs-receive
  • Cross-references from api/send.mdx and api/client.mdx to the new signal-protocol section render correctly

🤖 Generated with Claude Code


Generated by Claude Code


Summary by cubic

Documents the updated Signal cache durability model and the new Client::flush_pending_signal_state() API. Sends persist ratchet advances synchronously and abort on failure; live receives coalesce with retries and generation scoping; the new API forces a deterministic settle and may wait on locks or storage.

  • Docs
    • advanced/signal-protocol.mdx: adds “Flush scheduling: send vs. receive” with coalesced receive flushes, retry behavior, and generation‑scoped scheduler; clarifies unaffected offline drain/recovery paths and reconnect behavior; links to the new API.
    • api/client.mdx: adds flush_pending_signal_state() reference with example; clarifies success guarantee vs. no hard time bound; narrows the deadlock warning to permit‑holding callers (InboundDurabilityHook and synchronous inline EventHandler), explicitly noting ordinary Bot closures are safe.
    • api/send.mdx: notes synchronous pre‑wire durability for sends and that persistence failures surface as SendError::Internal; restores the missing “Error Types” heading and expands the Internal variant description.

Written for commit c0f54e0. Summary will update on new commits.

Summary by CodeRabbit

  • Documentation
    • Documented improved Signal state durability for outgoing direct, group, and status messages.
    • Added guidance for flushing pending Signal state and handling persistence failures.
    • Documented more efficient receive-side state flushing, including batching and retry behavior.
    • Clarified recovery and reconnect behavior for Signal state synchronization.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main doc updates about Signal-cache flush scheduling and the new flush_pending_signal_state API.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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 14, 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 14, 2026, 12:33 PM

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

@greptile-apps

greptile-apps Bot commented Jul 14, 2026

Copy link
Copy Markdown

Greptile Summary

This PR documents the updated Signal-state durability model and explicit flush API. The main changes are:

  • Synchronous pre-wire persistence for outbound Signal ratchet state.
  • Coalesced receive-side flushes with retry and generation scoping.
  • Reference documentation for flush_pending_signal_state() and its deadlock constraints.
  • Updated SendError::Internal documentation for persistence failures.

Confidence Score: 5/5

This looks safe to merge.

  • The revised warning correctly separates inline permit-holding handlers from detached Bot callbacks.
  • No blocking issues remain in the changed documentation.

Important Files Changed

Filename Overview
advanced/signal-protocol.mdx Explains send and receive flush scheduling, recovery behavior, generation scoping, and explicit durability settling.
api/client.mdx Documents flush_pending_signal_state(), its result semantics, usage, and narrowed deadlock warning.
api/send.mdx Documents pre-wire outbound persistence and the related SendError::Internal behavior.

Reviews (7): Last reviewed commit: "docs: narrow flush_pending_signal_state ..." | Re-trigger Greptile

Comment thread api/client.mdx
greptile-apps[bot]
greptile-apps Bot previously approved these changes Jul 14, 2026
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
putComment timed out

@coderabbitai coderabbitai 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.

Actionable comments posted: 4

🤖 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 `@advanced/signal-protocol.mdx`:
- Around line 1138-1148: Rewrite the documentation section around the Signal
cache flush behavior using concise sentences with one idea per sentence, active
voice, and direct second-person phrasing. Split long sentences and replace
passive constructions such as retry descriptions with explicit actors, while
preserving the existing send/receive durability rules, scheduler generation
behavior, synchronous recovery paths, and flush_pending_signal_state() usage
restrictions.

In `@api/client.mdx`:
- Around line 1458-1470: Update the `flush_pending_signal_state` documentation
to format the heading as a code reference and rewrite the prose using concise,
second-person sentences. Split compound sentences into single ideas while
preserving the existing behavior, timing caveats, failure handling, and warning
about calling it only from a control task.

In `@api/send.mdx`:
- Line 1259: Rewrite the Internal error description in the send_message
documentation as separate concise sentences, keeping the catch-all meaning and
the note about failures to durably persist the outbound Signal ratchet advance
before stanza transmission.
- Around line 46-48: Rewrite the Note in api/send.mdx using concise,
active-voice sentences: state that the system synchronously persists the
outbound Signal ratchet advance before transmitting DMs, group, or status
stanzas; explain that this prevents outbound counter, message-key, and IV reuse;
state that send_message returns Err when persistence fails; and retain the
existing flush-scheduling reference.
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 70509f4f-5ba8-45e7-b2f1-e6e4e8ef8ab0

📥 Commits

Reviewing files that changed from the base of the PR and between b842928 and b9f6fa8.

📒 Files selected for processing (3)
  • advanced/signal-protocol.mdx
  • api/client.mdx
  • api/send.mdx

Comment thread advanced/signal-protocol.mdx
Comment thread api/client.mdx
Comment thread api/send.mdx
Comment on lines +46 to +48
<Note>
For DMs, group, and status sends, the outbound Signal ratchet advance is persisted to the backend **synchronously, before the stanza is transmitted** — reusing an outbound counter would reuse its message key and IV, so the advance must be durable before anyone can act on the ciphertext. If that persistence write fails, `send_message` returns `Err` instead of transmitting an advance that couldn't be saved. See [Signal Protocol — flush scheduling](/advanced/signal-protocol#flush-scheduling-send-vs-receive) for the full durability model.
</Note>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use concise sentences and active voice.

The note merges multiple ideas into a single long sentence and uses passive voice ("is persisted"). As per coding guidelines, documentation must use concise sentences (one idea per sentence) and active voice.

📝 Proposed rewrite
 <Note>
-For DMs, group, and status sends, the outbound Signal ratchet advance is persisted to the backend **synchronously, before the stanza is transmitted** — reusing an outbound counter would reuse its message key and IV, so the advance must be durable before anyone can act on the ciphertext. If that persistence write fails, `send_message` returns `Err` instead of transmitting an advance that couldn't be saved. See [Signal Protocol — flush scheduling](/advanced/signal-protocol#flush-scheduling-send-vs-receive) for the full durability model.
+For DMs, group, and status sends, the client persists the outbound Signal ratchet advance to the backend **synchronously, before the stanza is transmitted**. Reusing an outbound counter would reuse its message key and IV. Therefore, the advance must be durable before anyone can act on the ciphertext. If that persistence write fails, `send_message` returns `Err` instead of transmitting an advance that it could not save. See [Signal Protocol — flush scheduling](/advanced/signal-protocol#flush-scheduling-send-vs-receive) for the full durability model.
 </Note>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<Note>
For DMs, group, and status sends, the outbound Signal ratchet advance is persisted to the backend **synchronously, before the stanza is transmitted** — reusing an outbound counter would reuse its message key and IV, so the advance must be durable before anyone can act on the ciphertext. If that persistence write fails, `send_message` returns `Err` instead of transmitting an advance that couldn't be saved. See [Signal Protocol — flush scheduling](/advanced/signal-protocol#flush-scheduling-send-vs-receive) for the full durability model.
</Note>
<Note>
For DMs, group, and status sends, the client persists the outbound Signal ratchet advance to the backend **synchronously, before the stanza is transmitted**. Reusing an outbound counter would reuse its message key and IV. Therefore, the advance must be durable before anyone can act on the ciphertext. If that persistence write fails, `send_message` returns `Err` instead of transmitting an advance that it could not save. See [Signal Protocol — flush scheduling](/advanced/signal-protocol#flush-scheduling-send-vs-receive) for the full durability model.
</Note>
🤖 Prompt for 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.

In `@api/send.mdx` around lines 46 - 48, Rewrite the Note in api/send.mdx using
concise, active-voice sentences: state that the system synchronously persists
the outbound Signal ratchet advance before transmitting DMs, group, or status
stanzas; explain that this prevents outbound counter, message-key, and IV reuse;
state that send_message returns Err when persistence fails; and retain the
existing flush-scheduling reference.

Source: Coding guidelines

Comment thread api/send.mdx
- `InvalidRequest` — the send request was malformed (e.g., invalid JID, bad message shape)
- `Client` — underlying transport/connection error
- `Internal` — catch-all for errors not yet assigned a typed variant
- `Internal` — catch-all for errors not yet assigned a typed variant. Includes a failure to durably persist the outbound Signal ratchet advance before the stanza was sent — see the durability note under [`send_message`](#send_message).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use concise sentences.

The description merges two separate directives with an em dash. As per coding guidelines, documentation must use concise sentences with one idea per sentence.

📝 Proposed rewrite
-- `Internal` — catch-all for errors not yet assigned a typed variant. Includes a failure to durably persist the outbound Signal ratchet advance before the stanza was sent — see the durability note under [`send_message`](`#send_message`).
+- `Internal` — catch-all for errors not yet assigned a typed variant. It includes a failure to durably persist the outbound Signal ratchet advance before the stanza was sent. See the durability note under [`send_message`](`#send_message`).
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- `Internal` — catch-all for errors not yet assigned a typed variant. Includes a failure to durably persist the outbound Signal ratchet advance before the stanza was sent — see the durability note under [`send_message`](#send_message).
- `Internal` — catch-all for errors not yet assigned a typed variant. It includes a failure to durably persist the outbound Signal ratchet advance before the stanza was sent. See the durability note under [`send_message`](`#send_message`).
🤖 Prompt for 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.

In `@api/send.mdx` at line 1259, Rewrite the Internal error description in the
send_message documentation as separate concise sentences, keeping the catch-all
meaning and the note about failures to durably persist the outbound Signal
ratchet advance before stanza transmission.

Source: Coding guidelines

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 3 files

Confidence score: 5/5

  • Safe to merge after the addressed issues were fixed.

You’re at about 96% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread api/client.mdx Outdated
Comment thread api/client.mdx Outdated
@greptile-apps
greptile-apps Bot dismissed their stale review July 14, 2026 12:43

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

greptile-apps[bot]
greptile-apps Bot previously approved these changes Jul 14, 2026

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 1 file (changes from recent commits).

You’re at about 96% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread api/client.mdx
@greptile-apps
greptile-apps Bot dismissed their stale review July 14, 2026 12:48

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

greptile-apps[bot]
greptile-apps Bot previously approved these changes Jul 14, 2026

@cubic-dev-ai cubic-dev-ai 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.

0 issues found across 1 file (changes from recent commits).

You’re at about 96% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Requires human review: Auto-approval blocked by 2 unresolved issues from previous reviews.

Re-trigger cubic

@greptile-apps
greptile-apps Bot dismissed their stale review July 14, 2026 12:52

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

greptile-apps[bot]
greptile-apps Bot previously approved these changes Jul 14, 2026

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 1 file (changes from recent commits).

You’re at about 96% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread api/client.mdx Outdated
Comment thread api/client.mdx Outdated
@greptile-apps
greptile-apps Bot dismissed their stale review July 14, 2026 12:58

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

@cubic-dev-ai cubic-dev-ai 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.

0 issues found across 1 file (changes from recent commits).

You’re at about 96% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Requires human review: Auto-approval blocked by 1 unresolved issue from previous reviews.

Re-trigger cubic

greptile-apps[bot]
greptile-apps Bot previously approved these changes Jul 14, 2026
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@greptile-apps
greptile-apps Bot dismissed their stale review July 14, 2026 13:00

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

greptile-apps[bot]
greptile-apps Bot previously approved these changes Jul 14, 2026

@cubic-dev-ai cubic-dev-ai 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.

0 issues found across 1 file (changes from recent commits).

You’re at about 96% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Auto-approved: Documentation-only PR describing existing durability model and new API method; no behavioral changes or tradeoffs to evaluate.

Re-trigger cubic

@mintlify

mintlify Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

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

Project Status Preview Updated (UTC)
whatsapp-rust 🟡 Building Jul 14, 2026, 12:32 PM

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

@greptile-apps
greptile-apps Bot dismissed their stale review July 14, 2026 13:08

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

@cubic-dev-ai cubic-dev-ai 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.

0 issues found across 1 file (changes from recent commits).

You’re at about 96% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Auto-approved: This PR updates three documentation files with notes on Signal cache flush scheduling and a new API method. The diff is purely informational; no behavior, configuration, or code is changed. The documentation clarifies existing implementation details and is clearly beneficial for users.

Re-trigger cubic

@jlucaso1
jlucaso1 merged commit 643ead2 into main Jul 14, 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