mpfaffenberger / mpfaffenberger/code_puppy

StatusDisplay: test-only else-branch in stop(), dead _get_status_panel(), and guessing absolute-vs-incremental token updates

Open
#411 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

StatusDisplay.stop() in code_puppy/status_display.py:288-316 has a surprising else-branch:

def stop(self) -> None:
    """Stop the status display"""
    if self.is_active:
        ...
        self._emit_final_stats()
        ...
    else:
        # Even if not active, ensure we print stats when stop is called
        # This is for testing purposes
        self._emit_final_stats()

Production code emits a spurious "Completed: 0 tokens in 0.0s (0.0 t/s avg)" line any time stop() is called on an inactive display — and the comment admits the branch exists for testing purposes. Tests should adapt to the code, never the reverse.

Two more problems in the same class:

  1. _get_status_panel() (lines 186-218) is dead code. Nothing in the codebase calls it (only _get_status_text is used by _update_display). It also contains the broken str(self.spinner) pattern — str() on a rich.spinner.Spinner yields '<rich.spinner.Spinner object at 0x...>', not the animation frame — so if anyone ever wired it up it would render garbage.

  2. update_token_count() (lines 176-182) guesses instead of being explicit. The API accepts either absolute or incremental token counts and uses a fragile heuristic to decide:

if tokens > self.token_count or tokens < 0:
    # Incremental update or reset
    self.token_count = tokens if tokens >= 0 else 0
else:
    # If tokens <= current count but > 0, treat as incremental
    self.token_count += tokens

If a caller passes an absolute count that happens to be <= the current count (e.g., after a provider resets usage mid-stream), the value silently gets added instead, inflating the rate. "In the face of ambiguity, refuse the temptation to guess."

Suggested fix

  • Delete the else branch in stop() and fix any test that relied on it.
  • Delete _get_status_panel().
  • Split the update API into two explicit methods: set_token_count(total: int) and add_tokens(delta: int).

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

Start in code_puppy/status_display.py, reading stop(), update_token_count(), _get_status_panel(), and _update_display; then inspect the callers and tests that use these entry points. Done means inactive stop() emits no stats, the dead panel method is removed, and token updates use explicit set_token_count() and add_tokens() methods without inflating totals.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.