Repository navigation
fix(agent_server): honor OH_PERSISTENCE_DIR in profile stores (#3815) - #3816
Conversation
…3815) LLMProfileStore() / AgentProfileStore() were instantiated with no arguments in conversation_service, profiles_router, agent_profiles_router, and openai/service. Both classes default to `~/.openhands/profiles` and `~/.openhands/agent-profiles`, so isolated agent-server instances were silently reading and writing the host user's profile directory regardless of OH_PERSISTENCE_DIR. That leaked profile state across instances and caused settings.json to be seeded from the host on first run, defeating onboarding tests and per-instance isolation. Add get_llm_profile_store / get_agent_profile_store accessors next to the existing get_settings_store / get_secrets_store / get_workspaces_store pattern. They cache module-level singletons, honor OH_PERSISTENCE_DIR via the shared _get_persistence_dir helper, and are exposed through the persistence package. reset_stores now resets them too. All 21 direct constructor call sites switch to the accessors. Existing tests that mocked the classes at their origin modules are repointed at the accessors so the singleton cache doesn't break patching; two auto-title integration tests now set OH_PERSISTENCE_DIR via monkeypatch instead of patching _DEFAULT_PROFILE_DIR. A new regression test asserts that both stores resolve under OH_PERSISTENCE_DIR and never read the host home directory. Fixes #3815 Co-authored-by: openhands <openhands@all-hands.dev>
Python API breakage checks — ✅ PASSEDResult: ✅ PASSED |
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
Coverage Report •
|
||||||||||||||||||||||||||||||||||||||||||||||||||
all-hands-bot
left a comment
There was a problem hiding this comment.
✅ QA Report: PASS
Functionally verified that profile APIs and the OpenAI-compatible model listing honor OH_PERSISTENCE_DIR instead of leaking reads/writes through HOME profile stores; CI is not fully green at the time of review.
Does this PR achieve its stated goal?
Yes. I reproduced the old behavior by running the real agent-server on the base branch: with OH_PERSISTENCE_DIR pointed at a fresh directory, /api/profiles, /v1/models, and /api/agent-profiles still read host HOME profiles, and profile writes landed under HOME/.openhands. On the PR branch, the same HTTP workflows kept LLM and agent profile reads/writes under the configured persistence directory and did not expose the host HOME profiles.
| Phase | Result |
|---|---|
| Environment Setup | ✅ make build completed successfully; no tests/linters were run locally. |
| CI Status | ❌ GitHub reported 21 successful, 2 failing, 7 pending, 1 skipped checks; failing: PR Description Check and Pre-commit checks. |
| Functional Verification | ✅ Started the actual agent-server and exercised affected profile APIs with curl. |
Functional Verification
Test 1: Isolated server no longer reads HOME profile stores
Step 1 — Reproduce / establish baseline (without the fix):
Ran /tmp/qa_profile_cross_branch_read.sh, which checked out origin/main, started python -m openhands.agent_server, created host HOME profiles through real HTTP POSTs, then restarted the base server with a fresh OH_PERSISTENCE_DIR and queried the affected APIs:
=== seed host HOME on base branch ===
BASE_HEAD=39039a13
HOME=/tmp/qa-profile-cross-4605/home
{"name":"host-llm","message":"Profile 'host-llm' saved"}
{"name":"host-agent","message":"Agent profile 'host-agent' saved"}
=== base branch isolated server with fresh OH_PERSISTENCE_DIR ===
OH_PERSISTENCE_DIR=/tmp/qa-profile-cross-4605/persist-base
LLM profiles: {"profiles":[{"name":"host-llm","model":"openai/gpt-4o-mini","base_url":null,"api_key_set":true}],"active_profile":null}
OpenAI models: {"object":"list","data":[{"id":"openhands_host-llm","created":0,"object":"model","owned_by":"openhands"}]}
Agent profiles: {"profiles":[{"id":"8864b2ad-682f-4275-9d8e-a11ad630fead","name":"host-agent","agent_kind":"openhands","revision":0,"llm_profile_ref":"host-llm","mcp_server_refs":null}],"active_agent_profile_id":null}
This confirms the bug: even with a fresh OH_PERSISTENCE_DIR, the base branch exposed the host HOME LLM profile through /api/profiles and /v1/models, and exposed the host agent profile through /api/agent-profiles.
Step 2 — Apply the PR's changes:
The same script checked out openhands/issue-3815-persistence-dir-profile-stores at 38aad406 while reusing the same HOME directory containing host-llm and host-agent, then started the server with a different fresh OH_PERSISTENCE_DIR.
Step 3 — Re-run with the fix in place:
The PR branch returned:
=== PR branch isolated server with same HOME and fresh OH_PERSISTENCE_DIR ===
PR_HEAD=38aad406
OH_PERSISTENCE_DIR=/tmp/qa-profile-cross-4605/persist-pr
LLM profiles: {"profiles":[],"active_profile":null}
OpenAI models: {"object":"list","data":[]}
Agent profiles: {"profiles":[{"id":"fb6910fd-f605-456e-9d36-cac58787fee9","name":"default","agent_kind":"openhands","revision":0,"llm_profile_ref":"default","mcp_server_refs":null}],"active_agent_profile_id":"fb6910fd-f605-456e-9d36-cac58787fee9"}
=== final stored files ===
HOME_OPENHANDS /tmp/qa-profile-cross-4605/home/.openhands
agent-profiles/.agent-profiles.lock
agent-profiles/host-agent.json
profiles/.profiles.lock
profiles/host-llm.json
BASE_PERSISTENCE /tmp/qa-profile-cross-4605/persist-base
PR_PERSISTENCE /tmp/qa-profile-cross-4605/persist-pr
.settings.lock
agent-profiles/.agent-profiles.lock
agent-profiles/default.json
profiles/.profiles.lock
settings.json
This shows the fix works for reads: the same HOME still contained host-llm and host-agent, but the PR server did not list them through the profile APIs or OpenAI model listing when OH_PERSISTENCE_DIR pointed at a fresh directory.
Test 2: Profile writes land under OH_PERSISTENCE_DIR
Step 1 — Reproduce / establish baseline (without the fix):
Ran git checkout origin/main && /tmp/qa_profile_server.sh /home/runner/work/software-agent-sdk/software-agent-sdk/pr-repo base2 8124. The script started the real server with both HOME and OH_PERSISTENCE_DIR set, then created LLM and agent profiles via HTTP:
BASE_HEAD=39039a13
=== base2 create LLM profile via HTTP ===
{"name":"qa-llm","message":"Profile 'qa-llm' saved"}
=== base2 create agent profile via HTTP ===
{"name":"qa-agent","message":"Agent profile 'qa-agent' saved"}
HTTP_STATUS:201
=== base2 file existence summary ===
EXISTS /tmp/qa-profile-base2-4030/home/.openhands/profiles/qa-llm.json
MISSING /tmp/qa-profile-base2-4030/persist/profiles/qa-llm.json
EXISTS /tmp/qa-profile-base2-4030/home/.openhands/agent-profiles/qa-agent.json
MISSING /tmp/qa-profile-base2-4030/persist/agent-profiles/qa-agent.json
This confirms the write-side bug on base: profile API writes ignored the configured persistence directory and created files under HOME.
Step 2 — Apply the PR's changes:
Checked out the PR branch at 38aad406 and reran the same HTTP profile create/list flow with a new HOME and OH_PERSISTENCE_DIR.
Step 3 — Re-run with the fix in place:
Ran git checkout openhands/issue-3815-persistence-dir-profile-stores && /tmp/qa_profile_server.sh /home/runner/work/software-agent-sdk/software-agent-sdk/pr-repo pr 8125:
PR_HEAD=38aad406
=== pr create LLM profile via HTTP ===
{"name":"qa-llm","message":"Profile 'qa-llm' saved"}
=== pr create agent profile via HTTP ===
{"name":"qa-agent","message":"Agent profile 'qa-agent' saved"}
HTTP_STATUS:201
=== pr file existence summary ===
MISSING /tmp/qa-profile-pr-4133/home/.openhands/profiles/qa-llm.json
EXISTS /tmp/qa-profile-pr-4133/persist/profiles/qa-llm.json
MISSING /tmp/qa-profile-pr-4133/home/.openhands/agent-profiles/qa-agent.json
EXISTS /tmp/qa-profile-pr-4133/persist/agent-profiles/qa-agent.json
This confirms the fix works for writes: the profile APIs now store both LLM and agent profiles under OH_PERSISTENCE_DIR and do not create HOME/.openhands profile files.
Issues Found
None from functional QA. CI currently has separate failing checks noted above.
This review was created by an AI agent (OpenHands) on behalf of the user.
There was a problem hiding this comment.
I’m OpenHands-GPT-5.5, @enyst’s AI agent, and this review was generated by an AI agent on behalf of @enyst.
I verified the PR’s behavior against OpenHands/agent-canvas and OpenHands/openhands-cli. The Agent Canvas default path is OK: scripts/dev-safe.mjs sets stateDir to ~/.openhands/agent-canvas and passes OH_PERSISTENCE_DIR=path.dirname(stateDir), so profile stores land under ~/.openhands/profiles and ~/.openhands/agent-profiles. The Docker entrypoint similarly defaults OH_PERSISTENCE_DIR to $HOME/.openhands. Agent Canvas also provides OH_SECRET_KEY, so local Agent Canvas LLM profile keys should be encrypted at rest.
The concern is the bare/local agent-server fallback this PR now applies to profile stores. get_llm_profile_store() and get_agent_profile_store() route through _get_persistence_dir(), whose no-env fallback can be workspace/.openhands. Since LLM profiles can include API keys, I don’t think local user-machine profile secrets should ever silently move outside ~/.openhands when OH_PERSISTENCE_DIR is absent.
Suggested fix: keep OH_PERSISTENCE_DIR taking precedence, but for the profile-store accessors specifically, fall back to Path.home() / ".openhands" rather than the generic agent-server persistence fallback. That preserves the isolated Agent Canvas/orchestrated behavior while keeping bare local profile secrets in the expected user config directory.
Plaintext local storage is acceptable as existing local behavior as long as it is confined to ~/.openhands; the important invariant here is location, not requiring every local plaintext profile secret to be rejected.
Concrete places to update:
openhands-agent-server/openhands/agent_server/persistence/store.py: add/use a profile-specific persistence-dir helper forget_llm_profile_store()andget_agent_profile_store().- Tests: add coverage for no-
OH_PERSISTENCE_DIRprofile-store fallback staying under~/.openhands.
…persistence-dir-profile-stores
Co-authored-by: openhands <openhands@all-hands.dev>
|
✅ Review complete. This review was performed through OpenHands Cloud Automation. You can log in and view the conversation here. |
all-hands-bot
left a comment
There was a problem hiding this comment.
Code Review: fix(agent_server): honor OH_PERSISTENCE_DIR in profile stores
🟡 Acceptable — production code is correct and clean; one test-reliability nit.
What this PR does
Extends the existing singleton-factory pattern (get_settings_store / get_secrets_store / get_workspaces_store) to cover LLMProfileStore and AgentProfileStore. All 21 direct no-arg constructor call sites are switched to the new accessors, which route through _get_persistence_dir(config) so OH_PERSISTENCE_DIR is consistently honoured. The fix is minimal, follows the established codebase idiom exactly, and ships a dedicated regression test.
What is good
- The two new factory functions in
persistence/store.pyare structurally identical to the existing three — double-checked locking,_store_lock,reset_stores()coverage. No special cases introduced. test_profile_store_persistence_dir.pyis a proper regression test: exercises the real code path (no mocks of the unit under test), asserts on directory resolution, and the fixture cleans up intry/finally.- Test patches correctly target the accessor (
get_agent_profile_store) rather than the underlying class, so the module-level singleton cache does not shadow the patch. Thelambda: Store(base_dir=...)idiom gives each call site a fresh instance pointing at the temp directory — fine since the stores are stateless beyondbase_dir. - The two auto-title integration tests now use
monkeypatch.setenv+reset_stores()instead of patching a private_DEFAULT_PROFILE_DIRconstant — a cleaner and more realistic setup.
One improvement worth making
In both test_autotitle_integration_routes_through_profile_store and test_autotitle_decrypts_cipher_encrypted_title_profile, reset_stores() is called after the with patch(...) block but outside any try/finally. If an assertion inside the block fails, the cleanup never runs: _llm_profile_store stays initialised pointing at the now-deleted tmp_path/profiles directory, and the next test that calls get_llm_profile_store() will silently reuse the stale singleton. The simplest fix is monkeypatch.addfinalizer(reset_stores) immediately after the setup reset_stores() call (see inline comment).
[RISK ASSESSMENT]
- [Overall PR]
⚠️ Risk Assessment: 🟢 LOW
Bug fix extending an existing, well-understood singleton pattern. Default behaviour (noOH_PERSISTENCE_DIRset) is unchanged because_get_persistence_dirfalls back toDEFAULT_PERSISTENCE_DIR(~/.openhands). No public API changes. Covered by a new regression test and the existing 1273-test agent-server suite.
VERDICT:
✅ Worth merging — production fix is correct, follows established patterns, well-tested. The test cleanup issue is non-blocking.
KEY INSIGHT:
Factorising store construction through _get_persistence_dir closes the last gap between OH_PERSISTENCE_DIR semantics and actual profile-store placement, completing the isolation guarantee the other store factories already provided.
This review was generated by an AI agent (OpenHands) on behalf of the user through OpenHands Automation. View conversation
Improve this review? If any feedback above seems incorrect or irrelevant to this repository, you can teach the reviewer to do better:
- Add a
.agents/skills/custom-codereview-guide.mdfile to your branch (or edit it if one already exists) with the/codereviewtrigger and the context the reviewer is missing. See the customization docs for the required frontmatter format.- Re-request a review - the reviewer reads guidelines from the PR branch, so your changes take effect immediately.
- When your PR is merged, the guideline file goes through normal code review by repository maintainers.
Resolve with AI? Install the iterate skill in your agent and run
/iterateto automatically drive this PR through CI, review, and QA until it's merge-ready.Was this review helpful? React with 👍 or 👎 to give feedback.
Absent OH_PERSISTENCE_DIR, route LLM/agent profile stores to ~/.openhands via a profile-specific helper rather than the workspace-relative agent-server default, so credential-bearing local profiles stay in the user config dir. OH_PERSISTENCE_DIR still takes precedence, preserving the isolation fix. Drop the now-unused config param from the accessors and add no-env fallback coverage. Addresses @enyst review feedback on #3816. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
@enyst good catch — addressed in 1d342dd. The concern was real: Fix: the profile-store accessors now resolve through a dedicated
The accessors no longer take a
Settings/secrets/workspaces stores are intentionally left on the existing |
|
🔍 Review in progress… We are performing the review through OpenHands Cloud Automation. You can log in and view the conversation here. |
all-hands-bot
left a comment
There was a problem hiding this comment.
✅ QA Report: PASS
The PR fixes the profile-store isolation bug: live agent-server profile APIs now read and write under OH_PERSISTENCE_DIR instead of leaking through HOME/.openhands.
Does this PR achieve its stated goal?
Yes. I exercised the real agent-server over HTTP and reproduced the bug on the PR base: an isolated server with OH_PERSISTENCE_DIR still read host LLM/agent profiles and wrote new profiles into HOME/.openhands. On the PR head, the same API flows no longer exposed the seeded host LLM/agent profiles, and new LLM/agent profiles were persisted under OH_PERSISTENCE_DIR/{profiles,agent-profiles}.
| Phase | Result |
|---|---|
| Environment Setup | ✅ make build completed; uv run agent-server started successfully |
| CI Status | unresolved-review-threads gate at time checked |
| Functional Verification | ✅ Real HTTP API calls verified profile read/write isolation |
Functional Verification
Test 1: Isolated server should not read host profile stores
Step 1 — Reproduce baseline without the fix:
Ran the base commit (dee24ecfa40040c8830e5b78befb7500b3814d1e) by starting uv run agent-server once with only HOME=/tmp/.../home to seed host profiles through POST /api/profiles/host_llm and POST /api/agent-profiles/host_agent, then restarted the server with the same HOME plus OH_PERSISTENCE_DIR=/tmp/.../persist and queried the isolated APIs:
Seeded host profile files:
TMP/home/.openhands/agent-profiles/host_agent.json
TMP/home/.openhands/profiles/host_llm.json
--- isolated GET /api/profiles with OH_PERSISTENCE_DIR set ---
{"profiles":[{"name":"host_llm","model":"openai/gpt-4o-mini","base_url":null,"api_key_set":true}],"active_profile":null}
--- isolated GET /api/agent-profiles with OH_PERSISTENCE_DIR set ---
{"profiles":[{"id":"3e7b730b-cd46-435f-8e7b-d2f1e9533aea","name":"host_agent","agent_kind":"openhands","revision":0,"llm_profile_ref":"host_llm","mcp_server_refs":null}],"active_agent_profile_id":null}
--- isolated persistence files ---
<none>
This confirms the bug: even with a fresh OH_PERSISTENCE_DIR, the base server read profiles from the host-style HOME/.openhands store.
Step 2 — Apply the PR's changes:
Checked out 1d342ddaca142b8e592e6fcb2e9b71be1fcccf80 and repeated the same seed-then-isolated-server flow.
Step 3 — Re-run with the fix in place:
Seeded host profile files:
TMP/home/.openhands/agent-profiles/host_agent.json
TMP/home/.openhands/profiles/host_llm.json
--- isolated GET /api/profiles with OH_PERSISTENCE_DIR set ---
{"profiles":[],"active_profile":null}
--- isolated GET /api/agent-profiles with OH_PERSISTENCE_DIR set ---
{"profiles":[{"id":"af54216c-d90f-4bd4-a61f-4c7253e0acce","name":"default","agent_kind":"openhands","revision":0,"llm_profile_ref":"default","mcp_server_refs":null}],"active_agent_profile_id":"af54216c-d90f-4bd4-a61f-4c7253e0acce"}
--- isolated persistence files ---
TMP/persist/.settings.lock
TMP/persist/agent-profiles/.agent-profiles.lock
TMP/persist/agent-profiles/default.json
TMP/persist/profiles/.profiles.lock
TMP/persist/settings.json
This confirms the fix: the isolated server did not expose host_llm or host_agent; it used the isolated persistence area instead (including its generated default agent profile/settings).
Test 2: Isolated server should write profile stores under OH_PERSISTENCE_DIR
Step 1 — Reproduce baseline without the fix:
On base commit dee24ecfa40040c8830e5b78befb7500b3814d1e, started uv run agent-server with both HOME=/tmp/.../home and OH_PERSISTENCE_DIR=/tmp/.../persist, then used real HTTP requests to save one LLM profile and one agent profile:
--- POST /api/profiles/qa_llm ---
{"name":"qa_llm","message":"Profile 'qa_llm' saved"}
HTTP:201
--- GET /api/profiles ---
{"profiles":[{"name":"qa_llm","model":"openai/gpt-4o-mini","base_url":null,"api_key_set":true}],"active_profile":null}
--- POST /api/agent-profiles/qa_agent ---
{"name":"qa_agent","message":"Agent profile 'qa_agent' saved"}
HTTP:201
--- GET /api/agent-profiles ---
{"profiles":[{"id":"ab2c7ffa-a0f7-4ed8-896a-b8e7fc553b85","name":"qa_agent","agent_kind":"openhands","revision":0,"llm_profile_ref":"qa_llm","mcp_server_refs":null}],"active_agent_profile_id":null}
--- profile files under HOME and OH_PERSISTENCE_DIR ---
TMP/home/.openhands/agent-profiles/qa_agent.json
TMP/home/.openhands/profiles/qa_llm.json
This confirms the write side of the bug: the API succeeded, but files landed under HOME/.openhands rather than the requested persistence directory.
Step 2 — Apply the PR's changes:
Checked out 1d342ddaca142b8e592e6fcb2e9b71be1fcccf80 and repeated the same HTTP POST/GET flow with a fresh HOME and OH_PERSISTENCE_DIR.
Step 3 — Re-run with the fix in place:
--- POST /api/profiles/qa_llm ---
{"name":"qa_llm","message":"Profile 'qa_llm' saved"}
HTTP:201
--- GET /api/profiles ---
{"profiles":[{"name":"qa_llm","model":"openai/gpt-4o-mini","base_url":null,"api_key_set":true}],"active_profile":null}
--- POST /api/agent-profiles/qa_agent ---
{"name":"qa_agent","message":"Agent profile 'qa_agent' saved"}
HTTP:201
--- GET /api/agent-profiles ---
{"profiles":[{"id":"411e7406-1864-44e7-ba99-118f36020266","name":"qa_agent","agent_kind":"openhands","revision":0,"llm_profile_ref":"qa_llm","mcp_server_refs":null}],"active_agent_profile_id":null}
--- profile files under HOME and OH_PERSISTENCE_DIR ---
TMP/persist/agent-profiles/qa_agent.json
TMP/persist/profiles/qa_llm.json
This confirms the fix works for writes: both the LLM profile and agent profile are persisted inside OH_PERSISTENCE_DIR.
Issues Found
None.
This review was created by an AI agent (OpenHands) on behalf of the user.
…eardown Register reset_stores() via request.addfinalizer so the singleton is cleared even if an assertion raises, preventing a stale store (pointed at a deleted tmp_path) from leaking into later tests. Replaces the unguarded trailing reset_stores() calls. Addresses all-hands-bot review thread (monkeypatch has no addfinalizer; request does). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
✅ Review complete. This review was performed through OpenHands Cloud Automation. You can log in and view the conversation here. |
all-hands-bot
left a comment
There was a problem hiding this comment.
🟢 Taste Rating: Good taste
The change follows the existing persistence-store accessor pattern and fixes a real isolation bug without widening the public API. The profile store base directory now consistently honors OH_PERSISTENCE_DIR while preserving the current ~/.openhands fallback for bare local profile usage, which is the right compatibility trade-off for stores that can contain credentials.
Validation looks solid: the new regression tests cover both LLM and agent profile stores under OH_PERSISTENCE_DIR, the home-directory fallback, and empty isolated stores. I also ran uv run pytest tests/agent_server/test_profile_store_persistence_dir.py -q locally and it passed.
[RISK ASSESSMENT]
- [Overall PR]
⚠️ Risk Assessment: 🟡 MEDIUM
This touches shared agent-server persistence plumbing and profile stores that may contain secrets, so the blast radius is above low. The implementation is still contained, follows existing singleton store patterns, adds regression coverage, and does not change REST contracts or dependencies.
VERDICT:
✅ Worth merging: Core logic is sound and the regression is covered.
KEY INSIGHT:
Centralizing profile-store construction is the simple fix here; it eliminates the scattered default-constructor behavior that caused isolated servers to leak back to host profile directories.
This review was generated by an AI agent (OpenHands) on behalf of the user through OpenHands Automation. View conversation
all-hands-bot
left a comment
There was a problem hiding this comment.
✅ QA Report: PASS
Verified the agent-server profile APIs as a real client; the PR fixes the OH_PERSISTENCE_DIR isolation bug for both LLM profiles and agent profiles while preserving the no-env HOME fallback.
Does this PR achieve its stated goal?
Yes. On the base commit, an agent-server started with OH_PERSISTENCE_DIR still listed and wrote profiles under HOME/.openhands, proving the isolation bug existed. On PR commit 0272099c, the same /api/profiles and /api/agent-profiles list/write flows used only the configured persistence directory, and host-home profiles remained untouched.
| Phase | Result |
|---|---|
| Environment Setup | ✅ uv sync --dev completed and local agent-server instances launched successfully |
| CI Status | 🟡 Observed 26 success, 4 in progress, 2 skipped, 0 failing checks at review time |
| Functional Verification | ✅ Base bug reproduced; PR fix verified for LLM + agent profile reads/writes and no-env fallback |
Functional Verification
Test 1: Reproduce base bug for LLM profiles
Step 1 — Reproduce / establish baseline (without the fix):
Checked out base commit b66197be, seeded:
- host-style profile:
/tmp/qa3816/base/home/.openhands/profiles/host-profile.json - isolated profile:
/tmp/qa3816/base/persist/profiles/isolated-profile.json
Started the server with HOME=/tmp/qa3816/base/home and OH_PERSISTENCE_DIR=/tmp/qa3816/base/persist, then ran GET /api/profiles:
LIST_STATUS 200
{"profiles":[{"name":"host-profile","model":"openai/host-model","base_url":null,"api_key_set":true}],"active_profile":null}
This confirms the bug exists because the base server ignored OH_PERSISTENCE_DIR and exposed the host profile instead of the isolated profile.
Step 2 — Apply the PR's changes:
Checked out PR commit 0272099c, seeded equivalent host and persistence directories, and started a new server with HOME=/tmp/qa3816/pr/home and OH_PERSISTENCE_DIR=/tmp/qa3816/pr/persist.
Step 3 — Re-run with the fix in place:
Ran GET /api/profiles:
LLM_LIST_STATUS 200
{"profiles":[{"name":"isolated-profile","model":"openai/isolated-model","base_url":null,"api_key_set":true}],"active_profile":null}
This confirms the fix works for reads: only the profile under OH_PERSISTENCE_DIR/profiles is visible.
Test 2: Verify profile writes go to the isolated persistence directory
Step 1 — Reproduce / establish baseline (without the fix):
On base commit b66197be, ran:
curl -X POST http://127.0.0.1:8766/api/profiles/base-api-written-profile -H 'Content-Type: application/json' --data '{"llm":{"model":"openai/base-api-written-model","api_key":"base-api-written-key"}}'Observed:
{"name":"base-api-written-profile","message":"Profile 'base-api-written-profile' saved"}
WRITE_STATUS:201
--- written files ---
/tmp/qa3816/base/home/.openhands/profiles/base-api-written-profile.json
This confirms base writes through the user-facing API land in host HOME, not the configured persistence directory.
Step 2 — Apply the PR's changes:
Used the PR server from Test 1 with the same environment shape.
Step 3 — Re-run with the fix in place:
Ran:
curl -X POST http://127.0.0.1:8767/api/profiles/pr-api-written-profile -H 'Content-Type: application/json' --data '{"llm":{"model":"openai/pr-api-written-model","api_key":"pr-api-written-key"}}'Observed:
{"name":"pr-api-written-profile","message":"Profile 'pr-api-written-profile' saved"}
LLM_WRITE_STATUS:201
--- written files ---
/tmp/qa3816/pr/persist/profiles/pr-api-written-profile.json
This confirms profile writes now honor OH_PERSISTENCE_DIR.
Test 3: Verify agent-profile reads/writes also use OH_PERSISTENCE_DIR
Step 1 — Reproduce / establish baseline (without the fix):
On base commit b66197be, seeded host and isolated agent profiles, then ran GET /api/agent-profiles:
{"profiles":[{"id":"cbf2e850-5e8b-490c-84c3-20d13c15bb2a","name":"host-agent","agent_kind":"openhands","revision":0,"llm_profile_ref":"host-profile","mcp_server_refs":null}],"active_agent_profile_id":null}
HTTP_STATUS:200
Then saved through the API:
{"name":"base-api-written-agent","message":"Agent profile 'base-api-written-agent' saved"}
WRITE_STATUS:201
--- written files ---
/tmp/qa3816/base/home/.openhands/agent-profiles/base-api-written-agent.json
This shows the base server also leaked/wrote agent profiles through host HOME.
Step 2 — Apply the PR's changes:
Used PR commit 0272099c with equivalent seeded host and isolated agent profiles.
Step 3 — Re-run with the fix in place:
Ran GET /api/agent-profiles and then saved an agent profile:
AGENT_LIST_STATUS 200
{"profiles":[{"id":"1271a5a9-1ab4-46e1-ba83-bb5c1f27bfcc","name":"isolated-agent","agent_kind":"openhands","revision":0,"llm_profile_ref":"isolated-profile","mcp_server_refs":null}],"active_agent_profile_id":null}
{"name":"pr-api-written-agent","message":"Agent profile 'pr-api-written-agent' saved"}
AGENT_WRITE_STATUS:201
--- written files ---
/tmp/qa3816/pr/persist/agent-profiles/pr-api-written-agent.json
This confirms agent-profile reads and writes now use OH_PERSISTENCE_DIR/agent-profiles.
Test 4: Verify host HOME remains untouched on the PR branch
After PR read/write operations, compared host and persistence files:
host home profile files:
/tmp/qa3816/pr/home/.openhands/agent-profiles/.agent-profiles.lock
/tmp/qa3816/pr/home/.openhands/agent-profiles/host-agent.json
/tmp/qa3816/pr/home/.openhands/profiles/.profiles.lock
/tmp/qa3816/pr/home/.openhands/profiles/host-profile.json
persistence profile files:
/tmp/qa3816/pr/persist/agent-profiles/.agent-profiles.lock
/tmp/qa3816/pr/persist/agent-profiles/isolated-agent.json
/tmp/qa3816/pr/persist/agent-profiles/pr-api-written-agent.json
/tmp/qa3816/pr/persist/profiles/.profiles.lock
/tmp/qa3816/pr/persist/profiles/isolated-profile.json
/tmp/qa3816/pr/persist/profiles/pr-api-written-profile.json
This shows the PR server did not create the API-written profiles in host HOME.
Test 5: Verify no-env fallback still uses HOME
Started a PR server without OH_PERSISTENCE_DIR and with HOME=/tmp/qa3816/fallback/home, then ran GET /api/profiles:
FALLBACK_STATUS 200
{"profiles":[{"name":"host-profile","model":"openai/host-model","base_url":null,"api_key_set":true}],"active_profile":null}
This confirms the PR preserves the documented fallback to ~/.openhands when OH_PERSISTENCE_DIR is unset.
Issues Found
None.
This review was generated by an AI agent (OpenHands) on behalf of the user.
enyst
left a comment
There was a problem hiding this comment.
I’m OpenHands-GPT-5.5, @enyst’s AI agent, and this review was generated by an AI agent on behalf of @enyst.
🟢 Taste Rating: Good taste
No roast needed; they fixed the important part instead of building a cathedral around it.
The latest commits do the right thing: profile stores now have their own persistence-dir resolver. OH_PERSISTENCE_DIR still wins for isolated Agent Canvas/orchestrated runs, but the no-env bare-local fallback is Path.home() / ".openhands", not workspace/.openhands. That is the correct boundary: profile secrets are user config, not random workspace droppings.
Also good: the fix does not turn local plaintext storage into a fake emergency. Existing local behavior can persist plaintext as long as it stays under ~/.openhands; this PR keeps the invariant about location without breaking userspace.
I updated my local branch to 0272099ce14364edb725e36df5a345af44b77cf2, reviewed the current diff, and ran the relevant tests:
uv run pytest tests/agent_server/test_profile_store_persistence_dir.py tests/agent_server/test_profiles_router.py tests/agent_server/test_agent_profiles_router.py -q
127 passed
[RISK ASSESSMENT]
- [Overall PR]
⚠️ Risk Assessment: 🟢 LOW
This is a narrow agent-server persistence routing change with targeted regression tests. The compatibility story is sane: configured OH_PERSISTENCE_DIR still provides isolation, while bare local profile stores fall back to the expected user config directory. CI is green on the PR checks I inspected.
VERDICT:
✅ Worth merging
KEY INSIGHT:
Profile stores are secret-bearing user configuration, so they need a user-home fallback; the generic server persistence fallback was the wrong abstraction for this specific data.
…nds#3815) (OpenHands#3816) Co-authored-by: Graham Neubig <gneubig@users.noreply.github.com> Co-authored-by: openhands <openhands@all-hands.dev> Co-authored-by: Simon Rosenberg <simon@openhands.dev> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
HUMAN:
Fixes a profile-store isolation bug where the agent server ignored
OH_PERSISTENCE_DIRand read/wrote the host's~/.openhands/profilesinstead.AGENT:
Why
LLMProfileStore()andAgentProfileStore()were constructed with no arguments throughout the agent-server (conversation_service.py,profiles_router.py,agent_profiles_router.py,openai/service.py), so they defaulted to~/.openhands/profilesand~/.openhands/agent-profileson the host. That meant an isolated agent-server pointed at a freshOH_PERSISTENCE_DIRstill read and wrote the user's profile dir, and itssettings.jsonwas seeded from whatever LLM profile the host happened to have. This defeated the isolation that onboarding tests, multi-instance deployments, and PR #1389's onboarding skip-logic depend on.Summary
get_llm_profile_store()/get_agent_profile_store()accessors next to the existingget_settings_store/get_secrets_store/get_workspaces_storepattern. Both cache module-level singletons (thread-safe under_store_lock)._get_profile_persistence_dir():OH_PERSISTENCE_DIRtakes precedence (this is the isolation fix), and when it is absent they fall back to~/.openhands— not the generic workspace-relative agent-server fallback (DEFAULT_PERSISTENCE_DIR = workspace/.openhands, withconversations_pathdefaulting toworkspace/conversations). Because LLM profiles can carry API keys, this keeps bare local profile secrets in the user's config directory rather than silently relocating them to a CWD-relative path (addresses @enyst's review). The accessors no longer take aconfigarg (no call site passed one, and the dir no longer depends on config).openhands.agent_server.persistenceand include them inreset_stores()for test isolation.OH_PERSISTENCE_DIRviamonkeypatchinstead of patching_DEFAULT_PROFILE_DIR, which now matches how production resolves the dir.Issue Number
Fixes #3815.
How to Test
Video/Screenshots
N/A — backend isolation fix; verified via the new regression test.
Type
Notes
ruff checkclean,pyrightclean on all touched agent-server files.Agent Server images for this PR
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdknikolaik/python-nodejs:python3.13-nodejs22-slimgolang: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:0272099-pythonRun
All tags pushed for this build
About Multi-Architecture Support
0272099-python) is a multi-arch manifest supporting both amd64 and arm640272099-python-amd64) are also available if needed