Skip to content

Conversation

@icecrasher321
Copy link
Collaborator

Summary

  • Redis unavailable with redis mode should trigger connection warning
  • Reconnect strategy should be the default

Type of Change

  • Other: UX improvement

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Feb 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Feb 2, 2026 6:04pm

Request Review

@icecrasher321 icecrasher321 changed the title improvement(rooms): redis client closed should fail fast improvement(rooms): redis client closed should fail with indicator Feb 2, 2026
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 2, 2026

Greptile Overview

Greptile Summary

This PR improves error handling when Redis is unavailable by implementing a fail-fast strategy. The changes introduce an isReady() method to the room manager interface that tracks Redis connection state, and all socket handlers now check this before processing requests. When Redis is unavailable, the system immediately notifies clients with a ROOM_MANAGER_UNAVAILABLE error code, which triggers the frontend to enter offline mode gracefully.

Key improvements:

  • Removed custom reconnection strategy from RedisRoomManager to use the Redis client's default behavior
  • Added isReady() method to both RedisRoomManager and MemoryRoomManager implementations
  • All socket handlers (operations, subblocks, variables, workflow) now check isReady() before processing
  • HTTP POST endpoints return 503 status when room manager is unavailable
  • Frontend socket-provider triggers offline mode when receiving ROOM_MANAGER_UNAVAILABLE code
  • Operations handler wraps room manager calls in try-catch to handle Redis errors gracefully

Confidence Score: 5/5

  • This PR is safe to merge with no issues found
  • The implementation is thorough and consistent across all handlers, follows defensive programming practices with try-catch blocks, and improves UX by providing clear error messages to users when realtime features are unavailable
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/socket/rooms/redis-manager.ts Removed custom reconnection strategy to use Redis client's default behavior, added isReady() method, and added 'end' event handler
apps/sim/socket/rooms/types.ts Added isReady() method to IRoomManager interface
apps/sim/socket/handlers/operations.ts Added isReady() check at handler entry and wrapped room manager calls in try-catch to emit appropriate errors when realtime is unavailable
apps/sim/app/workspace/providers/socket-provider.tsx Added offline mode trigger when receiving ROOM_MANAGER_UNAVAILABLE error code from join-workflow-error event

Sequence Diagram

sequenceDiagram
    participant Client as Frontend Client
    participant Socket as Socket Handler
    participant RoomMgr as Room Manager
    participant Redis as Redis

    Note over Redis: Redis becomes unavailable
    Redis-->>RoomMgr: Connection closed
    RoomMgr->>RoomMgr: isConnected = false

    Client->>Socket: join-workflow-request
    Socket->>RoomMgr: isReady()
    RoomMgr-->>Socket: false
    Socket->>Client: join-workflow-error<br/>{code: ROOM_MANAGER_UNAVAILABLE}
    Client->>Client: triggerOfflineMode()

    Client->>Socket: workflow-operation
    Socket->>RoomMgr: isReady()
    RoomMgr-->>Socket: false
    Socket->>Client: operation-forbidden<br/>{type: ROOM_MANAGER_UNAVAILABLE}
    Socket->>Client: operation-failed<br/>{retryable: true}

    Note over Redis: Redis reconnects
    Redis-->>RoomMgr: Connection ready
    RoomMgr->>RoomMgr: isConnected = true

    Client->>Socket: join-workflow-request
    Socket->>RoomMgr: isReady()
    RoomMgr-->>Socket: true
    Socket->>RoomMgr: addUserToRoom()
    RoomMgr->>Redis: Store session data
    Redis-->>RoomMgr: Success
    Socket->>Client: workflow-state
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

4 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@icecrasher321
Copy link
Collaborator Author

@cursor review

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

})
}
return
}
Copy link

Choose a reason for hiding this comment

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

Unprotected Redis call can cause unhandled promise rejection

Low Severity

The hasWorkflowRoom call at line 70 is outside any try-catch block, unlike the getWorkflowIdForSocket and getUserSession calls which were wrapped in error handling by this PR. If Redis becomes unavailable after the isReady() check passes but before hasWorkflowRoom executes, the Redis call will throw an unhandled error. This inconsistently breaks the error handling pattern established elsewhere in this handler, potentially causing ungraceful socket disconnection without the ROOM_MANAGER_UNAVAILABLE error being sent to the client.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants