fix(profiles): align main-process HOME with subprocess HOME within a profile (#27250)#27260
Open
xxxigm wants to merge 3 commits into
Open
fix(profiles): align main-process HOME with subprocess HOME within a profile (#27250)#27260xxxigm wants to merge 3 commits into
xxxigm wants to merge 3 commits into
Conversation
…profile
Pull the Hermes Python process's own HOME (and USERPROFILE on Windows so
Path.home() follows) over to the same per-profile directory subprocesses
already use, so a single active profile never has two competing HOME
values. Activation is gated on {HERMES_HOME}/home/ existing on disk and
honours HERMES_PRESERVE_HOST_HOME=1 as an escape hatch for the historical
split-HOME behaviour. Profile isolation is unchanged — different profiles
still resolve to different homes. Issue NousResearch#27250.
…rch#27250 36 regression tests for align_main_process_home_with_subprocess: activation gates (directory-driven, HERMES_HOME-driven), idempotency, the HERMES_PRESERVE_HOST_HOME opt-out (parametrised truthy/falsy values), profile-level isolation, Path.home()/expanduser agreement on POSIX, and that _make_run_env / _sanitize_subprocess_env keep producing the same HOME as the aligned main process.
Update the environment-variables reference with the new HERMES_PRESERVE_HOST_HOME flag and add a "Per-profile HOME for tools and the agent" section to the profiles user guide explaining why a single profile no longer carries two competing HOME values. Issue NousResearch#27250.
2ca6c14 to
aee4b9d
Compare
This comment was marked as spam.
This comment was marked as spam.
Collaborator
11 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.
What does this PR do?
Aligns the main Hermes Python process's
HOMEwith the per-profileHOMEthat tool subprocesses already see, so a single active profile no longer carries two competingHOMEvalues.In Docker (and any install where
${HERMES_HOME}/home/exists) the situation was:HOME=/opt/data(from the image'suseradd -d /opt/data hermes).HOME=/opt/data/home/(injected by_make_run_env,_sanitize_subprocess_env,code_execution_tool).That made paths like
~/.ssh,~/.gitconfig,~/.config/ghand~/workspaceresolve to different directories depending on whether the agent or a child tool expanded them — exactly the ambiguity reported in #27250.After this PR the invariant requested in the issue holds:
Activation is directory-gated (only fires when
${HERMES_HOME}/home/actually exists), andHERMES_PRESERVE_HOST_HOME=1is provided as an escape hatch for callers that depend on the historical split-HOME behaviour.Related Issue
Closes #27250.
Type of Change
Changes Made
hermes_constants.py— newalign_main_process_home_with_subprocess()(idempotent, import-safe). Whenget_subprocess_home()returns a path, setsos.environ["HOME"](andUSERPROFILEon Windows soPath.home()follows) to the same per-profile directory. Skips whenHERMES_PRESERVE_HOST_HOME=1. Also adds a small_truthy_envhelper.get_subprocess_home()docstring updated to point at the new function; behaviour unchanged (still a pure read).hermes_cli/main.py— invokes the alignment right after_apply_profile_override()finalisesHERMES_HOMEand before any subsequent module-level code cachesPath.home(). Wrapped intry/exceptso a bug here can never blockhermesfrom booting.tests/test_main_process_home_alignment.py— 36 new regression tests:TestAlignmentActivationGates— 4 cases (no-op whenHERMES_HOMEunset, no-op whenhome/subdir missing, aligns when both present, idempotent).TestPreserveHostHomeOptOut— 14 cases parametrised over truthy/falsy values forHERMES_PRESERVE_HOST_HOME.TestProfileIsolation— 2 cases (two profiles get different homes; main HOME equals subprocess HOME within one profile — the core issue invariant).TestSubprocessEnvStillAligned— 3 cases (_make_run_env/_sanitize_subprocess_envagree with aligned main HOME; opt-out keeps the split behaviour).TestPathHomeAgreement— 1 POSIX case assertingPath.home()andos.path.expanduser("~")follow the alignedHOME.TestGetSubprocessHomeStillPureRead— 1 case pinning thatget_subprocess_home()itself never mutates env.website/docs/reference/environment-variables.md— documents the newHERMES_PRESERVE_HOST_HOMEflag.website/docs/user-guide/profiles.md— new "Per-profileHOMEfor tools and the agent" subsection under How it works, explaining both halves of the alignment and the opt-out flag.How to Test
.venvis set up:python3 -m venv .venv && source .venv/bin/activate && pip install -e ".[all,dev]"HERMES_HOME=/opt/dataand/opt/data/home/present:/opt/data/home.HERMES_PRESERVE_HOST_HOME=1and re-run: main process keeps/opt/data, subprocesses still get/opt/data/home(historical split behaviour preserved).Checklist
Code
fix(profiles): ...,test(profiles): ...,docs(profiles): ...)scripts/run_tests.sh tests/test_main_process_home_alignment.py tests/test_subprocess_home_isolation.pyand all tests passPath.home()agreement, and the historical pure-read invariant)Documentation & Housekeeping
website/docs/reference/environment-variables.mdandwebsite/docs/user-guide/profiles.md)cli-config.yaml.exampleif I added/changed config keys — N/A (env-var only, no config-yaml surface)CONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/AUSERPROFILEaligned soPath.home()follows; POSIXPath.home()readsHOMEdirectly so settingos.environ["HOME"]is sufficient thereScreenshots / Logs