Skip to content

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
databricks:mainfrom
dgokeeffe:fix/pi-config-dir-env
Open

fix(pi): point pi at config dir via PI_CODING_AGENT_DIR instead of redirecting HOME#243
dgokeeffe wants to merge 1 commit into
databricks:mainfrom
dgokeeffe:fix/pi-config-dir-env

Conversation

@dgokeeffe

@dgokeeffe dgokeeffe commented Jul 24, 2026

Copy link
Copy Markdown

Problem

Pi redirected $HOME to APP_DIR/pi-home to isolate its configuration. On macOS that also changed default keychain resolution, causing gh auth, git credential helpers, and other keychain-backed tools to fail inside Pi.

Fix

Set Pi's supported PI_CODING_AGENT_DIR environment variable instead of replacing HOME:

 env["OAUTH_TOKEN"] = token
-env["HOME"] = str(PI_UCODE_HOME)
+env["PI_CODING_AGENT_DIR"] = str(PI_CONFIG_DIR)

Pi continues to store models.json, settings.json, and sessions under the existing ucode-private agent directory, while subprocesses keep the real user home and can resolve the login keychain normally.

Test changes

  • Redirect PI_CONFIG_DIR, models, settings, and backup paths consistently in both Pi E2E fixtures.
  • Assert build_runtime_env() sets PI_CODING_AGENT_DIR and preserves an existing HOME.
  • Update stale comments/docstrings that described the old HOME-based behavior.

Validation

  • uv run ruff check src/ucode/agents/pi.py tests/test_agent_pi.py tests/test_e2e.py tests/test_e2e_user_agent.py
  • uv run pytest tests/test_agent_pi.py tests/test_e2e_user_agent.py::TestPiUserAgent tests/test_e2e.py -q — 42 passed, 29 workspace-gated tests skipped

This remains an independent one-commit, four-file fix based on current main.

…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).
@dgokeeffe
dgokeeffe force-pushed the fix/pi-config-dir-env branch from 650cbc6 to fa12598 Compare July 26, 2026 00:38
@dgokeeffe

Copy link
Copy Markdown
Author

Rebased onto current main and tightened after review: the test now explicitly proves HOME is preserved, stale HOME-based comments/docstrings were updated, and focused validation is 42 passed / 29 workspace-gated skips with Ruff clean. A maintainer CI approval/review is now the remaining gate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant