-
Notifications
You must be signed in to change notification settings - Fork 40
sotopia redis optional #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
e3e11a4
sotopia redis optional
openhands-agent 6b74499
default local
openhands-agent 5d94ed8
default local
openhands-agent 8c372dc
Fix mypy and pytest failures for redis-optional PR
openhands-agent 9cab9e9
[autofix.ci] apply automated fixes
autofix-ci[bot] 1c83bbc
Fix FastAPI compound expressions for local backend
openhands-agent 1a177b4
[autofix.ci] apply automated fixes
autofix-ci[bot] 7b73b5a
Fix mypy type errors in database tests
ProKil bed1b28
Address select PR review comments
ProKil e8a8cdb
Fix circular import in aggregate_annotations
ProKil aa74db1
Add local backend testing to CI workflow
ProKil ab4f841
fix: handle None pk values in benchmark cleanup
ProKil 80e19f3
fix: remove incorrect pk field from Base models
ProKil eed0728
fix: revert pk defaults to default_factory for redis-om compatibility
ProKil a8642d6
fix: run tests with appropriate backends
ProKil 4998f2c
fix: add pk field to all Base classes for local backend
ProKil 78081d1
fix: use default_factory for pk fields to avoid redis-om validation eβ¦
ProKil 6b0146b
fix: exclude local storage tests from Redis backend run
ProKil 7b620a7
solved
XuhuiZhou f78d667
fix persistent profile
XuhuiZhou 86d8659
again
XuhuiZhou 78f1a29
update readme
XuhuiZhou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,13 +23,15 @@ jobs: | |
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| - name: Docker Compose | ||
| run: docker compose -f .devcontainer/docker-compose.yml up -d | ||
| - name: Run tests | ||
| run: docker compose -f .devcontainer/docker-compose.yml run --rm -u root -v /home/runner/work/sotopia/sotopia:/workspaces/sotopia devcontainer /bin/sh -c "cd /workspaces/sotopia; ls; uv sync --extra test --extra api; uv run pytest --ignore tests/cli --cov=. --cov-report=xml" | ||
| - name: Upload coverage report to Codecov | ||
| uses: codecov/[email protected] | ||
| with: | ||
| token: ${{ secrets.CODECOV_TOKEN }} | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| - name: Docker Compose | ||
| run: docker compose -f .devcontainer/docker-compose.yml up -d | ||
| - name: Run tests with local backend (default) | ||
| run: docker compose -f .devcontainer/docker-compose.yml run --rm -u root -v /home/runner/work/sotopia/sotopia:/workspaces/sotopia devcontainer /bin/sh -c "cd /workspaces/sotopia; ls; uv sync --extra test --extra api; uv run pytest --ignore tests/cli --cov=. --cov-report=xml" | ||
| - name: Run database tests with Redis backend | ||
| run: docker compose -f .devcontainer/docker-compose.yml run --rm -u root -v /home/runner/work/sotopia/sotopia:/workspaces/sotopia devcontainer /bin/sh -c "cd /workspaces/sotopia; SOTOPIA_STORAGE_BACKEND=redis uv run pytest tests/database/ --ignore=tests/database/test_local_storage.py -v" | ||
| - name: Upload coverage report to Codecov | ||
| uses: codecov/[email protected] | ||
| with: | ||
| token: ${{ secrets.CODECOV_TOKEN }} | ||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,7 +55,7 @@ dev-dependencies = [ | |
| "lxml-stubs", | ||
| "pandas-stubs", | ||
| "ruff", | ||
| "mypy" | ||
| "mypy", | ||
| ] | ||
|
|
||
| [tool.mypy] | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| # Redis to Local Storage Migration Scripts | ||
|
|
||
| This directory contains scripts to migrate data from a Redis dump file to the local JSON storage format. | ||
|
|
||
| ## Scripts | ||
|
|
||
| ### `migrate_redis_to_local.sh` (Main Script) | ||
| The master script that orchestrates the entire migration process. | ||
|
|
||
| **Usage:** | ||
| ```bash | ||
| ./scripts/migrate_redis_to_local.sh | ||
| ``` | ||
|
|
||
| **What it does:** | ||
| 1. Starts Redis with your dump file (`/Users/xuhuizhou/Downloads/dump_1.rdb`) | ||
| 2. Exports all data to `~/.sotopia/data/` in local JSON format | ||
| 3. Optionally stops Redis when done | ||
|
|
||
| ### `start_redis_with_dump.sh` | ||
| Starts a Redis server with the dump file loaded. | ||
|
|
||
| **Usage:** | ||
| ```bash | ||
| ./scripts/start_redis_with_dump.sh | ||
| ``` | ||
|
|
||
| **Features:** | ||
| - Automatically detects and stops existing Redis instances on port 6379 | ||
| - Uses `redis-stack-server` if available (required for dump files with Redis modules) | ||
| - Falls back to `redis-server` if redis-stack is not found | ||
| - Creates temporary directory for Redis data | ||
| - Waits for Redis to be ready before exiting | ||
|
|
||
| ### `export_redis_to_local.py` | ||
| Python script to export all models from Redis to local JSON storage. | ||
|
|
||
| **Usage:** | ||
| ```bash | ||
| # Basic usage (connects to redis://localhost:6379) | ||
| uv run python scripts/export_redis_to_local.py | ||
|
|
||
| # With custom Redis URL | ||
| uv run python scripts/export_redis_to_local.py --redis-url redis://localhost:6380 | ||
|
|
||
| # With custom output directory | ||
| uv run python scripts/export_redis_to_local.py --output-dir /path/to/output | ||
|
|
||
| # Quiet mode (no progress bars) | ||
| uv run python scripts/export_redis_to_local.py --quiet | ||
| ``` | ||
|
|
||
| **Exported Models:** | ||
| - AgentProfile | ||
| - EnvironmentProfile | ||
| - RelationshipProfile | ||
| - EnvAgentComboStorage | ||
| - EnvironmentList | ||
| - Annotator | ||
| - EpisodeLog | ||
| - AnnotationForEpisode | ||
| - NonStreamingSimulationStatus | ||
|
|
||
| ### `stop_redis.sh` | ||
| Stops the Redis server started by `start_redis_with_dump.sh`. | ||
|
|
||
| **Usage:** | ||
| ```bash | ||
| ./scripts/stop_redis.sh | ||
| ``` | ||
|
|
||
| ## Output Format | ||
|
|
||
| Data is exported to `~/.sotopia/data/` with the following structure: | ||
|
|
||
| ``` | ||
| ~/.sotopia/data/ | ||
| βββ AgentProfile/ | ||
| β βββ {uuid1}.json | ||
| β βββ {uuid2}.json | ||
| β βββ ... | ||
| βββ EnvironmentProfile/ | ||
| β βββ {uuid1}.json | ||
| β βββ ... | ||
| βββ EnvAgentComboStorage/ | ||
| β βββ {uuid1}.json | ||
| β βββ ... | ||
| βββ Annotator/ | ||
| β βββ {uuid1}.json | ||
| β βββ ... | ||
| βββ ... | ||
| ``` | ||
|
|
||
| Each JSON file contains a single model instance with 2-space indentation: | ||
|
|
||
| ```json | ||
| { | ||
| "pk": "01H7VJPFPQ67TTMWZ9246SQ2A4", | ||
| "env_id": "01H7VFHPJKR16MD1KC71V4ZRCF", | ||
| "agent_ids": [ | ||
| "01H5TNE5PMBJ9VHH51YC0BB64C", | ||
| "01H5TNE5P6KZKR2AEY6SZB83H0" | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| ## Using the Exported Data | ||
|
|
||
| After running the migration, you can use the local storage backend by setting the environment variable: | ||
|
|
||
| ```bash | ||
| export SOTOPIA_STORAGE_BACKEND=local | ||
| ``` | ||
|
|
||
| Then all Sotopia database operations will use the local JSON files instead of Redis: | ||
|
|
||
| ```python | ||
| from sotopia.database import AgentProfile, Annotator | ||
|
|
||
| # Automatically uses local storage when SOTOPIA_STORAGE_BACKEND=local | ||
| annotators = Annotator.all() | ||
| for annotator in annotators: | ||
| print(f"{annotator.name}: {annotator.email}") | ||
| ``` | ||
|
|
||
| ## Requirements | ||
|
|
||
| - Redis 8.0+ or redis-stack-server (for loading dump files with Redis modules) | ||
| - Python 3.10+ | ||
| - uv package manager | ||
| - Sotopia dependencies installed (`uv sync --all-extras`) | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### "Can't handle RDB format version X" | ||
| Your Redis version is too old. Upgrade to Redis 8.0+: | ||
| ```bash | ||
| brew upgrade redis | ||
| ``` | ||
|
|
||
| ### "The RDB file contains AUX module data I can't load" | ||
| The dump file was created with redis-stack-server (includes RediSearch, RedisJSON, etc.). Install redis-stack: | ||
| ```bash | ||
| brew install redis-stack | ||
| ``` | ||
|
|
||
| ### "Redis URL must specify one of the following schemes" | ||
| Make sure the `REDIS_OM_URL` environment variable is set correctly: | ||
| ```bash | ||
| export REDIS_OM_URL="redis://localhost:6379" | ||
| ``` | ||
|
|
||
| ## Migration Results | ||
|
|
||
| After successful migration, you should see output like: | ||
|
|
||
| ``` | ||
| Export Summary | ||
| ============================================================ | ||
| β Annotator: 3 records exported (0 errors) | ||
| β EnvAgentComboStorage: 450 records exported (0 errors) | ||
| β AnnotationForEpisode: 439 records exported (0 errors) | ||
| ============================================================ | ||
| Total: 892 records exported (0 errors) | ||
| ``` | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Hardcoded user-specific path in documentation
The README contains a hardcoded user-specific file path
/Users/xuhuizhou/Downloads/dump_1.rdbwhich appears to be a developer's local path that was accidentally committed. This exposes personal file system information and won't work for other users trying to follow the documentation.