remove budget level calendar alignemnt - #3434
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
💤 Files with no reviewable changes (1)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughSummary by CodeRabbit
WalkthroughCalendar-aligned reset moved off persisted budgets: ChangesCalendar-aligned budget refactoring
Sequence DiagramsequenceDiagram
participant Client
participant Handler as transports/bifrost-http/handlers/governance.go
participant Store as plugins/governance/store.go
participant VirtualKey as TableVirtualKey
Client->>Handler: create/update team (payload includes calendar_aligned)
Handler->>Store: persist/modify budgets (compute LastReset from payload)
Store->>VirtualKey: lookup by VirtualKeyID during ResetExpiredBudgetsInMemory
VirtualKey-->>Store: return CalendarAligned value used for reset decision
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Comment |
Confidence Score: 2/5Not safe to merge: fresh installs will fail on startup due to the broken migration, existing deployments will accumulate schema drift, and team/provider-config budgets will silently stop honouring calendar boundaries after the change goes live. Multiple distinct defects affect core paths: the existing All four changed files need attention: Important Files Changed
Reviews (7): Last reviewed commit: "remove budget level calendar alignemnt" | Re-trigger Greptile |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
transports/bifrost-http/handlers/governance.go (1)
1687-1694: 💤 Low valueStale comment describes old behavior.
The comment references "on the false → true transition" but the code was changed to trigger whenever
b.CalendarAlignedistrue, regardless of previous state. SinceTableBudgetno longer has aCalendarAlignedfield, the transition check is no longer possible. Update the comment to accurately reflect the new behavior.📝 Suggested comment update
- // Match the UI's calendar-alignment confirmation promise: on the - // false → true transition, snap LastReset to the current period - // start and zero out CurrentUsage now, instead of lazily waiting - // for the next period boundary in ResetExpiredBudgetsInMemory. + // When calendar_aligned is true in the request, snap LastReset to + // the current calendar period start and zero out CurrentUsage now, + // instead of waiting for the next period boundary in + // ResetExpiredBudgetsInMemory. if b.CalendarAligned {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@transports/bifrost-http/handlers/governance.go` around lines 1687 - 1694, Update the stale comment to reflect that the code now unconditionally applies the calendar-aligned reset when b.CalendarAligned is true (rather than only on a false→true transition); mention that this block sets existing.LastReset via configstoreTables.GetCalendarPeriodStart(b.ResetDuration, time.Now()) and zeroes existing.CurrentUsage immediately, and remove the reference to the removed TableBudget.CalendarAligned transition and to ResetExpiredBudgetsInMemory waiting behavior so the comment matches the current logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@plugins/governance/store.go`:
- Around line 1378-1383: The lookup uses the VK ID but gs.virtualKeys is keyed
by the virtual key value, so replace the Load key to use the budget's
virtual-key value (not VirtualKeyID) when calling gs.virtualKeys.Load; after
loading cast to configstoreTables.TableVirtualKey and read CalendarAligned into
calendarAligned (same as current cast), ensuring the calendar-aligned branch can
run. Refer to gs.virtualKeys.Load, budget.VirtualKeyID (replace), the budget's
virtual-key value field, and configstoreTables.TableVirtualKey.CalendarAligned
when making the change.
---
Nitpick comments:
In `@transports/bifrost-http/handlers/governance.go`:
- Around line 1687-1694: Update the stale comment to reflect that the code now
unconditionally applies the calendar-aligned reset when b.CalendarAligned is
true (rather than only on a false→true transition); mention that this block sets
existing.LastReset via configstoreTables.GetCalendarPeriodStart(b.ResetDuration,
time.Now()) and zeroes existing.CurrentUsage immediately, and remove the
reference to the removed TableBudget.CalendarAligned transition and to
ResetExpiredBudgetsInMemory waiting behavior so the comment matches the current
logic.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 705dc2f4-db1c-4f2c-aa0e-a4a1e81af3df
⛔ Files ignored due to path filters (1)
plugins/prompts/go.sumis excluded by!**/*.sum
📒 Files selected for processing (4)
framework/configstore/tables/budget.goplugins/governance/store.goplugins/prompts/go.modtransports/bifrost-http/handlers/governance.go
💤 Files with no reviewable changes (1)
- framework/configstore/tables/budget.go
f5ee0c2 to
63802ac
Compare
47a6eb6 to
59c5f71
Compare
63802ac to
b9d05f4
Compare
b9d05f4 to
d68f3c9
Compare
d68f3c9 to
f67bf9d
Compare
23d3ccd to
256fc09
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@transports/bifrost-http/handlers/governance.go`:
- Around line 1691-1698: The current code unconditionally snaps LastReset and
zeros CurrentUsage whenever b.CalendarAligned is true, causing unintended resets
on updates; modify the logic in the update path to compute desiredStart :=
configstoreTables.GetCalendarPeriodStart(b.ResetDuration, time.Now()) and only
set existing.LastReset = desiredStart and existing.CurrentUsage = 0 if
existing.LastReset does not equal desiredStart (or if existing.LastReset is
zero/uninitialized), thereby detecting the false→true transition (or initial
create) instead of always snapping on every update; keep the same symbols
b.CalendarAligned, existing.LastReset, existing.CurrentUsage,
configstoreTables.GetCalendarPeriodStart, b.ResetDuration and time.Now() when
implementing this check.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 987818fd-d81b-4545-9c02-75ed58c0cbeb
📒 Files selected for processing (4)
framework/configstore/tables/budget.goframework/configstore/tables/team.goplugins/governance/store.gotransports/bifrost-http/handlers/governance.go
💤 Files with no reviewable changes (1)
- framework/configstore/tables/budget.go
🚧 Files skipped from review as they are similar to previous changes (1)
- framework/configstore/tables/team.go
The merge-base changed after approval.
256fc09 to
0f30480
Compare
Merge activity
|
## Summary The `CalendarAligned` field has been moved from `TableBudget` to `TableVirtualKey`. Previously, each budget row stored its own `calendar_aligned` flag, but this caused redundancy since calendar alignment is a property of the virtual key, not individual budgets. Budget reset logic now looks up the virtual key associated with a budget to determine whether calendar alignment applies. ## Changes - Removed the `CalendarAligned` field from `TableBudget` and its associated database column. - Updated `ResetExpiredBudgetsInMemory` to resolve calendar alignment by loading the virtual key linked to the budget and reading `CalendarAligned` from there. - Removed `CalendarAligned` from budget struct literals in `createTeam` and `updateTeam` handlers, since it is no longer a budget-level property. - Simplified the `updateTeam` calendar-alignment transition logic: the previous `false → true` guard is no longer needed since the flag is no longer stored on the budget itself. - Bumped `github.com/jackc/pgx/v5` from `v5.9.1` to `v5.9.2` in the prompts plugin. ## Type of change - [ ] Bug fix - [x] Refactor - [ ] Feature - [ ] Documentation - [ ] Chore/CI ## Affected areas - [x] Core (Go) - [x] Transports (HTTP) - [ ] Providers/Integrations - [x] Plugins - [ ] UI (React) - [ ] Docs ## How to test ```sh go test ./... ``` 1. Create a virtual key with `calendar_aligned: true`. 2. Attach a budget to that virtual key. 3. Trigger `ResetExpiredBudgetsInMemory` and confirm the budget resets at the correct calendar boundary. 4. Confirm budgets attached to virtual keys without `calendar_aligned` reset on a rolling interval as before. ## Breaking changes - [x] Yes - [ ] No The `calendar_aligned` column is removed from the `budgets` table. A database migration dropping this column is required. Any existing data in that column will be lost; ensure virtual keys are configured with the correct `CalendarAligned` value before migrating. ## Related issues ## Security considerations None. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [ ] I added/updated tests where appropriate - [ ] I updated documentation where needed - [ ] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable
## Summary The `CalendarAligned` field has been moved from `TableBudget` to `TableVirtualKey`. Previously, each budget row stored its own `calendar_aligned` flag, but this caused redundancy since calendar alignment is a property of the virtual key, not individual budgets. Budget reset logic now looks up the virtual key associated with a budget to determine whether calendar alignment applies. ## Changes - Removed the `CalendarAligned` field from `TableBudget` and its associated database column. - Updated `ResetExpiredBudgetsInMemory` to resolve calendar alignment by loading the virtual key linked to the budget and reading `CalendarAligned` from there. - Removed `CalendarAligned` from budget struct literals in `createTeam` and `updateTeam` handlers, since it is no longer a budget-level property. - Simplified the `updateTeam` calendar-alignment transition logic: the previous `false → true` guard is no longer needed since the flag is no longer stored on the budget itself. - Bumped `github.com/jackc/pgx/v5` from `v5.9.1` to `v5.9.2` in the prompts plugin. ## Type of change - [ ] Bug fix - [x] Refactor - [ ] Feature - [ ] Documentation - [ ] Chore/CI ## Affected areas - [x] Core (Go) - [x] Transports (HTTP) - [ ] Providers/Integrations - [x] Plugins - [ ] UI (React) - [ ] Docs ## How to test ```sh go test ./... ``` 1. Create a virtual key with `calendar_aligned: true`. 2. Attach a budget to that virtual key. 3. Trigger `ResetExpiredBudgetsInMemory` and confirm the budget resets at the correct calendar boundary. 4. Confirm budgets attached to virtual keys without `calendar_aligned` reset on a rolling interval as before. ## Breaking changes - [x] Yes - [ ] No The `calendar_aligned` column is removed from the `budgets` table. A database migration dropping this column is required. Any existing data in that column will be lost; ensure virtual keys are configured with the correct `CalendarAligned` value before migrating. ## Related issues ## Security considerations None. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [ ] I added/updated tests where appropriate - [ ] I updated documentation where needed - [ ] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable
## Summary The `CalendarAligned` field has been moved from `TableBudget` to `TableVirtualKey`. Previously, each budget row stored its own `calendar_aligned` flag, but this caused redundancy since calendar alignment is a property of the virtual key, not individual budgets. Budget reset logic now looks up the virtual key associated with a budget to determine whether calendar alignment applies. ## Changes - Removed the `CalendarAligned` field from `TableBudget` and its associated database column. - Updated `ResetExpiredBudgetsInMemory` to resolve calendar alignment by loading the virtual key linked to the budget and reading `CalendarAligned` from there. - Removed `CalendarAligned` from budget struct literals in `createTeam` and `updateTeam` handlers, since it is no longer a budget-level property. - Simplified the `updateTeam` calendar-alignment transition logic: the previous `false → true` guard is no longer needed since the flag is no longer stored on the budget itself. - Bumped `github.com/jackc/pgx/v5` from `v5.9.1` to `v5.9.2` in the prompts plugin. ## Type of change - [ ] Bug fix - [x] Refactor - [ ] Feature - [ ] Documentation - [ ] Chore/CI ## Affected areas - [x] Core (Go) - [x] Transports (HTTP) - [ ] Providers/Integrations - [x] Plugins - [ ] UI (React) - [ ] Docs ## How to test ```sh go test ./... ``` 1. Create a virtual key with `calendar_aligned: true`. 2. Attach a budget to that virtual key. 3. Trigger `ResetExpiredBudgetsInMemory` and confirm the budget resets at the correct calendar boundary. 4. Confirm budgets attached to virtual keys without `calendar_aligned` reset on a rolling interval as before. ## Breaking changes - [x] Yes - [ ] No The `calendar_aligned` column is removed from the `budgets` table. A database migration dropping this column is required. Any existing data in that column will be lost; ensure virtual keys are configured with the correct `CalendarAligned` value before migrating. ## Related issues ## Security considerations None. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [ ] I added/updated tests where appropriate - [ ] I updated documentation where needed - [ ] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable
## Summary The `CalendarAligned` field has been moved from `TableBudget` to `TableVirtualKey`. Previously, each budget row stored its own `calendar_aligned` flag, but this caused redundancy since calendar alignment is a property of the virtual key, not individual budgets. Budget reset logic now looks up the virtual key associated with a budget to determine whether calendar alignment applies. ## Changes - Removed the `CalendarAligned` field from `TableBudget` and its associated database column. - Updated `ResetExpiredBudgetsInMemory` to resolve calendar alignment by loading the virtual key linked to the budget and reading `CalendarAligned` from there. - Removed `CalendarAligned` from budget struct literals in `createTeam` and `updateTeam` handlers, since it is no longer a budget-level property. - Simplified the `updateTeam` calendar-alignment transition logic: the previous `false → true` guard is no longer needed since the flag is no longer stored on the budget itself. - Bumped `github.com/jackc/pgx/v5` from `v5.9.1` to `v5.9.2` in the prompts plugin. ## Type of change - [ ] Bug fix - [x] Refactor - [ ] Feature - [ ] Documentation - [ ] Chore/CI ## Affected areas - [x] Core (Go) - [x] Transports (HTTP) - [ ] Providers/Integrations - [x] Plugins - [ ] UI (React) - [ ] Docs ## How to test ```sh go test ./... ``` 1. Create a virtual key with `calendar_aligned: true`. 2. Attach a budget to that virtual key. 3. Trigger `ResetExpiredBudgetsInMemory` and confirm the budget resets at the correct calendar boundary. 4. Confirm budgets attached to virtual keys without `calendar_aligned` reset on a rolling interval as before. ## Breaking changes - [x] Yes - [ ] No The `calendar_aligned` column is removed from the `budgets` table. A database migration dropping this column is required. Any existing data in that column will be lost; ensure virtual keys are configured with the correct `CalendarAligned` value before migrating. ## Related issues ## Security considerations None. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [ ] I added/updated tests where appropriate - [ ] I updated documentation where needed - [ ] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable

Summary
The
CalendarAlignedfield has been moved fromTableBudgettoTableVirtualKey. Previously, each budget row stored its owncalendar_alignedflag, but this caused redundancy since calendar alignment is a property of the virtual key, not individual budgets. Budget reset logic now looks up the virtual key associated with a budget to determine whether calendar alignment applies.Changes
CalendarAlignedfield fromTableBudgetand its associated database column.ResetExpiredBudgetsInMemoryto resolve calendar alignment by loading the virtual key linked to the budget and readingCalendarAlignedfrom there.CalendarAlignedfrom budget struct literals increateTeamandupdateTeamhandlers, since it is no longer a budget-level property.updateTeamcalendar-alignment transition logic: the previousfalse → trueguard is no longer needed since the flag is no longer stored on the budget itself.github.com/jackc/pgx/v5fromv5.9.1tov5.9.2in the prompts plugin.Type of change
Affected areas
How to test
go test ./...calendar_aligned: true.ResetExpiredBudgetsInMemoryand confirm the budget resets at the correct calendar boundary.calendar_alignedreset on a rolling interval as before.Breaking changes
The
calendar_alignedcolumn is removed from thebudgetstable. A database migration dropping this column is required. Any existing data in that column will be lost; ensure virtual keys are configured with the correctCalendarAlignedvalue before migrating.Related issues
Security considerations
None.
Checklist
docs/contributing/README.mdand followed the guidelines