invoke-ai/InvokeAI · error · HTTPException

Unexpected error while canceling by batch id: {e}

Error message

Unexpected error while canceling by batch id: {e}

What it means

This is a catch-all 500 handler in the cancel_by_batch_ids FastAPI route. Any unhandled exception raised by the session_queue service while canceling queue items by batch id (DB errors, service not ready, malformed input reaching the service layer) is wrapped into this HTTP 500. It hides the underlying cause in the detail string, so the original exception text is appended after the colon.

Source

Thrown at invokeai/app/api/routers/session_queue.py:352

@session_queue_router.put(
    "/{queue_id}/cancel_by_batch_ids",
    operation_id="cancel_by_batch_ids",
    responses={200: {"model": CancelByBatchIDsResult}},
)
def cancel_by_batch_ids(
    current_user: CurrentUserOrDefault,
    queue_id: str = Path(description="The queue id to perform this operation on"),
    batch_ids: list[str] = Body(description="The list of batch_ids to cancel all queue items for", embed=True),
) -> CancelByBatchIDsResult:
    """Immediately cancels all queue items from the given batch ids. Non-admin users can only cancel their own items."""
    try:
        # Admin users can cancel all items, non-admin users can only cancel their own
        user_id = None if current_user.is_admin else current_user.user_id
        return ApiDependencies.invoker.services.session_queue.cancel_by_batch_ids(
            queue_id=queue_id, batch_ids=batch_ids, user_id=user_id
        )
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"Unexpected error while canceling by batch id: {e}")


@session_queue_router.put(
    "/{queue_id}/cancel_by_destination",
    operation_id="cancel_by_destination",
    responses={200: {"model": CancelByDestinationResult}},
)
def cancel_by_destination(
    current_user: CurrentUserOrDefault,
    queue_id: str = Path(description="The queue id to perform this operation on"),
    destination: str = Query(description="The destination to cancel all queue items for"),
) -> CancelByDestinationResult:
    """Immediately cancels all queue items with the given destination. Non-admin users can only cancel their own items."""
    try:
        # Admin users can cancel all items, non-admin users can only cancel their own
        user_id = None if current_user.is_admin else current_user.user_id
        return ApiDependencies.invoker.services.session_queue.cancel_by_destination(
            queue_id=queue_id, destination=destination, user_id=user_id

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Check server logs for the full traceback printed before the HTTPException is raised — the wrapped {e} text names the real cause.
  2. Verify the database (SQLite file or Postgres) is reachable, not locked, and at the expected schema version (run any pending migrations).
  3. Confirm queue_id exists (GET /api/v1/queue/{queue_id}/status) before calling cancel_by_batch.
  4. Retry after resolving DB contention; restart the InvokeAI server if the service graph failed to initialize.
  5. Upgrade InvokeAI if the stack trace points inside session_queue service code (known bugs get fixed).

Example fix

// before (server-side catch-all obscures cause)
except Exception as e:
    raise HTTPException(500, detail=f"Unexpected error while canceling by batch id: {e}")
// after (client-side: inspect and surface the wrapped cause)
try:
    requests.put(f"{base}/api/v1/queue/{queue_id}/cancel_by_batch", json={"batch_ids": batch_ids})
    resp.raise_for_status()
except requests.HTTPError as e:
    detail = e.response.json().get('detail', '')
    if 'database is locked' in detail:
        time.sleep(1)  # retry after DB contention
    else:
        raise RuntimeError(f'cancel_by_batch_ids failed: {detail}') from e
Defensive patterns

Strategy: try-catch

Validate before calling

const status = await fetch(`${base}/api/v1/queue/${queueId}/status`);
if (!status.ok) throw new Error(`queue ${queueId} unavailable`);

Type guard

function isQueueBatchCancelResult(v): v is { canceled_count: number } {
  return typeof v === 'object' && v !== null && 'canceled_count' in v;
}

Try / catch

try {
  const r = await fetch(url, { method: 'PUT', body: JSON.stringify({ batch_ids }) });
  if (!r.ok) {
    const detail = (await r.json()).detail ?? '';
    throw new Error(`cancel_by_batch failed: ${detail}`);
  }
} catch (e) {
  logger.error('cancel_by_batch_ids 500', e);
  // check DB/server health before retry
}

Prevention

When it happens

Trigger: PUT /api/v1/queue/{queue_id}/cancel_by_batch with batch_ids, when the session queue service throws: DB connection failure, invalid queue_id, SQLite/Postgres lock, or an internal service bug while executing cancel_by_batch_ids.

Common situations: Database is down or migrated out of sync after an InvokeAI upgrade; queue_id refers to a deleted/unknown queue; disk I/O errors on the SQLite file; concurrent queue writes causing lock contention.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/9b1e3d80c8b6f28e. Report an issue: GitHub.