fix(pi): point pi at config dir via PI_CODING_AGENT_DIR instead of redirecting HOME#243
Open
dgokeeffe wants to merge 1 commit into
Open
fix(pi): point pi at config dir via PI_CODING_AGENT_DIR instead of redirecting HOME#243dgokeeffe wants to merge 1 commit into
dgokeeffe wants to merge 1 commit into
Conversation
…directing HOME Pi honors the PI_CODING_AGENT_DIR env var to resolve its config directory (~/.pi/agent), so redirecting /Users/david.okeeffe to APP_DIR/pi-home was unnecessary. The HOME redirect broke macOS keychain default resolution under ucode: the Security framework looks for the login keychain under the redirected HOME, finds none, and security default-keychain returns 'A default keychain could not be found'. As a result gh auth, the git credential helper, and any keychain-backed tool failed inside pi. Setting PI_CODING_AGENT_DIR to the existing PI_CONFIG_DIR preserves config isolation (models.json/settings.json/sessions still land under APP_DIR/pi-home/.pi/agent) while leaving /Users/david.okeeffe as the user's real home, so the login keychain stays discoverable. Tests: the two pi e2e sites monkeypatched PI_UCODE_HOME/PI_CONFIG_PATH to redirect pi at a tmp home. They now also patch PI_CONFIG_DIR (read by build_runtime_env) and PI_SETTINGS_PATH/PI_SETTINGS_BACKUP_PATH (previously masked because the HOME redirect made pi read settings from the un-patched real APP_DIR path).
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.
Problem
Pi redirected
$HOMEtoAPP_DIR/pi-hometo isolate its config (~/.pi/agent), but this broke macOS keychain default resolution under ucode. The Security framework looks for the login keychain under the redirectedHOME, finds none, andsecurity default-keychainreturns "A default keychain could not be found". As a resultgh auth, the git credential helper, and any keychain-backed tool failed inside pi.Root cause
Pi does honor a config-dir env var. From the installed package (
config.js):So the
$HOMEredirect was unnecessary — ucode can isolate pi's config the same way it isolates opencode (XDG_CONFIG_HOME) and gemini (GEMINI_CLI_HOME): by pointing the agent at a config dir via env var, without touching$HOME.Fix
build_runtime_envnow setsPI_CODING_AGENT_DIR = PI_CONFIG_DIRinstead ofHOME = PI_UCODE_HOME:def build_runtime_env(token: str) -> dict[str, str]: env = os.environ.copy() env["OAUTH_TOKEN"] = token - env["HOME"] = str(PI_UCODE_HOME) + env["PI_CODING_AGENT_DIR"] = str(PI_CONFIG_DIR) return envConfig isolation is preserved —
models.json,settings.json, and sessions still land underAPP_DIR/pi-home/.pi/agent(the existingPI_CONFIG_DIR). But$HOMEstays the user's real home, so the login keychain stays discoverable andgh/git credential helper/keychain-backed tools work unmodified.Test changes
The two pi e2e sites monkeypatched
PI_UCODE_HOME/PI_CONFIG_PATHto redirect pi at a tmp home. They now also patch:PI_CONFIG_DIR— read bybuild_runtime_envto set the env varPI_SETTINGS_PATH/PI_SETTINGS_BACKUP_PATH— previously masked because theHOMEredirect made pi read settings from the un-patched realAPP_DIRpath; without the redirect,_write_settingswould write to the real path while pi reads from the tmpPI_CONFIG_DIRThe pi unit test assertion (
env["HOME"] == ...→env["PI_CODING_AGENT_DIR"] == ...) is updated to match.Verification
uv run pytest tests/test_agent_pi.py tests/test_e2e_user_agent.py::TestPiUserAgent— 42 passeduv run pytest tests/ -q(full unit suite, e2e excluded) — 943 passeduv run ruff checkon changed files — cleanPI_CODING_AGENT_DIRis respected by inspecting the installed pi package source and by runningpi --list-modelswith the env var set to a throwaway config dir (pi reported loading<dir>/models.json)