Repository navigation
fix(models): a switch removes only the model values clauth wrote - #180
xingfanxia wants to merge 6 commits into
Conversation
A switch or a start removes every model key the landing account's [models] leaves unset, so a model picked with Claude Code's /model, or a hand-set CLAUDE_CODE_SUBAGENT_MODEL, is dropped on every switch. keep_unset_models = true in profiles.toml (hand-edited, default off) leaves such a key as the settings file holds it: model, advisorModel, the ANTHROPIC_DEFAULT_*_MODEL remaps and CLAUDE_CODE_SUBAGENT_MODEL. A row the account sets is still written, and CLAUDE_CODE_EFFORT_LEVEL is untouched. The builder reads the key only when a build would remove a value that is there, and an unreadable profiles.toml reads off, so with the key unset every build is what it was. Two builder tests that seed such a value now hold a HomeSandbox. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Configuration says what the key keeps on a switch and on a start, that a row an account sets then stays after a switch away, and lists it in the profiles.toml table. Auto-Switch's launch-demand rules note where a kept global model, subagent model or advisor now counts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
A note on the red CI: the three |
Takes the sync ledger's amended text (the three upstream commits left for the next sync, the 1.99.1 gate against upstream CI's 1.100.0) and fills in the deploy record, the live keep_unset_models confirmation, and the state of PR uwuclxdy#175, uwuclxdy#176 and uwuclxdy#180. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
uwuclxdy
left a comment
There was a problem hiding this comment.
The narrower design from your note (2) is the one I want: clauth removes a model key only while the file still holds the value clauth wrote there, so a /model pick or a hand edit survives a switch and nobody needs a knob. The base-env record already does this for custom [env] keys, so the fix extends it to the model keys. A global flag keeps clauth's own leftovers too (a preset's model ids following you onto an Anthropic account), and leaves the bug on for everyone who never sets it.
Picks up the rustc 1.100 clippy fixes that turned this PR's CI red. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The review asked for the narrower rule instead of a knob: clauth removes a model key only while the file still holds the value it wrote there. This takes the flag, its reader, its tests and its wiki rows back out, leaving these files as on mommy; the next commit builds the rule on the base-env record. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…wrote A switch or a start removed every model key the landing account leaves unset: `model`, `advisorModel`, the ANTHROPIC_DEFAULT_*_MODEL remaps and CLAUDE_CODE_SUBAGENT_MODEL. That moved a running session off a `/model` pick on every automatic switch and dropped a hand-set subagent model. The base-env record now keeps, per model key, the digest of the value clauth last wrote there. An unset row removes the key only while the live value is one clauth wrote; any other value is the user's and stays. A row still writes over the key. Where the record has no model entry yet (the upgrade) or an older clauth moved the marker, the record's own judges decide: an account's own value counts as clauth's. Entries land around the live write the way cover entries do, so a crash never turns clauth's value into the user's. Sibling builds (a shared start copy, the launch-demand read) read the record and never write it, and an unparseable record refuses a build only when such a key needs a decision. The model env keys leave the outgoing account's [env] strip list in the build, so an [env]-carried model key follows the same rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Configuration's model routing now states the rule (an unset row removes only the value clauth wrote) and the upgrade case; the launch-demand parentheticals in Auto-Switch say a global model, subagent model or advisor clauth did not write counts on a shared runtime; the storage layout, SECURITY.md and Security say base-env.json also holds the model digests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Done, and the flag is gone. |
A switch or a start now removes a model key the landing account does not set only while the settings file still holds the value clauth itself last wrote there. A
/modelpick, an/advisorpick or a hand edit survives. A row an account sets is still written over whatever the file holds. There is no new key.Cause. On every switch and every
clauth start,build_settingsinsrc/claude.rswrites each model key: the top-levelmodelandadvisorModel, plusANTHROPIC_DEFAULT_{OPUS,SONNET,HAIKU,FABLE}_MODELandCLAUDE_CODE_SUBAGENT_MODELinenv. It writes the account's row when the account has one and removes the key when it does not. Claude Code's/modelsaves its choice in that same top-levelmodelkey, and a running session reloadssettings.jsonwhen it changes. So on accounts with no[models]rows, every automatic switch moved a running session off the model the operator picked, and deleted a subagent model set by hand. The removal could not tell a value clauth wrote from one the operator wrote.Fix. It extends the base-env record (
~/.clauth/base-env.json), which already tells clauth's values from the user's for custom[env]keys, to the model keys.SavedBaseEnvgainsmodels: per model key, the SHA-256 digest of the value clauth last wrote there (wrote), pluspendingwith the same meaning as on aBaseEnvEntry. It keeps nobase: a row writes over the key as before, and nothing is put back when a row goes away, so no model value of the user's is ever stored. The field isNoneuntil the first live apply of this build, and a fresh stamp holds{}.settle_model_keysdecides each key the landing account leaves unset. The key is removed only when the record's entry names the live value. Where the record cannot speak for the live file, it uses the judges the record already uses for covers (Judge). With no model entries yet (no record, or one written before this change) it runs the migration's test: a value equal to the outgoing account's own value is clauth's (the active account, or every account while none is active). After an older clauth moved the marker (Unseen), any account's own value counts. Every other value is the user's and stays. "An account's own value" is its[env]entry for an env key, else its[models]row, since the build's "profile env last" pass writes the[env]one.land_live_settings). A written row's entry goes in the pre-write withpendingnaming the clauth value it replaces. A removal's entry stays in the pre-write, written there when the migration orUnseenjudge found the value, and retires after the live write. A crash between the two writes therefore never turns clauth's value into the user's.clauth startcopy, thestart --autoand delegate demand read, the proxy-delete check) read the record when such a key is held and never write it. So a shared start copies the operator's/modelpick from~/.claude/settings.jsonand leaves out the rows clauth wrote there for the active account. An--isolatedstart builds from{}and keeps nothing.[env]strip list inbuild_settings. That list removed an[env]-carried model key whatever the file held, so a value the user changed since would have been lost. The record decides those keys like the rest.Deliberately not changed.
release_saved_base_env) still leaves the departing account's model rows in place and still strips an[env]-carried model key, as the wiki already says.CLAUDE_CODE_EFFORT_LEVELis still written on every build. It is not a model key, and feat(models): set Claude Code's effort per model in each account #173 is working on effort.start::fallback_chainstill resolves adefaultfallback entry from the member's[models] default, not from a keptmodel.settings_syncalready keepsmodel,advisorModeland the managed env keys per profile, so a/modelin a session's copy still stays in that copy.v: 1; the new field is optional.User-visible surface. No new key, flag, TUI row or text. A model value the operator set now survives a switch and reaches a shared
clauth start, which the launch-demand walk then counts. In the wiki, Configuration's model-routing paragraph now states the rule and the upgrade case in place of "an unset row removes its key", and the storage-layout line forbase-env.jsonmentions the digests. Auto-Switch's launch-demand parentheticals ("the globalmodelnever counts", and the same for the subagent model andadvisorModel) now say a global value clauth did not write counts on a shared runtime. SECURITY.md and wiki/Security.md say the record also holds those digests. The README does not state the removal rule, so it is unchanged.Tests (each in a
HomeSandbox, or the runtime suite'swith_fake_home, with synthetic files only):tests/inline/actions.rs, throughswitch_profile_locked:a_presets_model_ids_never_follow_a_switch_onto_an_account_without_rows: all seven keys from one account's rows leave on the switch to a rowless account and come back with it.a_model_the_user_set_survives_a_switch_and_a_row_still_overwrites_it: a hand-set value under all seven keys survives the rowless switch, the next account's rows overwrite it, and those values leave on the switch after.clearing_a_row_on_the_active_account_removes_only_what_the_row_wrote: coversedit_profile_model.an_env_carried_model_key_leaves_only_while_it_holds_the_accounts_value: the same rule for a model key in an account's[env].with_no_record_an_upgrade_removes_only_the_outgoing_accounts_rowsanda_record_without_models_removes_only_the_outgoing_accounts_rows: the upgrade case, with the record deleted and with only itsmodelsfield gone. The outgoing account's rows leave, a/modelpick stays, and the record then holdsmodels.an_older_clauths_switch_leaves_its_model_rows_clauths: the marker was moved with no record entry. The older clauth's rows leave and a value no account writes stays.a_failed_first_removal_after_the_upgrade_still_removes_on_the_retry: the upgrade's first removal fails its live write and the retry still removes.tests/inline/claude.rs:an_unset_model_row_removes_only_the_value_clauth_wrote_live: the live apply on its own, all seven keys.a_shared_start_build_keeps_the_users_model_and_drops_the_ones_clauth_wrote: the session build andruntime_model_sourcesover the live file, plus the isolated case.an_unparseable_record_refuses_a_model_removal_it_would_decide: live and sibling builds refuse without quoting, and the live file is unchanged. A rows-only build still lands.with_no_record_a_hand_set_model_stays: no record and no accounts.a_failed_live_write_leaves_clauths_model_values_clauths:FailLiveSettingsWriteon a removal and on a row replacement, the second pinningpending.tests/inline/runtime.rsa_shared_copy_keeps_the_operators_model_pick_but_not_clauths_rows:write_merged_settingsunder both isolations.build_settings_clears_stale_model_knobs,build_settings_removes_only_an_advisor_model_clauth_wrote_when_the_profile_has_no_row(was..._removes_advisor_model_when_the_profile_has_no_advisor_row),runtime_model_sources_read_the_runtime_models_and_drop_a_missing_defaultandstart::a_global_advisor_model_counts_without_a_profile_row_only_when_the_user_set_it(was..._never_counts_without_a_profile_row). Each used to assert that a value seeded with no record is removed. Each now has clauth write the value through a live apply first, and two of them also assert that a hand-set value stays. Fourstart --autotests intests/inline/cli.rs(cmd_start_auto_never_judges_a_member_by_a_global_model_its_session_drops,..._by_a_subagent_model_the_session_scrubs,..._a_no_model_launch_with_a_fallback_keeps_the_blanket_scoped_judgment,..._an_unresolved_default_keeps_its_known_headline_on_the_scoped_rung) seeded a globalmodelby hand and expected a member without adefaultto drop it. Each now has clauth's live apply write thatmodelfirst (a newclauth_wrote_the_global_modelhelper), and its assertions are unchanged. The two record-stamp assertions inthe_first_settings_apply_stamps_the_record_and_keeps_it_while_emptygain"models": {}.Mutations, each run with nextest on the tests above (all pass without a mutation). The first ten ran on 17 tests. The pre-write mutation passed all 17, so I added
a_failed_first_removal_...and ran that mutation and the last one on 18:Unseenjudged asRecorded:an_older_clauths_switch_leaves_its_model_rows_clauthsred.pendingnever written:a_failed_live_write_leaves_clauths_model_values_clauthsred.a_failed_first_removal_after_the_upgrade_still_removes_on_the_retryred.[env]strip list keeps removing model keys:an_env_carried_model_key_...red.an_unparseable_record_...red.modelsread asRecorded:a_record_without_models_...red.MODEL_KEYS: 10 red. Dropping it from the array instead does not compile.agent
@xingfanxiamommy(9ca6de2e) in with a merge commit, since the earlier CI failures came from the rustc 1.100 lints fixed there. Then one commit reverts the flag, one adds the rule and its tests, and one updates the docs.cargo +1.100.0 fmt --all -- --checkclean;cargo +1.100.0 clippy --locked --all-targets --all-features -- -D warningsclean; the same with--releaseclean;cargo +1.100.0 nextest run --locked --all-targets --all-features --no-fail-fast12665 passed, 0 failed, 16 skipped; the same with--release12658 passed, 0 failed, 16 skipped; the mutation runs above. A first full debug run failed the fourcli.rstests listed under Tests, which still seeded the old rule; the numbers are from the rerun after that fix. Not run on Linux or Windows; I'm leaving those to CI. Not tried against a real Claude Code session or a real switch. operator verification: unknown[env]edits pass their pre-edit maps for this; model edits have no such path, and I did not add one. (3) During the upgrade's one-time judgment, an account whoseconfig.tomldoes not read names nothing, so its value counts as the user's and stays. The cover migration strips in a similar spot. (4) A rows-only build over a torn record writes its rows without recording them, so after the repair a later rowless switch keeps them as the user's. (5) A mommy build from before this change reading a record that hasmodelsfails ondeny_unknown_fields. The record has not shipped in a release yet (v0.18.2 predates it), so I keptv: 1. (6) The demand walk now readsbase-env.jsonandprofiles.tomlonce per member build when the operator's file holds a model key that member leaves unset. I have not measured it.🤖 Generated with Claude Code