fix(SUB-003): subscription rate-limit — persist reset time, skip retries on 429, default max_retries=0 (#476)#477
Open
vybe wants to merge 3 commits into
Open
fix(SUB-003): subscription rate-limit — persist reset time, skip retries on 429, default max_retries=0 (#476)#477vybe wants to merge 3 commits into
vybe wants to merge 3 commits into
Conversation
…t max_retries=0 Three related fixes for subscription rate-limit handling: 1. Persist authoritative reset timestamp — parse "resets 8pm (America/New_York)" from 429 body and store in new subscription_credentials.rate_limited_until column. is_subscription_rate_limited() checks this first before falling back to the 2h event-count heuristic, preventing ping-pong when Anthropic's window is 5-8h. 2. Never retry rate-limited executions — _maybe_schedule_retry() now returns early on 429/rate-limit errors. The next scheduled cron tick is the correct recovery path; queuing retries during a subscription outage just floods the backlog. 3. Change default max_retries from 1 to 0 — retries are now opt-in per schedule. Scheduled agents are typically stateful and idempotent; skipping a run is preferable to thundering-herd replay when many tasks fail simultaneously. Closes #476 Co-Authored-By: Claude <noreply@anthropic.com>
… retry opt-in Co-Authored-By: Claude <noreply@anthropic.com>
…, SUB-003) Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
Author
|
Hey @vybe — this PR is targeting |
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
rate_limited_until— parse"resets 8pm (America/New_York)"from the 429 body and store in a newsubscription_credentials.rate_limited_untilcolumn.is_subscription_rate_limited()checks this authoritative timestamp before falling back to the 2h event-count heuristic, preventing the slow ping-pong where Trinity considers an exhausted subscription viable again every 2 hours while Anthropic's actual window is 5–8h._maybe_schedule_retry()now returns early on 429/rate-limit errors. The next cron tick is the correct recovery path; queuing retries during a subscription outage just floods the backlog with guaranteed-to-fail work.max_retriesfrom 1 → 0 — retries are now opt-in per schedule. Scheduled agents are typically stateful and idempotent; skipping a run is preferable to thundering-herd replay when many tasks fail simultaneously.Changes
db/migrations.py— add_migrate_subscription_rate_limited_until(ALTER TABLE adds column, idempotent)db/subscriptions.py—set_subscription_rate_limited_until()setter + updatedis_subscription_rate_limited()checks durable timestamp firstdatabase.py— expose new setter on facadeservices/subscription_auto_switch.py—_parse_rate_limit_reset()parser + wired intohandle_rate_limit_error()db_models.py+scheduler/models.py+db/schedules.py—max_retriesdefault 1 → 0scheduler/service.py— early return in_maybe_schedule_retry()for rate-limit errorsTest Plan
is_subscription_rate_limited()returns True whenrate_limited_untilis in the futureis_subscription_rate_limited()clears expiredrate_limited_untiland falls back to event count_parse_rate_limit_reset("resets 8pm (America/New_York)")returns a future UTC ISO string_maybe_schedule_retry()returns without scheduling when error contains "429"max_retries=0Closes #476
🤖 Generated with Claude Code