Replace fixed-interval LLM log polling with exponential backoff#160
Conversation
…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>
There was a problem hiding this comment.
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 viasetTimeout. - Tracks consecutive “no new entries” polls in
_logPollSameCountand 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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
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.
| var delay = _LOG_POLL_DELAYS[Math.min(_logPollSameCount, _LOG_POLL_DELAYS.length - 1)]; | ||
| _logPollTimeout = setTimeout(pollLLMLog, delay); | ||
| } |
There was a problem hiding this comment.
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.
The
/llm_logpoll ran on a fixedsetIntervalforever — accumulating stale intervals across sessions, navigation, and generation lifecycle events.Approach
Replaced
setIntervalwith a self-reschedulingsetTimeoutpattern. After each poll, the next one is scheduled based on how many consecutive "no new entries" results have been seen: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 nextsetTimeoutpollLLMLog()— tracksfoundNewper poll; resets or increments_logPollSameCountbefore calling_scheduleLogPoll(); error path also increments backoff_logPollSameCount = 0so polling snaps back to 15 s after a manual clearWarning
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/usr/bin/python python -m pytest tests/ -x -q --tb=short(dns block)/usr/bin/python python -m pytest tests/ -q --tb=short(dns block)/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: