Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ Preconditions:
missing name and invalid bodies or names reject with `HttpError` status
404 and 422. It re-activates `qa-direct`, so the list afterwards is as
before.
- **Persistence directory with `~` (`F22.persistence-dir`), known bug.**
- **Persistence directory with `~` (`F22.persistence-dir`).**
Launch a second server whose `OH_PERSISTENCE_DIR` is `~/qa-f22-tilde`
(its `HOME` is the run's `home/`), save and activate a meta-profile there,
and look where the files landed. The second server is stopped when the
Expand All @@ -666,18 +666,14 @@ Preconditions:
control-agent-server api POST /api/meta-profiles/qa-tilde/activate --run "$T" --expect 200
control-agent-server api GET /api/meta-profiles --run "$T" --check meta_profiles len-eq 1 --check active_meta_profile eq qa-tilde
control-agent-server state ls 'home/qa-f22-tilde/settings.json' --run "$T" --expect-count 1
control-agent-server state ls 'home/qa-f22-tilde/meta-profiles/qa-tilde.json' --run "$T" --expect-count 1 # bug: count eq 0
control-agent-server state ls 'home/qa-f22-tilde/meta-profiles/qa-tilde.json' --run "$T" --expect-count 1
```
`settings.json` lands in `home/qa-f22-tilde/` (the settings store expands
`~` through `get_user_persistence_dir`). Expected the meta-profile next to
it; today it is written to `server/~/qa-f22-tilde/meta-profiles/qa-tilde.json`,
a directory literally named `~` under the server's working directory,
because `default_meta_profile_dir()` uses `Path(os.environ["OH_PERSISTENCE_DIR"])`
without `expanduser()` or the relative-path anchoring every other store
gets (`meta_profile_store.py`). The API still works because the router and
the routing tool share that helper; the files are just outside the
persistence directory. The `--save` file lands under the second run's
`evidence/` directory.
`settings.json` lands in `home/qa-f22-tilde/` and the meta-profile next to
it in `home/qa-f22-tilde/meta-profiles/qa-tilde.json`: both stores resolve
`OH_PERSISTENCE_DIR` through `get_user_persistence_dir`, which expands `~`
and anchors a relative value, so nothing is written to a directory
literally named `~` under the server's working directory. The `--save`
file lands under the second run's `evidence/` directory.

## Gotchas

Expand Down Expand Up @@ -723,6 +719,6 @@ Preconditions:
- `503` and `500` bodies use the server's generic shape: `detail` is
`Internal Server Error` and the route's message is in `exception`.
- The store directory comes from `OH_PERSISTENCE_DIR` read at call time
(`default_meta_profile_dir()`), falling back to `~/.openhands/meta-profiles`
when it is unset; give the server an absolute `OH_PERSISTENCE_DIR`
(`F22.persistence-dir`).
(`default_meta_profile_dir()`, through `get_user_persistence_dir`, so `~`
is expanded like in every other store), falling back to
`~/.openhands/meta-profiles` when it is unset (`F22.persistence-dir`).
9 changes: 4 additions & 5 deletions openhands-sdk/openhands/sdk/llm/meta_profile_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from __future__ import annotations

import json
import os
import re
import tempfile
from collections.abc import Iterator
Expand All @@ -23,6 +22,7 @@

from openhands.sdk.llm.llm_profile_store import PROFILE_NAME_REGEX
from openhands.sdk.logger import get_logger
from openhands.sdk.utils.path import get_user_persistence_dir


_LOCK_TIMEOUT_SECONDS: Final[float] = 30.0
Expand All @@ -37,11 +37,10 @@ def default_meta_profile_dir() -> Path:
persisted state. Honor that for bare ``MetaProfileStore()`` instances so
runtime tools read the same meta-profiles exposed by the HTTP API. Without
that env var, keep the standalone SDK default under ``~/.openhands``.
Resolved at call time through ``get_user_persistence_dir`` so ``~`` and
relative values land where the other stores put their files.
"""
env_dir = os.environ.get("OH_PERSISTENCE_DIR")
if env_dir:
return Path(env_dir) / "meta-profiles"
return Path.home() / ".openhands" / "meta-profiles"
return get_user_persistence_dir() / "meta-profiles"


class MetaProfileLimitExceeded(Exception):
Expand Down
11 changes: 11 additions & 0 deletions tests/sdk/llm/test_meta_profile_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ def test_default_store_honors_oh_persistence_dir(
assert store.base_dir == tmp_path / "meta-profiles"


def test_default_store_expands_user_in_oh_persistence_dir(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setenv("HOME", str(tmp_path))
monkeypatch.setenv("OH_PERSISTENCE_DIR", "~/state")

store = MetaProfileStore()

assert store.base_dir == tmp_path / "state" / "meta-profiles"


def test_load_valid_meta_profile(tmp_path: Path) -> None:
_write(tmp_path, "balanced", VALID)
store = MetaProfileStore(base_dir=tmp_path)
Expand Down
Loading