fix(addie): reset daily cost cap at UTC midnight instead of rolling 24h - #6211
Open
coolmacool wants to merge 1 commit into
Open
fix(addie): reset daily cost cap at UTC midnight instead of rolling 24h#6211coolmacool wants to merge 1 commit into
coolmacool wants to merge 1 commit into
Conversation
The daily conversation cost cap used a rolling 24h window, but the user-facing "try again tomorrow" message implies a calendar reset that never happened — a user capped at 6pm was still blocked at 8am the next day. Switch to a UTC-midnight boundary computed inside Postgres so the cutoff and recorded charges share one clock, avoiding app/DB clock skew at the boundary. Also log when an unmapped-WorkOS-identity Slack user hits the tighter member_free cap, so that known tier-misattribution risk is diagnosable from logs. Fixes adcontextprotocol#6048
IPR Policy Agreement Required@coolmacool — thanks for the contribution. Before this PR can be merged, the AgenticAdvertising.Org IPR Policy requires your agreement. To agree, post a new comment on this PR with the exact phrase: Your signature is recorded once and covers all contributions to AAO repositories. See |
Author
|
I have read the IPR Policy |
IPR Policy — signedThanks, @coolmacool. Your agreement to the IPR Policy is recorded at |
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
recorded_at > NOW() - interval), but the user-facing message says "try again tomorrow" — implying a calendar reset that never happened. A user capped at 6pm was still blocked at 8am the next day (only 14 of the required 24h elapsed). Fixes Bug: Daily Addie conversation limit not resetting after 24 hours #6048.date_trunc('day', NOW() AT TIME ZONE 'UTC')) so the cutoff and therecorded_attimestamps it's compared against share one clock — an app-clock cutoff compared against DB-clock timestamps would reintroduce the same class of boundary bug this issue was about.retryAfterMsnow counts down to the next UTC midnight instead of a per-charge "24h anniversary."slack:<id>scope key) hits themember_freetier cap, so it's diagnosable from logs that they may be getting a tighter cap ($5/day) than their real subscription tier warrants, instead of requiring a support escalation to notice.Test plan
npx tsc --project server/tsconfig.json --noEmit— cleannpx vitest run server/tests/unit/claude-cost-tracker.test.ts server/tests/unit/claude-cost-tier-resolution.test.ts server/tests/unit/claude-client-cost-gate.test.ts— 50/50 pass. Rewrote the cost-tracker test suite's rolling-window block into a calendar-day-semantics block (mid-window unblock at midnight, exact 23:59:59.999/00:00:00 boundary,retryAfterMscorrectness, no cross-day bleed).npm run db:migrate), exercisingPostgresStoredirectly rather than the in-memory DI store the unit tests use: backdated-yesterday charge excluded, today's charge blocks withretryAfterMsaccurate to the millisecond, exact-midnight inclusive boundary, and the new Slack-unmapped warn log fires as designed.code-reviewerandsecurity-revieweragents run; findings addressed (app/DB clock-skew fix, midnight-burst tradeoff documented).node scripts/check-changeset-protocol-scope.cjs origin/main— passed, no changeset needed (server-only Addie change).Risks / follow-ups
member_free) is now observable via logs but not fixed — that's a separate, larger identity-resolution feature, out of scope here.