Repository navigation
fix(sdk): expand ~ in OH_PERSISTENCE_DIR for the meta-profile store - #5884
Conversation
default_meta_profile_dir() built the path from the raw OH_PERSISTENCE_DIR value, so '~/x' wrote meta-profiles to '<cwd>/~/x/meta-profiles' while settings.json landed in the expanded directory. Resolve it through get_user_persistence_dir() like every other store, which expands '~' and anchors relative values. Drop the F22.persistence-dir known-bug marker. Fixes #5878 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014MKndVj7XWvRQmvW9w2bDg
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Review — PR #5884
Scope: In scope. default_meta_profile_dir() lives in the SDK, and its only consumers (the agent-server meta-profiles router, launch.py, and bare MetaProfileStore()) are in this repository. No cross-repo ownership question.
Change: default_meta_profile_dir() now returns get_user_persistence_dir() / "meta-profiles" instead of carrying its own Path(os.environ["OH_PERSISTENCE_DIR"]) copy. Call-time evaluation is preserved, so the router, launch.py, and bare MetaProfileStore() all pick up the same resolution as settings.json, LLM profiles, agent profiles, and the skills caches.
Verification I ran on b1f62cd:
- Live, through the real agent-server entry point (
python -m openhands.agent_serverwithHOME=<tmp>/home,OH_PERSISTENCE_DIR=~/qa-f22-tilde, empty server cwd):POST /api/meta-profiles/qa-tildeto 201 andPOST .../activateto 200 wrotehome/qa-f22-tilde/settings.jsonandhome/qa-f22-tilde/meta-profiles/qa-tilde.jsontogether, and no directory literally named~existed anywhere under the run tree. - Same probe against base
origin/main(6e7a853):default_meta_profile_dir()returns the literal~/x/meta-profiles, confirming the reported symptom. uv run pytest tests/sdk/llm/test_meta_profile_store.py tests/sdk/utils/test_path.py-> 34 passed.uv run pytest tests/cross/test_persistence_dir_call_sites.py tests/agent_server/test_meta_profiles_router.py tests/agent_server/test_active_meta_profile.py tests/sdk/tool/test_classify_and_switch_llm.py tests/sdk/test_settings.py tests/agent_server/test_settings_router.py-> 391 passed.ruff check,ruff format --check,pyright, andscripts/check_import_rules.pyon the changed file: clean.control_agent_server.py map check --file F22:ok: true, no problems, so the removed known-bug marker is consistent with the map's own contract.- Head CI: all 53 check runs on b1f62cd pass; none failing.
Behavior note (non-blocking): the fallback path and absolute values are unchanged; a relative OH_PERSISTENCE_DIR now anchors to _INITIAL_CWD (import-time cwd) with a warning instead of the cwd at file access, which is exactly what every other store does. That is the intended unification, not a regression.
Acceptance: Linked issue #5878 (bug, priority:low, ready-for-dev) asks for meta-profiles at $HOME/x/meta-profiles/ using the same resolution as every other store. The head delivers that, with a regression test and a live-verified fix.
No material correctness, security, compatibility, or acceptance-criterion defects found.
✅ APPROVED
HUMAN:
This PR proposes a fix for a bug uncovered during the first full agentic run of
verify-agent-server.AGENT:
I'm an AI agent (Claude Code) helping Engel Nyst (@enyst) with project maintenance.
Requested by Engel · project thread
Why
With
OH_PERSISTENCE_DIR='~/x', the agent server writessettings.json(and the LLM profiles) to$HOME/x/, but meta-profiles go to<server cwd>/~/x/meta-profiles/, a directory literally named~. The API keeps working because the router and the routing tool share the same helper, but the files sit outside the persistence directory.Summary
default_meta_profile_dir()(openhands-sdk/openhands/sdk/llm/meta_profile_store.py) now returnsget_user_persistence_dir() / "meta-profiles", so~is expanded and a relative value is anchored exactly as for every other store. It is still evaluated at call time, so the router,launch.pyand bareMetaProfileStore()pick it up unchanged.OH_PERSISTENCE_DIR='~/state'.F22.persistence-dirmap bullet drops its# bugmarker and "known bug" label; prose and Gotchas now describe the expected behaviour.Issue Number
Fixes #5878
How to Test
uv run pytest tests/sdk/llm/test_meta_profile_store.py -k persistence_dir: the new test fails on main (PosixPath('~/state/meta-profiles')) and passes here.uv run pytest tests/sdk/llm/test_meta_profile_store.py tests/agent_server/test_meta_profiles_router.py tests/agent_server/test_active_meta_profile.py tests/sdk/tool/test_classify_and_switch_llm.py tests/sdk/test_settings.py tests/sdk/launch tests/agent_server/test_settings_router.py tests/sdk/tool/test_registry.py: 450 passed.control-agent-server map run --file F22 --only F22.persistence-dir --fresh --repeat 2 --checkout <main checkout>reportsxfailtwice on main (6e7a853); the same command from this branch without--checkoutreportsxpasstwice. After removing the marker,control-agent-server map checkreports no problems andmap run --file F22 --only F22.persistence-dir --freshreportspass.pre-commit run --files <changed files>: all hooks pass.Video/Screenshots
n/a
Type
Notes
Related history: #3836 added
OH_PERSISTENCE_DIRsupport to the meta-profile store with its own copy of the lookup; this PR replaces that copy with the shared helper. Tracked in umbrella #5653.🤖 Generated with Claude Code
https://claude.ai/code/session_014MKndVj7XWvRQmvW9w2bDg
Generated by Claude Code
🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdkpython-node-runtimepython-node-runtimepython-node-runtimegolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:b1f62cd-pythonRun
All tags pushed for this build
About Multi-Architecture Support
b1f62cd-python) is a multi-arch manifest supporting both amd64 and arm64b1f62cd-python-amd64) are also available if needed