security(gateway): re-resolve skills_sync path constants per call - #56523
Open
srojk34 wants to merge 1 commit into
Open
security(gateway): re-resolve skills_sync path constants per call#56523srojk34 wants to merge 1 commit into
srojk34 wants to merge 1 commit into
Conversation
tools/skills_sync.py's HERMES_HOME/SKILLS_DIR/MANIFEST_FILE are resolved
once at import time via get_hermes_home(), which is a context-local
ContextVar under the multiplexed gateway (multiple profiles sharing one
process). gateway/run.py calls sync_skills() directly in-process on every
profile's startup, so freezing the path at import time pins every later
profile's sync to whichever profile's HERMES_HOME was active when this
module was first imported -- a later-starting profile silently syncs
bundled skills into the FIRST profile's directory instead of its own, and
never gets its own bundled skills synced at all. The module's own comment
already flagged this ("Uses subprocess because sync_skills() caches
HERMES_HOME at module level") for the CLI/hermes-update path, which routes
around it via subprocess isolation -- but gateway/run.py's in-process call
has no such isolation.
_rmtree_writable's safety guard (SKILLS_DIR.resolve() as the scope floor
for a destructive rmtree) also benefited from this fix: a frozen wrong-
profile skills_root could desync the guard from the actual skills
directory being operated on.
Adopt tools/skills_hub.py's already-established fix for this exact bug
class: a module __getattr__ (PEP 562) that resolves HERMES_HOME/
SKILLS_DIR/MANIFEST_FILE dynamically per access, honoring the active
profile override, while a test's patch("tools.skills_sync.SKILLS_DIR", ...)
still sets a real module attribute that shadows dynamic resolution
entirely -- preserving every existing test seam in
tests/tools/test_skills_sync.py unmodified. All ~20 internal call sites in
the module now resolve fresh via the corresponding _hermes_home()/
_skills_dir()/_manifest_file() functions instead of the frozen names.
|
Hourly triage from Hermes Agent:
No blocking code issue found in the reviewed path. |
5 tasks
Contributor
|
Thanks for carrying the established dynamic-path pattern from Problems
Suggested changes
This is an automated hermes-sweeper review. |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tools/skills_sync.py'sHERMES_HOME/SKILLS_DIR/MANIFEST_FILEare resolved once at import time viaget_hermes_home(), which reads a context-localContextVar(_HERMES_HOME_OVERRIDE) set per-request under the multiplexed gateway (multiple profiles served from one process, e.g. the desktoptui_gateway).gateway/run.pycallssync_skills()directly in-process on every profile's startup:Freezing the resolved path at import time pins every later profile's sync to whichever profile's
HERMES_HOMEhappened to be active the first time this module was imported in the process — a later-starting profile silently syncs bundled skills into the FIRST profile's directory instead of its own, and never gets its own bundled skills synced at all. The module's own comment (visible elsewhere in the codebase,hermes_cli/profiles.py) already flags this for the CLI/hermes updatepath — "Uses subprocess because sync_skills() caches HERMES_HOME at module level" — which routes around it via subprocess isolation, butgateway/run.py's in-process call has no such isolation._rmtree_writable's safety guard (SKILLS_DIR.resolve()as the scope floor for a destructivermtree, guarding against a catastrophic wipe of~/.hermes/) also benefits from this fix: a frozen wrong-profileskills_rootcould desync the guard from the actual skills directory being operated on.Fix
Adopt
tools/skills_hub.py's already-established fix for this exact bug class: a module__getattr__(PEP 562) that resolvesHERMES_HOME/SKILLS_DIR/MANIFEST_FILEdynamically per access, honoring the active profile override, while a test'spatch("tools.skills_sync.SKILLS_DIR", ...)still sets a real module attribute that shadows dynamic resolution entirely — preserving every existing test seam intests/tools/test_skills_sync.py(dozens of call sites) unmodified. All ~20 internal call sites in the module now resolve fresh via_hermes_home()/_skills_dir()/_manifest_file()instead of the frozen names.Test plan
pytest tests/tools/test_skills_sync.py tests/tools/test_skills_list_modified_diff.py -q— 75 passedpytest tests/test_profile_isolation_runtime.py -q— 14 passed (10 pre-existing + 4 new)pytest tests/hermes_cli/test_skills_hub.py -q— 28 passedTestSkillsHubPathResolutionfailures (a test-order-dependent state leak intools/skills_hub.py's own test suite) — confirmed viagit stashthat this happens identically without this change; each file passes cleanly run on its own.ruff checkon all changed files — cleanNote on file co-tenancy
Open PR #34577 ("keep bundled skill copies writable on Nix store") also touches
tools/skills_sync.py, but for an unrelated concern (shutil.copytreewrite-permission handling on read-only source filesystems, via new_copy_file_writable/_make_tree_owner_writablehelpers) — no functional overlap with this profile-isolation fix, though whichever merges second will need a small rebase around the constant-block region.