Skip to content

feat: add empty room expiry time to configuration and server logic#323

Merged
from2001 merged 2 commits intodevelopfrom
from2001/refactor-timing
Jan 28, 2026
Merged

feat: add empty room expiry time to configuration and server logic#323
from2001 merged 2 commits intodevelopfrom
from2001/refactor-timing

Conversation

@from2001
Copy link
Collaborator

┌──────────────────────────┬────────────────────┬────────────────────────────────────────────┐ 
│         Feature          │       Before       │                   After                    │ 
├──────────────────────────┼────────────────────┼────────────────────────────────────────────┤ 
│ Device ID mapping expiry │ 5 minutes          │ 24 hours                                   │ 
├──────────────────────────┼────────────────────┼────────────────────────────────────────────┤ 
│ Empty room removal       │ Immediate          │ After 24 hours of being empty              │ 
└──────────────────────────┴────────────────────┴────────────────────────────────────────────┘ 
  
┌────────────────────────┬─────────────────┬───────────────────┐ 
│         Config         │     Before      │       After       │  
├────────────────────────┼─────────────────┼───────────────────┤  
│ device_id_expiry_time  │ 300s (5 min)    │ 86400s (24 hours) │  
├────────────────────────┼─────────────────┼───────────────────┤  
│ empty_room_expiry_time │ N/A (immediate) │ 86400s (24 hours) │  
└────────────────────────┴─────────────────┴───────────────────┘  

This pull request introduces configurable delayed removal of empty rooms in the server, allowing rooms without clients to persist for a set period before being deleted. It adds a new configuration option, updates the relevant logic for room cleanup, and ensures the configuration and tests reflect these changes.

Empty Room Expiry Feature:

  • Added a new empty_room_expiry_time configuration option to ServerConfig, the default config file (default.toml), and validation logic, allowing control over how long empty rooms are kept before removal. [1] [2] [3] [4]
  • Updated the server's initialization to use the new empty_room_expiry_time value and added a room_empty_since dictionary to track when rooms become empty. [1] [2]

Room Cleanup Logic:

  • Modified the _cleanup_clients method to delay removal of empty rooms until they have been empty for at least empty_room_expiry_time, including logging when rooms become empty or are repopulated.
  • Ensured all tracking data for rooms, including the new empty room tracking, is properly cleaned up when a room is removed.

Testing and Defaults:

  • Updated tests to check for the new default value of empty_room_expiry_time and its presence in custom configurations. [1] [2]

Close #240

@from2001
Copy link
Collaborator Author

Note:

Network Variables are deleted when their parent Room is removed after the 24-hour empty room expiry.

Or more detailed:

  • Network Variables persist as long as the Room exists
  • When a Room is deleted (after being empty for 24 hours), all associated Network Variables (global and client) are deleted together

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds configurable delayed removal of empty rooms to the server, preventing immediate deletion when the last client disconnects. The changes update both the device ID mapping expiry time and introduce a new empty room expiry time, both set to 24 hours (previously 5 minutes and immediate respectively).

Changes:

  • Added empty_room_expiry_time configuration parameter (24 hours) to control how long empty rooms persist before removal
  • Updated device_id_expiry_time from 5 minutes to 24 hours
  • Implemented delayed room cleanup logic that tracks when rooms become empty and removes them only after the expiry period

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
STYLY-NetSync-Server/src/styly_netsync/config.py Added empty_room_expiry_time field to ServerConfig dataclass and validation logic
STYLY-NetSync-Server/src/styly_netsync/default.toml Updated device_id_expiry_time to 86400s and added empty_room_expiry_time configuration with documentation
STYLY-NetSync-Server/src/styly_netsync/server.py Added room_empty_since tracking dictionary and implemented delayed room removal logic in _cleanup_clients
STYLY-NetSync-Server/tests/test_config.py Updated tests to verify new default values for both timing parameters

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Add comprehensive tests for the delayed room removal feature:
- Empty rooms are tracked when all clients disconnect
- Empty rooms are NOT removed before expiry time
- Empty rooms ARE removed after expiry time elapsed
- Room tracking is cleared when a client rejoins
- Multiple rooms are tracked independently
- EMPTY_ROOM_EXPIRY_TIME is configurable from config

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

Clear timing about Client Network Variables and empty room

2 participants