feat(playground): add session management endpoint (#127)#129
Merged
DevanshuNEU merged 1 commit intoDec 25, 2025
Merged
Conversation
## Changes
### services/playground_limiter.py
- Add SessionData and IndexedRepoData dataclasses
- Add get_session_data() - retrieve complete session state
- Add set_indexed_repo() - store indexed repo in session
- Add has_indexed_repo() - check if session has repo
- Add clear_indexed_repo() - remove repo from session
- Add create_session() - create new session with hash structure
- Add _ensure_hash_format() - migrate legacy string sessions to hash
- Update _check_session_limit() to use HINCRBY for atomic ops
- Add comprehensive logging and metrics
### routes/playground.py
- Add GET /session endpoint
- Returns session info including indexed repo and search counts
- Creates new session if none exists
- Handles Redis unavailable (503)
### tests/test_playground_limiter.py (NEW)
- 36 test cases covering:
- Data classes (IndexedRepoData, SessionData)
- Session data retrieval
- Indexed repo storage/retrieval
- Legacy migration (string -> hash)
- Rate limiting with hash storage
- Full session lifecycle workflow
### tests/conftest.py
- Add Redis hash operation mocks (hset, hget, hincrby, etc.)
## Redis Schema (Hash)
Key: playground:session:{token}
Fields:
- searches_used: int
- created_at: ISO timestamp
- indexed_repo: JSON blob (optional)
Closes OpenCodeIntel#127
|
@DevanshuNEU is attempting to deploy a commit to the Dev's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements session management infrastructure for anonymous playground users, enabling the anonymous indexing feature (Epic #114).
Changes
Core Implementation
New Methods in PlaygroundLimiter
get_session_data()set_indexed_repo()has_indexed_repo()clear_indexed_repo()create_session()Redis Schema (Hash)
API Response Schema
{ "session_id": "pg_abc123...", "created_at": "2025-12-24T10:00:00Z", "expires_at": "2025-12-25T10:00:00Z", "indexed_repo": { "repo_id": "repo_abc123", "github_url": "https://github.com/user/repo", "name": "repo", "file_count": 198, "indexed_at": "...", "expires_at": "..." }, "searches": { "used": 12, "limit": 50, "remaining": 38 } }Testing
Technical Notes
Unblocks
Closes #127