GuideCore Concepts
Async Jobs & SSE Streams
Handling 202 Accepted responses for B2 (audit/order) and B4 (research/memo) with SSE keepalives and cancellation refunds.
Long-running Tier B engines — POST /api/v1/in/audit/order (25 credits) and POST /api/v1/in/research/memo (30 credits) — immediately reserve credits and return HTTP 202 Accepted with an AsyncJobResponse payload (status: "queued").
Concurrency & Isolation
- Global worker cap: Heavy async execution is bounded globally at max 2 concurrent jobs (
heavySem). Additional jobs queue cleanly in Postgresapi_async_jobs. - Owner isolation: Only the API key that created a job may poll, stream, or cancel it. Any foreign key receives HTTP
404(not_found) so job existence is never leaked across tenants. - Startup recovery: Any job stranded by a server restart is reconciled cleanly with automatic refund if unrecoverable.
Polling vs. SSE Progress Streaming
| Method | Endpoint | Behavior |
|---|---|---|
| Poll Status | GET /api/v1/in/jobs/{job_id} | Returns status (queued | running | completed | failed | cancelled), progress_pct (0–100), stage, result, or error (0 credits) |
| Stream SSE | GET /api/v1/in/jobs/{job_id}/events | Emits progress, completed, failed, or cancelled events plus : keepalive comments every 15 seconds (0 credits) |
| Cancel & Refund | DELETE /api/v1/in/jobs/{job_id} | Cancels a queued or running job and atomically refunds all reserved credits (0 credits) |
{
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"engine": "audit_order",
"status": "completed",
"progress_pct": 100,
"stage": "done",
"result": { "...": "engine output payload" },
"error": null,
"credits_reserved": 25,
"credits_charged": 25,
"credits_refunded": 0,
"created_at": "2026-12-02T10:15:00Z",
"completed_at": "2026-12-02T10:15:42Z"
}