fix(edge): fix shared result tables in llm_limiter and incomplete reset in circuit_breaker#153
Open
levleontiev wants to merge 3 commits intomainfrom
Open
fix(edge): fix shared result tables in llm_limiter and incomplete reset in circuit_breaker#153levleontiev wants to merge 3 commits intomainfrom
levleontiev wants to merge 3 commits intomainfrom
Conversation
5f49653 to
a5ff14e
Compare
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
This PR fixes two significant bugs and adds performance optimizations in
fairvisor/edge:llm_limiter.lua: Shared Result Tables (Bug Fix)_resultand_reconcile_resultto return results fromcheckandreconcile. This caused data corruption when multiple rules/policies used the LLM limiter in the same request, or across concurrent requests in the same worker._clear_result. Updated functions to return new table literals.circuit_breaker.lua: Incomplete Auto-Reset (Bug Fix)checkfunctions auto-reset logic only deleted thestate_key, but did not clear therate_keys`. Since the sliding window calculation continued immediately after reset, it would see the old (high) rates and immediately re-trip the breaker.checkto call_M.reset()which correctly clears both state and rate keys.llm_limiter.lua: _simple_word_estimate Optimization (Perf)string.subtruncation with index-based scanning to avoid large memory allocations for large request bodies. Also replacedstring.subwithstring.bytein the backslash-scanning loop (Zero-Allocation policy).saas_client.lua: Authorization Header Caching (Perf)Bearer ...token in_stateto avoid redundant string concatenations and validation regex on every SaaS API call (heartbeats, event flushes, config polls).Testing
busted: All passed.