Skip to content

docs(appstate): correct the batched-sync iteration cap comment - #1206

Merged
jlucaso1 merged 1 commit into
mainfrom
fix/appstate-max-iterations-comment
Aug 4, 2026
Merged

docs(appstate): correct the batched-sync iteration cap comment#1206
jlucaso1 merged 1 commit into
mainfrom
fix/appstate-max-iterations-comment

Conversation

@jlucaso1

@jlucaso1 jlucaso1 commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

What the comment claimed

sync_collections_batched documented itself as matching WA Web:

Matches WA Web's serverSync() outer loop (3JJWKHeu5-P.js:54278-54305).
Max 5 iterations (WA Web's C=5 constant).

Both lines are wrong.

What WA Web actually does

In WAWebSyncdServerSync the constants are var y=5, C=500 and the loop is

for (var a=[], i=[].concat(t), l=0; (l<y || i.length>0 && l<C) && i.length!==0; )

The body only runs while i.length !== 0, so the condition collapses to l < 500. y never bites. The effective cap is 500, and there is no C=5.

Exhausting it is not a failure either: the collections are marked ErrorRetry and handed to the finite-retry state machine, which spaces the next attempt with exponential backoff.

Why this matters beyond the wrong number

Our cap of 5 is not "WA Web with a smaller number", it is a different mechanism. WA Web can afford 500 rounds because it puts backoff between them; our loop iterates with none. So raising 5 toward 500 on its own would turn a truncated sync into up to 500 back-to-back IQ rounds. The cap and the spacing have to move together, and the comment now says so at the const where the value is chosen rather than in the doc header.

The bundle path is dropped too. A hash-named file plus line numbers rots on every WhatsApp version bump; the module name does not.

Scope

Comments only, no behaviour change.

cargo fmt --all --check and cargo clippy -p whatsapp-rust --all-targets -- -D warnings clean.

WA Web's serverSync outer loop bounds at C = 500, not 5: the y = 5 beside
it never bites, because the `||` between them keeps 500 the only real
limit. Exhausting it there marks the collections retryable and hands them
to a backoff state machine rather than giving up.

The doc comment claimed a `C=5` constant that does not exist, and pinned a
bundle path that rots on every WhatsApp version bump. The rationale for
our own 5 now sits at the const where the value is chosen, including why
raising it alone would only buy up to 500 back-to-back IQ rounds.
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0f413a37-b612-4f14-b6d6-5d5e3b032270

📥 Commits

Reviewing files that changed from the base of the PR and between 13fce2f and 088e7ac.

📒 Files selected for processing (1)
  • src/client/app_state.rs

📝 Walkthrough

Summary by CodeRabbit

  • Documentation
    • Clarified comments describing app-state synchronization behavior and its iteration limits.
    • Documented how the synchronization loop compares with the web client’s approach.

Walkthrough

The pull request updates comments in src/client/app_state.rs. The comments reference WA Web’s serverSync() and explain why the implementation retains its five-iteration cap. Runtime behavior does not change.

Changes

App-state synchronization documentation

Layer / File(s) Summary
Document synchronization loop behavior
src/client/app_state.rs
The sync_collections_batched documentation now references WA Web’s serverSync(). Comments explain that the five-iteration behavior remains unchanged instead of adopting WA Web’s 500-round limit and retry backoff.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the documentation correction for the batched-sync iteration cap.
Description check ✅ Passed The description directly explains the corrected WhatsApp Web behavior, the retained local cap, and the comments-only scope.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/appstate-max-iterations-comment

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.

@greptile-apps

greptile-apps Bot commented Aug 4, 2026

Copy link
Copy Markdown

Greptile Summary

The PR corrects documentation around the batched app-state synchronization iteration cap without changing executable behavior.

  • Removes a stale hash-named WA Web bundle reference and the incorrect claim that WA Web uses a five-iteration cap.
  • Documents WA Web's effective 500-iteration bound and explains why the local cap must not be raised without accompanying retry and backoff behavior.

Confidence Score: 5/5

The PR appears safe to merge because it changes comments only and introduces no actionable defect.

The executable batched-sync loop and its five-iteration limit remain unchanged, while the revised comments more clearly distinguish the local behavior from WA Web's iteration and retry model.

Important Files Changed

Filename Overview
src/client/app_state.rs Updates comments around sync_collections_batched and MAX_ITERATIONS; no runtime behavior is modified.

Reviews (1): Last reviewed commit: "docs(appstate): correct the batched-sync..." | Re-trigger Greptile

@jlucaso1
jlucaso1 merged commit 5e41840 into main Aug 4, 2026
24 of 25 checks passed
@jlucaso1
jlucaso1 deleted the fix/appstate-max-iterations-comment branch August 4, 2026 03:34
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

📦 Binary size report

Metric main PR Δ
bin size (stripped) 9.95 MiB 9.95 MiB 0
bin .text 7.98 MiB 7.98 MiB 0
bin allocated (text+data+bss) 9.95 MiB 9.95 MiB 0
llvm-lines wacore 512,919 512,919 0
llvm-lines wacore copies 16,742 16,742 0
llvm-lines whatsapp-rust lib 727,450 727,450 0
llvm-lines whatsapp-rust lib copies 22,955 22,955 0
deps crates (Cargo.lock) 462 462 0
.text per crate
Crate main PR Δ
.text whatsapp_rust 1.80 MiB 1.80 MiB 0
.text wacore 689.71 KiB 689.41 KiB -312 B (-0.04%) 🔽
.text wacore_binary 91.42 KiB 91.42 KiB 0
.text wacore_libsignal 170.64 KiB 170.64 KiB 0
.text wacore_appstate 22.35 KiB 22.35 KiB 0
.text wacore_noise 21.79 KiB 21.79 KiB 0
.text waproto 1.74 MiB 1.74 MiB 0
.text whatsapp_rust_sqlite_storage 515.62 KiB 515.62 KiB 0
.text whatsapp_rust_tokio_transport 40.49 KiB 40.49 KiB 0
.text whatsapp_rust_ureq_http_client 11.83 KiB 11.83 KiB 0
.text std 984.91 KiB 984.91 KiB 0
.text other deps 1.90 MiB 1.90 MiB +312 B (+0.02%) 🔺

Baseline: 13fce2f07 (latest main run) · Head: d0f480f17 · Graphs

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.

1 participant