8000 fix(admin): count each session's own spend from pi-durable's usage ledger by geminixiang · Pull Request #162 · geminixiang/mikan · GitHub
[go: up one dir, main page]

Skip to content

fix(admin): count each session's own spend from pi-durable's usage ledger - #162

Merged
geminixiang merged 1 commit into
mainfrom
fix/admin-usage-ledger
Oct 9, 2026
Merged

geminixiang merged 1 commit into
mainfrom
fix/admin-usage-ledger

Conversation

@geminixiang
Copy link
Copy Markdown
Owner

Problem

The Admin portal summed usage over every entry a session's conversation shows. A thread started from the run that caused it is a fork, and its entries include the history it inherited, so the parent's spend was counted again in every such thread (session totals and the 14-day chart).

Change

Part Change
Session totals (/admin/api/session-usage) Read pi-durable's per-conversation usage ledger (pi.usage) through SessionStore.spend
Daily chart (/admin/api/conversation-usage) Counts only a session's own answers (SessionStore.ownResponseUsage)
Migration 0013-session-usage pi-durable writes the ledger from generation only, so sessions imported from 0.5.3 had none. The step adds each conversation's own imported answers to its ledger once, marked in mikan.session

Operators must run mikan migrate after upgrading; the daemon refuses to start while a step is pending.

Eval (.workspace/usage-eval; state written by main, then migrated and read by each checkout)

Case main this branch
U0 steps mikan migrate runs on upgrade none 0013-session-usage
U1 channel session 25,007 (own 25,007) 25,007
U2 thread started from its cause 33,344 (own 16,704) 16,704
U3 session imported from 0.5.3 1,500 1,500
U4 response time 18 ms 16 ms
U5 second mikan migrate unchanged unchanged
U6 channel daily chart total (added during implementation, same bug) 58,351 (own 41,711) 41,711

Verification

  • Admin test: a forked thread reports no spend of its own and the parent reports its imported answer after the backfill.
  • Migration tests: dry run writes nothing, a second run adds nothing, a forked thread gets nothing.
  • Full gate.
  • mikan migrate (dry run, then real) on a copy of a local test state: the step is pending, then applied; that state has no imported sessions.

…dger

The Admin portal summed usage over every entry a session's conversation shows, and a thread started from the run that caused it shows the history it forked from, so its parent's spend was counted again. Session totals now read pi-durable's per-conversation usage ledger, which also holds failed attempts and compaction, and the daily chart counts only a session's own answers.

The ledger is written by generation only, so sessions imported from 0.5.3 have none. Migration 0013-session-usage records their imported answers in the ledger once per conversation.
@geminixiang
geminixiang force-pushed the fix/admin-usage-ledger branch from 4fa3aea to b3c194a Compare October 9, 2026 14:37
@geminixiang
geminixiang merged commit c889276 into main Oct 9, 2026
2 checks passed
@geminixiang
geminixiang deleted the fix/admin-usage-ledger branch October 9, 2026 14:39
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.

1 participant

0