Skip to content

fix(update): persist LLM costs to llm_costs table during incremental updates - #108

Merged
RaghavChamadiya merged 1 commit into
repowise-dev:mainfrom
j-j-m:fix/update-cost-tracker
Apr 30, 2026
Merged

RaghavChamadiya merged 1 commit into
repowise-dev:mainfrom
j-j-m:fix/update-cost-tracker

Conversation

@j-j-m

@j-j-m j-j-m commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Summary

repowise update resolves an LLM provider via resolve_provider(...) but never attaches a CostTracker to it. Because CostTracker._persist() is gated on session_factory is not None and repo_id is not None, every LLM call made during an update silently bypasses persistence — no error, no warning. As a result, the llm_costs table (and therefore repowise costs) only ever reflects the initial repowise init run.

For long-lived projects driven by CI-style updates, this is invisible until you go looking: the wiki keeps growing, but repowise costs reports $0.00 indefinitely.

Repro

  1. repowise init a project — costs land in llm_costs
  2. Make a commit, run repowise update — wiki pages regenerate, but llm_costs gets no new rows ❌
  3. repowise costs — only the init run shows up

You can confirm this in 0.3.1 / 0.4.0 with:

sqlite3 .repowise/wiki.db "SELECT COUNT(*), MIN(ts), MAX(ts) FROM llm_costs;"
# rows only from your init timestamp; updates contribute nothing

Fix

Mirror the wiring init_cmd.py already does (provider._cost_tracker = cost_tracker at lines 385 and 1289) inside update_cmd.py, right after resolve_provider(...). Falls back to an in-memory CostTracker() if DB initialization fails, preserving the prior no-crash behavior.

The block is intentionally identical in shape to init's _make_cost_tracker() so the two stay in sync.

Diff size

+30 / -0, all in one function. No tests added — there is no existing CostTracker-attachment test covering init's wiring either, and the change is structurally identical to that already-working code path. Happy to add one if you'd like.

Verification

  • make test-fast — green (15/15 in tests/unit/cli/test_commands.py)
  • ruff check — no new lint errors introduced (10 pre-existing → 10 post-change)
  • ruff format --check — added block is format-clean

`repowise update` resolves an LLM provider but never attaches a
CostTracker, so every call made during decision rescan and page
regeneration silently bypasses persistence. As a result, the
`llm_costs` table — and therefore `repowise costs` — only ever
reflects the initial `repowise init` run; long-lived projects driven
by CI updates report $0 forever.

Mirror the wiring that `init` already does: build a DB-backed
CostTracker after `resolve_provider(...)` and attach it to
`provider._cost_tracker` so subsequent calls land rows in
`llm_costs`. Falls back to an in-memory tracker on DB-init failure
to preserve the prior no-crash behavior.

@RaghavChamadiya RaghavChamadiya left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

2 participants