Skip to content

Fix pi pin default model and backup settings.json#117

Merged
asujithan merged 2 commits into
mainfrom
fix/pi-pin-default-model
May 28, 2026
Merged

Fix pi pin default model and backup settings.json#117
asujithan merged 2 commits into
mainfrom
fix/pi-pin-default-model

Conversation

@asujithan
Copy link
Copy Markdown
Collaborator

@asujithan asujithan commented May 28, 2026

Summary

Fixes Pi config management issue from pr #69 : ucode writessettings.json (pinning defaultProvider/defaultModel) but only ever backed up and rolled back models.json. That left two failure modes:

  1. A pre-existing user settings.json was silently overwritten with no restore path.
  2. If Pi validation failed or the user ran ucode revert, models.json was rolled back but settings.json was orphaned — pinning a provider/model that no longer existed in the restored models.json, making Pi fail to start on the next run.

Changes

  • src/ucode/agents/pi.py
    • Add PI_SETTINGS_BACKUP_PATH.
    • _write_settings now calls backup_existing_file(PI_SETTINGS_PATH, PI_SETTINGS_BACKUP_PATH) before the merge, symmetric to the existing models.json backup in write_tool_config.
  • src/ucode/agents/__init__.py
    • validate_all_tools now also calls restore_file(PI_SETTINGS_PATH, PI_SETTINGS_BACKUP_PATH, managed) when Pi validation fails, so both managed files roll back together.
  • src/ucode/cli.py
    • revert() now restores settings.json alongside models.json and prints a "Pi settings: restored | unchanged" row.

Tests Added

  • tests/test_agent_pi.py::TestWriteToolConfig::test_pre_existing_settings_are_backed_up_before_first_write
    — pre-existing settings.json is copied to the backup path before ucode's pin is applied; the merged file retains user keys.
  • tests/test_agent_pi.py::TestValidateAllToolsPiRollback::test_failed_pi_validation_rolls_back_settings — drives validate_all_tools with validate_tool stubbed to fail and asserts settings.json is removed on the managed-rollback branch.

Test plan

  • uv run ruff check .
  • uv run pytest --ignore=tests/test_e2e.py --ignore=tests/test_e2e_user_agent.py — 593 passed
  • CI checks

JamesHWade and others added 2 commits May 28, 2026 16:32
Pi inherits the full environment from ucode, including any env vars that
its pi-ai package recognizes as auth for a built-in provider (e.g.
HF_TOKEN → huggingface). Pi's findInitialModel then picks the built-in
before reaching our databricks-claude provider, routes to the wrong host,
and validation 401s.

Write settings.json alongside models.json so findInitialModel uses our
provider/model directly. Fixes #68.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@asujithan asujithan requested a review from AarushiShah-db May 28, 2026 17:37
@asujithan asujithan merged commit 58c62d5 into main May 28, 2026
2 checks passed
@asujithan asujithan deleted the fix/pi-pin-default-model branch May 28, 2026 19:08
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.

3 participants