Repository navigation
fix(db): keep token_ledger when resetting usage data - #16005
Merged
diegosouzapw merged 2 commits intoOct 9, 2026
Merged
diegosouzapw merged 2 commits into
diegosouzapw merged 2 commits into
Conversation
resetUsageHistory() listed token_ledger among the tables it empties, so Settings > Storage > Reset usage data deleted the token transfer record that balances are computed from (getBalance) and that idempotency keys live in: balances changed and an already-applied transfer could be applied again. token_ledger is not usage analytics. Remove it from the reset targets; the deletedTokenLedger field stays (always 0) so the API response keeps its shape.
diegosouzapw
merged commit Oct 9, 2026
ac8723a
into
diegosouzapw:release/v3.8.52
29 of 51 checks passed
Owner
|
Thanks @pacocartones — resetting usage history no longer deletes token_ledger, so balances survive a 1d or all reset. The response still reports deletedTokenLedger as 0. This is in the upcoming release. |
6 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
resetUsageHistory()no longer deletestoken_ledger. The table is the record behind token balances and transfer idempotency keys, not usage analytics, so a usage reset must not change balances or free idempotency keys.deletedTokenLedgerstays in the result and in the purge API response (always 0), so the response shape does not change.Related Issues
Validation
tests/unit/usage-history-reset-token-ledger.test.ts: fails on the base (ledger empty after the reset), passes with the change;tests/unit/usage-history-reset.test.tsstill passesnpm run lint(whole repo) andprettier --checkon the touched files pass on the branchTests Added Or Updated
tests/unit/usage-history-reset-token-ledger.test.ts(new): seeds a grant and a transfer older than a day and runsresetUsageHistory("1d")and("all"); asserts the rows,getBalance()and the idempotency of a retried transfer.Coverage Notes
src/lib/db/cleanup.tsonly (removes one reset target, documents one field); covered by the new test.Reviewer Notes
cleanup.tsand the purge route (addsdeletedAgentSessionMessages) in other hunks; I will rebase if it lands first.