Give a session a HOME when the node was handed none - #115
Merged
Merged
Conversation
`omnyshell exec worker-1 -- echo $HOME` came back empty on a node installed as a service. The node is not at fault and neither is the session: systemd hands a system unit PATH, LANG and even USER, but sets HOME only if the unit asks, and sessions inherit the node's environment faithfully. So there was nothing to inherit. It failed quietly, which is the worse part: `cd ~` went nowhere and said nothing — landing you in the node's working directory — `~/…` stopped expanding, and anything keeping state under a home directory wrote elsewhere. Running this repo's own `omnyshell local` with HOME unset left a `.omnyshell/history/` in the checkout, which is the same gap seen from the other side. resolveUserHome now asks the password database when the environment is silent: by USER/LOGNAME first, then by the process's own uid — the real key, and the only one left in a bare container, which sets neither. Root falls back to /root where there is no password database to read. Where there is genuinely no answer it says so rather than guessing: a wrong home would send git, ssh and package managers somewhere that is not the user's. Both node shell backends now fill HOME into a session's environment when the node process has none, never overriding one already set; expandUserHome and omnyshellHome resolve through the same path. Verified on Linux, where it actually bites: in a container with neither HOME nor USER, resolveUserHome answers /root, a session environment gains HOME=/root, and `~/x` expands to /root/x. macOS hides this — zsh sets HOME for itself at startup — so a Debian node running sh is where it shows. v1.57.0 is tagged, so this carries the bump to 1.57.1 and its changelog. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KdG8bDrddXkEkzgPq23D6q
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
yaml ^3.1.4, and dev-only test ^1.32.0 and dependency_validator ^5.0.6. No source change: the suite passes unmodified against these versions (689 unit tests), `dart analyze` is clean and dependency_validator finds nothing. Noted in the 1.57.1 section this branch already opened, since that version is not yet released. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KdG8bDrddXkEkzgPq23D6q
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.
omnyshell exec worker-1 -- echo $HOMEcomes back empty on a node installedas a service.
Neither the node nor the session is at fault. systemd hands a system unit
PATH,LANGand evenUSER, but setsHOMEonly if the unit asks — andsessions inherit the node's environment faithfully, so there was nothing to
inherit. Read straight off a running node's agent process:
No
HOME, and the unit's onlyEnvironment=isOMNYSERVER_HOME.Why it matters more than it looks
It fails quietly.
cd ~goes nowhere and says nothing — you stay in thenode's working directory —
~/…stops expanding, and anything keeping stateunder a home directory (git, ssh, package managers) writes somewhere else.
Running this repo's own
omnyshell localwithHOMEunset left a.omnyshell/history/in the checkout:omnyshellHome()was falling back to.. Same gap, seen from the other side.The fix
resolveUserHomeasks the password database when the environment is silent:HOME/USERPROFILEwhen set and non-empty — always the answer.USER/LOGNAMElooked up in/etc/passwd. systemd setsUSER, so thisis the common case.
/proc/self/status— the real key, and theonly one left in a bare container, which sets neither variable.
/rootfor uid 0 where there is no password database to read at all.same tools to a directory that is not the user's.
Both node shell backends now pass the session environment through
withUserHome— which fills
HOMEin only when the node process has none, and never overridesone already set.
expandUserHomeandomnyshellHomeresolve through the samepath.
Verified
On Linux, where it actually bites — a container with neither
HOMEnorUSER:macOS hides this — zsh sets
HOMEfor itself at startup, so a Debian noderunning
shis where it shows. Worth knowing before trying to reproducelocally.
16 new unit tests (the environment, the passwd lookup by name and by uid, an
empty
HOME, a malformed passwd line, an unknown uid, and the refusal toguess), with the process environment and both file paths injectable so none of
it depends on the machine running the suite. 689 unit tests pass on macOS and
Linux;
dart analyzeclean.v1.57.0is tagged, so this carries the bump to 1.57.1 —pubspec.yamlandlib/src/version.dart, pinned together byversion_test.dart— plus itschangelog section.
Not in this PR
The OmnyServer side is worth fixing too: the unit it generates sets only
OMNYSERVER_HOME, and addingHOMEthere would cover formulas as well —apt-get,gitanddart pubrun with that same environment. This change doesnot touch them.
🤖 Generated with Claude Code
https://claude.ai/code/session_01KdG8bDrddXkEkzgPq23D6q