Session work execution is synchronous — blocks HTTP response for full AI duration #18
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
In Mode 1 (jobs), AI evaluation and execution both run via
setImmediate()in background tasks. The HTTP response returns immediately with the current state (evaluating/executing) and the client polls or connects via SSE/WebSocket.In Mode 2 (sessions),
POST /api/sessions/:id/requestcallsagentService.executeWork()inline — the HTTP response is held open for the full AI execution duration (typically 5-30 seconds). This is inconsistent, blocks the request thread, and provides a poor Workshop UX where a POST appears to hang.See
artifacts/api-server/src/routes/sessions.tsaroundPOST /sessions/:id/request(line ~212).Requirements
POST /sessions/:id/requestto:a. Debit the balance estimate immediately and return
202 Acceptedwith arequestIdb. Run AI work in a background task (same
setImmediatepattern as jobs)c. Update the session request record with
state: "executing"→state: "complete"when doned. If AI fails, refund the debited sats back to session balance and set
state: "failed"GET /api/sessions/:id/requests/:requestIdto poll request status (mirrorsGET /jobs/:id)session:request:completeevent withsessionIdandrequestIdexecuteWorkStreamingso session responses are also streamableGET /api/sessions/:id/requests/:requestId/streamSSE endpoint (mirrorsGET /jobs/:id/stream)Acceptance Criteria
POST /api/sessions/:id/requestreturns within 200 ms (does not block on AI)requestIdcan be polled viaGET /api/sessions/:id/requests/:requestIdGET /api/sessions/:id/requests/:requestId/streamstreams tokens in real timetestkit.ts(tests 9-16) still passFiles
artifacts/api-server/src/routes/sessions.tslib/db/src/schema.ts(addstatefield tosessionRequestsif not present)artifacts/api-server/src/lib/stream-registry.ts(extend to support session request IDs)[triage] Scope refinement:
routes/sessions.ts(sync handler)