Skip to content

Conversation

@pheller
Copy link
Member

@pheller pheller commented Sep 11, 2025

Refactor sessions into a database table, support logon concurrency

  • Users were limited to a single concurrent session based on a boolean flag in the user record, but it's desirable to permit multiple concurrent sessions for the same user id in some situations.
  • Now, individual users have a concurrency limit (default 1, 0 means unlimited), and this is determined by examining the number of concurrent related rows in the session table. This is determined by sessions that have a logon time, but not a logoff time.
  • The server will take care to close all active sessions when it exits normally.
  • To avoid ambiguity, "Session" now means the persistent record of a connection and lives in Prodigy.Core.Data.Session, and the former Prodigy.Server.Session has been renamed Prodigy.Server.Context, which is used to store ephemeral state related to connection while that connection is active.

- remove logged_on attribute from user schema, add a concurrency limit
- add session schema, one user to many sessions
- add a SessionSupervisor to hook into the server lifecycle and do cleanup
- add a SessionManager responsible for manipulating the session table
- fix repocase to ensure the database doesn't shutdown till the test completes
- update test_helper
# Conflicts:
#	apps/server/lib/prodigy/server/service/messaging.ex
Session is now a persistent record of when users sessions begin and end (and thus which are presently active), and Context was chosen to represent the ephemeral details that are necessary to the operation of the service during a single user connection.
@pheller pheller requested a review from Copilot September 11, 2025 00:24
Copy link

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 PR refactors session management from a simple boolean flag to a proper database table with support for concurrent sessions.

  • Replaced user-level logged_on boolean with a dedicated session table
  • Added configurable concurrency limits per user (default: 1, 0 for unlimited)
  • Renamed Session to Context to better reflect ephemeral connection state

Reviewed Changes

Copilot reviewed 32 out of 32 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
apps/server/lib/prodigy/server/session_manager.ex New module for managing user sessions with concurrency control
apps/server/lib/prodigy/server/session_cleanup.ex New GenServer for cleaning up sessions on shutdown
apps/core/priv/repo/migrations/20250908221355_create_sessions.exs Database migration creating session table and removing logged_on field
apps/core/lib/prodigy/core/data/session.ex New Session schema for persistent session records
apps/core/lib/prodigy/core/data/user.ex Updated User schema to include concurrency_limit and sessions relationship
apps/server/lib/prodigy/server/context.ex Renamed from Session to Context for ephemeral connection state
apps/server/lib/prodigy/server/service/logon.ex Updated to use SessionManager for concurrency control
apps/server/lib/prodigy/server/service/logoff.ex Updated to close sessions via SessionManager

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@pheller pheller marked this pull request as ready for review September 11, 2025 01:17
@pheller pheller merged commit b6ada92 into ProdigyReloaded:main Sep 12, 2025
1 check passed
@pheller pheller deleted the session-management branch September 12, 2025 00: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