Repository navigation
fix(doctor): surface GH_CONFIG_DIR hint when gh auth lives at a different HOME - #78095
Conversation
|
Codex review: needs real behavior proof before merge. Summary Reproducibility: yes. the linked Linux report gives a concrete Real behavior proof Next step before merge Security Review detailsBest possible solution: Merge this focused diagnostic after refreshed current-head proof and normal gates, preserving the boundary that OpenClaw only detects and explains the mismatch without reading, copying, or migrating GitHub CLI credentials. Do we have a high-confidence way to reproduce the issue? Yes: the linked Linux report gives a concrete Is this the best way to solve the issue? Yes: a doctor note plus GitHub skill troubleshooting docs is the narrow maintainable fix; the current code direction avoids token reads, credential migration, and a new OpenClaw config surface. What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 09fcd1981486. |
dfa44c1 to
d50b342
Compare
…rent HOME When OpenClaw spawns an agent shell with a different HOME than the user that ran `gh auth login` (per-agent codex homes, systemd User= services, sudo'd shells), `gh` looks at $XDG_CONFIG_HOME/gh or $HOME/.config/gh and reports "not logged into any GitHub hosts" even though the operator HOME has a valid hosts.yml. Add `detectGhConfigDirMismatch` in src/agents/skills/gh-config-discovery.ts: a pure helper that takes process env plus a fileExists probe and returns either "auth-discoverable", "no-known-auth", "explicit-gh-config-dir-set", or a "mismatch" with the alternate config dir, the host file path, and a suggested GH_CONFIG_DIR value to set on the gateway service environment. The helper checks `/root`, `$SUDO_USER`'s home, and `$USER`'s home as candidate operator homes on Linux/macOS, and uses platform-specific path joins so the same logic works on Windows test runners. Wire the helper into the doctor skills health flow: when the github skill is reported and the gh binary is present, call the discovery helper and, on a mismatch, print a "GitHub CLI" note with the operator-actionable fix instructions before any unavailable-skill repair prompt. Update skills/github/SKILL.md with a troubleshooting subsection that documents GH_CONFIG_DIR for service/agent environments where HOME differs from the user that ran `gh auth login`. Fixes openclaw#78063.
d50b342 to
7bc5e12
Compare
|
Landed via rebase onto
Thanks @tmimmanuel! |
Summary
HOMEthan the user that rangh auth login(per-agent codex homes, systemdUser=services, sudo'd shells),ghlooks up its config under$XDG_CONFIG_HOME/ghor$HOME/.config/ghand reportsnot logged into any GitHub hosts, even though the operator HOME has a validhosts.yml. Issue GitHub CLI auth can be missed when agent HOME differs from root gh config #78063 reports the symptom:HOME=/root/.openclaw/agents/main/agent/codex-home/home gh auth statusreturns "not logged in" whileghis fully authenticated under/root/.config/gh.GH_TOKEN/GITHUB_TOKENrabbit holes when the real fix is to setGH_CONFIG_DIR=/root/.config/gh(or equivalent) on the gateway service environment.detectGhConfigDirMismatchinsrc/agents/skills/gh-config-discovery.tsthat takes process env + afileExistsprobe and reports eitherauth-discoverable,no-known-auth,explicit-gh-config-dir-set, ormismatchwith the alternate config dir, hosts file, and a suggestedGH_CONFIG_DIRvalue.src/commands/doctor-skills.tsnow calls the helper from the doctor skills health flow when thegithubskill is reported and theghbinary is present, printing a "GitHub CLI" note with the operator-actionable fix before any unavailable-skill repair prompt.skills/github/SKILL.mdgains a troubleshooting subsection documentingGH_CONFIG_DIRfor service/agent environments.ghauth between homes. No new config option added; we read existing process env. The requirement engine is unchanged. No changes toghitself or its skill metadata other than docs.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
${XDG_CONFIG_HOME}not processed when installing a skill)Root Cause (if applicable)
ghresolves its config dir as$GH_CONFIG_DIR->$XDG_CONFIG_HOME/gh->$HOME/.config/gh(Linux/macOS) or$AppData/GitHub CLI(Windows). When OpenClaw spawns an agent shell withHOMEredirected to a per-agent codex home, theghlookup misses the operator's authenticated config. The previous doctor flow only checked whether theghbinary was onPATHand never inspected config-dir layout, so the GitHub skill looked ready while runtime calls failed.ghconfig dir against well-known operator homes that might hold ahosts.yml.docs/plugins/codex-harness.md), and several adjacent issues ([Bug]: GitHub skill requires OpenClaw restart after CLI installation but restart guidance is unclear #65958, docs(github): clarify restart after gh setup #75169, [Bug]: ${XDG_CONFIG_HOME} is not process when installing a skill #53628) already point at gh-skill setup gaps. This PR closes the specific HOME-mismatch case without changing the isolation model.Regression Test Plan (if applicable)
src/agents/skills/gh-config-discovery.test.ts(new, 13 cases for the pure helper) andsrc/commands/doctor-skills.test.ts(4 new cases coveringdescribeGhConfigDirHintFromDiscovery).HOME=/root/.openclaw/agents/main/agent/codex-home/homesetup yields amismatchresult whosesuggestedEnvValueequals/root/.config/gh, and the formatted hint containsGH_CONFIG_DIR=/root/.config/gh. SUDO_USER and USER fallbacks resolve to the right candidate dirs.GH_CONFIG_DIRalready set, missingghbinary, missinggithubskill, and aligned HOME all correctly suppress the hint. Linux, macOS, and Windows path layouts are exercised.gh-binary preconditions.User-visible / Behavior Changes
openclaw doctornow prints a "GitHub CLI" note when it detects an authenticatedhosts.ymloutside the agent process's effectiveghconfig dir, including the suggestedGH_CONFIG_DIRenv value. No new config keys; no changes to existing skill behavior. The GitHub skill docs gain a troubleshooting subsection.Diagram (if applicable)
Security Impact (required)
NoNo(helper reads HOME/USER/SUDO_USER/APPDATA from process env and probeshosts.ymlexistence; never reads token contents)NoNoNoRepro + Verification
Environment
ghCLI)Steps
upstream/main.pnpm test src/commands/doctor-skills.test.ts src/agents/skills-status.test.ts(plus the newsrc/agents/skills/gh-config-discovery.test.ts).pnpm tsgo:coreandpnpm tsgo:core:test.detectGhConfigDirMismatchdirectly vianode(throughtsx), passing the sameHOMEthe issue reports and a syntheticfileExiststhat pretends/root/.config/gh/hosts.ymlis present.Expected
kind: "mismatch"withalternateConfigDir = /root/.config/ghandsuggestedEnvValue = /root/.config/gh.GH_CONFIG_DIR=/root/.config/ghline.Actual
pnpm testfor the three test files: 28 passed in 15.68s.pnpm tsgo:coreexit 0;pnpm tsgo:core:testexit 0.node/tsxinvocation against the helper produced the expectedmismatchresult and the operator hint (transcript below).Real behavior proof
Behavior or issue addressed: Issue GitHub CLI auth can be missed when agent HOME differs from root gh config #78063 - agent shells with
HOME=/root/.openclaw/agents/main/agent/codex-home/homereportedghas unauthenticated even though/root/.config/gh/hosts.ymlwas a valid login. The doctor flow had no diagnostic for this HOME mismatch.Real environment tested: Ubuntu 24.04 workstation, Node 22.22.0, pnpm 10.33.2, branch
fix/78063-gh-config-dir-mismatchat headdd5ed0fa64. Live invocation of the new helper vianode(throughtsxfor ESM TypeScript path resolution).Exact steps or command run after this patch:
nodeproof script that imports the new helper by absolute path and runs three scenarios: the exactHOME=/root/.openclaw/agents/main/agent/codex-home/homereproduction from the issue, the operator's already-appliedGH_CONFIG_DIR=/root/.config/ghworkaround, and an alignedHOME=/rootbaseline.node_modules/.bin/tsx /tmp/proof-78063.mtsand captured stdout.openclaw doctorwill print on the affected systems.Evidence after fix:
Live console output captured at branch head
dd5ed0fa64(realnode/tsxinvocations against the new helper, not lint/test gates):Observed result after fix: With the agent HOME from the issue,
detectGhConfigDirMismatchcorrectly identifies the/root/.config/ghcandidate, reports it as amismatch, and produces the exact operator hint a user would need to copy into the gateway service env file. WithGH_CONFIG_DIRalready set, the helper short-circuits toexplicit-gh-config-dir-set(no false-positive hint). With aligned HOME, the helper reportsauth-discoverableand no hint. The doctor flow only invokes the helper when thegithubskill is enabled andghis onPATH.What was not tested: A live macOS reproduction with a real systemd analogue (the issue is reported on Ubuntu); a live Windows reproduction (the helper covers Windows
APPDATApaths but the issue scenario is Linux-only); end-to-end interaction withghitself (we read documented gh behavior, not the binary).Evidence
tsxcapture of the operator hint).Human Verification (required)
HOMEfrom the issue produces a mismatch result whosesuggestedEnvValuematches the operator's documented workaround.~/.openclaw/gateway.systemd.env.GH_CONFIG_DIRalready set short-circuits the discovery (no duplicate hint).ghbinary missing suppresses the hint (the existing install hint covers it).githubskill missing suppresses the hint (no spurious noise on agents that disabled github)./home/<user>(or/Users/<user>on darwin).APPDATAandUSERPROFILElookups produce backslash-joined paths.gh auth logincycle on a macOS or Windows host; the actual systemd service env file reload behavior; tab-complete or shell-eval edge cases.Review Conversations
Compatibility / Migration
YesNo(the helper reads existing env; nothing new is required)NoRisks and Mitigations
hosts.ymlfor an unrelated user, and the operator follows the suggestedGH_CONFIG_DIRblindly.GH_CONFIG_DIRat the discovered alternate; it does not modify env or copy credentials. The hint includes the candidateHOMEso operators can sanity-check before applying it. The discovery is gated on thegithubskill being enabled andghbeing onPATH./rootcandidate could be misleading on hosts where the gateway intentionally runs under an unprivileged user that has its ownhosts.yml.auth-discoverableshort-circuits before any candidate scan when the agent's own HOME already hashosts.yml.