Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
> acceptance are aligned for an actual 0.3.0 publication.

### Changed
- Align `/parse` with Naruon's signed PDF DOM transport at a bounded 64 MiB.
The endpoint still validates authentication before multipart parsing and
rejects the first byte above the ceiling with `413`.

- `/parse`를 언어 선택형 파서로 일반화: MinerU `-l japan`/`-m ocr` 하드코딩을 제거하고 optional form 필드 `language`(MinerU 3.4.4 공식 기본 `ch`, 공개 언어군/alias 검증)와 `mode`(`auto`/`ocr`/`txt`, 기본 `auto`)로 파라미터화. `mode=auto`는 born-digital PDF가 강제 OCR을 건너뛰도록 함. 기존 입력 `language=japan&mode=ocr`는 공식 규약대로 `ch`/`ocr`로 정규화됨.
- OpenAPI 제목/설명, README, `ArticleNode.headline` 문서를 일반 문서용 (section heading) 표현으로 재구성하여 특정 언어/신문 가정을 소비자에게 노출하지 않도록 함. 응답 스키마 필드는 하위 호환을 위해 변경하지 않음.

Expand Down
44 changes: 44 additions & 0 deletions docs/adr/0003-bounded-pdf-upload-transport.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# ADR-0003: Bounded PDF upload transport

**Status:** Accepted
**Date:** 2026-08-21
**Decision owner:** NewsDOM maintainers
**Scope:** Authenticated `POST /parse` upload boundary
**Figma File ID:** N/A — sidecar API contract; no visual surface.

## Context

Naruon's direct PDF DOM upload contract is bounded at 64 MiB, but the owning
NewsDOM sidecar still rejected the same customer PDF above 20 MiB. That
cross-service mismatch made the equivalent email and manual workflows behave
differently and caused a customer-visible failure after the request crossed a
service boundary.

## Decision

Set `MAX_PARSE_UPLOAD_BYTES` to 64 MiB. Keep bearer authentication before
multipart body parsing, the streaming first-byte-over-limit check, PDF
signature validation, temporary-file cleanup, and the `413 Payload Too Large`
response unchanged.

Naruon remains the consumer-side owner of its signed persistence boundary. This
ADR only changes the sidecar's transport ceiling; parser runtime, concurrency,
storage quotas, and deployment capacity remain separate controls.

## Consequences

- Customers can use the same bounded 64 MiB expectation for direct and sidecar
PDF DOM ingestion.
- A larger valid upload can reach the parser, so deployment capacity and parser
timeout controls remain mandatory.
- No unbounded body read is introduced; the endpoint continues to stop on the
first byte above the limit.

## References (APA 7th)

Internet Engineering Task Force. (2022). *HTTP semantics (RFC 9110).* RFC
Editor. https://www.rfc-editor.org/rfc/rfc9110

National Institute of Standards and Technology. (2025). *Secure software
development framework (SSDF) version 1.2* (NIST Special Publication 800-218
Rev. 1, Initial Public Draft). https://doi.org/10.6028/NIST.SP.800-218r1.ipd
1 change: 1 addition & 0 deletions docs/adr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This directory contains Architecture Decision Records (ADRs) for the `newsdom-ap
| ADR | Title | Status | Date |
| --------------------------------------------------------- | --------------------------------------------- | -------- | ---------- |
| [0001](0001-defer-openssf-best-practices-enrollment.md) | Defer OpenSSF Best Practices Enrollment | Accepted | 2026-04-24 |
| [0003](0003-bounded-pdf-upload-transport.md) | Align the bounded PDF transport with Naruon | Accepted | 2026-08-21 |
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Resolved

## ADR Status

Expand Down
21 changes: 21 additions & 0 deletions docs/doctoring/bounded-pdf-upload-transport.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Doctoring record: bounded PDF upload transport

**Observed gap:** The live NewsDOM sidecar accepted only 20 MiB while the
Naruon direct PDF DOM contract allowed 64 MiB, so equivalent customer workflows
were inconsistent.

**Correction:** `MAX_PARSE_UPLOAD_BYTES` and its boundary tests now use 64 MiB.
Authentication remains checked before multipart parsing, and streaming input
still fails closed at the first byte over the bound.

**Evidence:** `tests/test_parse_endpoint.py` covers the 64 MiB contract and the
unknown-size streaming over-limit path. Full coverage and exact-head hosted
checks remain required before merge.

**References (APA 7th):**

- Internet Engineering Task Force. (2022). *HTTP semantics (RFC 9110).* RFC
Editor. https://www.rfc-editor.org/rfc/rfc9110
- National Institute of Standards and Technology. (2025). *Secure software
development framework (SSDF) version 1.2* (NIST Special Publication 800-218
Rev. 1, Initial Public Draft). https://doi.org/10.6028/NIST.SP.800-218r1.ipd
4 changes: 3 additions & 1 deletion src/newsdom_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
from .schemas import HealthResponse, ParseResponse, ReadinessResponse
from .service import parse_pdf

MAX_PARSE_UPLOAD_BYTES = 20 * 1024 * 1024
# Keep the sidecar transport ceiling aligned with Naruon's direct PDF DOM
# upload. The streaming read still rejects the first byte above this bound.
MAX_PARSE_UPLOAD_BYTES = 64 * 1024 * 1024
Comment thread
seonghobae marked this conversation as resolved.
Resolved
MAX_AUTHORIZATION_HEADER_BYTES = MAX_BEARER_HEADER_BYTES
UNSUPPORTED_MEDIA_DETAIL = "Unsupported Media Type"
PAYLOAD_TOO_LARGE_DETAIL = "Payload Too Large"
Expand Down
5 changes: 5 additions & 0 deletions tests/test_parse_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,11 @@ def fake_parse_pdf_bytes(file_path, filename, **kwargs):
assert response.json()["detail"] == "Payload Too Large"


def test_parse_endpoint_budget_matches_naruon_transport_contract():
"""Keep the sidecar upload ceiling aligned with Naruon's PDF transport."""
assert MAX_PARSE_UPLOAD_BYTES == 64 * 1024 * 1024
Comment thread
seonghobae marked this conversation as resolved.
Resolved


@pytest.mark.asyncio
async def test_parse_endpoint_rejects_large_file_without_size_metadata():
upload = _ReadTrackingUpload(b"%PDF-" + (b"x" * MAX_PARSE_UPLOAD_BYTES))
Comment thread
seonghobae marked this conversation as resolved.
Resolved
Expand Down
Loading