Skip to content

fix(tui): keep model settings the edit screen does not show - #488

Open
Goldloli wants to merge 1 commit into
TIGER-AI-Lab:mainfrom
Goldloli:fix/tui-preserve-model-settings
Open

Goldloli wants to merge 1 commit into
TIGER-AI-Lab:mainfrom
Goldloli:fix/tui-preserve-model-settings

Conversation

@Goldloli

Copy link
Copy Markdown

What does this PR do?

Fixes the TUI model edit screen discarding settings it never shows, and makes save_models replace models.yaml atomically.

_edit_model rebuilt every entry from the four fields the screen renders, so editing a single value deleted everything else the model schema permits:

data[name] = {
    "api_key": api_key.strip(),
    "base_url": base_url.strip(),
    "api_type": api_type,
    "thinking_level": thinking_level,
}

An entry configured by hand with api_keys (round-robin), temperature or max_tokens lost all of them by changing the base URL in the TUI, with no warning — e.g. load_model_config prefers api_keys over api_key, so the round-robin setup silently collapsed to whatever was typed in the API key prompt.

Changes in src/clawbench/tui.py:

  • _edit_model copies 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 that api_keys takes precedence over api_key so an edited key does not look effective when it is not.
  • An entry that authenticates through api_keys no longer gets an empty api_key invented for it when the prompt is left blank ("" or "api_key" in cfg guard).
  • save_models writes the YAML to a temporary file in the same directory, fsyncs it, and os.replaces it over models.yaml, so an interrupted save cannot truncate the file. This reuses the pattern already used by _write_verdict in clawbench/eval/rescore.py.

Corpus

  • v2
  • v1
  • both
  • not applicable

Test plan

Host-side tests only; no container, model key or network needed.

$ uv run pytest            # 333 passed, 3 skipped  (was 330 passed, 3 skipped)
$ uv run ruff check .      # All checks passed!
$ uv run ruff format --check .   # 101 files already formatted
$ uv run pyright src/clawbench tests   # 0 errors, 0 warnings

New tests in tests/test_tui_helpers.py:

  • test_tui_edit_model_keeps_fields_the_screen_does_not_show — an entry with api_keys, temperature and max_tokens is 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 — an api_keys-only entry stays api_keys-only and gains no empty api_key.
  • test_tui_save_models_replaces_the_file_atomically — a single os.replace from 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 to preserved = {} (tests unchanged), the first two tests fail with KeyError: 'api_keys'; restoring it turns them green again. Reverting save_models to write_text makes the third test fail with assert 0 == 1 on the recorded os.replace calls.

Related issues

Fixes #453

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

No deployments
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.

Editing a model in the TUI silently deletes its other settings

1 participant