ayushKishor commited on
Commit
aef38b9
·
1 Parent(s): 02b94ab

Prevent UI from sticking while running

Browse files
Files changed (2) hide show
  1. mp1/frontend/app.js +26 -8
  2. mp1/frontend/index.html +1 -1
mp1/frontend/app.js CHANGED
@@ -5,6 +5,8 @@
5
  selectedDocIds: 'pluto.selectedDocIds',
6
  detailLevel: 'pluto.detailLevel',
7
  };
 
 
8
 
9
  const stages = ['route', 'extract', 'merge', 'evidence_check'];
10
  const stageEls = {};
@@ -161,18 +163,18 @@
161
  pipelineRunning = true;
162
  const sessionId = createSessionId();
163
  const queryTimestamp = Date.now();
164
- activeSessionId = sessionId;
165
- syncControls();
166
- runBtn.innerHTML = '<span class="spinner"></span> Running...';
167
- resetUI();
168
 
169
  try {
 
 
 
 
170
  listenSSE(sessionId);
171
- const response = await fetch('/api/run', {
172
  method: 'POST',
173
  headers: { 'Content-Type': 'application/json' },
174
  body: JSON.stringify(buildQueryPayload(query, sessionId, queryTimestamp)),
175
- });
176
  const data = await parseJsonResponse(response, 'Server returned an invalid response');
177
  activeSessionId = data.session_id || sessionId;
178
  if (!response.ok || data.error) {
@@ -207,11 +209,11 @@
207
  benchBody.innerHTML = '<div id="benchLoader" class="bench-loader"><span class="spinner"></span> Running side-by-side comparison...</div>';
208
 
209
  try {
210
- const response = await fetch('/api/compare', {
211
  method: 'POST',
212
  headers: { 'Content-Type': 'application/json' },
213
  body: JSON.stringify(buildQueryPayload(query)),
214
- });
215
  const data = await parseJsonResponse(response, 'Benchmark returned an invalid response');
216
  if (!response.ok || data.error) {
217
  throw new Error(data.error || `Benchmark error: ${response.status}`);
@@ -901,6 +903,22 @@
901
  }
902
  }
903
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
904
  function formatSize(bytes) {
905
  if (bytes < 1024) {
906
  return `${bytes} B`;
 
5
  selectedDocIds: 'pluto.selectedDocIds',
6
  detailLevel: 'pluto.detailLevel',
7
  };
8
+ const RUN_TIMEOUT_MS = 180000;
9
+ const BENCH_TIMEOUT_MS = 180000;
10
 
11
  const stages = ['route', 'extract', 'merge', 'evidence_check'];
12
  const stageEls = {};
 
163
  pipelineRunning = true;
164
  const sessionId = createSessionId();
165
  const queryTimestamp = Date.now();
 
 
 
 
166
 
167
  try {
168
+ activeSessionId = sessionId;
169
+ syncControls();
170
+ runBtn.innerHTML = '<span class="spinner"></span> Running...';
171
+ resetUI();
172
  listenSSE(sessionId);
173
+ const response = await fetchWithTimeout('/api/run', {
174
  method: 'POST',
175
  headers: { 'Content-Type': 'application/json' },
176
  body: JSON.stringify(buildQueryPayload(query, sessionId, queryTimestamp)),
177
+ }, RUN_TIMEOUT_MS, 'Pipeline request timed out. The server may still be working; try again or refresh the app.');
178
  const data = await parseJsonResponse(response, 'Server returned an invalid response');
179
  activeSessionId = data.session_id || sessionId;
180
  if (!response.ok || data.error) {
 
209
  benchBody.innerHTML = '<div id="benchLoader" class="bench-loader"><span class="spinner"></span> Running side-by-side comparison...</div>';
210
 
211
  try {
212
+ const response = await fetchWithTimeout('/api/compare', {
213
  method: 'POST',
214
  headers: { 'Content-Type': 'application/json' },
215
  body: JSON.stringify(buildQueryPayload(query)),
216
+ }, BENCH_TIMEOUT_MS, 'Benchmark request timed out. Try again after the server finishes the current work.');
217
  const data = await parseJsonResponse(response, 'Benchmark returned an invalid response');
218
  if (!response.ok || data.error) {
219
  throw new Error(data.error || `Benchmark error: ${response.status}`);
 
903
  }
904
  }
905
 
906
+ async function fetchWithTimeout(url, options = {}, timeoutMs = 120000, timeoutMessage = 'Request timed out') {
907
+ const controller = new AbortController();
908
+ const timeoutId = window.setTimeout(() => controller.abort(), timeoutMs);
909
+
910
+ try {
911
+ return await fetch(url, { ...options, signal: controller.signal });
912
+ } catch (error) {
913
+ if (error && error.name === 'AbortError') {
914
+ throw new Error(timeoutMessage);
915
+ }
916
+ throw error;
917
+ } finally {
918
+ window.clearTimeout(timeoutId);
919
+ }
920
+ }
921
+
922
  function formatSize(bytes) {
923
  if (bytes < 1024) {
924
  return `${bytes} B`;
mp1/frontend/index.html CHANGED
@@ -185,7 +185,7 @@
185
  <span>Pluto v2 Pipeline | Deterministic routing | Real model switching | Evidence checking</span>
186
  </footer>
187
 
188
- <script src="/static/app.js?v=5"></script>
189
  </body>
190
 
191
  </html>
 
185
  <span>Pluto v2 Pipeline | Deterministic routing | Real model switching | Evidence checking</span>
186
  </footer>
187
 
188
+ <script src="/static/app.js?v=6"></script>
189
  </body>
190
 
191
  </html>