Skip to content

Replace fixed-interval LLM log polling with exponential backoff#160

Merged
CyberSecDef merged 3 commits into
mainfrom
copilot/backoff-log-polling-intervals
Apr 9, 2026
Merged

Replace fixed-interval LLM log polling with exponential backoff#160
CyberSecDef merged 3 commits into
mainfrom
copilot/backoff-log-polling-intervals

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 8, 2026

The /llm_log poll ran on a fixed setInterval forever — accumulating stale intervals across sessions, navigation, and generation lifecycle events.

Approach

Replaced setInterval with a self-rescheduling setTimeout pattern. After each poll, the next one is scheduled based on how many consecutive "no new entries" results have been seen:

Consecutive stale polls Next poll delay
0–1 15 s
2 30 s
3 60 s
4 2 min
5 5 min
6+ 10 min

Any poll that finds new entries resets the counter immediately back to 15 s.

Key changes (static/js/script.js)

  • _logPollTimeout / _logPollSameCount / _LOG_POLL_DELAYS — replace _logPollInterval; track backoff state
  • _scheduleLogPoll() — cancels any pending timeout, picks the delay for current _logPollSameCount, fires next setTimeout
  • pollLLMLog() — tracks foundNew per poll; resets or increments _logPollSameCount before calling _scheduleLogPoll(); error path also increments backoff
  • Clear-log handler — resets _logPollSameCount = 0 so polling snaps back to 15 s after a manual clear
var _LOG_POLL_DELAYS = [15000, 15000, 30000, 60000, 120000, 300000, 600000];

function _scheduleLogPoll() {
  if (_logPollTimeout) clearTimeout(_logPollTimeout);
  var delay = _LOG_POLL_DELAYS[Math.min(_logPollSameCount, _LOG_POLL_DELAYS.length - 1)];
  _logPollTimeout = setTimeout(pollLLMLog, delay);
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.openai.com
    • Triggering command: /usr/bin/python python -m pytest tests/ -x -q --tb=short (dns block)
    • Triggering command: /usr/bin/python python -m pytest tests/ -q --tb=short (dns block)
    • Triggering command: /usr/bin/python python -m pytest tests/ -q (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested review from Copilot and removed request for Copilot April 8, 2026 23:34
Copilot AI linked an issue Apr 8, 2026 that may be closed by this pull request
…15s→30s→60s→2min→5min→10min)

Agent-Logs-Url: https://github.com/CyberSecDef/NovelForge/sessions/fac5c436-d508-4afd-90e7-34f7c1b2efc5

Co-authored-by: CyberSecDef <17597068+CyberSecDef@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot April 8, 2026 23:43
Copilot AI changed the title [WIP] Implement backoff for log polling intervals Replace fixed-interval LLM log polling with exponential backoff Apr 8, 2026
Copilot AI requested a review from CyberSecDef April 8, 2026 23:43
@CyberSecDef CyberSecDef marked this pull request as ready for review April 8, 2026 23:58
Copilot AI review requested due to automatic review settings April 8, 2026 23:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the client-side LLM log polling loop to avoid permanently running fixed-interval timers by switching to a self-rescheduling setTimeout approach with an exponential-ish backoff when polls return no new entries.

Changes:

  • Replaces setInterval-based polling with a _scheduleLogPoll() helper that re-arms polling via setTimeout.
  • Tracks consecutive “no new entries” polls in _logPollSameCount and applies a delay from _LOG_POLL_DELAYS.
  • Resets the backoff counter when new log entries are detected (and on manual clear).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread static/js/script.js
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 9, 2026 00:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread static/js/script.js
Comment on lines +1529 to +1531
var delay = _LOG_POLL_DELAYS[Math.min(_logPollSameCount, _LOG_POLL_DELAYS.length - 1)];
_logPollTimeout = setTimeout(pollLLMLog, delay);
}
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With exponential backoff, polling can reach a 10-minute delay. If a user starts a new LLM action after a long idle period, the UI may not show new /llm_log entries (and sticky status updates) for up to the full backoff delay because the backoff is only reset after a poll detects new entries. Consider resetting _logPollSameCount (and triggering an immediate/near-immediate poll) when client-side actions that generate LLM traffic start (e.g., outline generation, chapter generation/revision, illustration generation), so logs remain responsive while still backing off during true idle periods.

Copilot uses AI. Check for mistakes.
@CyberSecDef CyberSecDef merged commit fe78030 into main Apr 9, 2026
13 checks passed
@CyberSecDef CyberSecDef deleted the copilot/backoff-log-polling-intervals branch April 9, 2026 00: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.

LLM Log Polling Never Stops

3 participants