Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/ci/unit-paths.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ src/tests/core/test_source_passages.py
src/tests/core/test_source_origins.py
src/tests/core/test_structure_skeleton.py
src/tests/core/test_temporal.py
src/tests/core/test_text_metering.py
src/tests/core/test_metering.py
src/tests/eval/test_s55_hard_forget.py
src/tests/eval/test_s55_selfhost_restore.py
src/tests/model/test_component_version.py
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ jobs:
trap - EXIT
test "$(docker compose --env-file .env exec -T postgres \
psql -U rememberstack -d rememberstack -Atc \
'SELECT version_num FROM alembic_version')" = 'p9_45_0066'
'SELECT version_num FROM alembic_version')" = 'p9_46_0067'
test "$(docker compose --env-file .env exec -T postgres \
psql -U rememberstack -d rememberstack -Atc \
'SELECT count(*) FROM deployments')" = '1'
Expand Down
85 changes: 75 additions & 10 deletions decisions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6387,8 +6387,8 @@ declaration contradicting a recognizable byte class raises a typed client
error. For formats indistinguishable within a class, the filename and
declaration select the D133/D138 registry family and posture, while
legacy OLE needs a declared office subtype. Store the resulting MIME, and use
it consistently for the conversion route, original storage class, and managed
text metering. Every object-store write must provide a class: raw media hot,
it consistently for the conversion route, original storage class, and (through
the route) the managed meter's cost class (D150). Every object-store write must provide a class: raw media hot,
other raw originals cold; query-facing derived objects and P3 snapshots hot;
retry checkpoints and private K transcripts cold. Make the port argument
required so future omissions fail before storage.
Expand Down Expand Up @@ -6877,8 +6877,8 @@ therefore scales with every accepted page. The engine records only the
registry's `scan_page` cost class with that quantity; provider-reported
`pages_processed` is diagnostic evidence, not the billable quantity. The
separate managed cloud copies the same quantity to a `doc-scan` receipt and
does not also charge `doc-text` for that PDF. This receipt mapping is a
required cloud follow-up, not a claim about current cloud behavior.
does not also charge `doc-text` for that PDF. The engine reports that
quantity to a metered deployment's control plane before any OCR call (D150).
Conversion, source mapping and coverage stay in the engine under D60/D61.
The PDF route needs a configured OCR provider and parks under D117 when it is
unavailable. Converter and route changes require versioned re-conversion;
Expand Down Expand Up @@ -7300,8 +7300,8 @@ evaluated separately as a retrieval aid. Measured LoCoMo cost shares (2026-09-14
derived from open gaps. Rule 4 holds: no re-chunking, no chunk re-embedding, unchanged reuse
identities, each later snapshot version pays only for its edit.
- **Readiness** expects the enabled layers' stages (all on: unchanged; facts off: `reconcile` at
either version). `processing_profile_id` is `doc-text-standard-v1`, `doc-text-claims-v1` or
`doc-text-sources-v1`; `profile_complete` certifies every stage the measured profile requires
either version). `processing_profile_id` is `<cost class>-standard-v1`, `-claims-v1` or
`-sources-v1` (D150; for example `doc-text-claims-v1`); `profile_complete` certifies every stage the measured profile requires
(standard: today's predicate), otherwise `failed` / `processing_profile_changed`. Frontiers order
lineages; they are not readiness.
- **Retrieval** reads the served (enabled) layers. A `layers` selection on
Expand Down Expand Up @@ -7475,10 +7475,8 @@ deployment's values into another's work.
unless a content keeps the key and returns whether it did. The caller serializes
registration and discard per key. The declared size must
match, and the uploader chooses the storage class (D51 routing is not applied). A
deployment with managed text metering measures the object exactly as `ingest` does;
that profile accepts only native text up to 10 MB, so a larger object is refused
before it is read into memory, and an accepted one is measured from the spooled copy
and released to the raw store on approval, where it already is.
metered deployment measures the version in the convert stage, as for every ingest
path (D150); registration itself measures nothing.
- *No deployment state on local disk.* `SelfHostSettings.forget_manifest_bucket_name`
keeps D74 hard-forget manifests as immutable objects in that dedicated bucket
(`ObjectStoreForgetManifestStore`, same contract as the local root) instead of
Expand Down Expand Up @@ -7655,3 +7653,70 @@ No ingestion or paid-product reuse identity changes.
See [analysis](plan/analysis/retrieval_work_amplification_20261106.md),
[D91 §4.2](plan/designs/request_path_metering_and_cost_export_design.md#42-request-scope-exact-interface)
and [D142 §8.2](plan/designs/postgres_p1_search_projection_design.md#8-query-and-filtering-contract).


## D150. A metered deployment measures each new version in the convert stage

**Status:** accepted. **Date:** 2026-11-07. **Amends:** the managed text metering of
D139, D143 §4.5 and D147 (in-entry notes).

**Context.** A managed deployment (one with a meter scope) reports how much work each new
source version needs to a commercial control plane, which places holds on the customer's
balance before any work that costs money. Until now the engine measured at ingest, and
only plain UTF-8 text and Markdown up to 10 MB could be measured: every PDF, office
document, HTML page or larger text was refused at the door (`409`/`413`/`422`), and the
accepted bytes were staged in the measurement row until approval. The control plane's
D94 asks instead for one generic receipt per source version — a cost class, an integer
quantity and its unit — with every PDF page billed as one `doc-scan` unit and any other
text a provider-free route reads billed as `doc-text` characters.

**Decision.** Measurement moves from ingest into the convert stage, where the route that
will read the file is known.

- *Which class.* The conversion route decides (`core/metering.py`). The `pdf` route —
every page through OCR (D139) — is `doc-scan`: the page count from the page tree,
taken **before** the OCR call, through the route's `count_pages` (bytes) or
`count_pages_from_url` (a by-URL route, D147). A local reading route (text, Markdown,
code, HTML, EPUB, office documents, email, notebooks, spreadsheets, delimited files,
datasets) is `doc-text`: the whitespace-normalized character count of the
`document.md` it produced. These routes call no model provider, so counting their
output still comes before every paid stage (structure models, embeddings,
extraction). `card` reads nothing and is free: no measurement. Any other route has no
managed cost class, and a metered deployment fails the version
(`rate_class_unavailable`) rather than run provider work it cannot bill.
- *Parking.* After recording the measurement the convert work parks with the defer
reason `admission`, which no claim takes. The meter drain's approval releases it in the
same transaction that records the approval (`release_admission_on`); the park reads the
approval under the lock the approval takes, so a race leaves the work queued, never
stranded. On release, a PDF is OCR'd; a reading route re-chains its stored reading
(replay before regenerate), so nothing is converted twice.
- *Ingest refuses nothing for metering.* Every entry point writes the original to the raw
store at once and enqueues convert, metered or not. Unchanged bytes create no version
and are never measured, so there are no `no_op` receipts.
- *Receipt.* `rememberstack.ingest_measurement.v3`: role `primary`, the Project triple,
stable opaque lineage and source-version IDs, `format_family`, `cost_class`,
`native_quantity`, `unit` (exactly one per class: `normalized_character`, `page`,
`image`, `millisecond`), canonical source bytes, classifier and algorithm versions,
the processing profile and `measured_at`. The terminal receipt
(`rememberstack.document_version_outcome.v3`) is `succeeded` or `failed`. The
processing profile is `<cost class>-<layers>-v1`, the layers being D143's
`standard`, `claims` or `sources`.

**Alternatives.** Measuring office and HTML text at ingest would run every converter twice,
inside the request, and the shared API of a hosted deployment does not convert at all.
Billing a PDF by its text layer or splitting text and scanned pages contradicts D139.
Staging bytes in the outbox cannot hold large files (PostgreSQL's `bytea` stops at 1 GB)
and is moot for objects a client already uploaded directly. Refusing formats at ingest
turned a pricing gap into a capability gap.

**Consequences.** A metered deployment accepts every format its routes read, of any size
the routes handle. One reuse boundary is declared (CLAUDE.md Rule 4): the ingest-time text
classifier stored every metered text as `text/plain` or `text/markdown`; without it a metered
deployment keeps the registry MIME, so CSV, code, configuration and logs take their own D138
routes (`table`, `text` with their postures) like an unmetered one. A lineage whose previous
version was ingested under the old classifier re-converts, re-chunks and re-extracts once at its
next version, accepted because the hosted service relaunches without customer data. The meter outbox drops `staged_content` and the `no_op` disposition
and gains `cost_class`, `unit` and `format_family` (`p9_46_0067`, which refuses to run
while staged originals remain undrained). Unmetered deployments are unaffected. The
control plane must accept the v3 receipt before a deployment runs this release.

3 changes: 2 additions & 1 deletion openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3948,7 +3948,8 @@
"scheduled",
"retry_backoff",
"budget",
"no_route"
"no_route",
"admission"
],
"type": "string"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript-client/contracts/metadata.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"openapiHash": "44060532567a00d7f0bd59eca87660c429a199c2ce19589d4583267b6e3da7f0",
"openapiHash": "f1e84090bd89fa81174d84ac101553d2e25a0e0997fa67b9c7b8b588f3741402",
"publishedBaseline": {
"revision": "dd0c78015099cdd84ab5f3501744d6e225125989",
"version": "0.17.2"
},
"pythonSourceRevision": "2cde3baf7a820164170f2e4b91065056309f68e8",
"sourceHash": "a1c11187ef1d89412ff46decee1eb0582e73660144adb728bdf6393848b7df31"
"sourceHash": "f92cfe0d9da6e54d591038b96ff13699b491c4409825dc9d38b4d6540ef951ba"
}
6 changes: 4 additions & 2 deletions packages/typescript-client/contracts/openapi-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -9017,7 +9017,8 @@
"scheduled",
"retry_backoff",
"budget",
"no_route"
"no_route",
"admission"
],
"type": "string"
},
Expand Down Expand Up @@ -11765,7 +11766,8 @@
"scheduled",
"retry_backoff",
"budget",
"no_route"
"no_route",
"admission"
],
"type": "string"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/typescript-client/contracts/schemas.json
Original file line number Diff line number Diff line change
Expand Up @@ -4446,7 +4446,8 @@
"scheduled",
"retry_backoff",
"budget",
"no_route"
"no_route",
"admission"
],
"type": "string"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/* eslint-disable */
export type OutputPipelineStageReadiness = {
component_version: string;
defer_reason: 'scheduled' | 'retry_backoff' | 'budget' | 'no_route' | null;
defer_reason: 'scheduled' | 'retry_backoff' | 'budget' | 'no_route' | 'admission' | null;
finished_at: string | null;
stage: string;
status: 'missing' | 'pending' | 'running' | 'succeeded' | 'failed' | 'dead_letter' | 'skipped';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/* eslint-disable */
export type PipelineStageReadiness = {
component_version: string;
defer_reason?: 'scheduled' | 'retry_backoff' | 'budget' | 'no_route' | null;
defer_reason?: 'scheduled' | 'retry_backoff' | 'budget' | 'no_route' | 'admission' | null;
finished_at?: string | null;
stage: string;
status: 'missing' | 'pending' | 'running' | 'succeeded' | 'failed' | 'dead_letter' | 'skipped';
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript-client/src/metadata.generated.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* Generated from Python; regenerate with npm run generate. */
export default {
"openapiHash": "44060532567a00d7f0bd59eca87660c429a199c2ce19589d4583267b6e3da7f0",
"openapiHash": "f1e84090bd89fa81174d84ac101553d2e25a0e0997fa67b9c7b8b588f3741402",
"publishedBaseline": {
"revision": "dd0c78015099cdd84ab5f3501744d6e225125989",
"version": "0.17.2"
},
"pythonSourceRevision": "2cde3baf7a820164170f2e4b91065056309f68e8",
"sourceHash": "a1c11187ef1d89412ff46decee1eb0582e73660144adb728bdf6393848b7df31"
"sourceHash": "f92cfe0d9da6e54d591038b96ff13699b491c4409825dc9d38b4d6540ef951ba"
};
3 changes: 2 additions & 1 deletion packages/typescript-client/src/schemas.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4447,7 +4447,8 @@ export default {
"scheduled",
"retry_backoff",
"budget",
"no_route"
"no_route",
"admission"
],
"type": "string"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-client/src/version.generated.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/* Generated package version; regenerate with npm run generate. */
export const version = "0.1.0";
export const pythonCompatibility = {"openapiHash":"44060532567a00d7f0bd59eca87660c429a199c2ce19589d4583267b6e3da7f0","publishedBaseline":{"revision":"dd0c78015099cdd84ab5f3501744d6e225125989","version":"0.17.2"},"pythonSourceRevision":"2cde3baf7a820164170f2e4b91065056309f68e8","sourceHash":"a1c11187ef1d89412ff46decee1eb0582e73660144adb728bdf6393848b7df31"} as const;
export const pythonCompatibility = {"openapiHash":"f1e84090bd89fa81174d84ac101553d2e25a0e0997fa67b9c7b8b588f3741402","publishedBaseline":{"revision":"dd0c78015099cdd84ab5f3501744d6e225125989","version":"0.17.2"},"pythonSourceRevision":"2cde3baf7a820164170f2e4b91065056309f68e8","sourceHash":"f92cfe0d9da6e54d591038b96ff13699b491c4409825dc9d38b4d6540ef951ba"} as const;
7 changes: 4 additions & 3 deletions plan/designs/e0_files_design.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,15 @@ for a family D132 does not cover (for example, an archive); the converter
validates that format. Remaining unrecognized binary is stored as a D138
binary card. The stored
`content_objects.mime` is the decided MIME and drives the D38 route, D51
original class, and managed text metering. Text flavours cannot be settled by
original class, and, through that route, a metered deployment's cost class
(D150). Text flavours cannot be settled by
bytes: once bytes establish text, D133/D138 registry hints select Markdown,
CSV, code, configuration, or plain text and their distinct processing postures.
Textual email, notebooks, RTF, and delimited data keep their registry families;
their converters validate full structure. Recognizable HTML markup retains
`text/html` for its separate converter, and an empty upload
is valid text in the self-host profile (the managed text profile rejects an
empty measured source).
is valid text in every deployment; a metered one bills it at the per-source
minimum (D150).

For legacy OLE office containers, bytes establish the office class and the
declared legacy office MIME selects its subtype. Otherwise an ambiguous OLE
Expand Down
13 changes: 7 additions & 6 deletions plan/designs/processing_layers_design.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,15 @@ whose gap was discharged (§5.3) reports that layer's stages as `skipped`. The c
(`p1`, `live_graph`, `p3`) are unchanged. A version with an open gap in an enabled layer is not
ready until it is processed.

**Metering.** Every model call is metered per stage in `cost_ledger` as today. The managed text
meter stamps the `processing_profile_id` from the layers enabled at measurement time:
**Metering.** Every model call is metered per stage in `cost_ledger` as today. The managed
meter (D150) stamps the `processing_profile_id` from the measured cost class and the layers
enabled at measurement time, `<cost class>-<layers>-v1` (for example `doc-scan-claims-v1`):

| Enabled layers | `processing_profile_id` | Stages its receipt requires |
| Enabled layers | `processing_profile_id` suffix | Stages its receipt requires |
| --- | --- | --- |
| sources, claims, facts | `doc-text-standard-v1` (unchanged) | today's twelve |
| sources, claims | `doc-text-claims-v1` | the eight above (`reconcile` at either version) |
| sources | `doc-text-sources-v1` | the four above |
| sources, claims, facts | `-standard-v1` | today's twelve |
| sources, claims | `-claims-v1` | the eight above (`reconcile` at either version) |
| sources | `-sources-v1` | the four above |

The outcome receipt certifies **the measured profile**, not the current configuration and not a
frontier: `profile_complete` is true only when every stage the measured profile requires succeeded,
Expand Down
12 changes: 7 additions & 5 deletions src/remember/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ class PipelineStageReadiness(BaseModel):
]
finished_at: datetime | None = None
# Why waiting work waits: `no_route` (no converter for the file's type),
# `budget` (the spend budget is exhausted), `scheduled` (due later), or
# `retry_backoff` (a `failed` stage waiting for its next attempt).
defer_reason: Literal["scheduled", "retry_backoff", "budget", "no_route"] | None = (
None
)
# `admission` (a metered deployment's conversion waiting for its control
# plane's approval), `budget` (the spend budget is exhausted), `scheduled`
# (due later), or `retry_backoff` (a `failed` stage waiting for its next
# attempt).
defer_reason: (
Literal["scheduled", "retry_backoff", "budget", "no_route", "admission"] | None
) = None


class VersionPipelineReadiness(BaseModel):
Expand Down
4 changes: 4 additions & 0 deletions src/rememberstack/adapters/converters/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ def provider_limit_bytes(self) -> int | None:
"""The configured OCR input ceiling for pre-converter admission."""
return self._provider_limit_bytes

def count_pages(self, *, content: bytes) -> int:
"""Count the PDF's pages from its page tree, before any OCR call."""
return pdf_page_count(content=content)

def convert_path(self, *, path: Path, mime: str) -> ConversionResult:
""":meth:`convert` for a PDF on local disk, never holding it whole (D147).

Expand Down
10 changes: 5 additions & 5 deletions src/rememberstack/adapters/selfhost/managed_metering.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
import httpx
from pydantic import SecretStr

from rememberstack.model.metering import ManagedDocumentVersionOutcomeV2
from rememberstack.model.metering import ManagedIngestMeasurementV2
from rememberstack.model.metering import ManagedDocumentVersionOutcome
from rememberstack.model.metering import ManagedIngestMeasurement
from rememberstack.model.metering import MeterAdmissionResult
from rememberstack.model.metering import MeterReceiptConflict
from rememberstack.model.metering import MeterReceiptUnauthorized
from rememberstack.model.metering import MeterReceiptUnavailable


class ControlPlaneMeterReceipts:
"""Deliver v2 receipts with a deployment-scoped ``umc_mi_`` bearer."""
"""Deliver v3 receipts with a deployment-scoped ``umc_mi_`` bearer."""

def __init__(
self,
Expand All @@ -30,7 +30,7 @@ def __init__(
self._client = httpx.Client(timeout=timeout_s, transport=transport)

def admit_measurement(
self, *, measurement: ManagedIngestMeasurementV2
self, *, measurement: ManagedIngestMeasurement
) -> MeterAdmissionResult:
"""Post one canonical measurement and validate its stable decision."""
body = self._post(
Expand All @@ -44,7 +44,7 @@ def admit_measurement(
"meter admission returned an invalid decision"
) from error

def acknowledge_outcome(self, *, outcome: ManagedDocumentVersionOutcomeV2) -> None:
def acknowledge_outcome(self, *, outcome: ManagedDocumentVersionOutcome) -> None:
"""Post one terminal receipt and require an explicit acknowledgement."""
body = self._post(
path="/processed-input/outcomes", payload=outcome.model_dump(mode="json")
Expand Down
Loading
Loading