Skip to content

feat(playground): add session management endpoint (#127)#129

Merged
DevanshuNEU merged 1 commit into
OpenCodeIntel:mainfrom
DevanshuNEU:feat/127-session-management
Dec 25, 2025
Merged

feat(playground): add session management endpoint (#127)#129
DevanshuNEU merged 1 commit into
OpenCodeIntel:mainfrom
DevanshuNEU:feat/127-session-management

Conversation

@DevanshuNEU

Copy link
Copy Markdown
Collaborator

Summary

Implements session management infrastructure for anonymous playground users, enabling the anonymous indexing feature (Epic #114).

Changes

Core Implementation

  • SessionData dataclass - Complete session state for API responses
  • IndexedRepoData dataclass - Repo details stored in session
  • GET /api/v1/playground/session - New endpoint returning session info

New Methods in PlaygroundLimiter

Method Purpose
get_session_data() Retrieve complete session state
set_indexed_repo() Store indexed repo in session
has_indexed_repo() Check if session has repo (for 1-repo limit)
clear_indexed_repo() Remove repo from session
create_session() Create new session with hash structure

Redis Schema (Hash)

Key: playground:session:{token}
Fields:
├── searches_used: "12"
├── created_at: "2025-12-24T10:00:00Z"
└── indexed_repo: '{"repo_id":"abc","github_url":"...","name":"repo",...}'

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

  • 36 new test cases covering all functionality
  • Full lifecycle tests (create → search → index → search)
  • Legacy migration tests (string → hash format)
  • Error handling tests

Technical Notes

  • Uses Redis Hash for atomic operations (HINCRBY)
  • Backward compatible with legacy string sessions (auto-migrates)
  • Fail-open design (allows requests if Redis unavailable)
  • Comprehensive logging with Sentry integration

Unblocks

Closes #127

## 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
@vercel

vercel Bot commented Dec 25, 2025

Copy link
Copy Markdown

@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.

@vercel

vercel Bot commented Dec 25, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
opencodeintel Ignored Ignored Preview Dec 25, 2025 6:20pm

@DevanshuNEU DevanshuNEU merged commit 8a057bf into OpenCodeIntel:main Dec 25, 2025
6 checks passed
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.

feat(backend): Anonymous session management

1 participant