Make job evaluation and execution run in the background

Refactors `runEvalInBackground` and `runWorkInBackground` to execute AI tasks asynchronously. Updates `pollJob` in `ui.ts` to handle 'evaluating', 'executing', and 'failed' states, and corrects `data.status` to `data.state` and `data.rejectionReason` to `data.reason`.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 418bf6f8-212b-4bb0-a7a5-8231a061da4e
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: ecf857ee-fa4d-47db-b4c1-b374ffb3815d
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/9f85e954-647c-46a5-90a7-396e495a805a/418bf6f8-212b-4bb0-a7a5-8231a061da4e/Q83Uqvu
Replit-Helium-Checkpoint-Created: true
This commit is contained in:
alexpaynex
2026-03-18 21:00:43 +00:00
parent 1b5c7045da
commit b02efc9057
2 changed files with 127 additions and 108 deletions

View File

@@ -440,14 +440,28 @@ router.get("/ui", (_req, res) => {
pollTimer = setInterval(async () => {
try {
const r = await fetch(BASE + '/api/jobs/' + jobId);
if (!r.ok) return; // keep polling on transient errors
const data = await r.json();
const s = data.status;
const s = data.state;
// Failed is terminal regardless of phase
if (s === 'failed') {
clearInterval(pollTimer);
hide('card-eval');
hide('card-work');
$('rejected-reason').textContent = 'Error: ' + (data.errorMessage || 'Something went wrong. Try again.');
show('card-rejected');
setStep('rejected');
return;
}
if (phase === 'eval') {
// evaluating = AI running in background, keep waiting
if (s === 'evaluating') return;
if (s === 'rejected') {
clearInterval(pollTimer);
hide('card-eval');
$('rejected-reason').textContent = data.rejectionReason || 'Request was rejected.';
$('rejected-reason').textContent = data.reason || 'Request was rejected.';
show('card-rejected');
setStep('rejected');
} else if (s === 'awaiting_work_payment') {
@@ -461,20 +475,17 @@ router.get("/ui", (_req, res) => {
setStep('awaiting_work_payment');
}
} else if (phase === 'work') {
// executing = AI running in background, keep waiting
if (s === 'executing') return;
if (s === 'complete') {
clearInterval(pollTimer);
hide('card-work');
$('result-text').textContent = data.result;
show('card-result');
setStep('complete');
} else if (s === 'failed') {
clearInterval(pollTimer);
hide('card-work');
$('rejected-reason').textContent = 'Job failed: ' + (data.error || 'unknown error');
show('card-rejected');
}
}
} catch(e) { /* keep polling */ }
} catch(e) { /* keep polling through network errors */ }
}, 1500);
}