Skip to content

[AIT-296] fix: clear buffered operations unconditionally on ATTACHED (RTO4d)#1196

Open
ttypic wants to merge 1 commit intoAIT-276/apply-on-ackfrom
AIT-296/buffered-ops
Open

[AIT-296] fix: clear buffered operations unconditionally on ATTACHED (RTO4d)#1196
ttypic wants to merge 1 commit intoAIT-276/apply-on-ackfrom
AIT-296/buffered-ops

Conversation

@ttypic
Copy link
Contributor

@ttypic ttypic commented Mar 5, 2026

  • Ensured BufferedObjectOperations is always cleared when channel state transitions to ATTACHED, regardless of the hasObjects flag.
  • Updated tests to verify buffer clearing behavior (RTO4d).

Spec: ably/specification#416
Js: ably/ably-js#2150

Summary by CodeRabbit

  • Bug Fixes

    • Removed duplicate clearing of buffered operations during attachment so the buffer is cleared once on attach.
    • Preserve buffered object operations when a new sync starts (they are no longer discarded at sync start).
  • Tests

    • Added and expanded tests covering attach/sync flows, buffered operation handling, resync scenarios, and post-sync application of buffered ops.

@ttypic ttypic requested a review from sacOO7 March 5, 2026 11:23
@coderabbitai
Copy link

coderabbitai bot commented Mar 5, 2026

Walkthrough

Consolidates when buffered object operations are cleared: DefaultRealtimeObjects now unconditionally clears the buffer on ATTACHED (RTO4d), while ObjectsManager.startNewSync no longer clears bufferedObjectOperations. Tests expanded to cover these behaviors and related sync scenarios.

Changes

Cohort / File(s) Summary
Core Implementation
liveobjects/src/main/kotlin/io/ably/lib/objects/DefaultRealtimeObjects.kt
Added unconditional clearBufferedObjectOperations() in the ChannelState.attached branch; removed the duplicate clear from the earlier branch so the buffer is cleared once on ATTACHED (RTO4d).
Sync Manager
liveobjects/src/main/kotlin/io/ably/lib/objects/ObjectsManager.kt
startNewSync no longer clears bufferedObjectOperations; it still clears appliedOnAckSerials, bufferedAcks, resets sync state and emits Syncing.
Unit Tests
liveobjects/src/test/kotlin/io/ably/lib/objects/unit/objects/DefaultRealtimeObjectsTest.kt, liveobjects/src/test/kotlin/io/ably/lib/objects/unit/objects/ObjectsManagerTest.kt
Added test infrastructure and tearDown cleanup; new tests assert: buffer cleared on ATTACHED when hasObjects=true (RTO4d), pre-ATTACHED ops are discarded/not applied after sync, preservation/application of buffered ops across server-initiated resyncs, and that startNewSync clears acks/serials but not object-op buffer.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through code with eager paws,
Moved one clear to where it belongs,
No duplicate scrubbing of buffered laws,
Tests clap softly, affirming the songs,
Syncs now tidy — hops and prance! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: clearing buffered operations unconditionally on ATTACHED with reference to RTO4d requirement.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch AIT-296/buffered-ops

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 and usage tips.

@github-actions github-actions bot temporarily deployed to staging/pull/1196/features March 5, 2026 11:24 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1196/javadoc March 5, 2026 11:26 Inactive
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@liveobjects/src/test/kotlin/io/ably/lib/objects/unit/objects/DefaultRealtimeObjectsTest.kt`:
- Around line 300-301: The test expects bufferedObjectOperations to be preserved
across server-initiated resyncs, but ObjectsManager.startNewSync currently
clears bufferedObjectOperations; update the implementation by removing the call
that empties the buffer so that the ObjectsManager.bufferedObjectOperations (or
BufferedObjectOperations collection) is not cleared during startNewSync,
ensuring the behavior matches the test (and spec RTO5a2b) and leaving any
buffered ops intact across resyncs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 85bd7049-01ca-4888-839a-0787bcc94aa2

📥 Commits

Reviewing files that changed from the base of the PR and between f57632f and 8eb140f.

📒 Files selected for processing (3)
  • liveobjects/src/main/kotlin/io/ably/lib/objects/DefaultRealtimeObjects.kt
  • liveobjects/src/test/kotlin/io/ably/lib/objects/unit/objects/DefaultRealtimeObjectsTest.kt
  • liveobjects/src/test/kotlin/io/ably/lib/objects/unit/objects/ObjectsManagerTest.kt

…(RTO4d)

- Ensured `BufferedObjectOperations` is always cleared when channel state transitions to ATTACHED, regardless of the `hasObjects` flag.
- Updated tests to verify buffer clearing behavior (RTO4d).
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
liveobjects/src/test/kotlin/io/ably/lib/objects/unit/objects/DefaultRealtimeObjectsTest.kt (1)

34-41: Make instance cleanup automatic to avoid future test leaks.

Good addition of tearDown(). One maintainability gap: cleanup still depends on remembering to push every created DefaultRealtimeObjects into testInstances.

♻️ Small refactor to centralize tracking
 class DefaultRealtimeObjectsTest {

   private val testInstances = mutableListOf<DefaultRealtimeObjects>()
+
+  private fun trackedRealtimeObjects(relaxed: Boolean = false): DefaultRealtimeObjects =
+    getDefaultRealtimeObjectsWithMockedDeps(relaxed = relaxed).also { testInstances.add(it) }

   `@After`
   fun tearDown() {
     val cleanupError = AblyException.fromErrorInfo(ErrorInfo("test cleanup", 500))
     testInstances.forEach { it.dispose(cleanupError) }
     testInstances.clear()
   }

Then replace direct calls like getDefaultRealtimeObjectsWithMockedDeps() with trackedRealtimeObjects().

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@liveobjects/src/test/kotlin/io/ably/lib/objects/unit/objects/DefaultRealtimeObjectsTest.kt`
around lines 34 - 41, Tests rely on manually adding each DefaultRealtimeObjects
to testInstances for teardown, which is error-prone; create a helper
trackedRealtimeObjects() that constructs a DefaultRealtimeObjects (delegating to
getDefaultRealtimeObjectsWithMockedDeps() or similar), automatically appends it
to the testInstances list, and return it to callers so tests no longer need to
push instances themselves; update tests to call trackedRealtimeObjects() instead
of getDefaultRealtimeObjectsWithMockedDeps() and keep tearDown() as-is to
dispose all tracked DefaultRealtimeObjects.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@liveobjects/src/test/kotlin/io/ably/lib/objects/unit/objects/DefaultRealtimeObjectsTest.kt`:
- Around line 34-41: Tests rely on manually adding each DefaultRealtimeObjects
to testInstances for teardown, which is error-prone; create a helper
trackedRealtimeObjects() that constructs a DefaultRealtimeObjects (delegating to
getDefaultRealtimeObjectsWithMockedDeps() or similar), automatically appends it
to the testInstances list, and return it to callers so tests no longer need to
push instances themselves; update tests to call trackedRealtimeObjects() instead
of getDefaultRealtimeObjectsWithMockedDeps() and keep tearDown() as-is to
dispose all tracked DefaultRealtimeObjects.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2cf77248-6664-448e-971d-94a0cbbccd10

📥 Commits

Reviewing files that changed from the base of the PR and between 8eb140f and d89628c.

📒 Files selected for processing (4)
  • liveobjects/src/main/kotlin/io/ably/lib/objects/DefaultRealtimeObjects.kt
  • liveobjects/src/main/kotlin/io/ably/lib/objects/ObjectsManager.kt
  • liveobjects/src/test/kotlin/io/ably/lib/objects/unit/objects/DefaultRealtimeObjectsTest.kt
  • liveobjects/src/test/kotlin/io/ably/lib/objects/unit/objects/ObjectsManagerTest.kt
💤 Files with no reviewable changes (1)
  • liveobjects/src/main/kotlin/io/ably/lib/objects/ObjectsManager.kt
🚧 Files skipped from review as they are similar to previous changes (2)
  • liveobjects/src/test/kotlin/io/ably/lib/objects/unit/objects/ObjectsManagerTest.kt
  • liveobjects/src/main/kotlin/io/ably/lib/objects/DefaultRealtimeObjects.kt

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.

1 participant