[AIT-119] Implicit attach on channel.object.get()
Resolves AIT-119
Summary by CodeRabbit
-
Bug Fixes
- Fetching objects on unattached channels now implicitly attaches and waits for synchronization; clearer errors when subscription mode is disallowed.
-
Behavior Changes
- Presence retrieval now uses a promise-based sync wait, returning current state immediately when not waiting and raising a clear error if suspended while a sync is requested.
-
Tests
- Added tests for implicit attach-and-sync and expanded channel-mode error assertions.
✏️ Tip: You can customize this high-level summary in your review settings.
Walkthrough
RealtimeObject.get() now validates the channel mode, implicitly ensures channel attachment via RealtimeChannel.ensureAttached(), waits for OBJECT_SYNC if required, and returns the root object. PresenceMap.waitSync moved from callback to Promise; RealtimePresence.get() now uses async/await and ensureAttached().
Changes
| Cohort / File(s) | Summary |
|---|---|
RealtimeObject implementation src/plugins/objects/realtimeobject.ts |
Validate channel mode with _throwIfMissingChannelMode('object_subscribe'); implicitly attach by await this._channel.ensureAttached(); await OBJECT_SYNC when needed before returning root DefaultPathObject. |
RealtimeChannel API src/common/lib/client/realtimechannel.ts |
Added ensureAttached(): Promise<void> to attach when in attachable states or throw the channel's invalid state error in failed/non-attachable states. |
RealtimePresence src/common/lib/client/realtimepresence.ts |
Removed callback-based waitAttached flow; converted get() to async/await: await channel.ensureAttached(), optionally await members.waitSync() when waitForSync is true; throws ErrorInfo for suspended+waitForSync. |
PresenceMap sync API src/common/lib/client/presencemap.ts |
Replaced waitSync(callback) with waitSync(): Promise<void> that resolves immediately if not syncing or awaits the internal 'sync' event. |
Tests: objects & behavior test/realtime/objects.test.js |
Added test asserting RealtimeObject.get() implicitly attaches on an unattached channel and waits for OBJECT_SYNC; expanded invalid-channel-mode throw checks; removed one explicit throw expectation replaced by implicit-attach assertions. |
Sequence Diagram(s)
sequenceDiagram
participant Caller
participant RealtimeObject
participant RealtimeChannel
participant EventSystem
Caller->>RealtimeObject: get()
RealtimeObject->>RealtimeObject: _throwIfMissingChannelMode('object_subscribe')
alt mode invalid
RealtimeObject-->>Caller: throw Error
else mode valid
RealtimeObject->>RealtimeChannel: ensureAttached()
alt Channel not attached
RealtimeChannel->>EventSystem: attach()
EventSystem-->>RealtimeChannel: attached event
RealtimeChannel-->>RealtimeObject: resolved
else already attached
RealtimeChannel-->>RealtimeObject: resolved (no-op)
end
RealtimeObject->>EventSystem: await OBJECT_SYNC (once)
EventSystem-->>RealtimeObject: OBJECT_SYNC
RealtimeObject-->>Caller: return root DefaultPathObject
end
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
- Review focus:
RealtimeChannel.ensureAttached()state handling and thrown errors.- Places relying on old callback
waitSyncsignature and updated call sites. - Race conditions around awaiting a single OBJECT_SYNC and attachment ordering.
Poem
🐇
I gave the channel a gentle tap,
it blinked, then stitched the missing gap.
I waited as the sync unfurled—
the root hopped back into the world.
🌿✨
Pre-merge checks and finishing touches
❌ Failed checks (1 warning, 2 inconclusive)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
| Linked Issues check | ❓ Inconclusive | The linked issue AIT-119 lacks detailed requirements, but the code changes implement implicit channel attachment in RealtimeObject.get() as indicated by the issue title. | Verify with the issue tracker that the implementation matches all requirements, particularly regarding implicit attach behavior, sync wait semantics, and error handling for channel mode validation. |
| Out of Scope Changes check | ❓ Inconclusive | Changes to PresenceMap.waitSync(), RealtimeChannel.ensureAttached(), and RealtimePersence.get() appear to support the implicit attach feature but lack clear traceability to the linked issue. | Confirm that all modified files (presencemap.ts, realtimechannel.ts, realtimepresence.ts) are necessary dependencies for the implicit attach feature and document their relationship to AIT-119. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The PR title clearly and specifically describes the main change: implementing implicit attachment behavior when calling channel.object.get(). |
✨ Finishing touches
- [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
- [ ] Commit unit tests in branch
AIT-119/object.get-implicit-attach
[!WARNING] There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.
🔧 ast-grep (0.40.0)
test/realtime/objects.test.js
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.
Comment @coderabbitai help to get the list of available commands and usage tips.
Please could you either restructure or squash the commits? currently we have a commit where we add some duplicated logic and then another where we remove what we just added
Fixed (no code change, just restructutred commits).