Repository navigation
Conversation
The model edit flow rebuilt each entry from base_url, api_type, api_key and thinking_level, so editing one value silently deleted api_keys, temperature, max_tokens and any other field the screen does not render. Keep every field the screen does not edit, print the names of the preserved fields, warn when api_keys (which win over api_key) is present, and do not invent an empty api_key for an api_keys-only entry. save_models now writes models.yaml through a temporary file in the same directory and os.replace()s it, so an interrupted save cannot truncate the file.
This branch has not been deployed
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.
What does this PR do?
Fixes the TUI model edit screen discarding settings it never shows, and makes
save_modelsreplacemodels.yamlatomically._edit_modelrebuilt every entry from the four fields the screen renders, so editing a single value deleted everything else the model schema permits:An entry configured by hand with
api_keys(round-robin),temperatureormax_tokenslost all of them by changing the base URL in the TUI, with no warning — e.g.load_model_configprefersapi_keysoverapi_key, so the round-robin setup silently collapsed to whatever was typed in the API key prompt.Changes in
src/clawbench/tui.py:_edit_modelcopies every field it does not edit into the saved entry, so untouched settings survive. The screen prints the names of the fields it is preserving, and states explicitly thatapi_keystakes precedence overapi_keyso an edited key does not look effective when it is not.api_keysno longer gets an emptyapi_keyinvented for it when the prompt is left blank ("" or "api_key" in cfgguard).save_modelswrites the YAML to a temporary file in the same directory,fsyncs it, andos.replaces it overmodels.yaml, so an interrupted save cannot truncate the file. This reuses the pattern already used by_write_verdictinclawbench/eval/rescore.py.Corpus
Test plan
Host-side tests only; no container, model key or network needed.
New tests in
tests/test_tui_helpers.py:test_tui_edit_model_keeps_fields_the_screen_does_not_show— an entry withapi_keys,temperatureandmax_tokensis edited (base URL only, every other prompt keeps its current value) and all three are still in the file afterwards, plus the preserved-field notice.test_tui_edit_model_keeps_api_keys_only_entry_keyless— anapi_keys-only entry staysapi_keys-only and gains no emptyapi_key.test_tui_save_models_replaces_the_file_atomically— a singleos.replacefrom the same directory, the temporary file is gone, no stray files remain, and the content is the new mapping.A/B check: with only the
preserved = {...}collector reverted topreserved = {}(tests unchanged), the first two tests fail withKeyError: 'api_keys'; restoring it turns them green again. Revertingsave_modelstowrite_textmakes the third test fail withassert 0 == 1on the recordedos.replacecalls.Related issues
Fixes #453