Rework polling interval to introduce backoff#8715
Open
4ian wants to merge 5 commits into
Open
Conversation
The editor polls the generation-api to follow AI request progress. Two pollers ran at fixed, aggressive intervals regardless of activity: - The watch loop polled status every 1.4s (and full-fetched every 7s) for the selected request and its sub-agents, even while the backend was blocked on a single long LLM call producing nothing. - Event generation polled every 1s for up to 50 attempts (up to ~50 requests per generation). Both now back off exponentially during idle waits and snap back to the fast base interval as soon as activity is observed (a status change or new messages), so the many fast sequential steps of an agent run are not slowed down. The event-generation loop is now bounded by a total time budget instead of a fixed attempt count, keeping the maximum wait predictable. This cuts billed polling requests during otherwise-idle waits while keeping perceived latency essentially flat.
Move the adaptive polling interval logic out of AiRequestContext into a dedicated useAdaptivePollingInterval hook (plus small pure helpers getBackedOffIntervalInMs / getNextPollingIntervalInMs). AiRequestContext now just reports whether each watch tick saw activity, and the event generation loop reuses the shared backoff helper instead of duplicating the math. Adds unit tests for the pure helpers.
The sub-agent polling tests advanced fake timers by a fixed interval each tick, which no longer fires a tick now that the watch interval backs off ×1.5 after each idle tick. Advance by the actual backed-off interval so each tick fires, and reduce the "no full-fetch spam" test to the two status ticks that fit within the 7s full-fetch window under backoff. This also makes the "leaves an entity untouched" test fire its second tick (previously a no-op).
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.
No description provided.