Skip to content

Fix rate limit callback waits and support the predicate cache on trio - #160

Merged
RazerM merged 10 commits into
mainfrom
feature/ratelimit-callback-wait
Aug 23, 2026
Merged

RazerM merged 10 commits into
mainfrom
feature/ratelimit-callback-wait

Conversation

@RazerM

@RazerM RazerM commented Aug 22, 2026

Copy link
Copy Markdown
Member

Rate limit waits now wait for the callback to finish in all clients, and an exception raised by the callback propagates instead of being silently discarded, including in the sync client. The async client accepts a plain function as the callback, as the documentation shows.

The predicate cache now works on trio, with cache file I/O running in a worker thread, and the cache file lock is released correctly when a request is cancelled.

The event classes are modernised to attrs.define, and the file lock events are named explicitly.

@codecov

codecov Bot commented Aug 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.25%. Comparing base (3da8e84) to head (8f59dd7).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #160      +/-   ##
==========================================
+ Coverage   95.89%   96.25%   +0.35%     
==========================================
  Files           7        7              
  Lines        1097     1122      +25     
  Branches      126      123       -3     
==========================================
+ Hits         1052     1080      +28     
+ Misses         26       25       -1     
+ Partials       19       17       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@RazerM RazerM changed the title feature/ratelimit callback wait Fix rate limit callback waits and support the predicate cache on trio Aug 22, 2026
RazerM added 6 commits August 22, 2026 23:27
Add a RunBlocking event so the generator can defer blocking calls to the
caller. The sync client invokes them directly; the async client runs them
via anyio.to_thread, keeping cache reads, writes, and mkdir off the event
loop.
Replace @attr.s(slots=True) with @attrs.define and typed attributes.
The only locks these events carry are filelock.FileLock instances for
the predicate cache, and the async handler's acquire loop is specific
to filelock's non-blocking behaviour (raising Timeout). Name them
accordingly so future lock types get their own events instead of
overloading these.
@RazerM
RazerM force-pushed the feature/ratelimit-callback-wait branch 3 times, most recently from 2abf460 to 62e0668 Compare August 23, 2026 12:50
RazerM added 4 commits August 23, 2026 14:51
The async ReleaseFileLock handler's unshielded to_thread.run_sync
raised Cancelled at its entry checkpoint before lock.release() ran, so
a cancel scope firing while the predicate cache FileLock was held
leaked the lock until garbage collection, deadlocking other tasks and
processes. Shield the release, and shield each non-blocking acquire
attempt so a cancellation cannot discard a successful acquire either.
The documentation shows a plain function callback for both clients, but
AsyncSpaceTrackClient unconditionally awaited the callback's return
value, so a non-coroutine callback raised TypeError inside the rate
limit task group and aborted the in-flight request. Only await the
result when it is awaitable.
A callback exception was raised in the daemon thread and silently
discarded by the default threading excepthook, so the request proceeded
as if nothing happened, while the async client propagates the same
exception and aborts the request. Capture the callback outcome in the
thread and unwrap it after the join so both clients behave the same.
@RazerM
RazerM force-pushed the feature/ratelimit-callback-wait branch from 62e0668 to 8f59dd7 Compare August 23, 2026 12:51
@RazerM
RazerM merged commit c9c9f70 into main Aug 23, 2026
11 checks passed
@RazerM
RazerM deleted the feature/ratelimit-callback-wait branch August 23, 2026 13:04
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