Add manual Claude Code weekly reset contributions - #41
Merged
Merged
Conversation
A Claude Code account can store one manual UTC weekly reset. Completed weeks are emitted as the existing quota cycle contributions when this device has attributed usage in the week or on a boundary UTC day. Weeks with no such usage are omitted, and the cycle that contains now is never emitted. Anchors that differ by a whole number of weeks are the same schedule. Merging accounts transfers a schedule, keeps one copy when the phases match, and refuses the merge when they do not. Removing an account treats a stored schedule as a reference. Usage for these contributions is read only for the Claude Code account and only on the boundary days. EXPLAIN QUERY PLAN showed the existing provider/source index cannot bound that lookup, so this adds an index on provider, account, and start time. Co-authored-by: Dmitry Starkov <21260939+starkdmi@users.noreply.github.com>
Manual cycles now follow the same source, limit, and time filters as reconstructed cycles. A query for another source, a provider limit, or a date range that misses the week no longer returns that week's contribution. Co-authored-by: Dmitry Starkov <21260939+starkdmi@users.noreply.github.com>
An OR of many UTC day ranges made bundled SQLite use only the provider and account prefix, so each sync scanned the account's full history. Each day is now its own indexed range, combined with UNION ALL. Co-authored-by: Dmitry Starkov <21260939+starkdmi@users.noreply.github.com>
Anchor moves now share the merge transaction. An overlapping subscription rejects the merge and leaves both accounts' schedules where they were. Summary rewrites and sync-tracking clears join that transaction instead of starting a second one. Co-authored-by: Dmitry Starkov <21260939+starkdmi@users.noreply.github.com>
starkdmi
marked this pull request as ready for review
September 29, 2026 15:18
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
A Claude Code account can store one manual weekly reset anchor. Completed weeks are emitted as the existing
quota_cycle_contribution.v1records when this device has attributed usage in the week or on a boundary UTC day. The cycle that contains now is never emitted, and weeks with no such usage are omitted so the backend can fill them.Anchors that differ by a whole number of weeks are the same schedule.
account mergetransfers a schedule, keeps one copy when the phases match, and refuses the merge when they differ. Those writes share the rest of the merge in one transaction. If a later check fails, such as overlapping subscriptions, both accounts keep the schedules they had.account removetreats a stored schedule as a reference.Automatic capture from the status line is future work. This change only stores a manual anchor.
The boundary-day lookup needed an index on provider, account, and start time.
EXPLAIN QUERY PLANshowed the existing provider/source index cannot bound that read.Manual weekly contributions honor the same quota query filters as reconstructed cycles. A provider other than Claude Code returns none. An account filter limits the anchors. A source filter reads only that source. Any limit filter returns none, because these cycles have no limit id. A cycle is kept only when its half-open week overlaps
fromandto.Boundary-day events are read as one indexed range per UTC day and combined with
UNION ALL. Each range keeps the start-time bound on the provider, account, and start index. AnORof those same ranges does not: bundled SQLite then scans the account's whole history.Testing
cargo fmt -p statsai-store -p statsaicargo clippy -p statsai-store --all-targets -- -D warningscargo clippy -p statsai --all-targets -- -D warnings./scripts/rust-ci.sh fullcargo fmt -p statsai-store -p statsai,cargo clippy -p statsai-store -p statsai --all-targets -- -D warnings,cargo test -p statsai-store --lib quota::tests::weekly, andcargo test -p statsai --bin statsai merge_