[mirror] refactor(platform): consolidate 6 LD flags into 2 JSON flags#6
Open
yashwant86 wants to merge 2 commits intomm-base-12915from
Open
[mirror] refactor(platform): consolidate 6 LD flags into 2 JSON flags#6yashwant86 wants to merge 2 commits intomm-base-12915from
yashwant86 wants to merge 2 commits intomm-base-12915from
Conversation
…prices + cost limits) Matches the pattern set by copilot-tier-multipliers (just merged in Significant-Gravitas#12910) — one JSON flag per configuration domain, keyed by tier or window name. - Remove: stripe-price-id-{basic,pro,max,business} + copilot-{daily,weekly}-cost-limit-microdollars. - Add: copilot-tier-stripe-prices (JSON: {tier: price_id}) + copilot-cost-limits (JSON: {daily,weekly}). - get_subscription_price_id now parses the JSON flag and looks up by tier value. - get_global_rate_limits reads the new flag via a sibling _fetch_cost_limits_flag helper (60s cache, cache_none=False); keeps ChatConfig fallbacks when the JSON is unset / non-dict / per-key invalid. - Tests rewritten to mock the new JSON shapes + cover partial / invalid / missing-key fallbacks.
…n_price_id cache size
- copilot-cost-limits parser now rejects bool/str/float/list values via isinstance(v, int) and not isinstance(v, bool). Matches docstring promise ("non-int values are skipped") — int() was silently coercing True/"100"/1.9 into a rate-limit cap (CodeRabbit finding).
- get_subscription_price_id cache bumped from maxsize=1 → maxsize=8 (Sentry finding). The function takes a tier argument; maxsize=1 was thrashing the cache on concurrent calls for different tiers. 8 covers the 5 tier enum values with slack.
- Added a parametrized test asserting bool/str/float/list/None all default-fallback instead of coercing.
⚡ Risk Assessment —
|
| Files | Summary |
|---|---|
Cost Limits Flag Consolidationautogpt_platform/backend/backend/copilot/rate_limit.pyautogpt_platform/backend/backend/util/feature_flag.py |
Consolidates COPILOT_DAILY_COST_LIMIT and COPILOT_WEEKLY_COST_LIMIT into single COPILOT_COST_LIMITS JSON flag. Adds _fetch_cost_limits_flag() to parse and validate JSON object with strict int checks, rejecting booleans and coercible types. Updates get_global_rate_limits() to fetch consolidated flag with fallback to config defaults. |
Stripe Prices Flag Consolidationautogpt_platform/backend/backend/data/credit.pyautogpt_platform/backend/backend/util/feature_flag.py |
Consolidates 4 tier-specific stripe price flags (STRIPE_PRICE_BASIC/PRO/MAX/BUSINESS) into single COPILOT_TIER_STRIPE_PRICES JSON flag. Refactors get_subscription_price_id() to fetch JSON object keyed by tier enum value, with validation for dict type and string values. |
Test Coverage Updatesautogpt_platform/backend/backend/copilot/rate_limit_test.pyautogpt_platform/backend/backend/data/credit_subscription_test.py |
Adds comprehensive test suite for cost-limits JSON parsing (valid/invalid keys, type validation, negative values, partial payloads). Updates stripe-prices tests to mock JSON flag shape and adds edge cases (empty dict, partial dict, non-string values, non-dict payload). |
Sequence Diagram
sequenceDiagram
participant Caller
participant get_global_rate_limits
participant _fetch_cost_limits_flag
participant LD as LaunchDarkly
participant Config
Caller->>get_global_rate_limits: user_id, config_daily, config_weekly
get_global_rate_limits->>_fetch_cost_limits_flag: fetch copilot-cost-limits
_fetch_cost_limits_flag->>LD: get_feature_flag_value(COPILOT_COST_LIMITS)
LD-->>_fetch_cost_limits_flag: {"daily": int, "weekly": int} or None
_fetch_cost_limits_flag->>_fetch_cost_limits_flag: validate dict, check int types, reject bool/negative
_fetch_cost_limits_flag-->>get_global_rate_limits: parsed dict or None
get_global_rate_limits->>get_global_rate_limits: override.get("daily", config_daily)
get_global_rate_limits->>get_global_rate_limits: override.get("weekly", config_weekly)
get_global_rate_limits-->>Caller: (daily_limit, weekly_limit, tier)
Dig Deeper With Commands
/review <file-path> <function-optional>/chat <file-path> "<question>"/roast <file-path>
Runs only when explicitly triggered.
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.
Mirror of upstream Significant-Gravitas#12915 for benchmark. Do not merge.
Summary by MergeMonkey