Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 commits
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
@@ -1,4 +1,8 @@
## [Unreleased]
- 수동 PDF DOM 인식 업로드도 이메일 첨부 및 NewsDOM sidecar와 같은 64MiB
bounded transport 계약을 사용합니다. 한도를 넘으면 PDF를 저장하거나
sidecar에 전달하지 않고 `413`을 반환하므로 고객은 파일을 분할해
다시 업로드할 수 있습니다.
- 긴 이메일·첨부 본문을 의미 단위 청크로 임베딩한 뒤 기존 email/attachment 벡터 계약으로 평균화하고, 청크 요청·벡터 누적을 제한된 창으로 처리합니다. OpenAI `text-embedding-3-*`에는 저장 차원(`1536`)을 직접 요청하도록 보강했습니다. 합성 메일 fixture 5건(70청크)과 provider 요청 계약으로 1,536차원 벡터 경로를 검증했으며, 실행 시 선택한 임베딩 제공자에 본문·파싱된 첨부 텍스트를 전송할 수 있습니다. 회사 기밀 데이터는 fixture·commit·PR·log에 포함하지 않습니다.
- EmailDetail 테스트가 지원하지 않는 스레드 병합/분리 버튼을 `textContent`뿐 아니라 `aria-label`과 `title` 접근 가능 이름으로도 검출하도록 바꿔, 아이콘 전용 버튼 회귀를 놓치지 않습니다.

Expand Down
10 changes: 5 additions & 5 deletions backend/api/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
router = APIRouter(prefix="/api/data", tags=["data"])

DATA_VECTOR_DIMENSIONS = 1536
# Upper bound for the binary PDF DOM recognition upload variant. Kept in step
# with the NewsDOM sidecar's own MAX_PARSE_UPLOAD_BYTES (20 MiB): accepting more
# would let a caller stash a pending document the configured sidecar will always
# reject while the base64 copy inflates the database.
_MAX_PDF_DOM_UPLOAD_BYTES = 20 * 1024 * 1024
# Upper bound for the binary PDF DOM recognition upload variant. Keep this in
# step with NewsDOM's MAX_PARSE_UPLOAD_BYTES and the signed email-import
# transport ceiling so large customer PDFs are not accepted by one path and
# rejected by the next.
_MAX_PDF_DOM_UPLOAD_BYTES = 64 * 1024 * 1024
Comment thread
seonghobae marked this conversation as resolved.
Resolved
ATTACHMENT_PARSE_BREAKDOWN_EVIDENCE_SOURCE = (
"email_attachments.content_type, "
"email_attachments.parse_content_type, "
Expand Down
4 changes: 4 additions & 0 deletions backend/tests/test_data_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2898,6 +2898,10 @@ def test_data_pdf_dom_upload_persists_signed_organization_scope(mock_db):
assert stored_document.document_status == "pdf_dom_recognition_pending"


def test_data_pdf_dom_upload_budget_matches_newsdom_transport_contract():
assert data_api._MAX_PDF_DOM_UPLOAD_BYTES == 64 * 1024 * 1024


def test_data_pdf_dom_upload_rejects_invalid_signature_and_size(mock_db, monkeypatch):
token = _signed_session_token(_valid_session_payload())
client, previous_secret, original_overrides = _with_signed_auth(mock_db, token)
Expand Down
61 changes: 61 additions & 0 deletions docs/adr/0005-bounded-pdf-dom-upload-contract.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# ADR-0005: Bounded PDF DOM upload contract

**Status:** Accepted
**Date:** 2026-08-20
**Decision owner:** Naruon maintainers
**Scope:** Signed `POST /api/data/documents/pdf-dom-recognition` uploads

## Context

Naruon email imports and the NewsDOM sidecar are being aligned to a 64MiB
bounded PDF transport budget. The direct Data workspace upload still used an
independent 20MiB limit, so a customer could upload a large PDF through email
but receive an avoidable `413` when using the equivalent manual workflow.

## Decision

Set the direct PDF DOM upload and its pending-payload decoder to 64MiB. Keep the
signed-session boundary, PDF signature validation, one-byte-over-limit read,
base64 persistence contract, and `413` response unchanged. This ADR records
Naruon's consumer-side contract; the NewsDOM sidecar has its own ADR and must
pass its own checks before deployment.

## Consequences

- Email and manual PDF ingestion present the same bounded size expectation to
customers.
- The endpoint can persist more temporary database content, so existing
workspace quotas, background worker limits, and database capacity monitoring
remain required.
- No unbounded upload is introduced, and malformed or non-PDF payloads continue
to fail closed before recognition.

## Alternatives rejected

### Keep a separate 20MiB manual-upload limit

Rejected because it creates a customer-visible workflow inconsistency without a
different safety property after the sidecar contract is raised.

### Remove the upload limit

Rejected because request and database resource use must remain bounded at the
authenticated trust boundary.

## References (APA 7th)

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

RFC 9110 supports retaining an explicit `413 Payload Too Large` response when a
request exceeds the server's permitted content size.

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

The SSDF supports auditable input bounds, regression tests, and operational
controls for untrusted-input boundary changes.

No customer data or source PDF is included; the standards remain linked to their
authoritative publishers.
1 change: 1 addition & 0 deletions docs/adr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ govern implementation.
| [ADR-0002](0002-fitted-topic-artifact-consumption.md) | Conditionally consume only a versioned fitted topic artifact through a fail-closed adapter | Proposed | Target `PLANNED`; runtime `BLOCKED-UPSTREAM` |
| [ADR-0003](0003-separate-topic-measurement-from-agenda-generation.md) | Keep statistical measurement separate from agenda generation | Proposed | Target and future capability `PLANNED`; no implementation authorization |
| [ADR-0004](0004-status-weighted-calendar-conflicts.md) | Evaluate CalDAV VEVENT overlaps by occupying status; cancelled does not occupy | Accepted | `ACCEPTED-NARUON-POLICY`; advisory evaluate API only |
| [ADR-0005](0005-bounded-pdf-dom-upload-contract.md) | Keep direct PDF DOM uploads aligned with the 64MiB NewsDOM transport contract | Accepted | `ACCEPTED-NARUON-POLICY`; sidecar deployment remains separately governed |

The complete topic-intelligence requirements, architecture, contract, UML,
conceptual ERD, security, test, and operability graph is indexed at
Expand Down
24 changes: 24 additions & 0 deletions docs/doctoring/bounded-pdf-dom-upload-contract.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Doctoring record: bounded PDF DOM upload contract

**Observed gap:** The signed Data workspace PDF upload rejected files above
20MiB even though the aligned email-import and NewsDOM transport contracts
accept up to 64MiB.

**Correction:** The upload endpoint and pending-payload decoder now share a
64MiB bound. Signature validation, signed-session authorization, base64 storage,
worker deferral, and `413` rejection remain fail-closed.

**Evidence:** `backend/tests/test_data_api.py` asserts the 64MiB contract and
keeps the over-limit test monkeypatched to a small fixture. The NewsDOM sidecar
alignment is tracked separately in its own ADR and PR.

**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 SP 800-218 Rev. 1, Initial
Public Draft). https://doi.org/10.6028/NIST.SP.800-218r1.ipd

No customer or private reference data was read, and no source PDF is
redistributed.
Loading