Skip to content

feat(D147): convert by reference — pre-signed raw URLs for URL-capable routes - #545

Merged
fazpu merged 1 commit into
mainfrom
feat/convert-from-url
Nov 7, 2026
Merged

fazpu merged 1 commit into
mainfrom
feat/convert-from-url

Conversation

@fazpu

@fazpu fazpu commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

This adds a generic seam so the convert stage can hand a converter a reference instead of the bytes. It follows the owner's decision of 2026-11-07: no transport-driven upload caps. It also covers plan item 2i (OCR/vision providers fetch inputs by URL).

API

from rememberstack.ports import PresignedReadPort        # new, runtime_checkable
class PresignedReadPort(Protocol):
    def presign_get(self, *, key: ObjectKey, ttl_s: int) -> str: ...
MinIOObjectStore.presign_get(key=..., ttl_s=...)        # SigV4 query-signed GET URL, signed locally, no request

from rememberstack.core import UrlConverter             # new, runtime_checkable converter capability
class UrlConverter(Protocol):
    accepts_url: bool
    url_ttl_s: int                                       # lifetime of the URL the worker signs for this route
    name: str; version: str
    def convert_from_url(self, *, url: str, size: int, mime: str, hints: FileHints) -> ConversionResult: ...
  • When the URL path runs: the route is a UrlConverter, the raw store is a PresignedReadPort, and the version's byte_size is known. The worker then signs the raw object's URL and calls convert_from_url; it never reads the bytes.
  • Otherwise: the existing in-process bytes path runs. This is the self-host default, and LocalFSObjectStore can't presign.
  • Unchanged on the URL path: the PDF reading/provider limits are checked first. The existing-representation replay, envelope coherence checks, artifact writes, metering of result.usage_events and error mapping all stay the same. Lane checkpoints don't apply to a URL route.
  • Plan item 2i: an OCR or vision converter can implement convert_from_url and pass the URL to its provider, for example Mistral's document_url. No engine route changes in this PR.
  • Interface difference from the brief: the brief suggested presign_get(bucket, key, ttl). Object stores here are bound to one bucket each, so the bucket is the store's, and the method takes the key and TTL only.

Ingest of an object already in the raw bucket

Nothing exists today. Ingest (UploadIngestor.ingest and ingest_observed) needs the bytes. It derives the content hash, which is lineage identity under D55, and the content-addressed raw key {doc_id}/{sha256}/original{ext} from them. It also needs them for byte-based MIME detection and managed-text metering.

Proposed smallest seam, not built: UploadIngestor.ingest_staged(deployment_id, staged_key, filename, mime, …).

  1. It streams the staged object once from a staging prefix of the raw bucket to hash it. It keeps today's validation unchanged: content-based MIME detection, which reads a PDF's body and EOF and an Office file's ZIP metadata, plus D74 admission and managed-text metering. The existing metadata-only DocumentCatalog.record_upload is the building block for recording the version.
  2. It server-side copies the object to the content-addressed raw key.
  3. It records the version exactly as ingest does, then deletes the staged object.

This needs two ObjectStore additions: a streaming read and copy.

Tests

  • test_two_deployment_contexts_pg.py: B's route is now a URL route over a presigning raw store. B converts by URL with the right size, MIME and file name, and its raw store records zero direct reads. A still converts in-process from bytes.
  • test_minio_store.py: a real boto3 client signs a GET URL locally for fs-raw/doc/hash/original.pdf with X-Amz-Expires=900. A non-positive TTL is refused.
  • The port inventory now has 15 protocols.

Checks

  • ruff, pyright (0), import-linter, unit lane (3121 passed)

  • e0/convert DB tests and the two-database test on PG 19 RC 1

  • CI (green)

  • Codex review: APPROVE (round 1; one PR-body minor fixed)

  • I have read and agree to the RememberStack Contributor License Agreement v1.0.

🤖 Generated with Claude Code

https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm

… routes

The owner decided that no transport may cap uploads. A conversion route
that implements UrlConverter gets a short-lived pre-signed GET URL for the
raw object plus its size and MIME instead of the bytes, whenever the raw
store implements the new PresignedReadPort (MinIOObjectStore.presign_get,
SigV4 query signing, local) and the size is known. Every other route or
store keeps the bytes path. Covers provider fetch by URL for OCR/vision
routes (plan 2i) as the same capability.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
@fazpu

fazpu commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

Codex review round 1 (gpt-6.1-sol, max effort)

VERDICT: APPROVE

No blocker or major findings.

  • Minor — PR-body staged-ingest proposal: content_detection.py:213. “Detect MIME from the first bytes” does not preserve current validation: PDFs require body/EOF checks, and Office formats require ZIP metadata. Simplest fix: correct the proposal’s wording to retain existing MIME validation, D74 admission, and managed metering.

The ingest conclusion is otherwise sound: neither supported ingestor can register an existing raw object without bytes. However, document_catalog.py:77 already provides metadata-only registration through record_upload; it is a reusable building block, not a guarded ingest entry point. Stream/hash/immutable-copy is a reasonable minimal extension.

The implementation checks out: limits and representation replay precede signing; URL usage is metered before envelope validation; error mapping is preserved; bytes fallback and lane checkpoints retain their behavior. Presigning uses the bound bucket, validated key, and SigV4 GET signing. Rule 4 identities and component versions remain unchanged.

Validation: 102 passed, 1 expected failure. An additional URL-route run passed 17 reuse tests, with 33 conversions and zero worker raw reads; the existing Claimify expected failure remained. The dedicated PostgreSQL container was removed. Worktree unchanged.

Disposition (Claude)

The minor is accepted. The staged-ingest proposal in the PR body now keeps today's full validation: content-based MIME detection that reads a PDF's body and EOF and an Office file's ZIP metadata, plus D74 admission and managed-text metering. It names DocumentCatalog.record_upload as the building block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant