Skip to content

Conversation

@lawrence-forooghian
Copy link
Collaborator

@lawrence-forooghian lawrence-forooghian commented Aug 12, 2025

Improves the tests around delta decoding, and fixes the following scenarios:

  • delta decoding of JSON-valued message data: we were not setting the base payload to the message's data before decoding JSON
  • delta decoding when using the non-binary protocol: we were setting the base payload to the delta, not the result of vcdiff decoding

Specification references based on ably/specification#356.

Resolves #2082.

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability of delta decoding with correct base updates across encodings.
    • Better handling of mixed payloads (text, binary, JSON) in both binary and non-binary protocols.
  • Chores

    • Removed legacy delta decoding components and reduced private API surface.
  • Tests

    • Expanded and parameterized delta decoding tests to cover multiple data types and protocol modes.
    • Refined expectations for message delivery/discard behavior in delta scenarios.

Not sure of the thinking behind the current assertion but it seems it
was working by accident.
All but the first should be using deltas, so ensure this and assert it.
The existing assertion ignored messages that weren't using deltas.
@coderabbitai
Copy link

coderabbitai bot commented Aug 12, 2025

Walkthrough

The PR removes ARTDeltaCodec/ARTVCDiffDecoder from project/module maps and private headers, adjusts ARTDataEncoder to refine delta-base handling across encodings, deletes a VCDiff category implementation, adds a new default method in ARTClientOptions, and significantly updates tests to cover JSON and non-binary delta decoding.

Changes

Cohort / File(s) Summary
Project config and module maps cleanup
Ably.xcodeproj/project.pbxproj, Source/Ably.modulemap, Source/include/module.modulemap
Removed references/exports for ARTDeltaCodec.h and ARTVCDiffDecoder.h from project and module maps.
Private headers removal
Source/PrivateHeaders/Ably/ARTDeltaCodec.h, Source/PrivateHeaders/Ably/ARTVCDiffDecoder.h
Deleted private headers defining ARTDeltaCodec category and ARTVCDiffDecoder protocol.
Delta codec implementation pruning
Source/ARTDeltaCodec.m
Removed VCDiff decoder category implementation bridging to AblyDeltaCodec.
Delta base handling logic
Source/ARTDataEncoder.m
Switched import to AblyDeltaCodec.h. Refined base-setting logic: handle NSString, conditionally set base before/after base64 and vcdiff decoding, and update base post-delta application. Removed unconditional base update.
Client options change
Source/ARTClientOptions.m
Removed initDefaults and isProductionEnvironment. Added +getDefaultIdempotentRestPublishingForVersion: with version-based boolean.
Tests expansion and parameterization
Test/Tests/DeltaCodecTests.swift
Parameterized tests to run with/without binary protocol; expanded payload types (string, binary, JSON, nil); adjusted expected encodings; updated RTL19/RTL20 expectations and sequencing of publishes.

Sequence Diagram(s)

sequenceDiagram
  participant Publisher
  participant Realtime
  participant ARTDataEncoder as DataEncoder
  participant DeltaCodec

  Publisher->>Realtime: Publish messages (various payloads)
  Realtime->>DataEncoder: decode(data, identifier, encodings)
  alt encodings end not base64 and no vcdiff
    DataEncoder->>DataEncoder: setDeltaCodecBase(from data)
  end
  alt encodings include base64
    DataEncoder->>DataEncoder: base64 decode
    alt last encoding and no vcdiff
      DataEncoder->>DataEncoder: setDeltaCodecBase(from decoded)
    end
  end
  alt encodings include vcdiff
    DataEncoder->>DeltaCodec: applyDelta(delta, base)
    DeltaCodec-->>DataEncoder: decoded data
    DataEncoder->>DataEncoder: update base to decoded
  end
  DataEncoder-->>Realtime: decoded payload
  Realtime-->>Publisher: deliver message
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Assessment against linked issues

Objective Addressed Explanation
Fix delta decoding for JSON payloads (#2082, ECO-5518)
Ensure delta decoding works with non-binary protocol (#2082, ECO-5518)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Added +getDefaultIdempotentRestPublishingForVersion: and removed initDefaults/isProductionEnvironment (Source/ARTClientOptions.m, lines: not specified) Not related to delta decoding or JSON/non-binary protocol; alters client options behavior.

Poem

I twitch my ears at diff and test,
Hopped through deltas, JSON blessed.
Base set right, no needless frights,
Binary or not—now smooth in flights.
With headers trimmed and flows aligned,
I thump approval, carrot-signed. 🥕🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d33f1c3 and 4879b36.

📒 Files selected for processing (9)
  • Ably.xcodeproj/project.pbxproj (0 hunks)
  • Source/ARTClientOptions.m (0 hunks)
  • Source/ARTDataEncoder.m (5 hunks)
  • Source/ARTDeltaCodec.m (0 hunks)
  • Source/Ably.modulemap (0 hunks)
  • Source/PrivateHeaders/Ably/ARTDeltaCodec.h (0 hunks)
  • Source/PrivateHeaders/Ably/ARTVCDiffDecoder.h (0 hunks)
  • Source/include/module.modulemap (0 hunks)
  • Test/Tests/DeltaCodecTests.swift (7 hunks)
💤 Files with no reviewable changes (7)
  • Source/PrivateHeaders/Ably/ARTDeltaCodec.h
  • Source/include/module.modulemap
  • Source/ARTDeltaCodec.m
  • Source/PrivateHeaders/Ably/ARTVCDiffDecoder.h
  • Source/Ably.modulemap
  • Ably.xcodeproj/project.pbxproj
  • Source/ARTClientOptions.m
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: check (tvOS, test_tvOS18_4)
  • GitHub Check: check (iOS, test_iOS18_4)
  • GitHub Check: check (macOS, test_macOS)
🔇 Additional comments (11)
Source/ARTDataEncoder.m (5)

3-3: LGTM! Header import updated correctly.

The import change from ARTDeltaCodec.h to AblyDeltaCodec.h aligns with the broader refactoring to use the new delta codec implementation.


52-54: Good fix for JSON delta decoding!

Converting string data to UTF-8 before setting it as the delta base is essential for proper delta decoding of JSON-valued message data. This addresses the issue where the base payload wasn't being set correctly for JSON messages.


146-149: Correct implementation of RTL19d2.

The early check to set delta base for non-Base64-encoded, non-delta messages is properly placed and follows the specification.


160-161: Well-structured Base64 decoding with proper delta base handling.

The implementation correctly handles RTL19d1 (Base64-encoded non-delta messages) and includes a helpful comment about RTL19e1 (deriving base payload for Base64-encoded delta messages). The conditional check ensures the base is only set when appropriate.

Also applies to: 167-170


210-213: Critical fix for non-binary protocol delta decoding!

Setting the base to the decoded data after vcdiff decoding (RTL19e) correctly addresses the issue where the base was incorrectly being set to the delta itself in non-binary protocol scenarios. This is a key fix that ensures delta decoding works properly for both binary and non-binary protocols.

Test/Tests/DeltaCodecTests.swift (6)

6-22: Excellent test coverage for RSL4 message data types!

The test data now comprehensively covers all message types: strings, binary data, JSON arrays, and nil values. This ensures delta decoding is thoroughly tested across all supported data types.


33-37: Good parameterization for protocol testing.

The parameterized test approach effectively validates delta decoding for both binary and non-binary protocols, ensuring the fixes work correctly in both scenarios.


64-81: Smart sequential publishing approach!

Publishing messages sequentially with completion callbacks ensures delta generation doesn't exceed concurrent limits. The recursive helper function is well-structured and includes proper error handling.


90-90: Correct type assertion for diverse data types.

Using NSObject instead of String for the type assertion properly accommodates the expanded test data types (strings, arrays, binary data, and nil).


99-126: Thorough encoding verification for both protocols!

The test correctly verifies that:

  1. Messages are successfully decoded without requiring RTL18 recovery
  2. The expected encoding patterns match for both binary and non-binary protocols
  3. Different data types receive appropriate encodings (vcdiff with/without base64)

This provides strong validation that the delta decoding fixes work as intended.


185-185: Test expectations correctly updated.

The comments clarify that only 2 messages are delivered before the third message triggers recovery, with subsequent messages being discarded. This aligns with the expected behavior when delta decoding fails.

Also applies to: 240-240

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 2082-fix-delta-decoding

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot temporarily deployed to staging/pull/2083/features August 12, 2025 13:39 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/2083/jazzydoc August 12, 2025 13:41 Inactive
Fix the following scenarios:

- delta decoding of JSON-valued message data: we were not setting the
  base payload to the message's `data` before decoding JSON

- delta decoding when using the non-binary protocol: we were setting the
  base payload to the delta, not the result of vcdiff decoding

Specification references based on [1] at adf8d0f.

Resolves #2082.

[1] ably/specification#356
@lawrence-forooghian
Copy link
Collaborator Author

@CodeRabbit review

@coderabbitai
Copy link

coderabbitai bot commented Aug 12, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

1 similar comment
@coderabbitai
Copy link

coderabbitai bot commented Aug 12, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Collaborator

@maratal maratal left a comment

Choose a reason for hiding this comment

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

LGTM, what was Source/ARTDeltaCodec.m doing?

@lawrence-forooghian
Copy link
Collaborator Author

LGTM, what was Source/ARTDeltaCodec.m doing?

Nothing, as far as I could tell

@lawrence-forooghian lawrence-forooghian merged commit fca1213 into main Aug 13, 2025
9 of 11 checks passed
@lawrence-forooghian lawrence-forooghian deleted the 2082-fix-delta-decoding branch August 13, 2025 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Delta decoding is not working for JSON data

3 participants