Skip to content

Conversation

@VeskeR
Copy link
Contributor

@VeskeR VeskeR commented Jun 12, 2025

This is the spec equivalent of the object sync sequence handling in ably-js https://github.com/ably/ably-js/blob/main/src/plugins/objects/objects.ts#L215

Resolves PUB-1041

@github-actions github-actions bot temporarily deployed to staging/pull/333 June 12, 2025 08:46 Inactive
@VeskeR VeskeR changed the base branch from main to objects-plugin June 12, 2025 08:46
@VeskeR VeskeR force-pushed the PUB-1041/object-sync branch from d10e385 to 3336d98 Compare June 12, 2025 09:14
@github-actions github-actions bot temporarily deployed to staging/pull/333 June 12, 2025 09:15 Inactive
@lawrence-forooghian lawrence-forooghian added the live-objects Related to LiveObjects functionality. label Jun 12, 2025
@VeskeR VeskeR force-pushed the PUB-1041/object-sync branch 2 times, most recently from 36792eb to cdb9d58 Compare June 12, 2025 23:37
@github-actions github-actions bot temporarily deployed to staging/pull/333 June 12, 2025 23:37 Inactive
@VeskeR VeskeR force-pushed the PUB-1041/object-sync branch from cdb9d58 to f4dd5d4 Compare June 13, 2025 00:15
@github-actions github-actions bot temporarily deployed to staging/pull/333 June 13, 2025 00:15 Inactive
@VeskeR VeskeR force-pushed the PUB-1041/object-sync branch from f4dd5d4 to b4d8e4d Compare June 13, 2025 02:04
@github-actions github-actions bot temporarily deployed to staging/pull/333 June 13, 2025 02:05 Inactive
@VeskeR VeskeR force-pushed the PUB-1041/object-sync branch from b4d8e4d to 948ad9b Compare June 13, 2025 08:40
@github-actions github-actions bot temporarily deployed to staging/pull/333 June 13, 2025 08:40 Inactive
@VeskeR VeskeR force-pushed the objects-plugin branch 3 times, most recently from bebe5fa to 5a6893a Compare June 19, 2025 03:00
@VeskeR VeskeR force-pushed the PUB-1041/object-sync branch from 948ad9b to 39111b8 Compare June 19, 2025 03:05
@github-actions github-actions bot temporarily deployed to staging/pull/333 June 19, 2025 03:06 Inactive
@VeskeR VeskeR force-pushed the PUB-1041/object-sync branch from 39111b8 to 8a7c38e Compare June 19, 2025 03:06
@github-actions github-actions bot temporarily deployed to staging/pull/333 June 19, 2025 03:07 Inactive
@VeskeR VeskeR force-pushed the PUB-1041/object-sync branch from 8a7c38e to 2335a1d Compare June 19, 2025 04:30
@github-actions github-actions bot temporarily deployed to staging/pull/333 June 19, 2025 04:30 Inactive
lawrence-forooghian added a commit to ably/ably-liveobjects-swift-plugin that referenced this pull request Jul 4, 2025
Based on [1] at dd25dca.

The development approach here was roughly the following: I decided the
internal types and interfaces that I wanted to exist, and some of the
implementation details (e.g. the mutations that DefaultRealtimeObjects
performs during a sync sequence). I then asked Cursor to fill in the
most of the implementation and tests (providing it with the relevant
spec text). I have done some tweaking of the code that Cursor generated,
but that doesn't mean that all of the code that's here is exactly the
same as code that I would write, and I'm going to leave it that way.

I have looked through all (and changed some) of the tests that Cursor
generated, and in doing so also fixed the spec conformance tags (because
it got those very wrong), so I am _fairly_ confident that the tests are
testing what they claim to test. But I have not looked at them in minute
detail (in particular, the exact data created by the canned data
factories that it created). I also think that tests are one of those
things where there's not always one right way to write them, so I'm not
going to get hung up on "could it have done this test differently?" or
"are the tests consistent with each other?" at the moment.

There are some outstanding questions on the spec PR at the moment; have
implemented to best of my understanding, and will update later once
those are answered.

Not yet implemented:

- Checking of channel modes before performing operations (RTO2 and the
  points that refer to it); there's an outstanding question about this
  at [2]

[1] ably/specification#333
[2] https://github.com/ably/specification/pull/333/files#r2152297442
lawrence-forooghian added a commit to ably/ably-liveobjects-swift-plugin that referenced this pull request Jul 7, 2025
Based on [1] at dd25dca.

The development approach here was roughly the following: I decided the
internal types and interfaces that I wanted to exist, and some of the
implementation details (e.g. the mutations that DefaultRealtimeObjects
performs during a sync sequence). I then asked Cursor to fill in the
most of the implementation and tests (providing it with the relevant
spec text). I have done some tweaking of the code that Cursor generated,
but that doesn't mean that all of the code that's here is exactly the
same as code that I would write, and I'm going to leave it that way.

I have looked through all (and changed some) of the tests that Cursor
generated, and in doing so also fixed the spec conformance tags (because
it got those very wrong), so I am _fairly_ confident that the tests are
testing what they claim to test. But I have not looked at them in minute
detail (in particular, the exact data created by the canned data
factories that it created). I also think that tests are one of those
things where there's not always one right way to write them, so I'm not
going to get hung up on "could it have done this test differently?" or
"are the tests consistent with each other?" at the moment.

There are some outstanding questions on the spec PR at the moment; have
implemented to best of my understanding, and will update later once
those are answered.

Not yet implemented:

- Checking of channel modes before performing operations (RTO2 and the
  points that refer to it); there's an outstanding question about this
  at [2]

A note re the MutableState pattern that I've used here — done this so
that the class can essentially have mutating instance methods which can
call each other without having to worry about whose responsibility it is
to acquire the mutex.

[1] ably/specification#333
[2] https://github.com/ably/specification/pull/333/files#r2152297442
**** @(RTO5c1a)@ If an object with @ObjectState.objectId@ exists in the internal @ObjectsPool@:
***** @(RTO5c1a1)@ Override the internal data for the object as per "RTLC6":#RTLC6, "RTLM6":#RTLM6
**** @(RTO5c1b)@ If an object with @ObjectState.objectId@ does not exist in the internal @ObjectsPool@:
***** @(RTO5c1b1)@ Create a new @LiveObject@ using the data from @ObjectState@ and add it to the internal @ObjectsPool@:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we already have objectState.objectId, why can't we create zero-value liveobject from the same?

Copy link
Collaborator

@sacOO7 sacOO7 Jul 10, 2025

Choose a reason for hiding this comment

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

This feels like an alternative and duplicate of RTO6

Copy link
Collaborator

Choose a reason for hiding this comment

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

At the same time, RTO6 allow us to validate ObjectId properly, which is missing in current case

Copy link
Contributor Author

@VeskeR VeskeR Sep 5, 2025

Choose a reason for hiding this comment

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

RTO5c1b1 makes sense as the object creation here depends on ObjectState to have a correct field (ObjectState.counter for a counter and ObjectState.map for a map) to decide what object to create. If SDK can't find a recognizable field, the SDK can't process such ObjectState message and logs a warning instead (RTO5c1b1c).

Also, since ObjectState.objectId and ObjectState.counter/ObjectState.map are part of the same ObjectState object, the spec expects that realtime has sent a correct objectId that matches data from ObjectState.counter/ObjectState.map.

** @(RTO3a)@ @ObjectsPool@ is a @Dict<String, LiveObject>@ - a map of @LiveObject@s keyed by "@objectId@":../features#OST2a string
** @(RTO3b)@ It must always contain a @LiveMap@ object with id @root@
* @(RTO4)@ When a channel @ATTACHED@ @ProtocolMessage@ is received, the @ProtocolMessage@ may contain a @HAS_OBJECTS@ bit flag indicating that it will perform an objects sync, see "TR3":../features#TR3 . Note that this does not imply that objects are definitely present on the channel, only that there may be; the @OBJECT_SYNC@ message may be empty
** @(RTO4a)@ If the @HAS_OBJECTS@ flag is 1, the server will shortly perform an @OBJECT_SYNC@ sequence as described in "RTO5":#RTO5
Copy link
Collaborator

@sacOO7 sacOO7 Jul 11, 2025

Choose a reason for hiding this comment

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

In ably-js, we check if objects state is INITIALIZED, so irrespective of hasObjects, we always call startNewSync in such a case, can we include this case here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The check in ably-js you mentioned is only required so that library emits "syncing" -> "synced" events (in that order) for lifecycle events even if HAS_OBJECTS flag was false.
The lifecycle events are not part of this spec and will be added in the later PR, which will also address this spec point. Will work on the lifecycle events PR as soon as we finish addressing the outstanding comments on existing PRs.

In relation to this PR, it's fine for the spec to only check HAS_OBJECTS flag

@VeskeR VeskeR force-pushed the PUB-1041/object-sync branch from bfcf05b to b3e06dc Compare September 5, 2025 07:48
… phrasing in RTLM7*, RTLM8*, RTLM6d1a and RTLM6d1b

This uses phrasing initially added in 652daac commit
in #343 PR. It makes sense to
include those changes in this #333 PR
to make the OBJECT sync sequence and related spec items more clear.
@VeskeR VeskeR requested review from owenpearson and sacOO7 September 5, 2025 13:52
Copy link
Collaborator

@sacOO7 sacOO7 left a comment

Choose a reason for hiding this comment

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

LGTM ( You can recheck all review comments in case )

@VeskeR VeskeR merged commit 6d1dabd into main Sep 8, 2025
2 checks passed
@VeskeR VeskeR deleted the PUB-1041/object-sync branch September 8, 2025 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

live-objects Related to LiveObjects functionality.

Development

Successfully merging this pull request may close these issues.

5 participants