Add getRateLimitStatus JSON-RPC method#2023
Open
tonycpsu wants to merge 2 commits intoAsamK:masterfrom
Open
Conversation
Adds a read-only query returning the most recent rate-limit state
observed from send results. Callers can check whether the account is
currently rate-limited, how long until retry, and whether a captcha
challenge is required — without having to trigger a send and inspect
the response, and without having to reconstruct state themselves.
Useful for:
- Admin UIs that want to display current rate-limit state on load
- Monitoring/alerting (poll for active rate limits)
- Clients that restart and would otherwise lose tracked state
The status is tracked in-memory on the Manager: updated whenever a
SendMessageResult reports a rate-limit failure, cleared after a
successful captcha submission, and auto-expires when the retry-after
window elapses (getRateLimitStatus returns active=false once the
current time is past expiresAtEpochSeconds).
JSON-RPC response shape:
{
"active": bool,
"proofRequired": bool,
"retryAfterSeconds": long, // omitted if not active
"challengeToken": string, // omitted unless proofRequired
"expiresAtEpochSeconds": long // omitted if not active
}
D-Bus is not updated to expose this state; DbusManagerImpl returns
inactive as a stub since D-Bus clients already observe rate-limit state
via send results.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
Adds a read-only
getRateLimitStatusJSON-RPC method returning the most recent rate-limit state observed from send results. Callers can check whether the account is currently rate-limited without triggering a send and without having to track state themselves.Complements the recent retry-after work (#2016) and distinct captcha-rejected error code (#2021) by closing the loop: send results report rate-limit deltas, this method reports current rate-limit level.
Motivation
Today there is no way to query rate-limit state without attempting a send and inspecting the per-recipient result. That pattern forces clients to either:
getRateLimitStatusresolves this by exposing internal state the Manager already observes as sends pass through it.Behavior
State is tracked in-memory on the Manager:
SendMessageResultreports a rate-limit failure.submitRateLimitRecaptchaChallenge.getRateLimitStatus()returnsactive=false(and clears the stale snapshot), so callers don't need to compare timestamps themselves.JSON-RPC response shape
{ "active": false, "proofRequired": false }{ "active": true, "proofRequired": false, "retryAfterSeconds": 3420, "expiresAtEpochSeconds": 1713283000 }{ "active": true, "proofRequired": true, "retryAfterSeconds": 86000, "challengeToken": "abc123...", "expiresAtEpochSeconds": 1713366000 }retryAfterSeconds,challengeToken, andexpiresAtEpochSecondsare omitted from the JSON when null (non-active case, or non-proof-required for token).Use cases
D-Bus
DbusManagerImplimplements the new Manager method as a stub returninginactive(). Exposing this state over D-Bus is intentionally out of scope for this PR — D-Bus clients already observe rate-limit state via send results and don't have the restart-resilience use case in the same way.Files
lib/.../api/RateLimitStatus.java— new API recordlib/.../Manager.java— new interface methodlib/.../internal/ManagerImpl.java— state tracking + snapshot computation, hooked intotoSendMessageResultand the captcha-submit pathsrc/.../commands/GetRateLimitStatusCommand.java— new JSON-RPC/CLI commandsrc/.../commands/Commands.java— command registrationsrc/.../dbus/DbusManagerImpl.java— stub implementationsrc/test/.../SubscribeCallEventsTest.java— update existingStubManagerto implement the new method🤖 Generated with Claude Code