---
title: "Get Extraction Stale Count"
method: GET
path: "/api/admin/health/extraction/stale-count"
tags: ["admin-health"]
---

# Get Extraction Stale Count

`GET /api/admin/health/extraction/stale-count`

## Request

- Base URL: `https://app.thinqos.com` (the document declares no server; this is the origin it was published from)
- URL: `https://app.thinqos.com/api/admin/health/extraction/stale-count`
- Auth: none declared

Count chats the sweep would actually pick up on its next run.

Source-of-truth alignment: the sweep keys eligibility off the
``episodes_v2`` state machine (TOS-39 PR-2), so this banner must
do the same. The previous implementation queried only ``chats``
with the legacy ``last_extracted_at`` denormalized hint, which
has no idea about DEAD_LETTER and reported terminally-retired
chats as "awaiting" forever (regression observed 2026-05-28 for
chat f9ebb5b1 after an OperationalError(AdminShutdown) burst
drove its episode to DEAD_LETTER while ``last_extracted_at``
stayed NULL).

Predicate mirrors ``scheduler/jobs/extract_conversations.py``:

  - chat is alive (``deleted_at IS NULL``) and not opted out
    (``extraction_excluded = false``);
  - LATEST ``episodes_v2`` row (by ``started_at``) is one of:
      * NULL (never extracted),
      * ``failed`` (retry-eligible),
      * ``pending`` (durable worker queue item),
      * ``integrated`` AND a newer extractable message or dirty marker
        exists beyond the processed watermark,
      * ``extracting`` / ``windowing`` whose ``updated_at`` is older than
        the 1-hour in-flight cutoff (crashed worker);
  - ``dead_letter`` (terminal, manual triage) and live
    ``extracting``/``windowing`` (an active worker is on it) are excluded.

The sweep has separate pending/recent/backlog budgets, but this endpoint is
only a count, so it can express the union directly.

## Response `200`

Successful Response

- ExtractionStaleCountResponse
  - `stale_count` integer, required

---

[API](https://skmtc.dev/thinqos/apis/thinqos-api.md) · [All operations](https://skmtc.dev/thinqos/apis/thinqos-api/llms.txt) · [OpenAPI document](https://skmtc.dev/thinqos/apis/thinqos-api/revisions/ce2c2ce318b1?raw)
