Skip to content

Conversation

@lawrence-forooghian
Copy link
Collaborator

@lawrence-forooghian lawrence-forooghian commented May 22, 2025

Implements the changes of 34e53e5 from ably/specification#318.

Summary by CodeRabbit

  • Bug Fixes

    • Improved accuracy of channel state transitions when the connection state changes, ensuring channels respond correctly to failed, closed, or suspended connections.
  • Tests

    • Added new tests to verify correct channel behavior during detaching when the connection enters failed, closed, or suspended states.
    • Corrected typos in test descriptions and assertion messages for clarity.

@coderabbitai
Copy link

coderabbitai bot commented May 22, 2025

Walkthrough

The updates correct a method name typo from propogateConnectionInterruption to propagateConnectionInterruption throughout the codebase and refine the logic for propagating connection interruptions to channels. Several test assertion messages are fixed for spelling, and new tests are added to verify channel behavior during connection state transitions while detaching.

Changes

File(s) Change Summary
src/common/lib/client/baserealtime.ts Renamed the method propogateConnectionInterruption to propagateConnectionInterruption. Replaced the old mapping logic for propagating connection interruptions to channels with a more explicit switch-case structure, handling state transitions and error propagation more granularly based on connection and channel states.
src/common/lib/transport/connectionmanager.ts Corrected the method call typo from propogateConnectionInterruption to propagateConnectionInterruption in the notifyState method of ConnectionManager. No other logic was changed.
test/realtime/auth.test.js, test/realtime/resume.test.js Fixed typos in comments and assertion messages, changing "propogated" to "propagated". No changes to test logic or exported entities.
test/realtime/channel.test.js Fixed typos in assertion messages ("propogated" → "propagated"). Added three asynchronous tests to verify channel state transitions when detaching and the connection enters FAILED, CLOSED, or SUSPENDED states, including error handling and promise resolution/rejection checks.

Sequence Diagram(s)

sequenceDiagram
    participant ConnectionManager
    participant Channels
    participant Channel

    ConnectionManager->>Channels: propagateConnectionInterruption(connectionState, reason)
    alt For each Channel in relevant states
        Channels->>Channel: Handle connection interruption (switch-case on states)
        alt Connection state is FAILED
            Channel->>Channel: Transition to FAILED (propagate reason)
        else Connection state is CLOSED
            Channel->>Channel: Transition to DETACHED (propagate reason)
        else Connection state is SUSPENDED
            alt Channel state is ATTACHING or ATTACHED
                Channel->>Channel: Transition to SUSPENDED (propagate reason)
            else Channel state is DETACHING
                Channel->>Channel: Transition to DETACHED (do not propagate reason)
            end
        end
    end
Loading

Poem

In the warren, code hops anew,
Typo fixed, a name rings true!
Channels listen, states align,
Detaching bunnies test in line.
With every hop and error caught,
The garden grows—no bugs forgot!
🐇✨

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.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm warn config production Use --omit=dev instead.
npm warn EBADENGINE Unsupported engine {
npm warn EBADENGINE package: '@es-joy/[email protected]',
npm warn EBADENGINE required: { node: '^14 || ^16 || ^17 || ^18 || ^19 || ^20' },
npm warn EBADENGINE current: { node: 'v24.0.2', npm: '11.3.0' }
npm warn EBADENGINE }
npm warn EBADENGINE Unsupported engine {
npm warn EBADENGINE package: '[email protected]',
npm warn EBADENGINE required: { node: '^14 || ^16 || ^17 || ^18 || ^19' },
npm warn EBADENGINE current: { node: 'v24.0.2', npm: '11.3.0' }
npm warn EBADENGINE }
npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-05-22T09_09_30_175Z-debug-0.log

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

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 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.

@lawrence-forooghian lawrence-forooghian changed the title Make DETACHING channels become DETACHED when connection becomes SUSPENDED [ECO-5361] Make DETACHING channels become DETACHED when connection becomes SUSPENDED May 22, 2025
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

🧹 Nitpick comments (4)
src/common/lib/client/baserealtime.ts (1)

181-205: Add a defensive default branch to future-proof the switch

At the moment every known connection state is handled explicitly, but if the spec evolves a new state could slip through silently.
Logging an error (or throwing in dev builds) makes debugging far easier.

       case 'suspended':
         …
         break;
+      default:
+        this.logger.logAction(
+          Logger.LOG_ERROR,
+          'Channels.propagateConnectionInterruption()',
+          `Unhandled connection state: ${connectionState}`,
+        );
+        break;
test/realtime/channel.test.js (3)

1586-1638: Deduplicate setup code across the three new detaching-state tests

Each of the RTL3g/RTL3h tests repeats identical scaffolding (create realtime, override transport.onProtocolMessage, initiate detach, etc.). Extracting that into a helper such as withDetachingChannel(...) will:

  • reduce ~120 lines of duplication,
  • make individual tests easier to read,
  • ensure future fixes only need to be applied once.

No behavioural change required, purely a maintainability gain.


1641-1680: Use a scenario-specific channel name for the CLOSED test

Re-using 'detached_channel_when_connection_enters_failed' in the CLOSED test is confusing when reading logs or debugging failures.

- const channel = realtime.channels.get('detached_channel_when_connection_enters_failed');
+ const channel = realtime.channels.get('detached_channel_when_connection_enters_closed');

1682-1723: Rename channel in SUSPENDED test for clarity

Similarly, give the SUSPENDED test its own descriptive channel name:

- const channel = realtime.channels.get('detached_channel_when_connection_enters_failed');
+ const channel = realtime.channels.get('detached_channel_when_connection_enters_suspended');
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f6fbe35 and ccf7217.

📒 Files selected for processing (5)
  • src/common/lib/client/baserealtime.ts (1 hunks)
  • src/common/lib/transport/connectionmanager.ts (1 hunks)
  • test/realtime/auth.test.js (1 hunks)
  • test/realtime/channel.test.js (5 hunks)
  • test/realtime/resume.test.js (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
test/realtime/channel.test.js (3)
test/realtime/resume.test.js (3)
  • helper (10-10)
  • helper (616-616)
  • helper (681-681)
test/realtime/auth.test.js (4)
  • helper (32-32)
  • helper (513-513)
  • helper (1217-1217)
  • helper (1257-1257)
test/common/modules/objects_helper.js (1)
  • createPM (7-7)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: test-browser (firefox)
  • GitHub Check: test-browser (chromium)
  • GitHub Check: test-browser (webkit)
  • GitHub Check: test-node (16.x)
  • GitHub Check: test-node (20.x)
  • GitHub Check: test-node (18.x)
🔇 Additional comments (3)
test/realtime/auth.test.js (1)

771-772: Typo fix in test description
Corrects "propogated" to "propagated" to align terminology with the source code change. This is a harmless, consistency-only update.

test/realtime/resume.test.js (1)

451-451: Typo fix in assertion message
Updates the test expectation message from "propogated" to "propagated" to match the corrected method name. No functional change.

src/common/lib/transport/connectionmanager.ts (1)

1306-1307: Invoke correct interruption propagation method
Fixes the typo in the method call from the old propogateConnectionInterruption to the correctly named propagateConnectionInterruption, ensuring that channels are notified of connection interruptions (including SUSPENDED) as intended.

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.

2 participants