Skip to content

[mirror] refactor(platform): consolidate 6 LD flags into 2 JSON flags#6

Open
yashwant86 wants to merge 2 commits intomm-base-12915from
mm-pr-12915
Open

[mirror] refactor(platform): consolidate 6 LD flags into 2 JSON flags#6
yashwant86 wants to merge 2 commits intomm-base-12915from
mm-pr-12915

Conversation

@yashwant86
Copy link
Copy Markdown

@yashwant86 yashwant86 commented Apr 26, 2026

Mirror of upstream Significant-Gravitas#12915 for benchmark. Do not merge.


Summary by MergeMonkey

  • Reference Updates:
    • Updated docstrings for cost-limits and stripe-prices functions to reflect JSON flag consolidation.
  • Feature Drops:
    • Consolidated 6 LaunchDarkly flags into 2 JSON-based flags for cost limits and tier stripe prices.
  • Tidying Up:
    • Refactored flag parsing logic to use single JSON objects instead of individual scalar flags.

majdyz added 2 commits April 24, 2026 23:14
…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.
@bot-mergemonkey
Copy link
Copy Markdown

bot-mergemonkey Bot commented Apr 26, 2026

Risk AssessmentNEEDS-TESTING · ~25 min review

Focus areas: JSON flag parsing and type validation logic · Fallback behavior for invalid/missing LD values · Test coverage for edge cases (empty dict, partial dict, type coercion)

Assessment: Consolidates 6 LaunchDarkly flags into 2 JSON flags; changes cost-limit and stripe-price lookup logic.

Changes

Files Summary
Cost Limits Flag Consolidation
autogpt_platform/backend/backend/copilot/rate_limit.py
autogpt_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 Consolidation
autogpt_platform/backend/backend/data/credit.py
autogpt_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 Updates
autogpt_platform/backend/backend/copilot/rate_limit_test.py
autogpt_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)
Loading

Dig Deeper With Commands

  • /review <file-path> <function-optional>
  • /chat <file-path> "<question>"
  • /roast <file-path>

Runs only when explicitly triggered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants