Skip to content

Rework polling interval to introduce backoff#8715

Open
4ian wants to merge 5 commits into
masterfrom
claude/modest-lamport-paag7p
Open

Rework polling interval to introduce backoff#8715
4ian wants to merge 5 commits into
masterfrom
claude/modest-lamport-paag7p

Conversation

@4ian

@4ian 4ian commented Jun 14, 2026

Copy link
Copy Markdown
Owner

No description provided.

claude added 5 commits June 14, 2026 10:53
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).
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.

2 participants