Files
hermes-agent/tests/hermes_cli
liuzikaii 5f73e52c7e fix(models): catalog SWR refresh writes the requesting profile's cache (#103778, salvage #103779)
WHAT
- hermes_cli/model_catalog.py::_spawn_catalog_swr_refresh runs the background
  manifest refresh inside contextvars.copy_context(), so _write_disk_cache()
  resolves _cache_path() against the profile home that was active when
  get_catalog() was called (the HERMES_HOME ContextVar set by tui_gateway's
  _profile_scoped / Desktop model.options), not the process default home.
- The process-wide in-flight boolean becomes a set keyed by str(_cache_path()),
  so profile A's in-flight refresh no longer suppresses profile B's.

WHY
Under a routed profile B the bare threading.Thread lost the ContextVar override:
the fetched manifest was written to profile A's cache/model_catalog.json while B
stayed stale forever (and re-fetched on every picker open). The provider-list
sibling hermes_cli/models.py::_spawn_swr_refresh was already fixed this way in
5ff34f565e3; this brings the manifest worker in line. The per-path in-flight key
was reported by @nyl199310 in the issue thread.

Tests: tests/hermes_cli/test_model_catalog.py::TestSwrRefreshProfileScope — two
temp homes A/B under set_multiplex_active(True); both fail on origin/main's
model_catalog.py (B's file still stale; only A's path refreshed) and pass here.

Salvaged from #103779 by @Liuzikaii (copy_context hunk; its models.py hunk was
already on main and is dropped).

Fixes #103778

(cherry picked from commit 79bb1966172f25704e3fde5ef7c6f0e7672cd868)
2026-09-28 05:37:55 -07:00
..