Skip to content

fix(chat-store): correlate amendment operation acknowledgements - #236

Merged
jlucaso1 merged 23 commits into
mainfrom
fix/chat-store-operation-ack-stacked
Oct 7, 2026
Merged

jlucaso1 merged 23 commits into
mainfrom
fix/chat-store-operation-ack-stacked

Conversation

@jlucaso1

@jlucaso1 jlucaso1 commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Amendment ACKs use fresh stanza IDs, separately from the target message ID. This change correlates known operations, prevents unknown operation bursts from evicting already-admitted early message ACKs, and refuses normal message sends whose outgoing record was not admitted.

Refs #231. #235 has been merged into main as 09bfb1f. This PR now targets main. Merge commit 174712b incorporates that base without rewriting branch history and preserves all operation ACK, writer-loss and enqueue-only fixes. Engine and Cargo.lock remain unchanged.

Behavior:

  • Edit/revoke/reaction/poll-vote/forward/status paths register SendResult.message_id before the target recorder. List responses register the generated ID before sending; forwarding and status preserve remotely successful results while logging any post-send tracking refusal. No operation message rows are invented.
  • Operation registry remains at 256 entries / 60 seconds, scoped by chat and verified PN/LID aliases. Collisions are refused, differing outcomes retain order, and NACK warnings remain visible.
  • Unknown ACK admission remains at 64 entries / 60 seconds. Admitted waiters are retained; excess ACKs are rejected, logged and reported by flush/close. Permanent ACK loss survives rollback, retry and cancellation, including a later overflow behind an earlier unreceived backend error.
  • All eight normal message send paths propagate outgoing admission failure and skip send_message_with_options. UI sends report the pre-generated ID as failed; wire APIs return an error. The enqueue_only wire ID is announced only after successful outgoing admission. A media upload may precede final-message admission.
  • The inherited writer fix associates write-admission loss with barrier enqueue order and preserves the batch failure alongside overflow. A bounded retained outcome holds the first error and writer/ACK loss flags; older responses cannot acknowledge a newer failure.

Limits:

  • Generate the normal-message ID, admit its local outgoing record, then send with the same ID. Admission preserves ordering, not crash durability.
  • Recording after send remains bounded compatibility: a genuine ACK arriving after all 64 unknown slots are occupied can be rejected, with the loss reported by flush/close.
  • Chatless or evicted/expired operations can remain unknown when identity cannot be resolved safely. Registry survives reconnect within one writer, not restart. No durable outbox, exactly-once guarantee, increased cap or schema migration.
  • The pinned engine's edit stanza-ID override has different cache/secret semantics and is not used as a generic operation-ID mechanism.

Validation:

  • Final head 174712b: 372 chat-store + 279 session tests passed (651 total), 5 ignored, no failures; formatting and Clippy across all targets/features with warnings denied passed.
  • The conflict resolution's tree 6a21829 is byte-identical to the previously validated combined integration: 375 chat-store and 2045 native workspace tests passed, 23 ignored in the workspace, no failures. Workspace Clippy/fmt, WASM type checking and the workflow's WASM lint policy passed.
  • Pressure tests cover operation ACKs before registration, after registry eviction, without chat metadata and from 65 status broadcasts; admitted early message ACKs survive each burst. Record-before-send ACK/NACK tests cover both orders.
  • Public regressions cover ACK overflow after a cancelled backend failure, rollback/repair, cancellation after response delivery, later writer overflow, flush/close batch diagnostics and rejection after an already-queued barrier. Synthetic integration tests cover operation registration × rollback × revoke identity, including reopen/redelivery.
  • No real WhatsApp account or destructive user-data migration was executed.

Final-head CI and Pages are tracked on 174712b. At 16:04 UTC, the full Linux job passed, including workspace formatting, dependency checks, Clippy, tests, doctests, CLI budget and plugins. Windows/macOS/web/xtask/MSRV and Pages Build remain queued. The GitHub PR reports mergeable with no remaining conflicts. These current-head gates must pass before this PR is fully green.

Codex completed final-head review of 174712b at 15:57 UTC without new findings. CodeRabbit reviewed the actual 11-file diff against main and APPROVED 174712b at 15:59 UTC without actionable comments.

No PR was merged by this agent. No structural Pages change, engine change, real-account execution or destructive migration was performed.

Summary by CodeRabbit

  • Bug Fixes

    • Outgoing messages are no longer sent when they cannot first be recorded locally; callers receive a send failure instead.
    • Improved handling of server acknowledgements arriving before messages or operations are recorded, including reporting when acknowledgements cannot be retained.
    • Recording failures for reactions, edits, revocations, forwards, and status operations are handled without discarding successful server results.
  • Documentation

    • Clarified how write and acknowledgement admission failures are reported and retained.

@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 963e51d6-4e8c-4462-ae8e-65c3e0a6a106
📥 Commits

Reviewing files that changed from the base of the PR and between 09bfb1f and 174712b.

📒 Files selected for processing (11)
  • crates/chat-store/src/store/ack.rs
  • crates/chat-store/src/store/event.rs
  • crates/chat-store/src/store/mod.rs
  • crates/chat-store/src/store/writer.rs
  • crates/chat-store/tests/ack_pressure.rs
  • crates/chat-store/tests/operation_acks.rs
  • crates/session/src/whatsapp/mod.rs
  • crates/session/src/whatsapp/mutations.rs
  • crates/session/src/whatsapp/ops.rs
  • crates/session/src/whatsapp/sends.rs
  • docs/gotchas.md

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The chat store now bounds deferred acknowledgements and operation-ID correlation, and reports acknowledgement admission loss through flush and stop barriers. WhatsApp send paths handle local recording failures and register operation IDs for acknowledgement matching.

Changes

Chat-store acknowledgement flow

Layer / File(s) Summary
Operation-aware acknowledgement matching
crates/chat-store/src/store/ack.rs, crates/chat-store/src/store/event.rs, crates/chat-store/src/store/mod.rs, crates/chat-store/src/store/writer.rs, crates/chat-store/tests/operation_acks.rs
Deferred acknowledgements are deduplicated and bounded. The writer registers operation IDs and uses them when applying acknowledgements. Tests cover operation collisions, expiry, reconnects, and pressure.
Acknowledgement capacity-loss reporting
crates/chat-store/src/store/mod.rs, crates/chat-store/src/store/writer.rs, crates/chat-store/tests/ack_pressure.rs, docs/gotchas.md
Flush and stop outcomes include unmatched-ack admission loss alongside write-admission and backend errors. Tests cover pressure, rollback, cancellation, and retained failures.
Session recording and send ordering
crates/session/src/whatsapp/mod.rs, crates/session/src/whatsapp/sends.rs, crates/session/src/whatsapp/mutations.rs, crates/session/src/whatsapp/ops.rs
Outgoing sends handle chat-store recording failures before sending where required. Successful mutations and operations register returned IDs, and tracking failures are propagated or logged according to the path.

Priority: ⬇️ Low

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant WhatsApp as WhatsApp send path
  participant ChatStore
  participant writer
  participant server
  participant apply_event
  WhatsApp->>ChatStore: record_outgoing
  ChatStore->>writer: enqueue outgoing row
  WhatsApp->>server: send message
  server-->>apply_event: ServerAck
  apply_event->>writer: apply_server_ack_with_operations
  writer->>writer: retry matching deferred ACK after row insertion
Loading

Suggested reviewers: assisjp

Merge Risk: ⚪ Minimal · up to 17471

This change makes outgoing sends fail early when local recording is refused. It also bounds and correlates acknowledgements for edit, revoke, reaction and similar operations. No actionable merge-blocking risk was found. Confirm that final-head CI passes before merging.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.60% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 81 functions across 10 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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 and concisely describes the primary change: correlating amendment operation acknowledgements in chat-store.
Full details: Docstring Coverage

Explanation

Docstring coverage is 71.60% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 81 functions across 10 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@jlucaso1
jlucaso1 marked this pull request as ready for review October 7, 2026 12:50
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-07T15:57:41.308716Z 174712b New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Keep admission loss visible when a later barrier fails, while assigning a fresh response generation so an older result cannot clear newer failures. Cover cancellation and distinct failure generations with regressions.
Bring PR #235's cancellation regression fix into the operation-ACK branch without rewriting its history.

@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: 743df6cbe8

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

Comment thread crates/chat-store/src/store/writer.rs Outdated
Keep a bounded summary of the first unseen error and permanent write/ACK loss. Cover a cancelled backend error followed by writer overflow through the public flush API.
Incorporate the stacked base fix, propagate deferred ACK admission loss into the retained barrier outcome, and regress cancellation before a later ACK-capacity failure.
Retain write admission loss in this branch. The stacked operation-ACK branch adds ACK-loss reporting and its public API regression; do not promise that extension in the base documentation or helper.
Keep the operation-ACK branch's tested source tree unchanged. The base now exposes writer loss only; this branch extends the retained outcome with ACK-loss reporting.
Capture writer rejection under a short lock when a control barrier is queued, leaving later rejection for the next barrier. Keep the batch failure alongside the captured loss flag. Regress both flush/close diagnostics and a rejection following an already-queued flush.
Preserve the ACK-loss extension while incorporating causal barrier snapshots and batch-error diagnostics, with the base regressions.

@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: ef1df375dc

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

Comment thread crates/session/src/whatsapp/sends.rs
Keep the first writer error across refused inbound durability callbacks and subsequent retries. Regress suspension, repair and delivery of the original transaction cause without a prior flush.
Preserve the base writer failure. Make the enqueue-only ID announcement follow outgoing record admission, with synthetic channel/store coverage for accepted, full and stopped writer cases.

@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: 6ffe500695

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

Comment thread crates/chat-store/src/store/ack.rs
Base automatically changed from fix/chat-store-batch-failure to main October 7, 2026 15:49
@jlucaso1
jlucaso1 merged commit 153c4e3 into main Oct 7, 2026
10 checks passed
@jlucaso1
jlucaso1 deleted the fix/chat-store-operation-ack-stacked branch October 7, 2026 16:09
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