Skip to content

File a deleted user's usage under a label of its own - #44

Merged
bricke merged 1 commit into
mainfrom
fix/usage-by-account
Oct 9, 2026
Merged

bricke merged 1 commit into
mainfrom
fix/usage-by-account

Conversation

@bricke

@bricke bricke commented Oct 9, 2026

Copy link
Copy Markdown
Owner

Fixes #27.

Usage is recorded under the user's name, which outlives the account. If an admin deleted bob and later created another bob, the new account's usage page showed the first bob's requests, tokens and monthly totals. The admin's per-user views also merged the two people.

Delete now relabels. Deleting a user moves their per-request rows and monthly totals to bob (deleted 2026-10-09 14:03:12).

  • The admin can still read the history; a later bob starts with none of it.
  • Ledger.RelabelUser runs on the ledger's own queue, behind writes already queued, so the user's last requests move too. It waits for room in the queue rather than being dropped.
  • Labels can't collide with usernames, which never hold spaces or brackets.
  • The delete dialog says where the history goes.

Playground label. Playground calls were recorded as yardmaster-playground, a valid username, so a user given that name would see them as their own. They are now recorded as (playground). Rows already recorded under the old name stay under it.

Why not filter by user ID? users.id has no AUTOINCREMENT, so SQLite hands the ID of a deleted newest user to the next one. usage_monthly is keyed by name only. Both would have needed table rebuilds to fix, and the per-user views would still have merged people.

Not covered: names that were already reused before this change. Their merged history can't be split.

Tests:

  • TestRelabelUserMovesAllTheirUsage (ledger, including pruned monthly totals).
  • TestDeletedUsersUsageIsntInherited (through the API). It fails without the change.

Usage is recorded under the user's name, which outlives the account.
When an admin deleted bob and later created another bob, the new
account's usage page showed the first bob's requests, tokens and
monthly totals, and the admin's per-user views merged the two people.

Deleting a user now moves their per-request rows and monthly totals to
"bob (deleted 2026-10-09 14:03:12)". The history stays readable for the
admin, and a later bob starts with none of it. The move runs behind the
ledger writes already queued, so their last requests move too. Labels
can't collide with usernames, which never hold spaces or brackets.

Playground calls were recorded as yardmaster-playground, a valid
username, so a user given that name would have seen them as their own.
They are now recorded as (playground).

Fixes #27
@bricke
bricke merged commit 87977dc into main Oct 9, 2026
3 checks passed
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.

Usage is matched by user name, so a reused name sees the old account's history

1 participant