Fix pi pin default model and backup settings.json#117
Merged
Conversation
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>
AarushiShah-db
approved these changes
May 28, 2026
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.
Summary
Fixes Pi config management issue from pr #69 : ucode writes
settings.json(pinningdefaultProvider/defaultModel) but only ever backed up and rolled backmodels.json. That left two failure modes:settings.jsonwas silently overwritten with no restore path.ucode revert,models.jsonwas rolled back butsettings.jsonwas orphaned — pinning a provider/model that no longer existed in the restoredmodels.json, making Pi fail to start on the next run.Changes
src/ucode/agents/pi.pyPI_SETTINGS_BACKUP_PATH._write_settingsnow callsbackup_existing_file(PI_SETTINGS_PATH, PI_SETTINGS_BACKUP_PATH)before the merge, symmetric to the existingmodels.jsonbackup inwrite_tool_config.src/ucode/agents/__init__.pyvalidate_all_toolsnow also callsrestore_file(PI_SETTINGS_PATH, PI_SETTINGS_BACKUP_PATH, managed)when Pi validation fails, so both managed files roll back together.src/ucode/cli.pyrevert()now restoressettings.jsonalongsidemodels.jsonand 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.jsonis 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— drivesvalidate_all_toolswithvalidate_toolstubbed to fail and assertssettings.jsonis 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