Task File Lifecycle Management#
The MinerU API server (mineru/parser/api_server.py) and the Router (mineru/kit/router/) share a single retention model for uploaded source files, parse jobs, and parse outputs. Source and output bytes live in a shared content-addressed store under the upload directory, while metadata (uploads, file views, jobs) is held in memory. A background asyncio loop periodically scans for expired resources and reclaims them.
Retention Setting#
Retention is one setting shared by the API server and the Router, resolved by resolve_retention_seconds() in mineru/utils/retention.py. It can be supplied in three ways:
create_app(retention_seconds=...)in Python- the
--retention-secondsCLI flag - the
MINERU_API_RETENTION_SECONDSenvironment variable
| Item | Value |
|---|---|
| Default | 86400 (24 h) |
0 | Disables automatic reclamation |
| Negative or invalid value | Raises an error immediately (no silent fallback) |
| Scan interval | 300 seconds (5 min) |
An explicit argument takes precedence over the environment variable. An explicit expires_after on an upload continues to apply to that upload.
# Keep resources for 48 hours
mineru-kit api-server --retention-seconds 172800
# Keep resources persistently (no automatic reclamation)
mineru-kit api-server --retention-seconds 0
The old MINERU_API_TASK_RETENTION_SECONDS and MINERU_API_TASK_CLEANUP_INTERVAL_SECONDS variables are not part of this model; the scan interval is fixed at 300 seconds.
Client-side (in api_client.py)
| Variable | Default | Min | Purpose |
|---|---|---|---|
MINERU_TASK_RESULT_TIMEOUT_SECONDS | 3600 (1 h) | 1.0 | Max seconds the CLI client waits for a task result |
MINERU_TASK_RESULT_DOWNLOAD_TIMEOUT_SECONDS | 600 (10 min) | 1.0 | Max seconds allowed for downloading a result |
MINERU_TASK_RESULT_TIMEOUT_SECONDS was made configurable in PR #4881 to handle large documents that legitimately exceed the default 1-hour limit. It is read by get_task_result_timeout_seconds() via get_float_env(); non-numeric or below-minimum values log a warning and fall back to the default.
Expiration Behavior#
- Reads and submissions: an expired resource immediately returns
404for new reads and submissions. Deleting the bytes from disk may wait until the next scan. - Retention clock for tasks and artifacts: retention is counted from the actual completion of cleanup after a cancel or the end of inference. Time spent queued or running is not counted, so artifacts of long-running tasks do not expire before cleanup completes.
- Collection loop: when retention is greater than
0, a background task started during app lifespan sleeps for the scan interval, then expires terminal job metadata and calls the file store's collection routine to release unreferenced files. With retention0, no loop is started.
Shared Source Storage#
Source files use shared content-addressed storage:
- Multiple file-name views and multiple tasks can share the same bytes.
- Bytes are protected while a task is queued or running, and during hash prechecking, downloading, writing, and cross-worker transfer.
- Bytes are reclaimed only after the last reference is released.
Metadata and Restart#
Metadata stays in memory. After a restart, old resource IDs are not restored. The startup scan only removes managed, unreferenced files that are older than the retention time.
An upload directory may be used by only one API instance; a second instance pointed at the same directory fails at startup.
Router#
The Router applies the same retention setting (--retention-seconds):
- Expired routes and source caches are reclaimed synchronously.
- Cleanup of input copies awaiting retry stays in the background.
- Expired resources are not reopened.
Key Source Files#
| File | Role |
|---|---|
mineru/utils/retention.py | Shared retention default, scan interval, env var name, and validation |
mineru/parser/api_server.py | FileStore, JobStore, retention scan loop, create_app() |
mineru/kit/router/ | Router route and source-cache reclamation |
mineru/kit/commands/api_server.py | mineru-kit api-server --retention-seconds |
mineru/cli/api_client.py | Client-side MINERU_TASK_RESULT_TIMEOUT_SECONDS |
| PR #4881 | Made client-side result timeout configurable |