Skip to content

Stop calling the cloud while it rate limits - #6

Merged
wojciech-aniol merged 3 commits into
mainfrom
rate-limit-block
Oct 25, 2026
Merged

wojciech-aniol merged 3 commits into
mainfrom
rate-limit-block

Conversation

@wojciech-aniol

@wojciech-aniol wojciech-aniol commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

After an HTTP 429 the cloud blocks the account for some seconds, but other users of the same AristonAPI (the integration's coordinators and actions) kept sending requests inside the block. The block is now kept per account (API URL and login), so every API object of that account raises ConnectionException(429, "blocked locally for N s") without a request until it ends. Also, only 5xx and 408 are retried once; other 4xx are raised at once instead of being sent twice.

Changes

  • Module dict _blocked_until (time.monotonic), keyed by API URL and login: a new AristonAPI of the same account (setup retry, reload, config or reauth flow) sees the block, other accounts do not. A 429 sets it from the body ("blocked for N seconds", any case), else 60 s and a warning with the body. A later, shorter 429 does not end the block early.
  • Both request paths check it first. args[0] stays 429, so the integration's classify_error still sees a rate limit. A login inside the block raises ConnectionException() from that error, as before.
  • Retry once after 5 s only for 5xx and 408 (request timeout: a retry can work). 405 re-login, 404 → None and 429 without retry stay. Other 4xx (400, 401, 403…) raise ConnectionException(status) at once.
  • Async path decodes the 429 body to str, like the sync path.
  • Not taken from fustom/python-ariston-api#187: sleeping the block time inside the request, a block shared by all accounts, its R2 login and enum changes.

Tests

  • New tests/test_ariston_api.py with a fake cloud and clock (no network), sync and async: body parsing, 60 s default and its warning, no request inside the block, request after it, block per account, two 429s at once, login inside the block, 4xx not retried, 5xx and 408 retried once.
  • On main 21 of the 29 new tests fail. The 8 retry cases (5xx, 408) pass there on purpose: they guard the retry that stays.
  • 60 tests and ruff pass.
  • The integration (ariston-net at 634efac) passes all 597 tests with this library on PYTHONPATH, tests/test_requests.py counts included, so its bump PR should pass without changes.

Not checked

The 429 body text comes only from fustom/python-ariston-api#187; nobody here saw a real one. If it does not match, the block is 60 s.

🤖 Generated with Claude Code

On HTTP 429 the cloud blocks the account for some seconds ("Requests
are blocked for 66 seconds"). The integration shares one AristonAPI
between its coordinators and actions, and the others kept sending
requests inside the block. Each API object now remembers the block
(from the answer, else 60 s) and raises ConnectionException(429, ...)
without a request until it ends. args[0] stays 429, so callers still
see a rate limit. The async path now gives the 429 body as str too.

Only 5xx answers are retried once after 5 s. A 4xx (wrong value,
refused login) gets the same answer again, so a retry only doubled
the requests and the wait.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wojciech-aniol wojciech-aniol self-assigned this Oct 25, 2026
@wojciech-aniol
wojciech-aniol marked this pull request as ready for review October 25, 2026 08:58
wojciech-aniol and others added 2 commits October 25, 2026 10:44
Review fixes. Two requests at once can both get a 429; the second
one, with a shorter or unknown time, no longer ends the block early.
A 429 answer without "blocked for N seconds" is logged as a warning,
since nobody has seen the real text yet. The regex and the default
are private, so they do not become public names. New tests cover a
login inside the block and a 5xx retry that works.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review fixes. The integration builds a new AristonAPI on each setup
retry, reload and config or reauth flow, so a block kept in one object
was lost exactly when requests come in bursts. The block now lives in
the module, per API URL and login: new objects of the same account see
it, other accounts do not.

A 408 means "send it again", like a 5xx. Without the retry a short 408
on a new login made the integration ask for the password again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wojciech-aniol
wojciech-aniol merged commit f0ceb6a into main Oct 25, 2026
5 checks passed
@wojciech-aniol
wojciech-aniol deleted the rate-limit-block branch October 25, 2026 10:11
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.

1 participant