Skip to content

/spend by topic leaves out the money the knowledge compiler spent, so it does not add up to the page's own total #2679

Closed

Description

@AbirAbbas

Severity: P1 (the spend page contradicts itself) · Regression: yes (v0.8.2 made no knowledge calls)

What happened

Found in the 2026-11-16 hand-QA of dev@9eb0b516b (dev-20261114-9eb0b516b6f2, linux amd64) with a real OpenRouter key.
On a fresh home, one short turn is enough: the background knowledge compiler runs about 30 seconds after the turn and
bills one or two calls, and /spend then draws that money everywhere except under by topic. The top line, 14 days
and by model carry it; by topic does not, so its rows add up to less than the same page's header. New on dev:
v0.8.2 made no knowledge calls, so its by topic was whole.

 today $0.0030 of $500 · /budget sets the limits
 14 days came to $0.0030 · 19.5k tokens · loudest day: $0.0030 nov 16 (initial message asking five word hello)
 by topic
 · initial message asking five word hello                                      chat  ws1  $0.01
 ← by model →
 · deepseek-v4-flash                                                  conversation  2 calls  14.1k  $0.01
 · deepseek-v4-flash-0731                                                           1 call    2.7k  $0.01
 · deepseek-v4.1-flash                                                              2 calls   1.7k  $0.01
 · gemini-2.5-flash                                                                 1 call      1k  $0.01

The two deepseek-v4.1-flash calls are the knowledge compiler's ($0.0005304, 17.8% of the page's total after one turn;
in a longer session 55% of it: $0.06 of $0.11). Their rows in usage.jsonl have "role":"knowledge" and no session,
task or automation id, so the topic join has nothing to hang them on.

models-and-cost.md, "The spend place": "by model and by topic are the same money added up two ways — every dollar
under one heading is also a dollar under the other — so a page drawing both asked you to read one bill twice."; "by
topic — the three things money is ever spent on, because the ledger holds three ids: a piece of work, an automation, or
a conversation". The knowledge calls are documented as paid and visible: "Knowledge calls appear in Spend under the
model that served them" (models-and-cost.md), "Compilation is paid model work recorded in Spend" (settings.md). Under
a topic they do not appear at all. Reproduced 3 of 3 fresh homes. The money is not hidden from the daily limit, the header or
by model, so the severity is the page disagreeing with itself, not a missed charge.

Replication

Deterministic (no model). None: the repo's scripted endpoint prices every call at zero and has no knowledge pass
that bills.

Field (real models). A cheap OpenRouter model and an empty CODEAF_HOME:

  1. In an empty folder run codeaf, /model deepseek/deepseek-v4-flash, send say hello in five words.
  2. Wait 35 seconds, then /spend. Compare today and ← by model → (right arrow) with by topic.
  3. grep '"role":"knowledge"' "$CODEAF_HOME/v3/usage.jsonl" shows rows without session.

Where

The Spend place's by topic cut (internal/tui3/place_spend.go, spendplace.go) joins ledger ids to titles, and a row
with none of the three ids has nowhere to go. The knowledge compiler (internal/knowledge) writes its ledger row
with role: knowledge and no topic id.

The fix

A knowledge call lands under a topic of its own (the manual says the topic is one of three ids, so a fourth row such as
learning from your conversations needs the manual's list to change with it), or it is attributed to the conversation it
learned from by carrying that conversation's session id. Either way by topic sums to the header.

Acceptance

  • e2e: a scripted endpoint that bills non-zero usage and a knowledge pass: /spend shows rows under by topic that
    sum to the 14 days figure (to the cent).
  • Unit: a ledger with one role:"knowledge" row and no ids still appears in the topic rollup.

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions