Skip to content

fix(console): preserve usage reset boundaries - #44729

Merged
MrMushrooooom merged 2 commits into
v2from
go-monthly-reset
Sep 4, 2026
Merged

fix(console): preserve usage reset boundaries#44729
MrMushrooooom merged 2 commits into
v2from
go-monthly-reset

Conversation

@opencode-agent

Copy link
Copy Markdown
Contributor

Summary

  • capture one usage timestamp before updating fixed-window counters
  • use that timestamp for both period bounds and persisted counter timestamps
  • ignore delayed writes from older periods and prevent timestamps from moving backward

Why

A usage write can wait on the database across a weekly or monthly reset boundary. Previously, the period was selected using application time while time_*_updated was persisted with database now(). A write that selected the old period but executed after the boundary could therefore retain old usage and stamp it as current-period usage, preventing the next request from resetting the counter.

The update now treats each fixed-window write as an event at one timestamp. It adds within that event's period, resets when advancing to a new period, and ignores delayed events when a newer period is already stored.

Checks

  • bun typecheck (packages/console/app)
  • bun typecheck (packages/console/core)
  • bun test test/subscription.test.ts (packages/console/core)
  • bun x prettier --check packages/console/app/src/routes/zen/util/handler.ts
  • git diff --check

The full Console app test suite has two pre-existing failures in providerUsage.test.ts: Google normalized output tokens are currently 5, while the tests expect 3. The remaining five app tests pass.

Requested by: @MrMushrooooom (Jack via Slack)

@heimoshuiyu

Copy link
Copy Markdown
Contributor

LGTM

@MrMushrooooom
MrMushrooooom merged commit 8352add into v2 Sep 4, 2026
8 checks passed
@MrMushrooooom
MrMushrooooom deleted the go-monthly-reset branch September 4, 2026 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants