Skip to content

fix(agent_server): honor OH_PERSISTENCE_DIR in profile stores (#3815) - #3816

Merged
neubig merged 5 commits into
mainfrom
openhands/issue-3815-persistence-dir-profile-stores
Jun 22, 2026
Merged

neubig merged 5 commits into
mainfrom
openhands/issue-3815-persistence-dir-profile-stores

Conversation

@neubig

@neubig neubig commented Jun 20, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

Fixes a profile-store isolation bug where the agent server ignored OH_PERSISTENCE_DIR and read/wrote the host's ~/.openhands/profiles instead.


AGENT:

Why

LLMProfileStore() and AgentProfileStore() 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/profiles and ~/.openhands/agent-profiles on the host. That meant an isolated agent-server pointed at a fresh OH_PERSISTENCE_DIR still read and wrote the user's profile dir, and its settings.json was 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

  • Add get_llm_profile_store() / get_agent_profile_store() accessors next to the existing get_settings_store / get_secrets_store / get_workspaces_store pattern. Both cache module-level singletons (thread-safe under _store_lock).
  • Profile stores resolve their base dir via a dedicated _get_profile_persistence_dir(): OH_PERSISTENCE_DIR takes 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, with conversations_path defaulting to workspace/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 a config arg (no call site passed one, and the dir no longer depends on config).
  • Export both accessors from openhands.agent_server.persistence and include them in reset_stores() for test isolation.
  • Switch all 21 direct constructor call sites to the accessors. Repoint existing tests that mocked the classes at their SDK origin modules at the accessors (so the new singleton cache doesn't shadow the patch). Two auto-title integration tests set OH_PERSISTENCE_DIR via monkeypatch instead of patching _DEFAULT_PROFILE_DIR, which now matches how production resolves the dir.

Issue Number

Fixes #3815.

How to Test

# Regression tests: both stores resolve under OH_PERSISTENCE_DIR, never
# touch the host home dir, AND (new) fall back to ~/.openhands when
# OH_PERSISTENCE_DIR is unset (not a workspace-relative dir):
pytest tests/agent_server/test_profile_store_persistence_dir.py -v

# Full agent-server suite (pre-existing unrelated failures that reproduce
# on main — e.g. the terminal env-command test — are not from this PR):
pytest tests/agent_server/

# Profile-store tests across SDK + agent-server:
pytest tests/ -k profile_store

Video/Screenshots

N/A — backend isolation fix; verified via the new regression test.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

ruff check clean, pyright clean 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

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python amd64, arm64 nikolaik/python-nodejs:python3.13-nodejs22-slim Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:0272099-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-0272099-python \
  ghcr.io/openhands/agent-server:0272099-python

All tags pushed for this build

ghcr.io/openhands/agent-server:0272099-golang-amd64
ghcr.io/openhands/agent-server:0272099ce14364edb725e36df5a345af44b77cf2-golang-amd64
ghcr.io/openhands/agent-server:openhands-issue-3815-persistence-dir-profile-stores-golang-amd64
ghcr.io/openhands/agent-server:0272099-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:0272099-golang-arm64
ghcr.io/openhands/agent-server:0272099ce14364edb725e36df5a345af44b77cf2-golang-arm64
ghcr.io/openhands/agent-server:openhands-issue-3815-persistence-dir-profile-stores-golang-arm64
ghcr.io/openhands/agent-server:0272099-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:0272099-java-amd64
ghcr.io/openhands/agent-server:0272099ce14364edb725e36df5a345af44b77cf2-java-amd64
ghcr.io/openhands/agent-server:openhands-issue-3815-persistence-dir-profile-stores-java-amd64
ghcr.io/openhands/agent-server:0272099-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:0272099-java-arm64
ghcr.io/openhands/agent-server:0272099ce14364edb725e36df5a345af44b77cf2-java-arm64
ghcr.io/openhands/agent-server:openhands-issue-3815-persistence-dir-profile-stores-java-arm64
ghcr.io/openhands/agent-server:0272099-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:0272099-python-amd64
ghcr.io/openhands/agent-server:0272099ce14364edb725e36df5a345af44b77cf2-python-amd64
ghcr.io/openhands/agent-server:openhands-issue-3815-persistence-dir-profile-stores-python-amd64
ghcr.io/openhands/agent-server:0272099-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-amd64
ghcr.io/openhands/agent-server:0272099-python-arm64
ghcr.io/openhands/agent-server:0272099ce14364edb725e36df5a345af44b77cf2-python-arm64
ghcr.io/openhands/agent-server:openhands-issue-3815-persistence-dir-profile-stores-python-arm64
ghcr.io/openhands/agent-server:0272099-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-arm64
ghcr.io/openhands/agent-server:0272099-golang
ghcr.io/openhands/agent-server:0272099ce14364edb725e36df5a345af44b77cf2-golang
ghcr.io/openhands/agent-server:openhands-issue-3815-persistence-dir-profile-stores-golang
ghcr.io/openhands/agent-server:0272099-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:0272099-java
ghcr.io/openhands/agent-server:0272099ce14364edb725e36df5a345af44b77cf2-java
ghcr.io/openhands/agent-server:openhands-issue-3815-persistence-dir-profile-stores-java
ghcr.io/openhands/agent-server:0272099-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:0272099-python
ghcr.io/openhands/agent-server:0272099ce14364edb725e36df5a345af44b77cf2-python
ghcr.io/openhands/agent-server:openhands-issue-3815-persistence-dir-profile-stores-python
ghcr.io/openhands/agent-server:0272099-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim

About Multi-Architecture Support

  • Each variant tag (e.g., 0272099-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., 0272099-python-amd64) are also available if needed

…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>
@github-actions

github-actions Bot commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

Python API breakage checks — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-agent-server/openhands/agent_server
   agent_profiles_router.py236996%139, 143, 170, 259, 304–305, 505, 545–546
   conversation_service.py64812580%146–147, 156, 182–183, 187–188, 193, 277–278, 281–282, 292, 421–422, 453, 456, 463–469, 496, 502, 598, 604, 609, 615, 623–624, 633–636, 645, 657, 665, 710–711, 772, 813–817, 819–820, 823–824, 834, 846–851, 949, 956–960, 963–964, 968–972, 975–976, 980–984, 987–988, 1010–1011, 1015–1016, 1018–1020, 1022, 1025, 1033–1037, 1046, 1054–1058, 1061–1066, 1068–1069, 1083, 1093, 1097, 1099–1100, 1105–1106, 1112–1113, 1123, 1141–1142, 1172, 1187, 1220, 1522, 1525
   profiles_router.py156696%352–357
openhands-agent-server/openhands/agent_server/openai
   service.py1833978%64, 73–74, 78–79, 83–84, 113–115, 129, 133–143, 145, 149–151, 155, 170, 239, 245, 251, 254, 266, 274, 283, 376–377, 404, 440
openhands-agent-server/openhands/agent_server/persistence
   store.py3455883%42–43, 93, 97, 101, 105, 109, 115, 138–139, 161, 164–167, 169–170, 175, 212, 214–218, 220–224, 229–234, 338–339, 344, 346–347, 457, 483–484, 489, 491–492, 594, 596, 650–651, 655–657, 676, 708, 729, 826, 845
TOTAL328041417856% 

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@enyst enyst left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 for get_llm_profile_store() and get_agent_profile_store().
  • Tests: add coverage for no-OH_PERSISTENCE_DIR profile-store fallback staying under ~/.openhands.

all-hands-bot commented Jun 21, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Review complete.

This review was performed through OpenHands Cloud Automation. You can log in and view the conversation here.

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py are structurally identical to the existing three — double-checked locking, _store_lock, reset_stores() coverage. No special cases introduced.
  • test_profile_store_persistence_dir.py is 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 in try/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. The lambda: Store(base_dir=...) idiom gives each call site a fresh instance pointing at the temp directory — fine since the stores are stateless beyond base_dir.
  • The two auto-title integration tests now use monkeypatch.setenv + reset_stores() instead of patching a private _DEFAULT_PROFILE_DIR constant — 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 (no OH_PERSISTENCE_DIR set) is unchanged because _get_persistence_dir falls back to DEFAULT_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:

  1. Add a .agents/skills/custom-codereview-guide.md file to your branch (or edit it if one already exists) with the /codereview trigger and the context the reviewer is missing. See the customization docs for the required frontmatter format.
  2. Re-request a review - the reviewer reads guidelines from the PR branch, so your changes take effect immediately.
  3. 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 /iterate to 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>
@simonrosenberg

Copy link
Copy Markdown
Member

@enyst good catch — addressed in 1d342dd.

The concern was real: _get_persistence_dir()'s no-env fallback is workspace-relative (DEFAULT_PERSISTENCE_DIR = Path("workspace/.openhands"), and conversations_path defaults to workspace/conversations), so absent OH_PERSISTENCE_DIR the profile stores would have moved credential-bearing LLM profiles from ~/.openhands to a CWD-relative dir.

Fix: the profile-store accessors now resolve through a dedicated _get_profile_persistence_dir():

  • OH_PERSISTENCE_DIR still takes precedence (isolation fix preserved).
  • When it's absent, they fall back to Path.home() / ".openhands" — not the generic workspace-relative agent-server fallback — so bare local profile secrets stay in the expected user config directory.

The accessors no longer take a config arg (no caller passed one, and the dir no longer depends on config). Added regression coverage for the no-env fallback staying under ~/.openhands:

  • test_llm_profile_store_falls_back_to_home
  • test_agent_profile_store_falls_back_to_home

Settings/secrets/workspaces stores are intentionally left on the existing _get_persistence_dir() behavior; only the credential-bearing profile stores are pinned to ~/.openhands.

Copy link
Copy Markdown
Collaborator

🔍 Review in progress…

We are performing the review through OpenHands Cloud Automation. You can log in and view the conversation here.

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 ⚠️ 22 passing, 7 pending image/QA checks, 1 failing 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>

all-hands-bot commented Jun 21, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Review complete.

This review was performed through OpenHands Cloud Automation. You can log in and view the conversation here.

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 enyst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@neubig
neubig merged commit 2a9992b into main Jun 22, 2026
43 of 44 checks passed
@neubig
neubig deleted the openhands/issue-3815-persistence-dir-profile-stores branch June 22, 2026 01:36
pengzhang-create pushed a commit to Pyromind-Dynamics/software-agent-sdk that referenced this pull request Aug 13, 2026
…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>
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.

agent-server: OH_PERSISTENCE_DIR doesn't fully isolate state — LLM/agent profile stores ignore it

5 participants