Skip to content

fix(rooms): cleanup edge case for 1hr ttl#3163

Merged
icecrasher321 merged 4 commits intostagingfrom
fix/room-presence
Feb 7, 2026
Merged

fix(rooms): cleanup edge case for 1hr ttl#3163
icecrasher321 merged 4 commits intostagingfrom
fix/room-presence

Conversation

@icecrasher321
Copy link
Collaborator

Summary

If sockets entry got cleaned up by 1hr ttl -- room presence would not be cleaned.

Type of Change

  • Bug fix

Testing

Tested manually using redis cli

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 7, 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 7, 2026 8:18pm

Request Review

@icecrasher321
Copy link
Collaborator Author

@cursor review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 7, 2026

Greptile Overview

Greptile Summary

Summary

This PR addresses an edge case where a socket entry can expire via the 1-hour TTL before the corresponding room presence is cleaned up, leaving stale presence in rooms. The changes appear to add cleanup paths in the socket connection/workflow handlers and adjust the room managers/types/feature-flag configuration so that presence is removed when the underlying socket mapping is missing or has been evicted.

Overall, the change fits into the existing socket/rooms architecture by extending the room memory-manager / redis-manager cleanup logic and wiring it through the connection/workflow handlers so room presence stays consistent with the sockets index, even when TTL-based eviction happens asynchronously.

Confidence Score: 3/5

  • This PR is close to safe to merge, but has a correctness issue in workflow socket cleanup that can disconnect the wrong user under shared tabSessionId conditions.
  • Score reduced due to a definite cross-user cleanup bug introduced in the workflow handler; the rest of the changes appear localized to presence cleanup and type/signature updates with no other confirmed issues found.
  • apps/sim/socket/handlers/workflow.ts

Important Files Changed

Filename Overview
apps/sim/socket/handlers/workflow.ts Refactors duplicate/stale socket cleanup when joining workflows, but removes a userId guard so cleanup may target other users' sockets sharing the same tabSessionId.
apps/sim/socket/handlers/connection.ts Updates connection handling to account for TTL-expired socket mappings and trigger room presence cleanup; no definite issues found in this review.
apps/sim/socket/rooms/redis-manager.ts Adjusts Redis-backed room presence cleanup to handle missing socket entries after TTL eviction; no definite issues found in this review.
apps/sim/socket/rooms/memory-manager.ts Updates in-memory room presence manager to mirror TTL-expiry cleanup behavior; no definite issues found in this review.
apps/sim/socket/rooms/types.ts Extends room manager types/signatures to support additional cleanup context for TTL-expired sockets; no definite issues found.
apps/sim/lib/core/config/feature-flags.ts Tweaks feature flag configuration related to room/presence cleanup behavior; no definite issues found.

Sequence Diagram

sequenceDiagram
  participant Client
  participant SocketHandlers as Socket Handlers
  participant Rooms as Rooms Manager
  participant Redis as Redis (sockets + presence)

  Client->>SocketHandlers: Connect / Resume
  SocketHandlers->>Redis: Read socket entry (TTL-backed)
  alt socket entry present
    SocketHandlers->>Rooms: Join / update presence
    Rooms->>Redis: Write presence
  else socket entry missing (expired by 1hr TTL)
    SocketHandlers->>Rooms: Cleanup presence for stale socket
    Rooms->>Redis: Remove presence + room membership
  end

  Client->>SocketHandlers: Workflow events
  SocketHandlers->>Redis: Resolve socket entry
  alt missing/expired
    SocketHandlers->>Rooms: Cleanup stale presence
    Rooms->>Redis: Remove presence
  else present
    SocketHandlers->>Rooms: Update presence
    Rooms->>Redis: Persist presence
  end
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.

6 files reviewed, 1 comment

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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@icecrasher321 icecrasher321 merged commit 0cb6714 into staging Feb 7, 2026
6 checks passed
@icecrasher321 icecrasher321 deleted the fix/room-presence branch February 7, 2026 20:18
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.

1 participant