Skip to content

Commit 2099627

Browse files
committed
fix: add circuit breaker to agent status polling to eliminate 404 spam on static hosting
1 parent 1ce1dda commit 2099627

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Changelog — Agent Status Polling Fix
2+
3+
**Date:** 2026-03-25
4+
5+
## Summary
6+
7+
Added a circuit breaker to `getLocalStatus()` in `agent-cloud.js` to eliminate repeated `/api/agents/status` 404 errors on static hosting (GitHub Pages).
8+
9+
## Problem
10+
11+
The agent panel polls `getLocalStatus()` every 15 seconds to update the badge count. On GitHub Pages (where no backend exists), every poll resulted in a 404 error, spamming the browser console with dozens of `Failed to load resource: 404` messages.
12+
13+
## Changes
14+
15+
### Modified: `js/agent-cloud.js`
16+
- Added `_localStatusFailed` circuit breaker flag
17+
- After the first 404/network failure (when no custom agent URL is configured), all subsequent calls return `{ agents: [], docker: false }` immediately — zero network requests
18+
- Circuit breaker only activates on the default origin (not when `AGENT_CUSTOM_URL` is set by the user)
19+
- Resets on successful response, so local development with agent-runner still works normally

js/agent-cloud.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
var IDLE_TIMEOUT_MS = 5 * 60 * 1000; // Auto-stop after 5 min idle
1212
var CODESPACE_PREFIX = 'textagent-'; // Naming prefix for cleanup
1313
var idleTimer = null;
14+
var _localStatusFailed = false; // Circuit breaker: stop polling after first 404
1415

1516
// ── Public API ──
1617
M.agentCloud = {
@@ -136,16 +137,24 @@
136137

137138
/** Get local Docker agent status */
138139
getLocalStatus: async function () {
140+
// Circuit breaker: after the first failure on static hosting, stop polling
141+
if (_localStatusFailed) return { agents: [], docker: false };
139142
var baseUrl = localStorage.getItem(M.KEYS.AGENT_CUSTOM_URL) || (window.location.origin);
140143
baseUrl = baseUrl.replace(/\/api\/exec$/, '');
141144
try {
142145
var res = await fetch(baseUrl + '/api/agents/status', {
143146
method: 'GET',
144147
signal: AbortSignal.timeout(3000)
145148
});
146-
if (!res.ok) return { agents: [], docker: false };
149+
if (!res.ok) {
150+
// On static hosts (GitHub Pages), this will always 404 — stop retrying
151+
if (!localStorage.getItem(M.KEYS.AGENT_CUSTOM_URL)) _localStatusFailed = true;
152+
return { agents: [], docker: false };
153+
}
154+
_localStatusFailed = false; // Reset on success
147155
return await res.json();
148156
} catch (_) {
157+
if (!localStorage.getItem(M.KEYS.AGENT_CUSTOM_URL)) _localStatusFailed = true;
149158
return { agents: [], docker: false };
150159
}
151160
},

0 commit comments

Comments
 (0)