-
-
Notifications
You must be signed in to change notification settings - Fork 88
feat(ratelimit): persist request and token windows across restart #688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
aaa46f5
docs(ratelimit): spec for persisting counters across restarts
SantiagoDePolonia d87171a
docs(ratelimit): fix persistence spec races found in review
SantiagoDePolonia 37dfb1d
docs(ratelimit): add review notes to persistence spec
SantiagoDePolonia 71031be
docs(ratelimit): persist per-child window partitions
SantiagoDePolonia 68fca87
feat(ratelimit): persist request and token windows across restart
SantiagoDePolonia c37f743
fix(ratelimit): make counter snapshots crash-safe
SantiagoDePolonia 2be7660
fix(ratelimit): serialize persist start and bound SQL prune
SantiagoDePolonia 67d543c
refactor(ratelimit): make counter snapshots additive
SantiagoDePolonia fa8f7e5
test(ratelimit): share one counter suite across backends
SantiagoDePolonia 204d2fc
fix(ratelimit): skip malformed counter rows on SQL load
SantiagoDePolonia 973488a
fix(ratelimit): refresh rules even when the snapshot row survives
SantiagoDePolonia f8372b8
docs(ratelimit): trim the persistence spec to decisions
SantiagoDePolonia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -457,6 +457,9 @@ func TestRateLimitsEnabledByDefaultAndTogglable(t *testing.T) { | |
| if !result.Config.RateLimits.Enabled { | ||
| t.Fatal("rate limits should be enabled by default") | ||
| } | ||
| if result.Config.RateLimits.FlushInterval != 1 { | ||
| t.Fatalf("FlushInterval = %d, want 1", result.Config.RateLimits.FlushInterval) | ||
| } | ||
|
Comment on lines
+460
to
+462
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Clear
Proposed fix- "RATE_LIMITS_ENABLED",
+ "RATE_LIMITS_ENABLED", "RATE_LIMITS_FLUSH_INTERVAL",🤖 Prompt for AI Agents |
||
| }) | ||
|
|
||
| withTempDir(t, func(string) { | ||
|
|
@@ -471,6 +474,29 @@ func TestRateLimitsEnabledByDefaultAndTogglable(t *testing.T) { | |
| }) | ||
| } | ||
|
|
||
| func TestRateLimitsFlushIntervalEnv(t *testing.T) { | ||
| clearAllConfigEnvVars(t) | ||
|
|
||
| withTempDir(t, func(string) { | ||
| t.Setenv("RATE_LIMITS_FLUSH_INTERVAL", "0") | ||
| result, err := Load() | ||
| if err != nil { | ||
| t.Fatalf("Load() failed: %v", err) | ||
| } | ||
| if result.Config.RateLimits.FlushInterval != 0 { | ||
| t.Fatalf("FlushInterval = %d, want 0", result.Config.RateLimits.FlushInterval) | ||
| } | ||
| }) | ||
|
|
||
| clearAllConfigEnvVars(t) | ||
| withTempDir(t, func(string) { | ||
| t.Setenv("RATE_LIMITS_FLUSH_INTERVAL", "-1") | ||
| if _, err := Load(); err == nil || !strings.Contains(err.Error(), "flush_interval") { | ||
| t.Fatalf("Load() error = %v, want flush_interval", err) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| func TestParseRateLimitEnvLimits_RejectsUnknownField(t *testing.T) { | ||
| _, err := parseRateLimitEnvLimits(`[{"period":"minute","max_requsts":100}]`, true) | ||
| if err == nil { | ||
|
|
||
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: ENTERPILOT/GoModel
Length of output: 269
🏁 Script executed:
Repository: ENTERPILOT/GoModel
Length of output: 30139
🏁 Script executed:
Repository: ENTERPILOT/GoModel
Length of output: 8635
Reject flush intervals that overflow
time.Duration.A non-negative
FlushIntervalcan overflow during conversion totime.Duration. The resulting negative duration is clamped to zero byWithFlushInterval, disabling periodic persistence. Reject values greater than9223372036seconds invalidateRateLimitConfig.🤖 Prompt for AI Agents