fix(kb-classifier): bump default timeout 90s → 240s for long Hebrew caselaw

Labor-law caselaw uploads (4 DOCX, 2026-04-28) timed out at exactly 90s,
landing in awaiting_review with empty ai_suggestions. A live retry of the
same payload through ai-gateway returned valid metadata in 91.8s — one
second over the cap. PDF caselaw can be larger (20K-char cap vs DOCX 6K)
and ai-gateway's serialized OAuth session lengthens the tail under batch
load, so 180s would not be enough headroom either.

240s keeps the call fail-soft (user can still fill metadata manually) but
covers realistic Hebrew legal documents. Override via KB_CLASSIFIER_TIMEOUT_S.
This commit is contained in:
2026-04-28 16:38:53 +00:00
parent 737307d5a4
commit 301f24c6e4
+7 -4
View File
@@ -42,10 +42,13 @@ logger = logging.getLogger("shira.kb.classifier")
# it's no worse than 1. # it's no worse than 1.
_CONCURRENCY = int(os.environ.get("KB_CLASSIFIER_CONCURRENCY", "2")) _CONCURRENCY = int(os.environ.get("KB_CLASSIFIER_CONCURRENCY", "2"))
# Empirically the ai-gateway → Claude tool-call round-trip with a ~3KB # Empirically the ai-gateway → Claude tool-call round-trip with a ~3KB
# Hebrew system prompt + 5KB user content runs 18-25s. With 20 files # Hebrew system prompt + 5KB user content runs 18-25s. Long Hebrew
# queued through the gateway one-at-a-time, the tail can hit ~80s. # caselaw PDFs (full 20K-char first-3-pages cap) push the tail to
# Padded to 90s so we don't fail-soft on serialized queue waits. # ~92s on DOCX and noticeably more on dense PDFs; ai-gateway also
_TIMEOUT_S = float(os.environ.get("KB_CLASSIFIER_TIMEOUT_S", "90")) # serializes through one OAuth session, lengthening the tail in a
# batch. 240s buys headroom without making the user wait forever
# when something is genuinely stuck.
_TIMEOUT_S = float(os.environ.get("KB_CLASSIFIER_TIMEOUT_S", "240"))
_MAX_INPUT_CHARS = 20_000 # ~3 pages of Hebrew legal text _MAX_INPUT_CHARS = 20_000 # ~3 pages of Hebrew legal text
_semaphore = asyncio.Semaphore(_CONCURRENCY) _semaphore = asyncio.Semaphore(_CONCURRENCY)