Skip to content

fix(server): parse shutdown, KMP flag, uvicorn redaction - #578

Merged
chris-dare-dev merged 3 commits into
mainfrom
fix/batch-l-server-runtime
Nov 21, 2026
Merged

chris-dare-dev merged 3 commits into
mainfrom
fix/batch-l-server-runtime

Conversation

@chris-dare-dev

Copy link
Copy Markdown
Owner

Three server-runtime findings: parse cancellation, the test-only KMP flag, and log redaction on the uvicorn launch path.

#305: record what a cancelled parse actually did, and bound shutdown

  • Before, cancelling a parse never stopped the thread doing the work.
    • The row was written "failed: cancelled" at once, while rendering carried on and could still succeed.
    • A queued parse got no row at all.
    • At loop teardown, the default executor's thread join kept the process open until the render finished.
  • Each parse now runs on its own daemon thread. A first cancel asks the thread to skip rendering and keeps waiting, so the row follows what the thread actually did:
    • complete, if it finished;
    • failed with MinerU's error, if it was terminated;
    • "rendering was skipped", if MinerU finished late.
  • Shutdown waits a bounded time, then cancels again and records the parse as abandoned. A queued parse is recorded as never started.

#376: set KMP_DUPLICATE_LIB_OK on macOS only

  • Before, the whole suite ran with the flag set, a flag no server process ever has. A reintroduced duplicate OpenMP load could therefore never fail a test.
  • tests/conftest.py now sets it only on macOS, where the faiss-cpu and PyTorch wheels each bring their own OpenMP runtime.
  • A new test boots the app in a child process with the flag removed, on every platform, and checks /healthz and /readyz. Off macOS, a second test loads faiss and then torch in one process without the flag.

#321: redact logs on the uvicorn server.main:app path

  • Before, only the console script and the desktop child installed the Threat-8 RedactionFilter. Served as uvicorn server.main:app, nothing did:
    • uvicorn's access logger kept its own unfiltered handler;
    • FastMCP's basicConfig put an unfiltered RichHandler on root;
    • so a record logged with query printed it in the clear.
  • The module-level app now calls ensure_configured before building the app.
    • With no root handler yet, it configures logging fully on a stderr handler. That also leaves FastMCP's basicConfig with nothing to do.
    • With logging already set up, as on the CLI and desktop paths, it only adds the filter where it is missing and keeps the existing level and format.
  • configure() now filters the handlers of every existing logger, not only root's.

Closes #305
Closes #376
Closes #321

Verification

Cancelling a parse task never stopped the thread doing the work. The
row was written "failed: cancelled" at once while rendering carried on
and could still succeed, a queued parse got no row at all, and the
default executor's thread join at loop teardown kept the process open
until the render finished.

Each parse now runs on its own daemon thread. A first cancel asks the
thread to skip rendering and keeps waiting, so the row follows the
thread: complete if it finished, failed with MinerU's error if it was
terminated, "rendering was skipped" if MinerU finished late. Shutdown
waits a bounded time, then cancels again and records the parse as
abandoned; a queued parse is recorded as never started.
The whole suite ran under KMP_DUPLICATE_LIB_OK=TRUE, a flag no server
process ever has, so a reintroduced duplicate OpenMP load could never
fail a test. conftest now sets it only on macOS, where the faiss-cpu
and PyTorch wheels each bring a runtime, and the rest of the suite runs
the way production does.

A new test boots the app in a child process with the flag removed on
every platform and checks /healthz and /readyz. Off macOS a second one
loads faiss and then torch in one flag-free process.
Only the console script and the desktop child installed the Threat-8
RedactionFilter. Served as `uvicorn server.main:app`, nothing did:
uvicorn's access logger kept its own unfiltered handler and FastMCP's
basicConfig put an unfiltered RichHandler on root, so a record logged
with `query` printed it in the clear.

The module-level app now calls ensure_configured before building the
app. With no root handler yet, it configures logging fully on a stderr
handler, which also leaves FastMCP's basicConfig with nothing to do.
With logging already set up, as on the CLI and desktop paths, it only
adds the filter where it is missing and keeps the existing level and
format. configure() now filters the handlers of every existing logger,
not only root's.
@chris-dare-dev
chris-dare-dev merged commit 7cc5620 into main Nov 21, 2026
4 checks passed
@chris-dare-dev
chris-dare-dev deleted the fix/batch-l-server-runtime branch November 21, 2026 04:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant