Worker không chết vì SQLite locked, trang trắng không bị coi là lỗi

- tx(): chỉ ROLLBACK khi đang có transaction; BEGIN IMMEDIATE hết busy_timeout
  trước đây ném "cannot rollback - no transaction is active" che mất lỗi gốc.
- Luồng OCR/callback/coordinator chạy qua Worker.loop: lỗi được log.exception
  rồi thử lại, không còn giết luồng vĩnh viễn.
- OCR: model trả rỗng (trang trắng) thành trang không có block; output không
  parse được thì kèm 200 ký tự đầu vào thông báo lỗi.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-28 13:40:05 +00:00
parent a173348380
commit 3cbba8bd79
4 changed files with 61 additions and 21 deletions

View File

@@ -46,9 +46,11 @@ def validate_response(response: dict) -> list[dict]:
raise InvalidOutput("Model reached max_tokens", truncated=True)
if finish_reason != "stop" or not isinstance(raw, str):
raise InvalidOutput(f"Unexpected finish_reason: {finish_reason}")
if not raw.strip():
return [] # Trang trắng: model dừng ngay, không có gì để bóc.
blocks = parse_blocks(raw)
if not blocks:
raise InvalidOutput("No HTML layout blocks returned")
raise InvalidOutput(f"No HTML layout blocks returned: {raw[:200]!r}")
for block in blocks:
block["label"] = LABEL_ALIASES.get(block["label"], block["label"])
if block["label"] not in LABELS: