mpfaffenberger / mpfaffenberger/code_puppy

ModelNameCompleter crashes with AttributeError when no model is configured (get_active_model() returns None)

Open Beginner friendly
#419 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
814
Forks
278
Avg merge
2d 5h
Merged PRs (30d)
76

Description

Problem

ModelNameCompleter.get_completions() in code_puppy/command_line/model_picker_completion.py:73-118 crashes the prompt completion when no model is configured:

active_model_name = get_active_model()           # line 104 — can return None
if model_name.lower() == active_model_name.lower():   # AttributeError on None

get_active_model() delegates to get_global_model_name() (config.py:604), whose docstring explicitly states it returns None if unset (fresh install before /add_model, or an invalid configured model with an empty merged config). The first time the user types /model to fix that situation, the completer raises AttributeError: 'NoneType' object has no attribute 'lower' inside prompt_toolkit's completion thread.

Two adjacent smells in the same method:

  • active_model_name = get_active_model() is re-evaluated inside the per-model loop (once per model in the catalog) even though it cannot change during one completion pass — hoist it above the for.
  • self.model_names = load_model_names() is captured once in __init__ (line 70), so models added via /add_model mid-session never appear in completions until restart, while the description lookup is live via _load_models_config() — inconsistent freshness.

Suggested fix

active_model_name = (get_active_model() or "").lower()
for model_name in load_model_names():   # or refresh self.model_names per call
    ...
    if model_name.lower() == active_model_name:

Filed by Zen Reviewer C (code-puppy-60635a)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read ModelNameCompleter.get_completions() in code_puppy/command_line/model_picker_completion.py:73-118 and the None behavior documented around get_global_model_name() in config.py:604. Verify /model completion with no configured model and after /add_model; done means completion no longer crashes and newly added models appear without restarting.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.