Skip to content

Conversation

@sacOO7
Copy link
Collaborator

@sacOO7 sacOO7 commented Jul 24, 2025

Summary by CodeRabbit

  • New Features

    • Added support for tracking and utilizing tombstone timestamps for live objects and map entries, allowing more precise recording of when objects are removed or marked inactive.
    • Serialization and deserialization now include an optional timestamp field for enhanced data consistency.
    • Introduced simulation of object deletion via protocol messages to better mimic server-side deletion events.
  • Bug Fixes

    • Improved handling of tombstone operations to ensure correct timestamp assignment, defaulting to the current time if not provided.
  • Tests

    • Expanded test coverage to verify correct handling and propagation of tombstone timestamps in live objects and map entries.
    • Updated existing tests to use enhanced message structures and added new tests for tombstone timestamp scenarios.
    • Enhanced integration tests to validate object deletion events and update notifications.

1. Updated MsgpackSerialization accordingly.
2. Updated LiveMapManagerTests, added few more tests related to changes
@coderabbitai
Copy link

coderabbitai bot commented Jul 24, 2025

Walkthrough

The changes introduce an optional serialTimestamp field to ObjectMessage and ObjectMapEntry, propagate this field through serialization/deserialization, and update the handling of tombstone operations to use this timestamp for more accurate state management. Method signatures and relevant logic in live object, counter, and map classes, as well as associated tests, are updated to support and verify this new timestamp propagation.

Changes

File(s) Change Summary
Data Models
live-objects/src/main/kotlin/io/ably/lib/objects/ObjectMessage.kt
Added nullable serialTimestamp property to ObjectMessage and ObjectMapEntry data classes.
Serialization
live-objects/src/main/kotlin/io/ably/lib/objects/serialization/MsgpackSerialization.kt
Updated serialization/deserialization to support serialTimestamp in ObjectMessage and ObjectMapEntry.
Sync Data Pool Update
live-objects/src/main/kotlin/io/ably/lib/objects/ObjectsManager.kt
Changed syncObjectsDataPool to store ObjectMessage instead of ObjectState; updated usages.
Base Live Object
live-objects/src/main/kotlin/io/ably/lib/objects/type/BaseLiveObject.kt
Updated method signatures to propagate ObjectMessage and optional serialTimestamp for tombstones.
LiveCounter Implementation
live-objects/src/main/kotlin/io/ably/lib/objects/type/livecounter/*
Updated applyObjectState and applyObjectOperation to accept ObjectMessage and use serialTimestamp.
LiveCounter Manager
live-objects/src/main/kotlin/io/ably/lib/objects/type/livecounter/LiveCounterManager.kt
Updated applyState/applyOperation signatures and logic to handle optional serialTimestamp for tombstones.
LiveMap Implementation
live-objects/src/main/kotlin/io/ably/lib/objects/type/livemap/*
Updated applyObjectState and applyObjectOperation to accept ObjectMessage and use serialTimestamp.
LiveMap Manager
live-objects/src/main/kotlin/io/ably/lib/objects/type/livemap/LiveMapManager.kt
Updated applyState/applyOperation and map removal methods to handle optional serialTimestamp for tombstones and removals.
Test Helpers
live-objects/src/test/kotlin/io/ably/lib/objects/unit/TestHelpers.kt
Added extension property to access private tombstonedAt field for test assertions.
Unit Tests
live-objects/src/test/kotlin/io/ably/lib/objects/unit/objects/ObjectsManagerTest.kt,
live-objects/src/test/kotlin/io/ably/lib/objects/unit/type/livecounter/DefaultLiveCounterTest.kt,
live-objects/src/test/kotlin/io/ably/lib/objects/unit/type/livemap/DefaultLiveMapTest.kt
Updated tests to pass and verify ObjectMessage instead of ObjectState in sync-related assertions.
Manager Tests
live-objects/src/test/kotlin/io/ably/lib/objects/unit/type/livecounter/LiveCounterManagerTest.kt,
live-objects/src/test/kotlin/io/ably/lib/objects/unit/type/livemap/LiveMapManagerTest.kt
Updated tests to pass optional timestamp to applyState/applyOperation; added tests for tombstone timestamp handling.
Integration Tests and Helpers
live-objects/src/test/kotlin/io/ably/lib/objects/integration/DefaultLiveObjectsTest.kt,
live-objects/src/test/kotlin/io/ably/lib/objects/integration/helpers/Utils.kt
Added simulation of object deletion via ProtocolMessage and updated related integration tests.

Sequence Diagram(s)

sequenceDiagram
    participant Server
    participant ObjectsManager
    participant BaseLiveObject
    participant LiveCounterManager/LiveMapManager

    Server->>ObjectsManager: Sends ObjectMessage (with optional serialTimestamp)
    ObjectsManager->>BaseLiveObject: applyObjectSync(ObjectMessage)
    BaseLiveObject->>LiveCounterManager/LiveMapManager: applyState(ObjectState, serialTimestamp)
    LiveCounterManager/LiveMapManager->>BaseLiveObject: tombstone(serialTimestamp)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Assessment against linked issues

Objective Addressed Explanation
Support server-provided timestamp for sweeping old tombstones in LiveObject (Issues #1117, ECO-5447)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected.

Possibly related PRs

Suggested reviewers

  • ttypic

Poem

In fields of code, a timestamp hops—
Now tombstones know when time has stopped.
Messages carry moments true,
Through maps and counters, hopping through.
The rabbits cheer, for time’s now clear—
Old ghosts swept out, new dawn is near!
🐇⏳


📜 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 97f55f7 and 7023ff6.

📒 Files selected for processing (3)
  • live-objects/src/main/kotlin/io/ably/lib/objects/type/livecounter/DefaultLiveCounter.kt (1 hunks)
  • live-objects/src/main/kotlin/io/ably/lib/objects/type/livecounter/LiveCounterManager.kt (4 hunks)
  • live-objects/src/test/kotlin/io/ably/lib/objects/integration/DefaultLiveObjectsTest.kt (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • live-objects/src/main/kotlin/io/ably/lib/objects/type/livecounter/DefaultLiveCounter.kt
  • live-objects/src/main/kotlin/io/ably/lib/objects/type/livecounter/LiveCounterManager.kt
🧰 Additional context used
🧠 Learnings (8)
📓 Common learnings
Learnt from: sacOO7
PR: ably/ably-java#1106
File: live-objects/src/main/kotlin/io/ably/lib/objects/serialization/Serialization.kt:25-29
Timestamp: 2025-06-23T14:18:25.315Z
Learning: In the ably-java codebase, the DefaultLiveObjectSerializer class methods like writeMsgpackArray will have their type signatures updated to be non-nullable since the calling sites ensure objects are never null when passed to these methods.
Learnt from: sacOO7
PR: ably/ably-java#1106
File: live-objects/src/main/kotlin/io/ably/lib/objects/serialization/MsgpackSerialization.kt:207-211
Timestamp: 2025-06-23T14:28:23.301Z
Learning: In the Ably Java LiveObjects MessagePack deserialization code, the `action` field in ObjectOperation is guaranteed to always be present in the protocol, so using a default value during deserialization is acceptable and won't mask real protocol errors.
Learnt from: sacOO7
PR: ably/ably-java#1106
File: live-objects/src/main/kotlin/io/ably/lib/objects/serialization/Serialization.kt:38-46
Timestamp: 2025-06-23T14:14:17.847Z
Learning: In the ably-java codebase, the DefaultLiveObjectSerializer class uses intentional unsafe casting (`objects as Array<ObjectMessage>`) without type validation in both writeMsgpackArray and asJsonArray methods. This is a deliberate design decision to keep the dynamically-loaded class simple and let ClassCastException occur naturally for type mismatches.
Learnt from: sacOO7
PR: ably/ably-java#1092
File: live-objects/src/test/kotlin/io/ably/lib/objects/TestUtils.kt:48-61
Timestamp: 2025-06-03T09:15:18.827Z
Learning: User sacOO7 prefers simple test utilities without extensive error handling, believing tests should fail fast if incorrect field/method names are used rather than having defensive programming.
📚 Learning: in the ably-java liveobjects test code, extension properties with capital letter names (like `state`...
Learnt from: sacOO7
PR: ably/ably-java#1120
File: live-objects/src/test/kotlin/io/ably/lib/objects/integration/DefaultLiveObjectsTest.kt:0-0
Timestamp: 2025-08-01T09:53:16.730Z
Learning: In the ably-java LiveObjects test code, extension properties with capital letter names (like `State`, `ObjectId`) are defined in live-objects/src/test/kotlin/io/ably/lib/objects/integration/helpers/Utils.kt to provide access to internal fields of concrete implementations through their public interfaces. For example, `LiveObjects.State` casts to `DefaultLiveObjects` to access the internal `state` field for testing purposes.

Applied to files:

  • live-objects/src/test/kotlin/io/ably/lib/objects/integration/DefaultLiveObjectsTest.kt
📚 Learning: in livemapmanagertest.kt, the private field `livemapmanager` is used extensively in the `shouldcalcu...
Learnt from: sacOO7
PR: ably/ably-java#1113
File: live-objects/src/test/kotlin/io/ably/lib/objects/unit/type/livemap/LiveMapManagerTest.kt:16-16
Timestamp: 2025-08-01T05:50:33.039Z
Learning: In LiveMapManagerTest.kt, the private field `livemapManager` is used extensively in the `shouldCalculateMapDifferenceCorrectly` test method to test the `calculateUpdateFromDataDiff` functionality across multiple test scenarios, so it should not be removed as unused.

Applied to files:

  • live-objects/src/test/kotlin/io/ably/lib/objects/integration/DefaultLiveObjectsTest.kt
📚 Learning: in livemapmanagertest.kt, the private field `livemapmanager` is used in the `shouldcalculatemapdiffe...
Learnt from: sacOO7
PR: ably/ably-java#1113
File: live-objects/src/test/kotlin/io/ably/lib/objects/unit/type/livemap/LiveMapManagerTest.kt:16-16
Timestamp: 2025-08-01T05:50:33.039Z
Learning: In LiveMapManagerTest.kt, the private field `livemapManager` is used in the `shouldCalculateMapDifferenceCorrectly` test method to test the `calculateUpdateFromDataDiff` functionality, so it should not be removed as unused.

Applied to files:

  • live-objects/src/test/kotlin/io/ably/lib/objects/integration/DefaultLiveObjectsTest.kt
📚 Learning: in defaultlivemaptest.kt integration tests, operations are performed sequentially one after another,...
Learnt from: sacOO7
PR: ably/ably-java#1130
File: live-objects/src/test/kotlin/io/ably/lib/objects/integration/DefaultLiveMapTest.kt:241-241
Timestamp: 2025-08-01T10:30:27.049Z
Learning: In DefaultLiveMapTest.kt integration tests, operations are performed sequentially one after another, and subscription callback list updates happen one at a time, so thread-safe collections are not needed for collecting updates in test scenarios.

Applied to files:

  • live-objects/src/test/kotlin/io/ably/lib/objects/integration/DefaultLiveObjectsTest.kt
📚 Learning: in the ably-java liveobjects test code, an extension property `state` (capital s) is defined on the ...
Learnt from: sacOO7
PR: ably/ably-java#1120
File: live-objects/src/test/kotlin/io/ably/lib/objects/integration/DefaultLiveObjectsTest.kt:0-0
Timestamp: 2025-08-01T09:53:16.730Z
Learning: In the ably-java LiveObjects test code, an extension property `State` (capital S) is defined on the `LiveObjects` interface in live-objects/src/test/kotlin/io/ably/lib/objects/integration/helpers/Utils.kt to provide access to the internal `state` field by casting to `DefaultLiveObjects`. This allows tests to access internal state for verification purposes.

Applied to files:

  • live-objects/src/test/kotlin/io/ably/lib/objects/integration/DefaultLiveObjectsTest.kt
📚 Learning: in test utility code for the ably java live objects module, the team prefers to keep reflection-base...
Learnt from: sacOO7
PR: ably/ably-java#1092
File: live-objects/src/test/kotlin/io/ably/lib/objects/TestUtils.kt:21-32
Timestamp: 2025-06-03T09:15:15.338Z
Learning: In test utility code for the Ably Java Live Objects module, the team prefers to keep reflection-based field access utilities simple without additional error handling, allowing tests to fail fast if incorrect field names are used.

Applied to files:

  • live-objects/src/test/kotlin/io/ably/lib/objects/integration/DefaultLiveObjectsTest.kt
📚 Learning: in the ably-java codebase, the defaultliveobjectserializer class methods like writemsgpackarray will...
Learnt from: sacOO7
PR: ably/ably-java#1106
File: live-objects/src/main/kotlin/io/ably/lib/objects/serialization/Serialization.kt:25-29
Timestamp: 2025-06-23T14:18:25.315Z
Learning: In the ably-java codebase, the DefaultLiveObjectSerializer class methods like writeMsgpackArray will have their type signatures updated to be non-nullable since the calling sites ensure objects are never null when passed to these methods.

Applied to files:

  • live-objects/src/test/kotlin/io/ably/lib/objects/integration/DefaultLiveObjectsTest.kt
🧬 Code Graph Analysis (1)
live-objects/src/test/kotlin/io/ably/lib/objects/integration/DefaultLiveObjectsTest.kt (1)
live-objects/src/test/kotlin/io/ably/lib/objects/TestUtils.kt (1)
  • assertWaiter (11-20)
⏰ 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). (11)
  • GitHub Check: check-realtime-okhttp
  • GitHub Check: check-rest-okhttp
  • GitHub Check: check-liveobjects
  • GitHub Check: check-rest
  • GitHub Check: check-realtime
  • GitHub Check: check
  • GitHub Check: check (19)
  • GitHub Check: check (24)
  • GitHub Check: check (29)
  • GitHub Check: check (21)
  • GitHub Check: build
🔇 Additional comments (8)
live-objects/src/test/kotlin/io/ably/lib/objects/integration/DefaultLiveObjectsTest.kt (8)

9-9: LGTM: Import added for object deletion simulation.

The import for simulateObjectDelete helper function aligns with the new test approach of simulating server-sent object deletion messages rather than using REST API calls.


14-15: LGTM: Imports added for concrete LiveObject types.

The imports for DefaultLiveCounter, DefaultLiveMap, and LiveMapUpdate are necessary for the updated test implementation that needs to cast to concrete types and handle map update events.

Also applies to: 17-17


164-167: Good documentation update for the test purpose.

The updated comment clearly explains that the test simulates object deletion by sending OBJECT_DELETE protocol messages locally, which aligns with the PR's objective of handling server-provided timestamps for tombstone management. The spec reference (RTLO4e) provides good traceability.


169-169: Appropriate test method rename.

The rename from testObjectRemovalFromRoot to testObjectDelete better reflects the actual functionality being tested - object deletion via server protocol messages rather than just removal from collections.


196-214: Verify the map deletion simulation and update verification logic.

The test logic for map deletion looks sound - it subscribes to updates, simulates deletion, and verifies the update contains the expected REMOVED change for the "counterKey". The assertions properly validate both the update structure and content.


216-237: Verify the comprehensive map deletion test with all entries.

The test correctly verifies that when the valuesMap (containing 13 entries) is deleted, all entries are marked as REMOVED in the update event. The logic properly validates both the update count and that each change type is REMOVED.


188-188: simulateObjectDelete extension verified

The simulateObjectDelete extension is defined in
live-objects/src/test/kotlin/io/ably/lib/objects/integration/helpers/Utils.kt and correctly constructs a ProtocolMessage with an ObjectDelete operation before invoking defaultLiveObjects.handle(...). No changes are needed here.


179-194: Verify tombstone update amount in counter deletion

Please confirm that the deletion simulation emits an update equal to the negative of the counter’s current value:

  • Trace the implementation of simulateObjectDelete in the channel/object-handling code to ensure it creates a tombstone update carrying -currentValue.
  • Verify in DefaultLiveCounter (or the class handling counter updates) that this tombstone event is passed through unmodified so subscribers receive exactly -20.0 when deleting a 20.0 counter.
  • If the logic differs, adjust either the test expectation or the deletion/update implementation accordingly.
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/server-provided-tombstone-serial

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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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/1134/features July 24, 2025 13:22 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1134/javadoc July 24, 2025 13:25 Inactive
@sacOO7 sacOO7 changed the title [ECO-5447] Updated ObjectMessage with server provided serialTimestamp [ECO-5447][LiveObjects] Updated ObjectMessage with server provided serialTimestamp Jul 24, 2025
…mestamp

1. Updated LiveMap and LiveCounter impl to accept serialTimestamp from ObjectMessage
2. Updated unit tests for both LiveMap and LiveCounter
@github-actions github-actions bot temporarily deployed to staging/pull/1134/features July 25, 2025 10:53 Inactive
@sacOO7 sacOO7 marked this pull request as ready for review July 25, 2025 10:54
@github-actions github-actions bot temporarily deployed to staging/pull/1134/javadoc July 25, 2025 10:55 Inactive
@sacOO7 sacOO7 changed the title [ECO-5447][LiveObjects] Updated ObjectMessage with server provided serialTimestamp [ECO-5447][LiveObjects] use server-provided timestamp to sweep old tombstones Jul 25, 2025
@sacOO7 sacOO7 changed the title [ECO-5447][LiveObjects] use server-provided timestamp to sweep old tombstones [ECO-5447][LiveObjects] Use server-provided timestamp to sweep old tombstones Jul 25, 2025
@sacOO7 sacOO7 requested a review from ttypic July 25, 2025 11:43
@github-actions github-actions bot temporarily deployed to staging/pull/1134/features July 29, 2025 10:46 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1134/javadoc July 29, 2025 10:49 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1134/features July 29, 2025 15:31 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1134/javadoc July 29, 2025 15:33 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1134/features August 1, 2025 10:39 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1134/javadoc August 1, 2025 10:41 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1134/features August 1, 2025 12:09 Inactive
@sacOO7 sacOO7 force-pushed the feature/server-provided-tombstone-serial branch from 8b6f64f to 332ac0a Compare August 1, 2025 12:10
@github-actions github-actions bot temporarily deployed to staging/pull/1134/features August 1, 2025 12:11 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1134/javadoc August 1, 2025 12:13 Inactive
@sacOO7 sacOO7 force-pushed the feature/server-provided-tombstone-serial branch from 332ac0a to 97f55f7 Compare August 1, 2025 12:13
@github-actions github-actions bot temporarily deployed to staging/pull/1134/features August 1, 2025 12:14 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1134/javadoc August 1, 2025 12:15 Inactive
Copy link
Contributor

@ttypic ttypic left a comment

Choose a reason for hiding this comment

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

LGTM

- Added extra assertion for deleting of "valuesMap"
@sacOO7
Copy link
Collaborator Author

sacOO7 commented Aug 6, 2025

closing in favor of #1140

@sacOO7 sacOO7 closed this Aug 6, 2025
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.

3 participants