Skip to content

Commit 46408c5

Browse files
committed
fix: resolve 3 critical production bugs and add activity tracking
Critical Fixes: - fix: implement actual cleanup logic to prevent memory leaks * Add ActivityTracker module for last-activity tracking * Implement cleanup_expired_sessions with real cleanup logic * Add touch/1 API for manual TTL extension * Auto-track activity on call/cast operations - fix: enforce rate limiting to prevent DoS attacks * Add RateLimiter module with sliding window algorithm * Integrate rate limiting into session creation flow * Add telemetry events for rate limit monitoring * Add rate_limit_exceeded error type - fix: standardize macro argument names for consistency * Change :process_link macro to use :arg instead of :args * Fix get_session_id/0 nil handling in both macros * Add comprehensive macro consistency tests New Features: - Add Phoenix.SessionProcess.ActivityTracker module - Add Phoenix.SessionProcess.RateLimiter module - Add Phoenix.SessionProcess.touch/1 for manual TTL extension - Add rate limit telemetry events - Add activity-based TTL tracking Tests: - Add 18 new tests (ActivityTracker, RateLimiter, macro consistency) - Update test support to use GenServer state - All tests passing: 93 tests total Documentation: - Add FIXES_SUMMARY.md with complete fix documentation - Update README.md with new features - Update CLAUDE.md architecture documentation - Simplify state management to GenServer + optional Redux Files Changed: 20 files - 5 new modules and test files - 2 deleted (unreleased Agent module) - 13 updated (core fixes + documentation)
1 parent 5892ccd commit 46408c5

20 files changed

+1399
-414
lines changed

CLAUDE.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ The library is organized into several logical groups:
6767
- `Phoenix.SessionProcess.DefaultSessionProcess` - Default session implementation
6868

6969
**State Management Utilities**:
70-
- `Phoenix.SessionProcess.State` - Agent-based state storage
71-
- `Phoenix.SessionProcess.Redux` - Redux-style state with actions/reducers
70+
- `Phoenix.SessionProcess.Redux` - Optional Redux-style state with actions/reducers (advanced use cases)
7271
- `Phoenix.SessionProcess.MigrationExamples` - Migration examples for Redux
7372

7473
**Configuration & Error Handling**:
@@ -110,14 +109,10 @@ The library is organized into several logical groups:
110109
- Runs cleanup tasks periodically
111110

112111
6. **Phoenix.SessionProcess.Redux** (lib/phoenix/session_process/redux.ex:1)
113-
- Redux-style state management with actions and reducers
112+
- Optional Redux-style state management with actions and reducers
114113
- Provides time-travel debugging, middleware support, and action history
115-
- Best for complex applications requiring predictable state updates
116-
117-
7. **Phoenix.SessionProcess.State** (lib/phoenix/session_process/state.ex:1)
118-
- Agent-based state storage with simple get/put operations
119-
- Also supports Redux-style dispatch for hybrid approaches
120-
- Best for simple state management scenarios
114+
- Best for complex applications requiring predictable state updates and audit trails
115+
- Note: Most applications don't need this - standard GenServer state is sufficient
121116

122117
### Process Management Flow
123118

@@ -167,11 +162,16 @@ Configuration options:
167162

168163
## State Management Options
169164

170-
The library provides three state management approaches:
165+
The library provides two state management approaches:
166+
167+
1. **Standard GenServer State** (Recommended) - Full control with standard GenServer callbacks
168+
- Use `handle_call`, `handle_cast`, and `handle_info` to manage state
169+
- Simple, idiomatic Elixir - this is what you should use for 95% of cases
171170

172-
1. **Basic GenServer** - Full control with standard GenServer callbacks
173-
2. **Phoenix.SessionProcess.State** - Agent-based with simple get/put and Redux dispatch
174-
3. **Phoenix.SessionProcess.Redux** - Full Redux pattern with actions, reducers, middleware, time-travel debugging
171+
2. **Phoenix.SessionProcess.Redux** (Optional, Advanced) - Redux pattern for complex state machines
172+
- Actions, reducers, middleware, time-travel debugging
173+
- Only use if you need audit trails or complex state machine logic
174+
- Adds complexity - most applications don't need this
175175

176176
## Telemetry and Error Handling
177177

0 commit comments

Comments
 (0)