20 Commits
Author SHA1 Message Date
Hasan BasbunarandClaude Opus 5.5 ab36893f3c ocr lane: at SIGTERM the front lets the requests in flight send their last event
os._exit(0) followed at once the end of the drawings, so the request
threads never sent their error (a stream's error event, a 5xx without a
stream): the client saw a bare cut. Past the flag, the main thread now
ends the drawings in progress in a loop, the list re-read each turn,
until no place is taken any more or STOP_S at most, then exits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 18:30:42 +01:00
Hasan BasbunarandClaude Opus 5.5 e27749c6ec ocr lane: the drawing container's Popen runs out of the live lock
subprocess.Popen (a fork/exec) ran under Drawing.live_lock, so every
drawing's start, every end and the stop waited behind it. Popen now
runs before the lock; under the lock, if the stop is in progress the
process just launched is ended at once and the drawing refused, else
it is added to the drawings in progress.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 18:30:42 +01:00
Hasan BasbunarandClaude Opus 5.5 d8b05280a4 ocr lane: the SIGTERM handler takes no lock
The handler ran on the main thread and took Drawing.live_lock, which the
main thread also takes while stopping: a second SIGTERM (a stop sent
twice) then waited on itself until the SIGKILL. The handler is now
on_sigterm(srv): it sets the stopping flag and starts the server's
shutdown, and takes no lock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 18:30:42 +01:00
Hasan BasbunarandClaude Opus 5.5 9115514d89 ocr lane: a refused body is drained in at most DRAIN_S in all
The drain of a body a refusal leaves unread had only the BODY_S
inactivity delay per read, no total bound: a client sending a byte every
BODY_S - 1 held a thread for ever (ThreadingHTTPServer has no cap on
threads). The drain now reads with read1 and stops at the deadline, and
the connection is kept only if the whole announced body was read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 18:30:42 +01:00
Hasan BasbunarandClaude Opus 5.5 a64488f488 ocr lane: a Transfer-Encoding is refused before any read, on every route
The 404 path read the Content-Length bytes even when a Transfer-Encoding
was also present, then kept the connection: the tail of the chunked body
was parsed as the next request. The 411 now comes first, before any
read, with Connection: close and the connection closed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 18:30:42 +01:00
Hasan BasbunarandClaude Opus 5.5 fe93d31a01 ocr lane: a body over MAX_BODY is a 413 with nothing read and the connection closed
_drain marked the body read whole after reading only MAX_BODY of an
announced larger body, so the 413 kept the connection open and the rest
of the body was parsed as the next request. The 413 is now refused
before any read, and _read_whole is true only when the whole announced
body (at most MAX_BODY) was read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 18:30:42 +01:00
Hasan BasbunarandClaude Opus 5.5 1b2ada4f38 ocr lane: SIGTERM refuses new drawings and exits at once after ending the ones in progress
At SIGTERM the list of the drawings in progress was copied once after serve_forever ended: a thread that had already taken a place could still create a Drawing after it, that nobody ended; and the interpreter exit then waited for the ThreadPoolExecutor join, the reads in flight up to ENGINE_S, so TimeoutStopSec ended it a SIGKILL. A stopping flag is now set at SIGTERM and checked before a drawing is created, under the lock the drawing registers itself with, so no drawing can appear past the copy; the request is refused cleanly (a 503 with a Retry-After). The drawings in progress are ended, then the front exits at once, os._exit(0) after the cleanup, without waiting for the reads in flight.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 17:52:10 +01:00
Hasan BasbunarandClaude Opus 5.5 d9362cff67 ocr lane: a non-streamed document is bounded by NONSTREAM_S, answered a 504 that says to stream
A document read without stream had no total bound at the front (the proxy's own bound says nothing about the front: a page's read at the engine goes up to ENGINE_S = 600 s). Past NONSTREAM_S (7200 s, 2 h: 1000 pages at the 0.22 page/s measured beside the 27B under load take 4545 s) the front now stops the document, its reads and its drawing container as when the client leaves, and answers a 504 whose message says to send "stream": true for a long document, without a Retry-After. A streamed document has no such bound, its events come as they are read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 17:47:48 +01:00
Hasan BasbunarandClaude Opus 5.5 d2028cb5e9 ocr lane: the body's read has an inactivity delay, BODY_S, and gives the place back past it
The place was taken before rfile.read(n) and the socket had no delay: a client that announced a Content-Length and then went silent, or sent drop by drop, held one of the two places for ever. The body's read now runs under a socket delay of BODY_S (60 s) without a byte; past it the front answers a 408, gives the place back and closes the connection. Past the body, the socket waits as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 17:45:53 +01:00
Hasan BasbunarandClaude Opus 5.5 d947088c57 ocr lane: an early refusal drains the announced body before answering, so a RST does not eat the 429
A 429 or a 503 answered while the announced body is still unread makes the close send a RST: the proxy, which still sends up to 90 MiB, fails to write and answers a 503 try again, and the 429 with its Retry-After is lost. The body (bounded as the request is, MAX_BODY at most) is now read and thrown away in chunks of 1 MiB, never kept, before the refusal is answered; a fully drained refusal keeps the connection usable. A 429 still takes no place, so it costs no body memory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 17:43:53 +01:00
Hasan BasbunarandClaude Opus 5.5 2fb5a60e5d ocr lane: SIGTERM ends the drawings in progress, and the unit removes any qwen38-ocr-pages-* left
The front's SIGTERM handler was os._exit(0): Drawing.end() never ran, and the drawing containers (3 GiB and four cores each, up to 1000 pages) kept drawing after the lane stopped, even when the cockpit stopped it to free memory before a text lane's Load. The handler now stops the server, the front ends every drawing in progress before exiting 0, and ExecStartPre and ExecStopPost remove any qwen38-ocr-pages-* container left (docker by its path, a - in front), for a front that ended hard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 16:58:07 +01:00
Hasan BasbunarandClaude Opus 5.5 03d16ef257 ocr lane: the place is given back before a refusal is answered
A refusal was answered while the place was still held (the finally ran after the response was written), so a client refused once could be answered 429 on its very next request. The place is now given back in the finally, before the refusal's response is sent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 16:52:31 +01:00
Hasan BasbunarandClaude Opus 5.5 6476f0ab22 ocr lane: the drawing waits for a place to read, at most the read parallelism of pages held
The drawing thread submitted every page to the engine as soon as it was drawn, and the pool's queue held them all: a document of 1000 pages of 1 to 3 MiB each piled up in the front's memory beside the lane that serves. The drawing now takes a place (a semaphore of the read parallelism, OCR_PARALLEL) before reading a page's pictures from the container, and the place is given back when the page is read. The 60 s no-line delay only runs while the pipe is read, so waiting for a place never triggers it, and ocr_pages.py clears its alarm before writing a page, so a container waiting to write is never cut.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 16:51:09 +01:00
Hasan BasbunarandClaude Opus 5.5 78605991c1 ocr lane: the drawing container's stderr is read as it comes, its last 2000 bytes kept
It was a pipe read only at the end of the container's stdout: more than 64 KiB of warnings (Pillow, PDFium, a broken TIFF's pages) blocked the container on a full pipe, which was then stopped for having given no line in 60 s. A thread now drains it while the container runs, keeping only the tail for the error message.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 16:40:21 +01:00
Hasan BasbunarandClaude Opus 5.5 c9d703a71e ocr lane: a document's place is taken before its body is read, and given back on every way out
The two documents' slots were taken only after the whole body was read (up to 86 MiB), parsed and base64-decoded, so each 429 cost that memory beside the lane that serves. The place is now taken after the header checks and given back in a finally, so a refusal never reads the body.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 16:38:55 +01:00
Hasan BasbunarandClaude Opus 5.5 3d652102d1 ocr lane: a page the model did not read is named in errors only, not a page of the answer
docs/ocr-lane.md says a page that could not be read is named in errors, with its index and why, and the others come back. The front put it in pages too, as an empty Markdown with an error key, and counted it in usage_info.pages_processed. It is now only in errors (still sent as a page event with its error in a stream), and pages_processed counts the pages that came back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 16:37:33 +01:00
Hasan BasbunarandClaude Opus 5.5 455587c69a ocr lane: two documents at a time at its front, a drawing container that gives nothing is stopped
- a POST /v1/ocr holds a slot while its document is read (DOCS = 2, as the cockpit's relay already bounds it): a third request is a 429 with Retry-After, in the front's error JSON, and the slot is given back however the document ends (ended, failed, client gone)
- frames() reads the drawing container with a delay of DRAW_S = 2 x PAGE_S, PAGE_S read from ocr_pages.py: no line within it and the container is stopped the way work()'s finally stops it, and the document ends with an error saying a page was not drawn in that many seconds
- tests: a third document gets a 429 (200 before), a container that gives nothing gets an answer within DRAW_S (a client timeout before), and the busy count is back to 0 after each kind of end

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 16:16:45 +01:00
Hasan BasbunarandClaude Opus 5.5 a67e8a5e00 ocr lane: its page; a stream sends a page's picture when it is asked; a test's connection closed
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 15:21:18 +01:00
Hasan BasbunarandClaude Opus 5.5 a28802c606 ocr lane: its unit, installer and proof, its front and its engine in one unit, beside the lane that serves
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 15:21:18 +01:00
Hasan BasbunarandClaude Opus 5.5 e707945ad9 ocr lane: its front, /v1/ocr in Mistral's shape, its pages drawn in a container of their own
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 15:21:17 +01:00