Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Ourios

οὔριος — the fair wind that fills a ship’s sail.

Ourios is a log storage and query backend built on Apache Parquet, a Drain-derived online template miner, and Apache DataFusion. It is a work-in-progress; this book is where the design lives.

How this book is organised

  • Architecture — the pillars, hazards, and shared vocabulary. The load-bearing reading for anyone new to the project.
  • Benchmarks — the measurements that would falsify the thesis, stated as goals before any code exists to measure against.
  • RFCs — design decisions in progress. Each RFC is a contract between the people working on Ourios about how a given subsystem will be built; once accepted and implemented, it graduates into an architecture document.
  • Talks — lecture-length explanations of ideas from the RFCs, for when you want the background rather than the specification.

Project status

Greenfield. No code has been written yet; the design artefacts in this book are what exists today. Contributions, RFC discussion, and push-back on the invariants are all welcome — see CLAUDE.md in the repository root for the governing conventions.

Quickstart — single binary

The fastest path from zero to querying logs: one ourios-server process on your machine, local-disk storage, no auth. This is the development/evaluation posture — see Kubernetes (Helm) for the production topology and Authentication before exposing any listener beyond localhost.

1. Get the binary

Download a signed release archive (Linux; Apple-silicon and Intel macOS builds come from cargo build today):

curl -LO https://github.com/jensholdgaard/ourios/releases/latest/download/ourios-server-x86_64-unknown-linux-gnu.tar.xz
tar -xf ourios-server-x86_64-unknown-linux-gnu.tar.xz

Releases from v0.1.1 on attach offline provenance bundles (*.intoto.jsonl) alongside their assets, verifiable without any network round-trip:

gh attestation verify ourios-server-x86_64-unknown-linux-gnu.tar.xz \
  --repo jensholdgaard/ourios \
  --bundle ourios-server-x86_64-unknown-linux-gnu.intoto.jsonl

Or build from source with cargo build --release -p ourios-server.

2. Run it

The binary is one server with three roles — receiver (OTLP ingest), querier (the logs-DSL API), and the background compactor (on by default). Enable the two network roles and point everything at a scratch directory:

mkdir -p /tmp/ourios/data /tmp/ourios/wal

OURIOS_BUCKET_ROOT=/tmp/ourios/data \
OURIOS_WAL_ROOT=/tmp/ourios/wal \
OURIOS_RECEIVER_ENABLED=1 \
OURIOS_RECEIVER_GRPC_ADDR=127.0.0.1:4317 \
OURIOS_RECEIVER_HTTP_ADDR=127.0.0.1:4318 \
OURIOS_QUERIER_ENABLED=1 \
OURIOS_QUERIER_HTTP_ADDR=127.0.0.1:4319 \
./ourios-server

Startup prints the bound addresses and warns once that auth is in open mode:

receiver gRPC listening on 127.0.0.1:4317
receiver HTTP listening on 127.0.0.1:4318
querier HTTP listening on 127.0.0.1:4319

The ports are the OTLP defaults (4317 gRPC, 4318 HTTP) plus 4319 for the query API; the explicit 127.0.0.1 binds keep this quickstart on localhost (the server defaults to 0.0.0.0 for container use). Prefer a config file over env vars? See Configuration--config ourios.yaml makes the file the sole source.

3. Send logs

Ourios speaks OTLP and nothing else — any OpenTelemetry SDK or Collector can ship to it unmodified. The tenant is derived from the service.name resource attribute.

With a Collector, point the OTLP exporter at it:

exporters:
  otlp:
    # host:port is version-proof for the gRPC exporter; recent
    # Collectors also accept scheme'd forms.
    endpoint: localhost:4317
    tls:
      insecure: true

Or hand-deliver one OTLP/JSON record for a first smoke test:

curl -s http://localhost:4318/v1/logs \
  -H 'Content-Type: application/json' \
  -d '{
    "resourceLogs": [{
      "resource": { "attributes": [
        { "key": "service.name", "value": { "stringValue": "checkout" } }
      ]},
      "scopeLogs": [{ "logRecords": [{
        "timeUnixNano": "1751971200000000000",
        "severityNumber": 9,
        "body": { "stringValue": "user 42 logged in" }
      }]}]
    }]
  }'

An empty {} response is the OTLP success shape. The batch is fsynced to the write-ahead log before that acknowledgement — kill the process mid-ingest and acknowledged data survives.

4. Query

POST /v1/query takes the logs DSL as plain text, with the tenant in a header:

curl -s http://localhost:4319/v1/query \
  -H 'X-Ourios-Tenant: checkout' \
  -H 'Content-Type: text/plain' \
  -d 'severity >= info | limit 10'

The response carries the total match count, the returned rows (bodies reconstructed from their mined templates), and scan statistics that show the Parquet pruning at work:

{
  "rows": 1,
  "stats": { "row_groups_scanned": 1, "row_groups_pruned": 0, "bytes_read": 4096 },
  "records": [ {
    "time_unix_nano": 1751971200000000000,
    "severity_number": 9,
    "body": { "kind": "rendered", "line": "user 42 logged in", "reconstruction": "faithful" },
    "...": "..."
  } ]
}

The DSL’s full grammar — field predicates, regex, time ranges, aggregation pipelines like service == "api" and severity >= error | count by template_id — is specified in RFC 0002.

Where to next

  • Docker — the same server from the published image.
  • Kubernetes (Helm) — the production topology on S3-compatible object storage.
  • Authentication — static bearer tokens and OIDC; do this before any listener leaves localhost.
  • The MCP surface (agents querying Ourios over the Model Context Protocol) rides the querier at /mcp — enable with OURIOS_QUERIER_MCP_ENABLED=1 (RFC 0027).

Configuration

Two mutually exclusive sources (RFC 0020 / RFC 0004):

  • A YAML file via --config <path> — the file is then the sole source; the environment participates only through ${env:NAME} substitution inside it (with ${env:NAME:-default} defaults, $$ escaping — the OTel Collector data model).
  • OURIOS_* environment variables when no --config is given — the container/dev posture.

Parsing is strict: a malformed value is a startup error in either mode, and in config-file mode an unknown YAML key is rejected too (unrecognised OURIOS_*-lookalike env vars are simply not read — there is no unknown-key concept in the environment).

A complete file example

storage:
  # local (a filesystem directory as the store — dev/single-node) or
  # s3 (object storage as the source of truth — production; RFC 0019).
  backend: s3
  s3:
    bucket: ourios-logs
    region: eu-central-1
    # Any S3-compatible provider: AWS, MinIO, R2, Ceph/RGW, …
    endpoint: https://s3.eu-central-1.amazonaws.com
    # Secret hygiene is enforced: credentials MUST be ${env:…}
    # references — inline literals fail startup.
    access_key_id: ${env:OURIOS_S3_ACCESS_KEY_ID}
    secret_access_key: ${env:OURIOS_S3_SECRET_ACCESS_KEY}
  # RFC 0022: per-key promoted attribute columns (service.name is
  # always promoted). Each key costs bytes on every row — opt in
  # deliberately.
  promoted_attributes:
    resource: [k8s.namespace.name]
    log: [http.request.method, http.route]

receiver:
  enabled: true
  grpc_addr: 0.0.0.0:4317
  http_addr: 0.0.0.0:4318
  # The WAL stays on local disk by design, S3 or not (RFC 0019).
  wal_root: /var/lib/ourios/wal

querier:
  enabled: true
  http_addr: 0.0.0.0:4319
  default_window_secs: 3600
  mcp:
    enabled: false

auth:
  # See the Authentication guide. Omit the whole section for open
  # mode (development only — the server warns once at startup).
  tokens:
    - name: edge-collector
      token: ${env:OURIOS_EDGE_TOKEN}
      tenants: [checkout, payments]
  oidc:
    issuer: https://dex.example.com
    audience: ourios-collector
    tenant_claim: groups
    name_claim: name

Environment variables (no --config)

VariableMeaning
OURIOS_STORAGE_BACKENDlocal (default) or s3
OURIOS_BUCKET_ROOTlocal-backend store root
OURIOS_S3_BUCKET / OURIOS_S3_REGION / OURIOS_S3_ENDPOINT / OURIOS_S3_PREFIXS3 addressing
OURIOS_S3_ACCESS_KEY_ID / OURIOS_S3_SECRET_ACCESS_KEY / OURIOS_S3_SESSION_TOKENS3 credentials
OURIOS_RECEIVER_ENABLED / OURIOS_RECEIVER_GRPC_ADDR / OURIOS_RECEIVER_HTTP_ADDRreceiver role
OURIOS_WAL_ROOTWAL directory (receiver)
OURIOS_QUERIER_ENABLED / OURIOS_QUERIER_HTTP_ADDR / OURIOS_QUERIER_DEFAULT_WINDOW_SECSquerier role
OURIOS_QUERIER_MCP_ENABLEDthe /mcp agent surface (RFC 0027)
OURIOS_COMPACTION_ENABLED / OURIOS_COMPACTION_INTERVAL_SECSbackground compactor

Auth configuration is file-only — there are deliberately no OURIOS_AUTH_* variables; token values reach the file through ${env:…} references.

Docker

The release pipeline publishes a multi-arch image (amd64 + arm64) to GHCR, cosign-signed keyless:

docker pull ghcr.io/jensholdgaard/ourios:0.1.1

Verify the signature before trusting it — the identity is pinned to the exact release tag, so substitute both occurrences of the version when verifying another release (SECURITY.md is the authoritative verification reference):

cosign verify \
  --certificate-identity 'https://github.com/jensholdgaard/ourios/.github/workflows/image.yml@refs/tags/v0.1.1' \
  --certificate-oidc-issuer 'https://token.actions.githubusercontent.com' \
  ghcr.io/jensholdgaard/ourios:0.1.1

Image variants

Every release publishes three signed multi-arch images from the same source:

  • default (:<version>) — glibc binary on distroless/cc.
  • -static (:<version>-static) — static musl binary on distroless/static: no libc, libgcc, or libssl in the image, so the OS-package vulnerability surface scanners report is ~empty. Pick this one for the strictest supply-chain posture with the operational niceties (CA bundle, tzdata, nonroot passwd entry) kept.
  • -scratch (:<version>-scratch) — the same musl binary on bare scratch, plus only the CA bundle TLS needs. Nothing else in the filesystem: the absolute minimum attack surface, but also zero operational conveniences — no tzdata, no passwd entry, and CA-bundle updates arrive only with Ourios releases rather than base-image bumps.

All three run identically (same flags, ports, and config surface below).

Run

Same binary, same configuration surface as the quickstart — env vars, or a mounted config file:

docker run --rm \
  -p 4317:4317 -p 4318:4318 -p 4319:4319 \
  -v ourios-data:/var/lib/ourios \
  -e OURIOS_BUCKET_ROOT=/var/lib/ourios/data \
  -e OURIOS_WAL_ROOT=/var/lib/ourios/wal \
  -e OURIOS_RECEIVER_ENABLED=1 \
  -e OURIOS_QUERIER_ENABLED=1 \
  ghcr.io/jensholdgaard/ourios:0.1.1

With a config file instead (the production posture — auth lives in the file):

docker run --rm \
  -p 4317:4317 -p 4318:4318 -p 4319:4319 \
  -v ourios-data:/var/lib/ourios \
  -v "$PWD/ourios.yaml:/etc/ourios/ourios.yaml:ro" \
  -e OURIOS_EDGE_TOKEN \
  -e OURIOS_S3_ACCESS_KEY_ID -e OURIOS_S3_SECRET_ACCESS_KEY \
  ghcr.io/jensholdgaard/ourios:0.1.1 \
  --config /etc/ourios/ourios.yaml

Secrets stay out of the file via ${env:…} references — pass through every variable your file references (the example forwards the auth token and, for an S3-backend file like the Configuration example, the store credentials; a local-backend file needs neither OURIOS_S3_* variable). The server shuts down gracefully on SIGTERM — docker stop flushes the ingest pipeline before exit.

Local note: any OCI runtime works — with containerd, nerdctl run/nerdctl compose take the same arguments.

Kubernetes (Helm)

The chart at deploy/helm/ourios deploys the production topology: three workloads, one binary, backed by S3-compatible object storage (AWS S3, MinIO, R2, Ceph/RGW, … — RFC 0019):

  • receiver — a StatefulSet with a per-replica WAL PVC (the WAL is local by design; only data + audit go to S3);
  • querier — a stateless Deployment, scales independently;
  • compactor — a singleton Deployment.

Install

kubectl create secret generic ourios-s3 \
  --from-literal=OURIOS_S3_ACCESS_KEY_ID=… \
  --from-literal=OURIOS_S3_SECRET_ACCESS_KEY=…

helm install ourios deploy/helm/ourios \
  --set storage.backend=s3 \
  --set storage.s3.bucket=ourios-logs \
  --set storage.s3.region=eu-central-1 \
  --set storage.s3.endpoint=https://s3.eu-central-1.amazonaws.com \
  --set storage.s3.existingSecret=ourios-s3

(On AWS EKS, IRSA replaces the secret — leave existingSecret empty and annotate the service account with the role ARN; the two modes are mutually exclusive.)

The chart renders an RFC 0020 config file into a ConfigMap; credentials reach it as ${env:…} references resolved from the secret — never inline.

The chart’s README is the authoritative reference: full values.yaml documentation, the topology diagram, local-development (MinIO) recipes, and sizing notes. This page stays a pointer so the two never drift.

Sending and querying

In-cluster, point Collectors at the receiver Service (ourios-receiver:4317) and query the querier Service on 4319 — fronted by whatever ingress/TLS termination your cluster standardises on. Configure authentication before exposing either beyond the cluster boundary.

Authentication

Three postures, one enforcement path (RFC 0026 + RFC 0029). Whatever authenticates a request, the result is the same (name, tenants) binding: ingest batches must fall entirely inside the binding’s tenant set (whole-batch 403 otherwise, before the WAL), queries and MCP tool calls enforce the same set, and the name labels the audit trail and metrics. Rejections are deliberately undifferentiated — one 401 shape, no probing oracle.

Open mode (development only)

No auth section at all. Every request passes unbound; the server warns once at startup. Never expose an open-mode listener beyond localhost or a trusted network segment.

Static bearer tokens

The Collector-friendly baseline — static credentials in the config file, values injected via ${env:…} (inline literals fail startup):

auth:
  tokens:
    - name: edge-collector
      token: ${env:OURIOS_EDGE_TOKEN}
      tenants: [checkout, payments]   # or ["*"] for all tenants

Senders attach Authorization: Bearer <token>; with a Collector:

extensions:
  bearertokenauth:
    token: ${env:OURIOS_EDGE_TOKEN}
exporters:
  otlp:
    endpoint: ourios.example.com:4317   # TLS by default; gRPC host:port
    auth:
      authenticator: bearertokenauth

Comparison is constant-time; token values never appear in logs, errors, metrics, or audit events — only the name does.

OIDC (JWTs from an identity provider)

Adds standards-based machine identity in front of the same enforcement — any conforming issuer works; Dex (CNCF) is the recommended lightweight deployment and the one the acceptance suite runs against:

auth:
  oidc:
    issuer: https://dex.example.com
    audience: ourios-collector        # your client id
    tenant_claim: groups              # a string-list claim → the tenant set
    name_claim: name                  # the audit/metric label

Verification is local: the issuer is contacted once at startup (discovery + JWKS — an unreachable issuer fails startup, by design) and again only when an unseen key id appears (rotation). Signatures verify against the asymmetric allow-list only — RS256/384/512, PS256/384/512, ES256/384; alg: none and HMAC never verify.

Machine senders use the OAuth2 client-credentials flow — with a Collector this is zero custom code:

extensions:
  oauth2client:
    client_id: ourios-collector
    client_secret: ${env:DEX_CLIENT_SECRET}
    token_url: https://dex.example.com/token
    scopes: [openid, profile, groups]
exporters:
  otlp:
    endpoint: ourios.example.com:4317   # TLS by default; gRPC host:port
    auth:
      authenticator: oauth2client

Both halves coexist in one config — a static-token Collector and JWT-bearing senders authenticate side by side, each confined to its own tenant binding.

TLS

The listeners speak plaintext today; terminate TLS in front (ingress, service mesh, or an L4 proxy) — bearer tokens over plaintext are not auth. Native listener TLS is tracked on the auth epic.

OTLP log format — what crosses the wire vs. what Ourios consumes today

Status: investigation finding. Drafted 2026-05-13 to answer “is our template miner targeting the actual OTLP shape, or a made-up one?” Conclusion: the latter. This doc surfaces the gap and lists the RFC patches it implies; it does not change code.

The Ourios glossary commits the project’s ingest contract to OTLP over gRPC and HTTP — “we do not invent our own format” (docs/glossary.md, entry OTLP). The template-miner RFC (docs/rfcs/0001-template-miner.md) does not carry through on that commitment: §6.1’s record schema has eight fields, none of which exist on the OTLP wire, and the ingest signature today is MinerCluster::ingest(tenant_id, raw: &str) — a flat text line, not a structured LogRecord. This document closes the loop.

The first audience for this finding is the maintainer; the second is the RFC 0001 amendment PR and the future RFC 0003 (OTLP receiver) it implies.


1. What OTLP actually carries

The wire-level definition lives in opentelemetry-proto/opentelemetry/proto/logs/v1/logs.proto and the spec at opentelemetry.io/docs/specs/otel/logs/data-model. The relevant message hierarchy is:

LogsData
└── ResourceLogs[]
    ├── resource: Resource           ← Resource.attributes carries service.name, host.*, etc.
    ├── schema_url: string
    └── scope_logs: ScopeLogs[]
        ├── scope: InstrumentationScope   ← name, version, attributes
        ├── schema_url: string
        └── log_records: LogRecord[]

A single LogRecord carries:

FieldTypeNotes
time_unix_nanofixed64Event time at the source; 0 = unknown
observed_time_unix_nanofixed64When the collector saw it; required once observed
severity_numberenumNormalised TRACE..FATAL with sub-levels (1–24)
severity_textstringSource’s original level string
bodyAnyValueThe log content. Not necessarily a string.
attributesKeyValue[]Per-occurrence structured context
dropped_attributes_countuint32Truncation indicator
flagsfixed32Lower 8 bits = W3C trace flags
trace_idbytes (16)Trace correlation
span_idbytes (8)Span correlation
event_namestringIdentifier for structured-event records

Plus, inherited from the parent containers: the Resource attributes (the unit of “where did this come from” — typically service.name, host.name, k8s.pod.uid, etc.) and the InstrumentationScope name/version (which library/module emitted this record).

AnyValue is a oneof of: string_value, bool_value, int_value, double_value, array_value (recursive), kvlist_value (recursive map of strings → AnyValue), and bytes_value. The spec is explicit about the structured case:

Body MUST support AnyValue to preserve the semantics of structured logs emitted by the applications.

So a real OTLP emitter is at liberty to send a LogRecord whose body is, for example, {"msg": "user logged in", "user_id": 42, "from_ip": "10.0.0.1"} as a kvlist_value — with the parameters already structured out, not embedded in a free-text string.


2. What Ourios consumes today

MinerCluster::ingest(tenant_id: &TenantId, raw: &str) -> u64 (in crates/ourios-miner/src/cluster.rs). The pipeline:

  1. tokenize(raw) splits on Unicode whitespace (crates/ourios-miner/src/tokenize.rs).
  2. mask(tokens) runs UUID / IPv4 / NUM rules over the resulting &str slice (crates/ourios-miner/src/mask.rs).
  3. descend + leaf lookup attaches to or creates a template (crates/ourios-miner/src/tree.rs).

The Parquet record promised by RFC 0001 §6.1 carries:

tenant_id, template_id, template_version, params,
separators, body?, confidence, lossy_flag

That’s the entire data model. Zero fields from the OTLP wire are reflected in the record.


3. The gaps

3.1 Severity is missing from the record (and from the template key)

severity_number is one of the most common operator query filters: “show me all ERROR-or-worse from service.name = api in the last hour.” Today the miner has no severity field.

Worse: the template key doesn’t include severity. A line emitted at INFO and the same line emitted at ERROR would currently collapse to one template_id. That’s a §3.1-class problem (“no silent template merges”) in disguise — two semantically distinct events sharing one id.

3.2 Timestamps are missing from the record

time_unix_nano and observed_time_unix_nano carry the data that the B1 thesis gate (“predicate-pushdown query latency on time/template/tenant filters”) explicitly measures. Without a time column we cannot run B1 at all.

Today there is no time field on the record. The Parquet writer PR (Phase 2 in docs/roadmap.md) cannot land without RFC 0001 §6.1 amending to add at least time_unix_nano.

3.3 Resource and scope are missing

Resource.attributes is OTLP’s “who sent this” partition key — in real deployments, service.name is the natural partition for template trees (it’s effectively the per-service template namespace). Today our tenant_id is operator-supplied and has no declared mapping from OTLP fields. We need to decide: tenant_id := resource.attributes["service.name"]? Or some configured mapping rule? RFC 0003 (OTLP receiver) is the place for this; RFC 0001 just needs to make resource_attributes a record column so the decision can land.

InstrumentationScope.name distinguishes the same body text emitted from different code paths in the same service. Likely also belongs in the template key — myapp.login and myapp.checkout emitting "request received" are different events.

3.4 Attributes carry the structured params we try to mine

In a structured-logging world, the values our mask() rules try to extract from text (NUMs, IPs, UUIDs) are typically already typed and separated by the SDK as Attributes. A modern emitter sends:

  • body = "user logged in"
  • attributes = {"user.id": 42, "client.address": "10.0.0.1"}

Not:

  • body = "user 42 logged in from 10.0.0.1"
  • attributes = {}

Our miner gets the second form and does work to reconstruct roughly what the first form already had. Worse, given the first form, we currently mine "user logged in" as a flat fixed template and lose the typed attribute values entirely — they’d never reach the Parquet record. The operator query “show me all logins from client.address = 10.0.0.1” returns nothing.

The implication for the miner is significant: the params slot on the record cannot be only “things mask() extracted from the body string.” It must also carry the OTLP attributes of the record — either as a sibling column (operator-queryable) or folded into the existing params shape (more complex).

3.5 Body is not always a string

AnyValue body. Today ingest(raw: &str) cannot accept a structured body at all. Three plausible paths:

  1. Render-to-string at the receiver. Convert structured Body to a canonical JSON-ish string before handing to the miner. Loses the structure but preserves the existing miner shape. Risk: §3.3 (“bit-identical body reconstruction”) requires the rendered form to round-trip; canonicalising arbitrary AnyValue trees is non-trivial.
  2. Treat structured Body as not-mineable. Store it verbatim in the body? column with lossy_flag = false (it’s an explicit structured value, not a lossy reconstruction); the miner emits a template_id of “structured body” and the query path knows to read body? directly. Simpler, gives up templating for those records.
  3. Mine inner string fields. If body is a kvlist_value with a "msg" field, mine msg as the line. Pragmatic but ad-hoc; the field name is convention not spec.

Path (2) is the cleanest minimum; path (1) is the eventual ambition; path (3) is a configurable convenience layer. All three need an explicit spec decision.

3.6 Trace correlation is missing

trace_id, span_id, flags are how operators correlate logs to spans in the same trace. Real operators use this constantly. Today: no fields, no support. Add as record columns.

3.7 The ingest signature itself is wrong

ingest(tenant_id: &TenantId, raw: &str) cannot accept any of the above. The eventual signature is roughly:

#![allow(unused)]
fn main() {
fn ingest(&mut self, record: &OtlpLogRecord) -> u64
}

…where OtlpLogRecord is a struct that mirrors the OTLP wire shape (or borrows directly from a tonic-decoded protobuf message). This is a breaking change to the cluster’s public surface and is rightly the territory of RFC 0001’s amendment.


4. Implications

4.1 RFC 0001 §6.1 needs amendment

The minimum schema additions to make the record OTLP-faithful:

AddTypeRationale
time_unix_nanou64B1 gate; required column
observed_time_unix_nanoOption<u64>OTLP has both
severity_numberu8Operator queries; template key
severity_textOption<String>Source’s original level
attributesKeyValue[]The structured params we currently miss
resource_attributesKeyValue[]service.name etc.
scope_nameOption<String>Template-key candidate
scope_versionOption<String>Diagnostic / drift detection
trace_idOption<[u8; 16]>Trace correlation
span_idOption<[u8; 8]>Trace correlation
flagsu32W3C trace flags
event_nameOption<String>Structured-event records

Plus an explicit decision on:

  • Template key. Is the leaf identified by (masked_body_tokens) alone, or by some tuple of (severity_number, scope_name, masked_body_tokens)?
  • body representation. AnyValue → what does the miner see? (Per §3.5 above.)
  • tenant_id derivation. What OTLP field(s) define it?

4.2 RFC 0001 §6.2 (algorithm) needs a tokenize/mask amendment

tokenize + mask are designed for text. Once Body is AnyValue, the front of the pipeline branches: structured Body skips the tokenize/mask path entirely (or uses path (3) above on a configured field). The algorithm spec needs to acknowledge this fork.

4.3 RFC 0003 (OTLP receiver) becomes a prerequisite, not a follow-up

Today’s roadmap.md §5 lists the OTLP receiver as “first post-MVP shipping PR series.” That sequencing assumes the receiver is just the wire-decode-and-forward layer for an already-OTel-aligned record schema. With the gaps in §3 above, the receiver and the schema co-evolve: you cannot define the record without knowing what the receiver hands you, and you cannot define the receiver without knowing what the record expects. RFC 0003 should be drafted alongside the RFC 0001 amendment, not after it.

4.4 The Phase-3 corpus + bench need an OTLP-shaped corpus

The corpus runner (ourios-bench, Phase 3) cannot validly exercise the C2 thesis gate (template-count convergence) on flat-text input if the production input is OTLP. The corpus input must itself be OTLP-shaped — either a pre-recorded batch of LogsData protobuf, or a generator that emits realistic LogRecords including the structured-Body and attributes-bearing variants.

4.5 The current cluster’s behaviour is not fully wrong, just narrow

Plain-text traditional logs (Syslog, Log4j, slog with default text formatter) produce LogRecords with string Body and near-empty Attributes. The current miner handles those records correctly modulo the missing timestamp / severity / resource columns. So the current code is not throw-away; it’s the text arm of a fork that the OTLP-aware ingest will need.


5. Recommendation

Three follow-ups, in order:

  1. Patch RFC 0001 §6.1 + §6.2 (a meta:-shaped change to the record schema and the algorithm spec). Land the new columns, the template-key decision, and the AnyValue handling fork. Do this first because the rest of the work depends on it.

  2. Draft RFC 0003 — OTLP receiver. Cover (a) the wire-decode layer (tonic for gRPC, axum/hyper for HTTP/protobuf, against the official opentelemetry-proto crate); (b) the OtlpLogRecord → MinerCluster mapping; (c) the tenant_id derivation rule; (d) the WAL-before-ack sequencing under the new structured shape (§3.4); (e) build-vs-depend evaluation (tonic + hand-roll vs. embedding the rotel Rust collector vs. running the OTel Collector out-of-process and forwarding).

  3. Patch the miner crates to consume the new record shape and route Body through the AnyValue fork. Update the roadmap to reflect that OTel-native ingest is no longer strictly post-MVP for the C2 gate’s validity.

The user-visible effect: the eventual benchmarks measure what an actual OTel deployment would experience, not a flat-text caricature of it. The thesis claim of “Parquet + template mining

  • DataFusion is the right stack for OTel logs“ becomes testable in the form an operator would actually evaluate it.

6. References

Last updated: 2026-05-13.

Hazards

Referenced from CLAUDE.md §4 (“Before any change to the hot path, re-read docs/hazards.md”) and §10 (“When in doubt: 1. Read docs/hazards.md”). This document is the load-bearing reading for any hot-path reviewer. Each hazard names a specific failure mode, the mitigation we have committed to, the detection signal, and the rule for when a deviation is a tuning question vs. an architectural one.

How to use this document

  • Before opening a PR that touches any subsystem named in a hazard section: re-read that section. The PR description must explicitly say which hazard it touches and how the change preserves the mitigation.
  • In review: if a hazard is touched and not addressed in the PR description, that is a block, not a nit.
  • In production: the named detection signals are the alerts that cannot be silenced without an RFC. They exist precisely so the failure mode is visible before it corrupts data.

Hazards map onto invariants in CLAUDE.md §3. Hazards describe what goes wrong; invariants describe what we promised. They are two faces of the same constraint.


H1 — Template miner correctness

Failure mode. The miner merges semantically-distinct templates because they share token structure. The canonical horror: user logged in <*> and user logged out <*> differ in one token; below a permissive threshold they merge into user logged <*> <*>. A query for the login event silently returns logout rows. The operator never knows.

Mitigation.

  • Default similarity threshold ≥ 0.7 (strict).
  • Lowering the threshold below 0.7 requires an RFC, not a config change.
  • Three-zone confidence model: clean match (≥ threshold) / lossy match (floor ≤ x < threshold, retain body — reconstruction still succeeds, so lossy_flag is not set) / parse failure (< floor, retain body, increment counter). lossy_flag is reserved for the H7 case (genuine tokenizer / preprocessing failure where reconstruct(record) != ingested_bytes is possible); it is not a low-confidence signal. See docs/rfcs/0001-template-miner.md §6.6 for the precise definition.
  • Every template-widening event is audited: the audit record names the old template, the new template, tenant, timestamp, and reason.

Detection. All metrics carry tenant_id; some carry service.

  • merges_total counter: spike on stable input → service-version change or threshold drift.
  • body_retention_ratio gauge: rising → input shifted or threshold is too tight.
  • confidence_p01 histogram tail: collapsing → many matches are barely passing; threshold should be revisited.
  • parse_failures_total: nonzero is genuine failure, not lossy.

Escalation. A spike on one tenant is a tuning question (masking rules, per-tenant threshold). A spike across many tenants on a stable corpus is a policy question — RFC.

See also. CLAUDE.md §3.1; docs/rfcs/0001-template-miner.md §§6.3–6.4; docs/benchmarks.md C2 (template count convergence), C3 (merge rate).


H2 — Parameter cardinality blowup

Failure mode. A params slot captures something it should not — an entire stack trace, a base64 payload, a request body, a megabyte JSON blob. Parquet’s dictionary encoding for that column collapses (every value distinct). File sizes explode. Query latency on that column degrades by orders of magnitude. The backend’s compression claim evaporates for that workload.

Mitigation.

  • Per-parameter byte limit, default 256 B, ceiling 1 KiB — raising the ceiling requires an RFC.
  • Overflow spills the original value into the body column; the params slot is replaced by a truncation marker (length + hash, no original payload).
  • Counter increments on overflow.

Detection.

  • params_overflow_ratio per service: alert when > 1 % of lines for any one service hit overflow.
  • Parquet column-size variance: a column whose dictionary efficiency drops sharply between compactions usually means a new overflow pattern.

Escalation. Service-specific spike → masking rule that pre-redacts the offending field. Broad spike → revisit the limit (still ≤ 1 KiB). Anyone proposing > 1 KiB → RFC.

See also. CLAUDE.md §3.2; RFC 0001 §6.5; benchmarks C4.


H3 — WAL durability vs. latency

Failure mode. The ingester acknowledges an OTLP batch before the write is durably persisted. The ingester then crashes (process kill, host failure, container reschedule). The producer believes the data was accepted; we have lost data we promised to keep.

Mitigation.

  • An ack is emitted only after fsync (or equivalent durability primitive) on the WAL.
  • Batched fsync with an explicit operator-tunable knob: default flush every 100 ms or when the current segment fills, whichever first.
  • Crash-recovery test is part of CI: SIGKILL the ingester mid-batch, restart, assert no acknowledged data is missing. Test runs on every PR; failure blocks merge.
  • Replication, when added, is in addition to the WAL, not a replacement.

Detection.

  • ingest_ack_latency_p99: rising trend usually means fsync is the bottleneck.
  • wal_unflushed_bytes: bytes acked but not yet on durable storage — must always be bounded.
  • CI crash-recovery test: any failure is critical, regardless of flake history.

Escalation. Fsync latency rising → tune batch size or move to faster storage. Ack-without-fsync ever observed in code review → P0 bug, hotfix path.

See also. CLAUDE.md §3.4; RFC 0008 (WAL design); benchmark D2 (compaction keeps up).


H4 — The small-file problem

Failure mode. WAL segments get rotated and flushed to Parquet too eagerly. The result is thousands of small files per tenant per day. Object-storage LIST calls dominate query planning time. Cold cache hits are murderous. Operators see “query took 12 s on 4 GB of logs” and lose faith in the backend.

Mitigation.

  • Target row-group size 128 MB – 1 GB inside each Parquet file.
  • Target file size 256 MB – 2 GB post-compaction.
  • Background compaction job per tenant; cadence is a tunable.
  • Compaction is required to keep the WAL backlog bounded under sustained ingest (D2).

Detection.

  • File-size histogram per tenant: fewer than 5 % of files below 128 MiB at steady state.
  • File count vs. data volume: file count must grow sub-linearly with bytes ingested.

Escalation. Skewed file-size distribution on a single tenant → compaction tuning. Sustained small-file emission across the cluster → ingest-scaling block, RFC.

See also. CLAUDE.md §4 hazard 4; benchmarks D3.


H5 — Template schema evolution across deploys

Failure mode. A service ships a new version. Log format changes — a new field, a renamed token, reordered words. The template tree built from last month’s logs no longer matches the new format cleanly. Queries against template_id = X start returning incomplete results because some rows are now stored under template_id = X'. The operator sees a 30 % drop in event volume and misdiagnoses it as an outage.

Mitigation.

  • Templates are versioned: a template’s internal representation can change; the logical identity persists across versions.
  • Explicit alias mechanism: template_id.resolves_to(X) in the DSL resolves a query across all aliases of X.
  • Drift detection is a first-class query — operators can ask “what templates drifted in the last 24 h?” and get a list.
  • A new template_version emits an audit event, just like a merge.

Detection.

  • Spike in distinct template count immediately after a deploy → expected; investigate only if it persists past the deploy window.
  • Diff between template_id = X and template_id.resolves_to(X) result counts → measures alias coverage.
  • Audit event volume: drift events should correlate with deploy cadence, not appear randomly.

Escalation. Alias graph becomes a tangle (templates with > N aliases or cycles) → revisit alias semantics, RFC. Drift correlated with deploys → expected; not an alert.

See also. CLAUDE.md §3.5; RFC 0001 §6.7.


H6 — Query DSL vs. DataFusion SQL surface

Failure mode. A user-facing query surface accidentally exposes DataFusion specifics — a SQL keyword leaks into an error message, a planner hint becomes documented, a join type that doesn’t make sense in a logs context becomes reachable. We then cannot upgrade DataFusion or change the planner without breaking saved user queries and dashboards. The DSL has become a contract we never intended to sign.

Mitigation.

  • The DSL is a separately specified layer (docs/rfcs/0002).
  • All DSL constructs compile to DataFusion LogicalPlan, never to SQL strings. SQL never appears in any user-visible output.
  • No SQL escape hatch by default. If one is added later, it ships under a separate RFC, sandboxed, opt-in, and tenant-gated.
  • DSL evolution is a written semver contract with users; major versions ship with a deprecation window.

Detection.

  • PR review: any test or error message containing the substring “DataFusion” or referring to a DataFusion type by name in a user-facing surface is a block.
  • Any code path that constructs SQL strings from user input is a block.
  • User report: “this query worked yesterday after the upgrade” triggers a regression review.

Escalation. Leak found in user-facing surface → block + hotfix. Recurring temptation in implementation → tighten the API boundary, move shared helpers behind a non-exported module.

See also. CLAUDE.md §4 hazard 6; RFC 0002.


H7 — Bit-identical body reconstruction

Failure mode. An operator opens the UI and asks “show me what was actually logged.” We render the row from template + params and produce a string that drops a space, a quote, a separator, or a trailing newline. The operator chases a bug that doesn’t exist — or, worse, fails to chase a bug that does, because the rendered line looked normal.

Mitigation.

  • The miner either captures inter-token whitespace and separators or it sets lossy_flag = true on the row. There is no third option.
  • Reconstruction is a property test against the testdata corpus: for every non-lossy row, reconstruct(record) == ingested_bytes exactly. Property failure blocks merge.
  • The reader honours lossy_flag. The UI surfaces lossy rows with an explicit warning (“this row’s body cannot be exactly reconstructed”) rather than rendering them.
  • Tenants may opt into default-on body retention at a storage cost.

Detection.

  • Reconstruction property test (CI): zero failures, ever, on the committed corpus.
  • body_retention_ratio gauge: a sudden rise indicates input distribution change OR a regression in whitespace capture.
  • User complaint of “the rendered log does not match what we sent” → reproduce, add to corpus, fix.

Escalation. Ever fails on a real-world corpus → block + hotfix. Whitespace-capture state machine becomes a complexity sink → simplify by retaining more bodies; the storage cost is real but acceptable, lying to the user is not.

See also. CLAUDE.md §3.3; RFC 0001 §6.6; benchmarks C1.


H8 — Replication-induced dedup under clock drift

Forward-looking hazard. Ourios does not currently replicate at ingest, so this hazard is dormant. It is recorded here so that any future RFC proposing replication starts with the failure mode already understood.

Failure mode. A multi-ingester replication design quietly introduces a storage multiplier if dedup is keyed on filename and a time window. Even sub-second clock drift between replicas causes the dedup pass to miss duplicates: each replica writes “the same” record under a slightly different filename or window, the dedup miss is invisible to any single replica’s logs, and the user pays for redundancy they thought they had bought once. A widely-deployed log backend was found in 2026 to be carrying a ~2.3× storage multiplier from exactly this failure mode, motivating a full re-architecture of its durability layer.

Mitigation.

  • Currently: not a concern. Ourios does not replicate at ingest. Per CLAUDE.md §3.4, durability is per-ingester fsync on the WAL; per §3.6, object storage is the long-term truth. Replication, if introduced later, is “in addition to the WAL, not instead of it.”
  • When replication is proposed: dedup MUST be content-keyed, never time-windowed. The producer (or the OTLP layer) supplies an idempotency key — a content hash combined with a producer identifier and a sequence number. Ingesters treat the key as opaque. Clock drift becomes irrelevant to dedup correctness.
  • Time-window dedup is rejected by default, regardless of how cheap or convenient it appears. An RFC proposing it must read this hazard and address it explicitly.

Detection.

  • bytes_stored / bytes_received per tenant: must hover near 1 on a single-replica deployment. A multiplier > 1 + ε on a single-replica deployment indicates double-writing somewhere upstream.
  • On a future replicated deployment: this ratio should remain near 1 after dedup; a sudden rise indicates clocks drifted and the dedup pass is missing duplicates.
  • A “dedup hit rate” metric on the dedup pass — a sudden drop signals that something is masking what should be visible duplicates.

Escalation. Replication proposed → RFC must explicitly address this hazard. Time-window dedup proposed → block, redirect to a content-keyed approach. Storage multiplier > 1.05 on a single- replica deployment → P0 investigation, something is double-writing.

See also. CLAUDE.md §3.4 (WAL durability), §3.6 (object storage as truth). Cautionary tale: Grafana Loki’s 2026 re-architecture replacing replicate-at-ingest with Kafka-as-durability (InfoQ news, April 2026).


Adding a new hazard

A new hazard belongs in this document if all of the following hold:

  • It is a failure mode that silently corrupts data, lies to the user, or destroys the project’s value proposition.
  • It is not obvious from reading the code (otherwise it is a bug, not a hazard).
  • It has at least one named mitigation in the codebase or a committed RFC.

A new hazard is added via a meta: RFC, the same path as changes to CLAUDE.md §3 invariants.

Verification

Status: active. This document is the process spec. The proposed amendments to docs/rfcs/README.md and CLAUDE.md at the bottom of this file are tracked separately and applied in their own PR once the structure here is settled.

What this doc is for

The Ourios docs already define invariants (CLAUDE.md §3), hazards (docs/hazards.md), per-RFC testing strategies (RFC §6 — see §2.5), thesis-gates (docs/benchmarks.md), and the project’s testing discipline (CLAUDE.md §6.2). What is missing is the described process that connects them: how a contributor (human or agent) takes a §3 invariant or an H-x hazard, turns it into reviewable acceptance criteria, turns those into red tests, drives them green, and gates an RFC’s transition to accepted.

This doc fills that gap. It is human-readable process, not test code, not tooling, not a coverage policy.


1. The flow

Six links, four gates between them. The diagram below names them; the text after walks the chain in the order a contributor encounters it.

Invariant (§3)        Hazard (H-x)        RFC (§§1–4)
       \                 |                   /
        \________________|__________________/
                         ↓
                Acceptance criteria
              (RFC §5 — normative,
               structured prose)
                         ↓
                   Red tests
                  (compile, fail)
                         ↓
                  Green tests
              (unit + property + corpus)
                         ↓
                  Validated
        (corpus + thesis-gates pass on
         representative inputs)

The chain has two entry points (Invariant, Hazard) that converge on the third (RFC). An RFC enumerates the invariants and hazards it touches in its §1 Summary; reviewers verify the enumeration is exhaustive at the Drafted → Specified gate.

Invariant → RFC. A CLAUDE.md §3 invariant is a project-level promise. Until an RFC operationalises it, the invariant is a known debt. §4 Entry points describes the three doors into this chain.

Hazard → RFC. Each hazards.md H-x item names the RFCs and crates responsible in its Mitigation and See also fields. The hazard does not move; the RFC inherits the obligation to defend it.

RFC → Acceptance criteria. Acceptance criteria live in RFC §5 (see §2) and translate the invariants and hazards the RFC touches into testable scenarios. The Specified gate ratifies the list.

Acceptance criteria → Red tests. A red test is a compiling stub that fails — typically with todo!() or unimplemented!() — and references the scenario id in a doc comment. Red tests are not required at the Specified gate; they are the artefact of crossing the Red gate, immediately before implementation begins. Forcing stubs to compile at Specified would push authors into premature specificity about types and signatures. Red stubs are tagged #[ignore] so the outer CI loop stays green while the inner loop (the implementor running cargo test -- --ignored locally) sees the todo!()s fire as a TODO list — see §3 for the two-loop spec.

Red tests → Green tests. Implementation lands; each stub becomes a real test that passes; unit, property, and corpus tests cover the scenario as CLAUDE.md §6.2 dictates. The Green gate confirms every §5 acceptance criterion has a matching passing test.

Green tests → Validated. The thesis-gates in benchmarks.md §7 that the RFC’s pillars touch must pass on representative corpora. Once they do, the RFC’s status: flips to validated. Maintainer sign-off then flips it to accepted.

2. Acceptance criteria

The contract here is single-typed: every invariant or hazard the RFC touches resolves to one or more scenarios, each with an id, a leading clause grammar, and a greppable counterpart in test code.

2.1 Format

Structured prose using bold leading clauses. Each scenario carries a short numeric id (see §2.2) and follows the Given / When / Then / And pattern:

Scenario H1.1 — Semantically distinct templates do not silently merge

  • Given a corpus containing user logged in <*> and user logged out <*>
  • When similarity threshold is 0.7 (default)
  • Then the two remain distinct template_ids
  • And any widening produces an audit event recording both old and new templates

The format is the markdown the project already uses, not Gherkin. We do not adopt .feature files, cucumber-rs, or any other BDD tooling: the test code is Rust (CLAUDE.md §6.2), and the scenario lives in the RFC where reviewers are already reading. A second source of truth — a .feature file checked separately — would drift, and the tooling does not pay for itself at our scale.

2.2 Scenario ids

Three id grammars, chosen to make the source of the obligation visible at a glance:

  • H<n>.<m> — hazard-rooted; H1.1 is the first scenario defending hazard H1.
  • §3.<n>.<m> — invariant-rooted; §3.4.2 is the second scenario defending CLAUDE.md §3.4 (WAL-before-ack).
  • RFC<NNNN>.<m> — RFC-internal; reserved for scenarios that defend an RFC’s own design decisions, not a numbered invariant or hazard. Example: RFC0001.3 for a Drain3-extension behaviour that is not load-bearing for any §3 invariant but is part of the RFC’s contract.

Numbers within an id family are assigned in the order scenarios are written and never renumbered. A retired scenario keeps its number; new scenarios append. This gives git log -S "H1.1" a stable target across the lifetime of the project.

2.3 Greppability

The id is referenced from the test code in a doc comment, exactly:

#![allow(unused)]
fn main() {
/// Scenario H1.1 — Semantically distinct templates do not silently merge.
/// See `docs/rfcs/0001-template-miner.md` §5.
#[test]
fn login_and_logout_do_not_merge_at_default_threshold() { /* … */ }
}

grep -R "H1.1" . then yields the scenario in the RFC, the test in the crate, and any cross-references in the docs — bidirectional in one command. If a scenario is renamed, both ends move in the same commit.

2.4 Normative vs. exhaustive

Acceptance criteria are the normative tests an RFC promises will exist. The implementation will write many more — regression tests, edge cases, performance smokes — and those are not catalogued in the RFC. Reviewers ratify the normative set: every invariant and hazard the RFC touches has at least one scenario, and the scenarios as written are testable in principle.

The opposite mistake — listing every test the implementation will ever write — turns the RFC into a test plan and freezes the implementation. We do not do that.

2.5 Location in the RFC

Acceptance criteria are a new RFC §5, immediately before Testing strategy. The placement is deliberate: criteria are the spec the testing strategy operationalises, so reviewers reading the RFC top to bottom encounter the what before the how. The proposed amendment to docs/rfcs/README.md at the bottom of this file captures the renumbering: existing §5 Testing strategy shifts to §6, Open questions to §7, References to §8.

3. The RFC maturity model

Five stages, four gates. Each stage is a value of the RFC’s status: frontmatter field, so an RFC’s current maturity is visible without reading the body:

StageWhat existsGate to next
DraftedRFC §§1–4 and §§7–8 filled; §§5–6 may be stubbedPeer review of design
Specified§5 acceptance criteria written, scenarios numberedReview: do the criteria cover every invariant and hazard the RFC touches? Are they testable in principle?
RedTest stubs compile, are tagged #[ignore], and fail with todo!() (or equivalent) when runImplementation begins
GreenAll §5 criteria pass; unit + property + corpus tests greenValidation against representative inputs
ValidatedThesis-gates in benchmarks.md §7 pass on representative corporaMaintainer signs off; status flips to accepted

accepted is a distinct terminal status — it represents maintainer sign-off after Validated is reached. rejected and superseded are the other terminals, all three reachable from anywhere in the maturity ladder. A Drafted or Specified RFC may be rejected on review without ever reaching Red; an Accepted RFC may be superseded by a later one without re-traversing the chain.

The table is the spec; the paragraphs below explain what artefacts exist at each stage and what a reviewer is ratifying.

Drafted. The RFC has §§1–4 (Summary, Motivation, Proposed design, Alternatives considered) plus §§7–8 (Open questions, References) filled enough that two engineers reading it would produce roughly the same implementation. Acceptance criteria (§5) and Testing strategy (§6) may be empty or stubbed. The PR is open with status: drafted; review focuses on whether the design is correct in principle. The gate to Specified is a peer reviewer saying “yes, this design is what we want — now write down the contract.”

Specified. §5 Acceptance criteria is filled. Every invariant in CLAUDE.md §3 and every hazard in hazards.md that the RFC touches has at least one numbered scenario. §6 Testing strategy references those scenarios and names the technique (proptest, corpus, criterion) for each. The reviewer asks one question: could a competent implementor turn each criterion into a test as written? If the answer is no — for any criterion — the RFC has a gap and goes back to Drafted.

The Specified gate is the most valuable. It is the only gate where the cost of being wrong is bounded by review time rather than implementation time. We do not require test stubs to compile here; forcing stubs would push authors into premature decisions about function signatures, traits, and module structure, which is the Red gate’s job, not this one.

Red. Test stubs exist, are tagged #[ignore], and fail when run. Each stub carries a doc comment naming its scenario id (§2.3). Stubs may be todo!(), unimplemented!(), assert!(false) — anything that compiles and fails. Implementation may begin.

The Red signal lives at two granularities, deliberately:

  • Inner loop (local dev cycle). The implementor working on a stub runs cargo test <name> -- --ignored and watches the todo!() panic. Each panic is one TODO item; as the body fills in, the #[ignore] comes off and the test joins the default run.
  • Outer loop (CI). Default cargo test skips ignored tests, so the Red-stage PR lands cleanly through branch protection rather than fighting it. CI’s signal that the Red gate is satisfied is structural: stubs compile, every §5 scenario has an #[ignore]’d test with a matching id, and cargo test -- --include-ignored exits non-zero on each. (The greppability contract in §2.3 makes the per-scenario coverage check mechanical — grep -R "H1.1" returning both the RFC line and the test stub line is the assertion.)

The two-loop split is what lets us treat the Red status as a landable, mergeable state rather than a half-broken branch. A Red-stage main is healthy: outer loop green, inner loop fully populated with the work that needs doing.

The gate is mechanical: every scenario in §5 has at least one stub with a matching id, the stub is tagged #[ignore], and cargo test -- --include-ignored exits non-zero on each.

Green. Implementation lands. Every stub becomes a real test; unit, property, and corpus tests cover their scenarios as CLAUDE.md §6.2 dictates. cargo test --all-features passes. The reviewer confirms each §5 criterion now resolves to a passing test (the greppability contract makes this mechanical). No performance claim is made yet.

Validated. Every thesis-gate in benchmarks.md §7 that the RFC’s pillars touch passes on representative corpora. Maintainer inspects the corpus and the delta against target, signs off, and flips status: to accepted. The RFC is now binding; subsequent changes go through the regression handling in §3.1.

3.1 Regression handling after Validated

A failing test on a previously-Validated RFC is, by default, the test doing its job. The RFC does not reopen. Standard PR workflow: fix the regression, ship the patch, the test stays green.

The RFC reopens only when a single criterion fails repeatedly on the same code path — concretely, when the same scenario id fails on three independent commits within a 30-day rolling window, or when two distinct regressions touch the same criterion within the same window. The threshold is that the criterion has stopped being a defence and has become a moving target; that is a signal the RFC’s commitment is under-defended or under-specified, and the design (not just the implementation) needs revisiting.

This threshold is informal at the Specified gate; it sharpens once real signals exist. The point of writing it down now is that contributors do not race to reopen RFCs on every CI flake, nor pretend a repeated structural failure is just bad luck.

Thesis-gate failures during Validated follow benchmarks.md §7’s existing escalation rule (one fail on one corpus → tuning RFC; two or more → pillar RFC, pause), not this section.

3.2 Outer loop vs. inner loop

The maturity model is the outer loop. Each stage names a checkpoint that an external reviewer can verify: at Specified the scenarios are written, at Red the stubs compile and fail, at Green the same stubs pass. Nothing in the outer loop says how a developer fills the Red → Green transition.

The recommended inner loop is classic Beck-style TDD: write one failing test, make it pass with minimal code, refactor, triangulate by writing the next test that forces generalisation, repeat. It is not mandatory — a developer who prefers to stub all scenarios up front and implement against them is welcome to. The outer loop only requires that every §5 scenario has a stub by the Red gate and a passing test by the Green gate.

Two consequences worth being explicit about:

  1. More tests than scenarios. The inner loop typically writes many tests per scenario — one per concrete example, then regression tests as bugs surface. Acceptance criteria (§2.4) are the normative set the RFC is held to; the inner loop fills out the rest.
  2. No refactor stage in the model. Refactoring is part of the inner loop, not a maturity stage. A Green or Validated RFC may be refactored without re-traversing the chain, as long as every §5 criterion stays green.

The split is the BDD/ATDD outer-shell convention adapted to a project already committed to Rust, proptest, and criterion: the scenarios are written in the BDD-flavoured prose of §2.1 because they live in RFCs and humans read them; the tests are written in the TDD-flavoured loop developers already know.

4. Entry points

The same machinery, three doors:

  • Invariant entry — an item in CLAUDE.md §3. The criteria live in the RFC that operationalises that invariant; if no RFC yet exists for the relevant subsystem, the invariant is a known debt and the next RFC for that subsystem must address it.
  • Hazard entry — an item in hazards.md. Each hazard’s Mitigation section names the RFCs and crates responsible; their acceptance criteria must reference the hazard id.
  • RFC entry — a new RFC under docs/rfcs/. The RFC enumerates the invariants and hazards it touches in its §1 Summary; criteria in §5 must cover each.

5. Relationship to benchmarks.md

Correctness gates live here. Thesis-gates live in benchmarks.md §7. An RFC reaches Validated only when both:

  • Every §5 acceptance criterion has a passing test, and
  • Every thesis-gate in benchmarks.md §7 that the RFC’s pillars touch passes on representative corpora.

Single sentence; intentional non-duplication. benchmarks.md stays the performance owner.

6. Worked example

A concrete trace of the chain in §1, against an artefact that already exists. RFC 0001 Template miner is currently status: draft (becoming drafted once the amendment to docs/rfcs/README.md lands). Its operationalisation of CLAUDE.md §3.1 No silent template merges and hazards.md H1 Template miner correctness is the first place this process gets to bite on real material.

6.1 Invariant → RFC

CLAUDE.md §3.1 promises:

A template merge that crosses semantic boundaries (e.g. merging “user logged in” with “user logged out” because they share token structure) corrupts the backend.

hazards.md H1 names the canonical horror — user logged in <*> and user logged out <*> differing in one token, merging under a permissive threshold to user logged <*> <*>, a query for the login event silently returning logout rows.

RFC 0001 §6.4 Merge policy is the section that defends the invariant. As of the Drafted gate it commits to “When two templates become candidates for merge”, an audit event schema, and the rule “Default: strict. Never silent. No exceptions.”

6.2 RFC → Acceptance criteria

The Specified gate adds a new §5 to RFC 0001:

Scenario H1.1 — Semantically distinct templates do not silently merge

  • Given a corpus containing user logged in <*> and user logged out <*>
  • When similarity threshold is 0.7 (default)
  • Then the two remain distinct template_ids
  • And any widening produces an audit event recording both old and new templates

Scenario H1.2 — Lossy-zone match retains body

  • Given a line whose best match has confidence in the lossy zone (floor ≤ x < threshold)
  • When the line is ingested
  • Then the body column contains the original line bytes
  • And the row carries lossy_flag = false (the flag is reserved for tokenizer / preprocessing failure per docs/rfcs/0001-template-miner.md §6.6 — the lossy zone retains the body but reconstruction still succeeds)

Scenario H1.3 — Every widening emits an audit event

  • Given any sequence of inputs that triggers a template widening
  • When the widening completes
  • Then an audit event exists naming the old template, the new template, the tenant id, the timestamp, and the event_type

Three scenarios cover §3.1’s three rules: do not merge across semantics, retain bodies on low confidence, audit every widening. Reviewers ratify that this is exhaustive against CLAUDE.md §3.1 and H1; they do not catalogue every edge-case test the implementation will write.

6.3 Acceptance criteria → Red tests

The Red gate adds three stubs to crates/ourios-miner/tests/:

#![allow(unused)]
fn main() {
/// Scenario H1.1 — Semantically distinct templates do not silently merge.
/// See `docs/rfcs/0001-template-miner.md` §5.
#[test]
#[ignore = "RFC 0001 Red gate — implementation pending"]
fn h1_1_login_and_logout_remain_distinct_at_default_threshold() {
    todo!("RFC 0001 §6.4");
}

/// Scenario H1.2 — Lossy-zone match retains body.
/// See `docs/rfcs/0001-template-miner.md` §5.
#[test]
#[ignore = "RFC 0001 Red gate — implementation pending"]
fn h1_2_lossy_zone_match_retains_body() {
    todo!("RFC 0001 §6.6");
}

/// Scenario H1.3 — Every widening emits an audit event.
/// See `docs/rfcs/0001-template-miner.md` §5.
#[test]
#[ignore = "RFC 0001 Red gate — implementation pending"]
fn h1_3_every_widening_emits_an_audit_event() {
    todo!("RFC 0001 §6.4");
}
}

Default cargo test skips the ignored stubs and passes (outer loop / CI green); cargo test -- --ignored exits non-zero with all three failing (inner loop / Red signal). The gate is satisfied; implementation may begin.

6.4 Red → Green

Implementation lands across ourios-miner (and supporting types in ourios-core). The three stubs become real tests: H1.1 ingests the two-template corpus, asserts two distinct template_ids, and queries the audit log for absence of widening events. H1.2 ingests a line whose token similarity falls in the lossy zone and asserts that the row’s body carries the original bytes and lossy_flag is false (the flag is reserved for the H7 reconstruction-failure case; see RFC 0001 §6.6). H1.3 ingests a sequence that provokes a widening and asserts the audit event’s structure.

cargo test --all-features passes. Reviewers confirm each H1.x id now resolves to a passing test via grep. No benchmark claim is made.

6.5 Green → Validated

benchmarks.md C2 Template count convergence is the thesis-gate that H1 most directly touches: if the miner is silently merging across semantics, template count grows wrong. The benchmark harness runs C2 on the LogPAI corpora and any self-collected corpus available, plots template count vs. lines ingested, and asserts the convergence target.

Once C2 passes — and any other thesis-gate the RFC’s pillars touch — the maintainer signs off. RFC 0001’s status: flips to accepted. The miner’s contract is now binding.

6.6 The failure mode that re-opens the RFC

A hypothetical: six months in, three independent PRs land that each add a workaround to keep H1.1 green — a special-case for common verb pairs, then for HTTP method tokens, then for log-level tokens. Each workaround is small, each test stays green. By the fourth PR, a reviewer notices: the criterion has stopped being a defence and has become a moving target. Per §3.1, the RFC reopens. The right answer is not a fifth workaround; it is to revisit RFC 0001 §6.4 — the merge policy itself is under-specified for the workloads we are seeing.

This is what the threshold in §3.1 is for. It is not a CI-flake counter; it is a signal that the design’s defence has eroded and needs to be redrawn before more code is written on top of it.

7. What this doc is not

  • Not test-tooling guidance — proptest, criterion, etc. live in CLAUDE.md §6.2.
  • Not a coverage policy — Ourios is a correctness project; line coverage is the wrong metric.
  • Not an agent-instruction file — agents follow it because it is written down, not because it speaks to them.

8. Resolved decisions

Three questions raised during the outline review, decided before expansion so the rationale is preserved:

  • Maturity stages appear in RFC frontmatter as the status: field. Reviewers and tooling see an RFC’s current stage without reading the body. See §3.
  • Single regressions do not reopen a Validated RFC. A failing test on an existing criterion is the test doing its job; standard PR workflow applies. Repeated regression on the same criterion (rough threshold: same scenario id failing on three independent commits, or two distinct regressions touching the same criterion, both measured in a 30-day rolling window) signals the criterion has stopped being a defence and reopens the RFC. See §3.1.
  • Thesis-gate failures during Validated follow benchmarks.md §7, not this doc. One thesis-gate failing on one corpus → tuning RFC; two or more → pillar RFC and an implementation pause.

Proposed amendment — docs/rfcs/README.md

Two changes. Shown as the new text:

In Required frontmatter

Update the status field’s valid values from the current four-state list to the five-stage maturity model plus terminals:

status: drafted | specified | red | green | validated | accepted | rejected | superseded

The maturity stages (drafted through validated) are gates an RFC moves through; accepted is the terminal post-maintainer-signoff binding state; rejected and superseded are the off-ramps. See docs/verification.md §3.

In Required sections

Insert a new item between the current §4 Alternatives considered and §5 Testing strategy, renumbering subsequent items:

  1. Acceptance criteria — normative scenarios, one per invariant or hazard the RFC touches. Format: structured prose with Given / When / Then / And leading clauses; each scenario carries an id of the form H1.1, §3.4.2, or RFC<NNNN>.<m>, referenced from the test code so the mapping is greppable. See docs/verification.md §2.

Testing strategy shifts to §6, Open questions to §7, and References to §8.

In Lifecycle

Replace the current four-status list with the five-stage maturity model:

  1. Drafted — PR opened with status drafted. Sections §§1–4 and §§7–8 are filled. Discussion happens in PR review.
  2. Specified — §5 acceptance criteria are written, every invariant and hazard the RFC touches has at least one scenario, and review has confirmed the criteria are testable in principle.
  3. Red — test stubs exist and fail. Implementation may begin.
  4. Green — all acceptance criteria pass; unit + property + corpus tests green.
  5. Validated — thesis-gates in docs/benchmarks.md §7 pass on representative corpora. Maintainer flips status to accepted.

A regression detected after Validated either reopens the RFC (if a criterion is invalidated) or spawns a tuning RFC per benchmarks.md §7 (if a thesis-gate degrades). See docs/verification.md §3.

The earlier superseded and rejected entries remain unchanged.

Existing RFC frontmatter

RFC 0001 and RFC 0002 currently carry status: draft. The amendment PR renames both to status: drafted so the maturity model applies uniformly. No content change to the RFCs themselves at that step.


Proposed amendment — CLAUDE.md

A single new subsection under §5 Development workflow, following §5.5 One-word mode:

5.6 Verification process

The path from invariant or hazard to passing test is described in docs/verification.md. Acceptance criteria live in RFC §5; docs/rfcs/README.md defines the maturity stages an RFC moves through. The shortest version of the rule: if a criterion cannot be turned into a test, the RFC has a gap.

No change to §6.2 Testing discipline; verification.md links to it. The §6.2 content (proptest, corpus tests, crash recovery, criterion) is the catalogue of techniques; verification.md is the process that decides which technique is required where.


Applying the amendments

The body of this document is the verification process spec. The two proposed amendments above are pending application:

  • docs/rfcs/README.mdstatus: value list, new §5 Acceptance criteria in Required sections with renumbering, lifecycle rewrite, draftdrafted rename in RFC 0001 and 0002.
  • CLAUDE.md — new §5.6 Verification process.

Both should land in a single PR. RFC 0001 then gets a §5 Acceptance criteria applied as the first concrete use of the process — the worked example in §6 of this document is the target shape, and applying it will probably surface specificity gaps in RFC 0001’s existing design. That surfacing is the point.

Add this document to docs/SUMMARY.md under the Architecture header in the same PR that applies the amendments.

Glossary

Vocabulary used in the Ourios docs. Entries marked (Ourios) carry a project-specific meaning that may differ from the industry-default. Cross-references in italics point to other entries here.


Audit event. A structured record emitted by the miner every time a template is widened (parameters generalised), merged with another template, or versioned. Audit events are themselves stored as logs and are queryable. They are the trail by which an operator can answer “did this template silently change yesterday?” See hazards.md H1.

Bit-identical reconstruction. The property that, for any ingested log line, either Ourios can reproduce the exact original byte sequence from what it stored, or the row carries lossy_flag = true. Never an in-between. Tested as a property test against the corpus. See CLAUDE.md §3.3, hazards.md H7.

Body. The free-form text content of a log record. In OTel terms, the body field of a LogRecord. In Ourios storage, the body is either reconstructible from template + params (most rows) or retained verbatim in a dedicated column (lossy rows, parse failures, or tenants who opted in to always-retain).

Compaction. Background process that merges many small Parquet files into fewer large ones, targeting row-group sizes of 128 MB to 1 GB and file sizes of 256 MB to 2 GB. Driven by the small-file hazard (H4).

Confidence. A scalar in [0, 1] assigned by the miner to each matched row, measuring how well the row matched its assigned template. The three-zone model partitions confidence into clean match (≥ threshold), lossy match (floor ≤ x < threshold), and parse failure (< floor). (Ourios) — extends Drain, which is binary-classifying.

Corpus. A collection of anonymised log lines used as test input. Lives under testdata/corpus/. Public LogPAI corpora form the floor; self-collected corpora per deployment archetype are added over time. Reconstruction, template-count convergence, and merge rate are all measured against the corpus on every miner change.

DataFusion. The Apache project providing the query engine Ourios uses. Ingests logical plans, optimises them, executes against Parquet. Ourios extends DataFusion with two custom logical nodes (render, template_id.resolves_to) but otherwise treats it as a black box. DataFusion specifics never leak into the user-facing DSL (H6).

Drain. The 2017 paper (He, Zhu, Zheng, Lyu — ICWS 2017) that introduces a fixed-depth tree algorithm for online log parsing. The basis of the miner. See docs/rfcs/0001-template-miner.md and docs/talks/0001-template-miner.md.

Drain3. The IBM-maintained fork of Drain that adds persistent state, masking, variable-length wildcards, and dynamic thresholds. Some of its extensions are adopted in Ourios; some are explicitly not. RFC 0001 §4 lists the per-extension verdict.

Drift. The phenomenon where a service’s log format changes between deploys, producing new templates that are aliases of older ones. (Ourios) — drift is detected as a first-class query, not an after-the-fact discovery. See H5 and RFC 0001 §6.7.

DSL. The user-facing query language for Ourios logs (RFC 0002). Compiles to DataFusion logical plans; does not expose SQL. Two candidate predicate sublanguages (OTTL-borrowed vs. distanced) and three top-level surfaces (SQL-clause, LogQL-pipe, Insights-verb) are under design.

Floor. The lower bound of confidence below which the miner declares a parse failure. Default ~0.3. Below the floor, the row is stored body-only and parse_failures_total increments. (Ourios) — not present in the Drain paper.

Fsync. The POSIX call that forces buffered writes to durable storage. The WAL fsyncs before acknowledging an OTLP batch. See H3, CLAUDE.md §3.4.

Hazard. A named failure mode that, if not actively mitigated, silently corrupts data or destroys the project’s value proposition. The seven current hazards are catalogued in docs/hazards.md. New hazards are added via a meta: RFC.

Ingester. The Ourios role that receives OTLP over gRPC/HTTP, mines templates, writes to the WAL, and (eventually) flushes to Parquet via the compactor. One half of the ingester/querier binary split.

Length group. The first-level partition in the Drain parse tree: one branch per distinct token count. Drain assumes lines of different length are probably from different call sites and uses length as a cheap initial filter.

Log group. Drain’s term for a template together with the rows that have matched it. A leaf in the parse tree contains a list of log groups.

Lossy. A row whose lossy_flag is set, indicating that reconstruction from template + params may not be byte-identical. Always paired with the original body being retained on that row. See H7.

LogPAI. The benchmark-corpus project for log parsing (github.com/logpai/logparser). Ourios uses LogPAI corpora (HDFS, BGL, Spark, Apache, OpenSSH, Windows) as the public-corpus floor for benchmarks.

Masking. Pre-tokenisation regex rules that replace volatile sub-strings (IPs, UUIDs, numbers) with placeholders before the miner walks the tree. A Drain3 extension. Whether and where Ourios applies masking is a design choice in RFC 0001 §4.

Merge. When the miner widens an existing template to absorb a new line — e.g. replacing a literal token with a wildcard. Every merge fires an audit event. Strict thresholds make merges rare; audit makes them visible. See H1.

Miner. Short for template miner — the Ourios subsystem that runs Drain online over ingested log lines and emits (template_id, params, confidence, lossy_flag) for each row. Lives in the ourios-miner crate. Designed in RFC 0001.

OTLP. OpenTelemetry Protocol, the wire format for telemetry data. The Ourios ingest contract: incoming logs are OTLP over gRPC or HTTP. We do not invent our own format.

OTTL. OpenTelemetry Transformation Language, the OTel Collector’s text-based DSL for filtering and mutating telemetry in processor pipelines. Ourios deliberates between borrowing OTTL’s predicate sublanguage and distancing from it (RFC 0002).

Parquet. The Apache columnar file format Ourios uses for on-disk storage. Per-column compression, predicate pushdown via min/max statistics, bloom filters, page indexes. The on-disk truth of the system; local disk is cache and WAL only. See CLAUDE.md §§2.1, 3.6.

Params. The variable parts of a log line that the miner extracts when matching a template. Bounded per-parameter to 256 B by default; overflow spills to the body column. See H2.

Parse failure. A row whose match confidence falls below the floor. Stored body-only; parse_failures_total counter increments.

Predicate pushdown. A query-engine optimisation where filter predicates are applied as early as possible — at the storage layer rather than after a full scan. Parquet’s min/max page statistics make this nearly free for time-range and equality filters. The mechanism by which predicate queries beat zstdcat | grep (B1).

Property test. A test that asserts an invariant over many randomly-generated inputs (typically via proptest). In Ourios: reconstruction is always a property test; the parser round-trips; the miner’s tree operations preserve invariants. See CLAUDE.md §6.2.

Querier. The Ourios role that accepts queries (over the DSL), plans them through DataFusion, scans Parquet, and returns results. Other half of the ingester/querier split.

Reconstruction. The act of producing the original body of a log line from the stored template + params (and, where retained, the captured whitespace state). Subject to the bit-identical guarantee. See H7.

Row group. Parquet’s unit of compression and predicate-pushdown locality — a horizontal partition of rows within a file. Target size 128 MB to 1 GB. Smaller row groups mean faster row-group skip but worse compression and more metadata overhead.

Similarity. The Drain match score between an incoming line and a log group’s template: the fraction of token positions where the line matches the template (wildcards count as matches). The single most important knob in the system. See RFC 0001 §3.

SUMMARY.md. mdBook’s table-of-contents file (docs/SUMMARY.md) that defines book navigation. Drafts (no link target) appear as greyed-out entries.

Template. The structural pattern of a class of log lines, with variable parts replaced by wildcards. E.g. ERROR db connection failed for user <*>. The miner extracts templates online from raw logs. (Ourios) — every template is scoped per tenant; the same string in two tenants is two templates.

Template id. The identifier of a template within a tenant. Either a hash of the canonical template string or a per-tenant monotonic integer (open question, RFC 0001 §6.1).

Template tree. The Drain parse tree, scoped per tenant. Its shape is root → length group → token-prefix nodes (depth d) → leaf log groups. (Ourios) — Drain assumes one tree; we keep one per tenant (CLAUDE.md §3.7).

Template version. A monotonic integer that bumps when a template’s representation changes (e.g. token order, new wildcard). The logical identity of the template persists across versions via the alias mechanism. See drift, RFC 0001 §6.7.

Tenant. An isolation boundary: a customer, a project, an environment. Every code path that touches data takes a tenant_id; every Parquet file is partitioned by tenant; every template tree is scoped per tenant. Multi-tenancy is not bolted on (CLAUDE.md §3.7).

Thesis-gate. A benchmark goal whose failure on representative corpora invalidates an architectural pillar — meaning the response is an RFC to revisit CLAUDE.md §2, not a tuning sprint. The five thesis-gates are catalogued in docs/benchmarks.md §7.

Threshold (st). The Drain similarity cutoff above which a line is assigned to an existing log group rather than opening a new one. Ourios default ≥ 0.7; values below 0.7 require an RFC (H1, CLAUDE.md §3.1).

Token-prefix node. Drain’s intermediate tree level: branches on the value of the line’s first N tokens (depth d, paper default 3–4). Below it, at the leaf, is a list of log groups.

Truncation marker. The placeholder that replaces an oversized params slot when the per-parameter byte limit is exceeded. The original value spills to the body column. See H2.

WAL. Write-ahead log. The Ourios ingester writes every acknowledged batch to the WAL, fsyncs, and only then acknowledges to the OTLP client. WAL segments are eventually flushed to Parquet by the compactor. The crash-recovery test SIGKILLs the ingester mid-batch and asserts no acknowledged data is lost. See H3, CLAUDE.md §3.4.

Benchmarks

Referenced from CLAUDE.md §6.2 (“regressions block merges”) and from docs/rfcs/0001-template-miner.md §8. Flat-file, living document, parallel to docs/hazards.md. Updated with measured results as they come in.

This document is an honesty contract with ourselves. The thesis (CLAUDE.md §2) claims that Parquet + Drain-derived template mining + DataFusion beats the naive alternative of byte-level compression over flat text. That claim is falsifiable. This file lists the measurements that would falsify it.

The thresholds were pinned before any number was measured; if we miss them on representative corpora, the thesis is wrong and a pillar changes. As of 2026-06-14 the four gating thesis-gates B1, B2, C1, C2 all pass on the §1 hardware baseline (§9.4/§9.6). A1 fails but no longer gates — RFC 0011 (accepted) reclassified the compression-vs-zstd ratio as a recorded diagnostic (its failure is structural; see §2 / the §7 table).

0. How to read this document

Every goal below carries two labels.

  • Scopethesis-gate, tuning-goal, or diagnostic.
    • A thesis-gate failing on representative corpora means a pillar (CLAUDE.md §2) is wrong. The response is an RFC, not a sprint.
    • A tuning-goal failing means the design is sound but the implementation needs work. The response is a PR.
    • A diagnostic is measured and recorded but gates nothing — it characterises a property or guards against regression. A1 was reclassified here by RFC 0011 (accepted); see §2.
  • Barmust-win, should-win, stretch, or informational.
    • must-win — shipping without it is shipping a broken claim.
    • should-win — expected on representative corpora; explained when missed.
    • stretch — aspirational; missing is not a bug.
    • informational — a diagnostic’s bar: the number is recorded for insight, never blocks.

A goal with scope thesis-gate and bar must-win is load-bearing for the whole project. Four of those below are gating — B1, B2, C1, C2, each marked [THESIS]. A1 keeps the [THESIS] tag (a thesis-relevant measurement) but RFC 0011 (accepted) set its scope to diagnostic: it is recorded, not gating (see its section below and the §7 table).

1. Corpora and methodology

Before any goal is meaningful, the corpora and methodology must be pinned — otherwise we will argue about numbers instead of about architecture.

  • Public: LogPAI corpora (HDFS, BGL, Spark, Apache, OpenSSH, Windows) — the same corpora the Drain paper reports on. Lets us reproduce published claims as a sanity floor.
    • LogHub HDFS_v1 is the first of these wired in, as a bench-time-fetched corpus for the query gates: .github/workflows/query-bench.yml downloads HDFS_v1.zip from the official Zenodo record (record 8196385, DOI 10.5281/zenodo.8196385, md5-pinned in the workflow), uses the extracted HDFS.log (~1.47 GiB plain text — above §8’s ≥ 1 GiB canonical minimum) in-job, and discards it with the runner. It is never redistributed: not committed (the testdata/corpus/README.md anonymisation gate — LogHub data is explicitly not sanitised), not attached to a release, not uploaded as an artifact; only aggregate numbers leave the job. LogHub’s license notice, included here as it requires: “The datasets are freely available for research or academic work. For any usage or distribution of the datasets, please refer to the loghub repository URL (https://github.com/logpai/loghub) and cite the loghub paper: Jieming Zhu, Shilin He, Pinjia He, Jinyang Liu, Michael R. Lyu. Loghub: A Large Collection of System Log Datasets for AI-driven Log Analytics. In IEEE International Symposium on Software Reliability Engineering (ISSRE), 2023. The above license notice shall be included in all copies.”
  • Self-collected (deferred): at least one anonymised corpus per target deployment archetype. Proposed set:
    1. Structured Java/Spring service (well-templated, low entropy).
    2. Go service under Kubernetes (heterogeneous, mid entropy).
    3. Heterogeneous k8s aggregate across many services (high entropy, mixed formats).
  • Hardware baseline: a commodity 8 vCPU / 32 GiB RAM host with gp3-class SSD. All must-win numbers are quoted against this baseline; scaling to larger hardware is a separate question. The realised baseline (the baseline-8vcpu-32gib hardware tag, first used for the §9.4 authoritative run) is a dedicated host with 8 dedicated vCPU, 32 GiB RAM, and a local NVMe-class SSD — at or above the spec on every axis, so numbers quoted against the tag satisfy this baseline. It is identified only by the tag.
  • Reference system: zstdcat <file.zst> | grep <pattern>. The “naive alternative” the thesis beats or does not beat. Everything is quoted relative to this, not in absolute terms.

Goals quoted below assume this setup. When a goal is measured on a different setup, the measurement is annotated.

2. Compression goals (Category A)

The core claim that template mining does useful work before byte codecs run.

A1 [THESIS] — End-to-end compression ratio vs. zstd-alone

Demoted to a diagnostic (RFC 0011, accepted). A1 is refuted on every corpus class — including the maximally-templated one — for structural reasons, so it no longer gates any RFC’s validated. It is still measured and recorded (§7 table / §9 series) as the columnar queryability premium and a codec-regression guard. The scope, bar, target, and falsifier below are retained as the diagnostic’s reference line — now informational, not gating.

  • Scope: diagnostic (RFC 0011; originally thesis-gate).
  • Bar: informational (RFC 0011; originally must-win).
  • Metric: bytes(raw_corpus) / bytes(ourios_parquet_directory) compared to bytes(raw_corpus) / bytes(zstd_compressed_corpus).
  • Target: Ourios ratio ≥ the zstd-alone ratio, on every corpus in §1. Best-case corpora (well-templated services) should show ≥ 10×.
  • Falsifier: if any representative corpus yields ≤ 2× improvement over zstd-alone, the template-mining pillar is not pulling its weight on that class of logs. Open an RFC.
  • Why recorded (diagnostic, not a bar): CLAUDE.md §2 pillar #2 describes a logical 50–200× reduction (lines → (template_id, params)) whose payoff is query pruning (B1/B2), not on-disk bytes vs a byte codec. A1 tracks the on-disk ratio as the columnar queryability premium + a codec-regression guard; RFC 0011 (accepted) demoted it from a gate to this diagnostic.

A2 — Bytes per line, amortised

  • Scope: tuning-goal.
  • Bar: should-win.
  • Metric: total Parquet bytes for tenant / line count for tenant.
  • Target:
    • Structured service logs: ≤ 30 B/line.
    • Heterogeneous k8s: ≤ 100 B/line.
    • Stretch: ≤ 15 B/line on high-repetition corpora.
  • Why: makes A1 legible to operators, who think in bytes-per-line, not ratios.

3. Query performance goals (Category B)

Why not zstdcat | grep? Because the query layer is supposed to exploit structure the tree extracted.

B1 [THESIS] — Predicate-pushdown queries

  • Scope: thesis-gate.
  • Bar: must-win.
  • Query shape: count events WHERE tenant=X AND ts BETWEEN t1 AND t2 AND level='ERROR'.
  • Reference: zstdcat files_in_range.zst | grep ERROR | wc -l on the same corpus, same time window.
  • Target: Ourios ≥ 10× faster at 1 GiB corpus, widening to ≥ 100× at 100 GiB.
  • Falsifier: if Ourios is not materially faster than the zstdcat pipeline on predicate queries, DataFusion + Parquet statistics are not delivering on the “skip row groups via footer reads” pillar (CLAUDE.md §2.1). Open an RFC.
  • Instruments: B1 is proven structurally (deterministically) by ourios-querier’s rfc0007_1_* tests. The criterion bench crates/ourios-bench/benches/b1.rs adds the wall-clock ratio: a b1/synthetic group (controlled pruning instrument vs. an in-process zstdcat | grep reference) and a b1/real-corpus group (set OURIOS_B1_CORPUS_DIRS to a comma-separated list of corpus dirs; skipped when unset). The real arm runs OTLP corpora only (corpus/otel-demo-v*, which carry real per-record severity): B1’s predicate filters on severity, and the RFC 0006 §3.3 plain-text loader assigns every line a fixed severity (9 / INFO), so a severity predicate over a plain-text corpus has no selectivity and such dirs are skipped with a note. CI runs land via .github/workflows/query-bench.yml on ci-runner — indicative only. The authoritative numbers are the baseline-8vcpu-32gib run of 2026-06-12 (§9.4): PASS at 34.2× / 25.4× on the two ~1 GB OTel-Demo corpora, with exact row-count agreement against the reference pipeline. Open quality improvement (non-blocking): the measured error bands are ultra-thin (11 / 28 rows), which flatters pruning — a denser error band is the remaining methodological wish.

B2 [THESIS] — Template-exact queries

  • Scope: thesis-gate.
  • Bar: must-win.
  • Query shape: SELECT * WHERE template_id = X AND ts BETWEEN ….
  • Target: latency proportional to result cardinality, not to corpus size, above a corpus size of ~10 GiB. Concretely: median latency ≤ 200 ms for a query returning 10 000 rows, regardless of whether the corpus is 10 GiB or 10 TiB.
  • Falsifier: if template-exact queries scan proportionally to corpus size, template mining is buying compression but not query locality — the inverted-index collapse thesis (CLAUDE.md §2) is wrong in practice. Open an RFC.
  • Instruments: B2 is proven structurally (deterministically) by ourios-querier’s rfc0007_2_* test — for a fixed result the scanned row groups + bytes stay flat as the corpus grows. The criterion bench crates/ourios-bench/benches/b2.rs adds the wall-clock view: a b2/synthetic group (result held constant, corpus scaled 1×/10×/50×) and a b2/real-corpus group over real corpora (set OURIOS_B2_CORPUS_DIRS to a comma-separated list of corpus dirs; skipped when unset, since the corpora aren’t committed). Both loader formats feed it: the OTLP/JSON corpus/otel-demo-v* releases and the bench-time-fetched plain- text LogHub HDFS_v1 (§1). Run with cargo bench -p ourios-bench --bench b2. CI runs land via .github/workflows/query-bench.yml on ci-runner — indicative only. The authoritative numbers are the baseline-8vcpu-32gib run of 2026-06-12 (§9.4): PASS — the windowed template-exact scan stays at 1 row group with a flat ~4.2–5.9 ms latency band across every corpus, including the first reading from a second corpus family (LogHub HDFS_v1, 11.2 M rows: 1/14 row groups, 5.92 ms), while the full-span variant grows with corpus size. The formal target speaks above ~10 GiB, which remains a future scale extension; the flat shape holding at 11.2 M rows across two corpus families is the operative evidence.

B3 — Substring queries (the hard case)

  • Scope: tuning-goal.
  • Bar: must-match; stretch: beat.
  • Query shape: SELECT * WHERE body LIKE '%<substring>%' or equivalent.
  • Target: not slower than the reference system. Stretch: faster on well-templated corpora by searching the template text rather than every line.
  • Why this is only tuning-goal, not thesis-gate: substring search is the case where the tree does not help directly. We are allowed to match the reference system here; losing against it is a bug but not a pillar failure.

4. Miner correctness goals (Category C)

Correctness is not a performance goal, but it belongs here because these are the properties the benchmark harness actually measures on every run.

C1 [THESIS] — Bit-identical reconstruction rate

  • Scope: thesis-gate.
  • Bar: must-win.
  • Metric: of all non-lossy-flagged rows, fraction whose reconstruct(template, params) equals the ingested bytes exactly.
  • Target: 100.000%.
  • Falsifier: a single row that reconstructs wrong without a lossy flag is a violation of CLAUDE.md §3.3 and a blocker, not a benchmark regression. Accompanied by: the lossy-flagged fraction should be ≤ 5% on structured corpora, ≤ 20% on heterogeneous ones, as a quality signal (not a gate).
  • Why this is a thesis-gate: if we cannot promise reconstruction, the honesty contract (lecture §6) collapses.

C2 [THESIS] — Template count convergence

  • Scope: thesis-gate.
  • Bar: must-win.
  • Metric: template count as a function of lines ingested, on a corpus from a single stable service.
  • Grain (amended for #444, 2026-07-10): because the metric is defined per stable service, the gate is evaluated per service.name on a multi-service corpus, not on the whole corpus. A corpus passes iff every service with ≥ 1 M lines converges; a single-service (or plain-text <unknown>) corpus is gated on that one service’s exact-millionth-line ratio, reproducing the pre-amendment verdict for historical converged corpora. The whole-corpus ratio is retained as a diagnostic. See RFC 0006 §3.4.3.
  • Target: template count grows sub-linearly and plateaus within of its steady-state value by 1 M lines. Steady-state value is corpus-specific but is on the order of 10²–10⁴ templates for a normal service.
  • Falsifier: if template count grows linearly with corpus size, Drain has failed to abstract — we are storing one template per line, which means the tree is providing compression only accidentally. That is the inverse of the thesis. Open an RFC.

C3 — Merge rate

  • Scope: tuning-goal.
  • Bar: should-win.
  • Metric: merges_total / lines_ingested.
  • Target: ≤ 1 merge per 10⁵ lines on stable corpora, with every merge carrying an audit event. Spikes above this rate are investigated; they usually indicate a new service version.
  • Why only tuning-goal: merge rate depends on corpus stability more than on algorithm quality. The auditing is the invariant (§3.1); the rate is a signal.

C4 — Parameter overflow rate

  • Scope: tuning-goal.
  • Bar: must-win.
  • Metric: fraction of rows where any params slot hit the 256 B limit.
  • Target: ≤ 1% on representative corpora, per CLAUDE.md §3.2.
  • Falsifier (tuning sense): if >1% on a common archetype, either the limit is too tight for that workload or a masking rule is missing. The response is tuning, not an RFC.

5. Ingest goals (Category D)

The hot path must keep up with real deployments; otherwise none of the above matters.

D1 — OTLP → WAL throughput

  • Scope: tuning-goal.
  • Bar: must-win.
  • Metric: lines/second/core sustained, with WAL fsync batched at 100 ms (the CLAUDE.md §3.4 default).
  • Target: ≥ 100 000 lines/s/core, with p99 ingest-ack latency ≤ 200 ms.
  • Falsifier (tuning sense): below this we cannot ingest a meaningful share of production traffic per node, which makes the operational story uninteresting.

D2 — WAL → Parquet compaction keeps up

  • Scope: tuning-goal.
  • Bar: must-win.
  • Metric: WAL backlog (bytes, segments) as a function of time under sustained ingest at D1’s rate.
  • Target: bounded; backlog returns to zero during any one-hour window of sustained load.
  • Falsifier (tuning sense): a growing backlog under steady-state load means compaction is the bottleneck — a correctness-adjacent bug because it lets the WAL grow unboundedly.

D3 — Small-file count under sustained load

  • Scope: tuning-goal.
  • Bar: should-win.
  • Metric: number of Parquet files per tenant per day after background compaction has settled.
  • Target: file sizes cluster in the 256 MiB–2 GiB band per CLAUDE.md §4 / hazard 4. Fewer than 5% of files below 128 MiB at steady state.
  • Why: the small-file problem is a named hazard, not a nice-to-have.

6. Honesty goals (Category E)

Not performance. Not falsifiable by a benchmark in the usual sense. Listed here because the benchmark harness asserts them on every run.

E1 — Zero silent merges

  • Scope: correctness invariant (not a benchmark).
  • Metric: in the corpus-test suite, for every row whose template_id changed over its lifetime in the tree, an audit event exists with matching timestamp and tenant.
  • Target: 100%. This is a proptest, not a measurement.

E2 — Zero cross-tenant leakage

  • Scope: correctness invariant (not a benchmark).
  • Metric: no template mined under tenant A ever appears in tenant B’s tree or in a row for tenant B.
  • Target: 100%. Asserted via corpus tests that interleave lines from two synthetic tenants and verify complete isolation.

7. The thesis-gate summary

The five [THESIS]-tagged goals, consolidated:

#GoalFailing means
A1Compression ≥ 3× over zstd-alone — diagnostic, not gating (RFC 0011)Recorded for the columnar queryability premium + codec-regression guard; does not block any RFC’s validated. Refuted on every corpus class incl. max-templated HDFS_v1 (§9.5) for structural reasons — template mining’s compression is logical/query-pruning, captured by B1/B2
B1Predicate queries ≥ 10× faster than zstdcat | grepParquet statistics pillar not delivering
B2Template-exact queries scale with result size, not corpus sizeInverted-index-collapse thesis is wrong in practice
C1100% bit-identical reconstruction on non-lossy rowsHonesty contract with user violated
C2Template count plateaus sub-linearlyDrain has failed to abstract

Policy: if one thesis-gate fails on one representative corpus, that is a corpus-specific tuning RFC. If two or more thesis-gates fail on any representative corpus, that is a pillar-level RFC — we pause implementation and revisit CLAUDE.md §2 before continuing.

This escalation rule is the point of the whole document. The worst failure mode for a greenfield project is shipping something whose central claim quietly fails on real data and then papering over it with more implementation. These goals exist so we cannot do that to ourselves without noticing.

8. What is deliberately out of scope

  • SIEM-style full-text search latency — explicitly out of scope (CLAUDE.md §1).
  • Cross-tenant aggregation queries — tenancy is isolation-first (CLAUDE.md §3.7). Aggregations that cross tenants are an RFC topic, not a benchmark.
  • LLM-based parser comparisons — interesting, deferred. Listed in RFC 0001 §7 as an alternative. Benchmarking it would be a separate RFC.
  • Cold-start query latency — below a corpus size of ~1 GiB the overhead of Parquet metadata dominates, and the thesis is uninteresting. Benchmarks start at 1 GiB.

9. Status

First measurements landed 2026-06-01 (the writer-side gates A1 / C1 / C2 — see §9.1). They are diagnostic, not canonical: they ran on a GitHub-hosted runner (ci-runner), not the §1 hardware baseline (baseline-8vcpu-32gib), against an OTel-Demo corpus that is shape-representative (real multi-service template + envelope diversity) but not size-representative — every corpus is well below §8’s ≥ 1 GiB canonical minimum, so this run is intentionally diagnostic, not a thesis verdict. The query-side gates now have instruments — B1 and B2 are proven structurally in ourios-querier, and both have criterion latency benches with real-corpus arms (§B1/§B2 “Instruments”; OTel-Demo for B1, OTel-Demo + the bench-time-fetched LogHub HDFS_v1 for B2, run on ci-runner via .github/workflows/query-bench.yml as indicative numbers). 2026-06-11 extended the writer-side scale series to ~1 GB (§9.2) and landed the first B1/B2 query readings (§9.3) — recorded here as indicative ci-runner entries per the maintainer’s 2026-06-12 authorization. 2026-06-12 landed the authoritative baseline run (§9.4): every gate measured on the §1 hardware (baseline-8vcpu-32gib), recorded per the maintainer’s 2026-06-12 authorization. B1, B2, C1, and C2 pass authoritatively; on that basis RFC 0007 flipped to validated (its gates, per docs/verification.md §3, are the querier-pillar ones — B1/B2). A1 fails authoritatively and carries a hardware-sensitivity caveat (§9.4). (A1 was subsequently reclassified a recorded diagnostic, not a gate — RFC 0011, accepted 2026-06-14. The A1 readings throughout §9 are diagnostic; A1 gates nothing, and the “open gate” / “must-win” framing in the dated entries below is superseded.)

Reviewers: a PR that materially affects the hot path must either (a) cite the benchmark result and its delta against the relevant goal, or (b) explain why the hot-path effect is bounded below measurability. “I did not run the benchmarks” is a PR rejection, per CLAUDE.md §6.6.

No ourios-bench --update-benchmarks-md run has populated this region yet. It is the bench-managed results area — automated runs replace everything between these markers with one table per (git-sha, hardware). The hand-written §9.1 below is the curated diagnostic narrative and lives outside the region so automated runs never touch it. (This empty region is pre-placed so the first --update-benchmarks-md run replaces it in place rather than appending a second results section at end-of-file.)

9.1 Results — 2026-06-01 (diagnostic, ci-runner)

Corpus. corpus/otel-demo-v{1..4} — OTel Demo 2.2.0 logs captured via the collector fileexporter (workflow .github/workflows/capture-otel-demo-corpus.yml), business-service logs only (collector self-telemetry + load-generator filtered out), OTLP/JSON. Sizes 30 / 136 / 272 / 547 MiB — all below §8’s ≥ 1 GiB canonical benchmark minimum (this run is deliberately sub-minimum, to chart the trend, hence diagnostic). Hardware. ci-runner (hosted, ~4 vCPU) — not the §1 baseline, so deltas are indicative, not authoritative.

A1 — compression (target: ourios ≥ 3.0× zstd-19).

Scale series (ourios at the production ZSTD-3 default):

corpussizeourioszstd-19A1 delta
v130 MiB15.5×33.3×0.465
v2136 MiB21.5×32.3×0.666
v3272 MiB23.4×32.3×0.725
v4547 MiB24.6×32.4×0.758

Codec sweep (v4 = 547 MiB, ourios ZSTD level varied):

ourios ZSTDouriosA1 delta
3 (prod default)24.6×0.758
926.2×0.808
1526.4×0.816
1926.9×0.829

A1 verdict: FAIL (target 3.0×; best observed 0.829). Both levers are bounded. Scale lifts the delta but plateaus ~0.78 (ourios asymptotes ~25×; zstd-19 is flat ~32× — the logs are locally repetitive, so zstd compresses them well at any size, not via a whole-corpus window). Raising ourios’s codec to ZSTD-19 adds only ~+0.07 and saturates by level 9. Even at equal codec strength, ourios stays ~17% larger than monolithic zstd-19: a structural cost of columnar Parquet (per-column/per-chunk framing, page indexes, row-group metadata, bloom filters) versus zstd-19 over one concatenated stream. That same chunking is what enables row-group skipping — so the ~17% space premium is the price of queryability, not an optimisation target. On pure compression of this corpus, ourios ≈ 0.83× zstd-19; the thesis rests on query performance (B1/B2), not on beating a byte codec.

C1 — reconstruction (target: 100% bit-identical or flagged lossy). PASS at every size: 1.0 reconstruct rate, ~1.1% of records flagged lossy (structured/kvlist bodies) and retained verbatim per CLAUDE.md §3.3.

C2 — template-count convergence (target: sub-linear). PASS (supportive). Templates grew 282 → 429 → 722 → 1322 while records grew 38k → 183k → 366k → 735k — sub-linear throughout. The formal gate abstains below 1 M lines (§3.4.3), but the curve shape is the strongest evidence yet for the template-mining premise.

Escalation (§7). One gate (A1) fails, on a size-non-representative corpus (all < §8’s 1 GiB minimum) and non-baseline hardware — so this is “corpus-specific,” not the two-gate pillar-level pause. C1 + C2 support the thesis. The production ZSTD-3 default is retained: the codec gain is small, saturates by level 9, and the residual gap is structural, so a higher default isn’t worth the ingest-CPU.

9.2 Results — 2026-06-11 (diagnostic, ci-runner) — A1 / C1 / C2 at ~1 GB

Corpus. corpus/otel-demo-v5 (1,042,274,219 B) and corpus/otel-demo-v6 (1,034,615,505 B) — same capture pipeline as §9.1, extending the scale series to ~1 GB (both within 4% of, but still just under, §8’s ≥ 1 GiB binary minimum). v6 was captured with the OTel Demo failure flags enabled (adFailure cartFailure productCatalogFailure), so it carries a real error band; v5 is an unflagged capture. Hardware. ci-runner — indicative, not the §1 baseline. Runs. bench.yml 27370641352 (v5), 27373716667 (v6).

A1 — compression (target: ourios ≥ 3.0× zstd-19).

corpussizerunourioszstd-19A1 delta
v51,042,274,219 B2737064135226.3×31.7×0.828
v61,034,615,505 B2737371666726.0×31.5×0.824

A1 verdict: FAIL (target 3.0×). The scale series now reads 0.465 (v1, 30 MiB) → 0.666 (v2) → 0.725 (v3) → 0.758 (v4) → 0.828 (v5) / 0.824 (v6): the delta is size-driven and still rising, but decelerating — the crossover is not reached at ~1 GB, consistent with §9.1’s structural reading (ourios asymptotes ~26×; zstd-19 stays flat ~32×). v5 ≈ v6 shows the failure-flag error band does not perturb A1. This is the first A1 miss at (essentially) canonical size, so §9.1’s “size-non-representative” mitigation no longer applies; it remains a single-gate fail (no §7 two-gate pause), the §9.1 structural explanation stands, and the thesis-deciding counterpart — B1/B2 — now passes indicatively (§9.3). Whether the §7 corpus-specific tuning-RFC response triggers is a maintainer decision, sensibly taken once an authoritative baseline-8vcpu-32gib run confirms the number. (Resolved 2026-06-12: the §9.4 baseline run confirms — and slightly worsens — the deltas; the decision is now live with the maintainer.)

C1 — reconstruction (target: 100% bit-identical or flagged lossy). PASS on both: 1.000000 — v5 reconstructs 1,213,004 / 1,213,004 non-lossy rows exactly (lossy ratio 0.0114); v6 1,208,323 / 1,208,323 (lossy 0.0112).

C2 — template-count convergence (target: ratio ≥ 0.5 at 1 M lines). PASS on both — and for the first time on ≥ 1 M-line corpora, so the formal gate applies rather than §9.1’s abstention: v5 convergence ratio 0.756 (end count 1605, sample cadence 1336); v6 ratio 0.760 (end count 1606, cadence 1329).

9.3 Results — 2026-06-11 (indicative, ci-runner) — first B1 / B2 query readings

Corpus. corpus/otel-demo-v{4,5,6} (the §9.1 / §9.2 captures). The LogHub HDFS_v1 B2 arm did not run (fetch_hdfs off — memory-bound on the hosted runner), so only one corpus family has fed the query gates. Hardware. ci-runner — indicative, not the §1 baseline. Runs. query-bench.yml 27379085890 (B1 + the B2 structural metrics, after the effective-timestamp stack #178/#179) and 27357104694 (the prior run; its windowed / full-span latencies are quoted where noted). Recording. B1/B2 entries land in §9 per the maintainer’s 2026-06-12 authorization. RFC 0006 never reserved §9 (its §1 anticipated B1/B2 landing “in a follow-up extension PR once the querier is live” — RFC 0007); the workflow itself never writes §9 — every entry here is curated by hand.

B1 — predicate pushdown vs zstdcat | grep (target: ≥ 10× at 1 GiB). Query: severity ERROR, full corpus span. Run 27379085890:

corpusrowsRGs scannedourios bytesreference bytes (zstd)ouriosreferencespeedup
v5113/6326,1021,403,0256.14 ms245.5 ms40.0×
v6285/6764,0821,455,9128.50 ms258.5 ms30.4×

Row counts agree exactly with the reference pipeline on both corpora. v4 is skipped: the unflagged 100-user capture genuinely contains zero error-band rows, so the predicate selects nothing.

B1 verdict: PASS (indicative) — both corpora clear the ≥ 10× bar at 3–4× margin, on the first real-corpus reading. Caveats, stated plainly: ci-runner, not the §1 baseline; the error bands are ultra-thin (11 / 28 rows — extreme selectivity is the friendliest case for pruning); both corpora sit just under the §8 1 GiB minimum. An authoritative baseline-8vcpu-32gib rerun (ideally with a denser error band) is required before this counts as the canonical B1 number.

B2 — template-exact latency ∝ result, not corpus. Windowed 1-hour template-exact query, result roughly constant as the corpus grows. Structural metrics (run 27379085890): scanned row groups stay flat at 1 — v4 1/5, v5 1/6 (17,632 rows, 1.86 MB), v6 1/6 (11,750 rows, 1.59 MB). Wall-clock (prior run 27357104694): windowed latencies sit in a flat ~3.4–4.1 ms band (v4 3.59 / v5 4.13 / v6 3.40 ms) while the full-span variant grows with corpus size (7.3 / 10.6 / 10.6 ms) — exactly the result-bound-vs-corpus-bound split the gate asks for.

B2 verdict: PASS (supportive, indicative) — the flat shape is confirmed on real corpora at ~1 GB; the formal target speaks above ~10 GiB, which remains unmeasured, and the second corpus family (HDFS_v1) hasn’t fed the arm yet.

RFC 0007 validated assessment. These are the measurements the RFC 0007 green → validated gate needs, but not yet in the form the ladder requires (§1 quotes must-win numbers against baseline-8vcpu-32gib): see the status note in docs/rfcs/0007-querier.md. The RFC stays green with a validated-pending note — authoritative baseline rerun required; denser error band and a second corpus family supporting. (Resolved 2026-06-12: the §9.4 authoritative run delivered the baseline rerun and the second corpus family (HDFS_v1); RFC 0007 is validated. The denser error band remains an open quality improvement.)

9.4 Results — 2026-06-12 (authoritative, baseline-8vcpu-32gib)

Corpus. corpus/otel-demo-v{1..6} (the §9.1 / §9.2 captures; 30 MiB → ~1 GB) for A1 / C1 / C2 and B1/B2’s OTel-Demo arms, plus — for the first time — the bench-time-fetched LogHub HDFS_v1 (§1; ~1.47 GiB plain text, 11,175,629 rows ingested across 5 files) feeding the B2 arm as the second corpus family. Hardware. baseline-8vcpu-32gib — the §1 baseline (8 dedicated vCPU, 32 GiB RAM, local NVMe-class SSD). These are the authoritative numbers the §1 methodology quotes must-win gates against; the §9.1–§9.3 ci-runner entries remain indicative history. Runs. Dedicated baseline host (no CI run id): one ourios-bench run per corpus (A1/C1/C2) plus one query-bench run (B1 + B2), executed 2026-06-11/12; raw logs retained by the maintainer. Recorded per the maintainer’s 2026-06-12 authorization.

A1 — compression (target: ourios ≥ 3.0× zstd-19).

corpussizeourioszstd-19A1 delta
v130 MiB14.6×33.3×0.439
v2136 MiB19.9×32.3×0.615
v3272 MiB21.4×32.3×0.665
v4547 MiB22.5×32.4×0.693
v5994 MiB23.8×31.7×0.751
v6987 MiB23.6×31.5×0.749

A1 verdict: FAIL (authoritative) (target 3.0×; best observed 0.751). The delta is monotonic with corpus size and the crossover is unobserved, consistent with §9.1’s structural reading. One finding must be recorded honestly: the authoritative deltas sit below the ci-runner series (0.465 → 0.828) at every size — the ourios side compressed less effectively on this hardware (e.g. v5: 23.8× vs CI’s 26.3×) while zstd-19 stayed essentially stable (31.7× on both) — i.e. the ourios writer’s output is environment-sensitive (suspected row-group sizing / threading effects on the resulting encodings). That is now an open A1 investigation item alongside the structural gap itself. A1 gates the compression pillar (RFC 0006’s remit); the §7 escalation response is with the maintainer.

C1 — reconstruction (target: 100% bit-identical or flagged lossy). PASS (authoritative) on every corpus: 1.000000 throughout — v5 reconstructs 1,213,004 / 1,213,004 non-lossy rows exactly (lossy ratio 0.0114), v6 1,208,323 / 1,208,323 (lossy 0.0112); v1–v4 likewise 1.000000 (lossy 0.0097–0.0112). The formal ≥ 1 M-line gate passes on the baseline.

C2 — template-count convergence (target: ratio ≥ 0.5 at 1 M lines). PASS (authoritative) on both ≥ 1 M-line corpora: v5 ratio 0.756 (end template count 1605, sample cadence 1336), v6 ratio 0.760 (end count 1606, cadence 1329). v1–v4 abstain (< 1 M lines), as in §9.1.

B1 — predicate pushdown vs zstdcat | grep (target: ≥ 10× at 1 GiB). Query: severity ERROR, full corpus span. v4 is skipped (zero error-band rows, as in §9.3).

corpusrowsRGs scannedourios bytesreference bytes (zstd)ouriosreferencespeedup
v5113/6326,1021,403,0255.86 ms200.27 ms34.2×
v6285/6764,0821,455,9128.03 ms203.87 ms25.4×

Row counts agree exactly with the reference pipeline on both corpora (11 and 28).

B1 verdict: PASS (authoritative) — both corpora clear the ≥ 10× bar at 2.5–3.4× margin on the §1 baseline. Remaining caveat, non-blocking: the error bands are still ultra-thin (11 / 28 rows — the friendliest case for pruning); a denser error band stays an open quality improvement.

B2 — template-exact latency ∝ result, not corpus.

Full-span template-exact (result grows with the corpus, so latency may too):

corpusrows returnedRGs scannedbyteslatency
v489,3825/55,514,0336.84 ms
v5168,4876/66,785,7149.57 ms
v6168,3136/66,801,2559.69 ms
hdfs-v11,723,23214/1416,523,42130.19 ms

Windowed 1-hour template-exact (the gate’s shape: result roughly constant as the corpus grows):

corpuscorpus rowsrows returnedRGs scannedbyteslatency
v4735,37712,8541/51,674,7184.39 ms
v51,367,53217,6321/61,857,9995.07 ms
v61,360,04011,7501/61,592,2794.19 ms
hdfs-v111,175,62928,2071/141,737,8525.92 ms

The HDFS_v1 row is the first reading from the second corpus family (plain-text, the template-diversity case): the corpus is 8–15× the OTel-Demo row counts, yet the windowed scan still touches 1 row group (13 pruned) and stays inside the same flat latency band, while the full-span variant grows with the corpus (6.84 → 30.19 ms) — exactly the result-bound-vs-corpus-bound split the gate asks for.

B2 verdict: PASS (authoritative) — windowed ~10–28 k-row results answer in 4.2–5.9 ms (gate: ≤ 200 ms for ~10 k rows), flat from 735 k to 11.2 M rows across two corpus families. The formal target’s ≥ 10 GiB regime remains a future scale extension; the measured shape is the operative evidence.

RFC 0007 green → validated (resolved). The docs/verification.md §3 ladder reads: “Every thesis-gate in benchmarks.md §7 that the RFC’s pillars touch passes on representative corpora.” RFC 0007’s pillar is the query engine (pillar #3); its gates are B1 and B2, both now passing authoritatively on the §1 baseline over ~1 GB+ corpora including a second family. A1 does not gate RFC 0007 — it belongs to the template-mining/compression pillar, measured under RFC 0006. RFC 0007 is therefore flipped to validated (see its status note); accepted awaits maintainer sign-off per the ladder.

9.5 Results — 2026-06-13 (diagnostic, local unknown hardware) — A1 / C1 / C2 on HDFS_v1

Corpus. LogHub HDFS_v1 (Zenodo record 8196385, md5 76a24b4d…) — 11,175,629 lines, 1,577,982,906 raw bytes; fetched at bench time, never redistributed (query-bench.yml). The maximally-templated log corpus (a handful of templates over 11.2 M lines) — the single best case for the template-mining compression premise. Run via ourios-bench --gates a1,c1,c2 --parquet-zstd-level 19 --allow-unknown-hardware. Local hardware → diagnostic, not authoritative; A1’s verdict is corpus-structural and hardware-independent (compressed bytes are deterministic), C1/C2 are ratios, so the findings hold regardless of the runner.

gateresultverdict
A1ourios 8.300× vs zstd-19 16.000× → delta 0.516× (raw 1.578 GB → ourios 189.98 MB, zstd-19 98.21 MB)FAIL — now diagnostic (RFC 0011)
C11.000000 — 11,175,578 / 11,175,578 non-lossy rows bit-identical; lossy ratio 4.6e-06 (51 rows)PASS
C2end template count 40 at 11.2 M lines (33 at 1 M); ratio 0.825 — sub-linear, formal gate applies (≥ 1 M, §3.4.3)PASS

A1 — the decisive finding (→ RFC 0011). A1 had only ever been measured on OTel-Demo (best 0.829×, §9.1/§9.4). HDFS_v1 is the corpus that should most reward template mining, yet A1 fails harder (0.516×): the more templated the corpus, the more completely monolithic zstd-19 captures its redundancy in one window (16×), while template mining’s extracted params (block IDs, timestamps, IPs) are high-cardinality columns that don’t compress as well and the columnar layout adds framing. The best case for template mining is the best case for the byte codec. So ≥ 3× over zstd cannot hold on any realistic log corpus — A1 is demoted to diagnostic and template mining’s compression value is recognised as logical/query-pruning (B1/B2), not on-disk bytes. See RFC 0011.

C1 + C2 — the miner pillar’s real gates, PASS on a representative corpus. At 11.2 M lines C1 is bit-identical (1.0) with a 4.6e-06 lossy ratio, and C2 plateaus at 40 templates with the formal gate applying (not abstaining, unlike the §9.1 sub-1 M runs). Under RFC 0011 these are RFC 0001’s validated thesis gates — both pass here. The authoritative baseline-8vcpu-32gib representative rerun (for the actual RFC 0001 validated flip) followed on 2026-06-14 (§9.6); as expected of deterministic verdicts, the numbers are identical.

9.6 Results — 2026-06-14 (authoritative, baseline-8vcpu-32gib) — C1 / C2 on HDFS_v1

Corpus. LogHub HDFS_v1 (Zenodo record 8196385, md5 76a24b4d…) — 11,175,629 lines, 1,577,982,906 raw bytes; fetched at bench time on the baseline host, md5-verified, never redistributed. Hardware. baseline-8vcpu-32gib — the §1 baseline (8 dedicated vCPU, 32 GiB RAM, local SSD), provisioned for this run and torn down immediately after. These are the authoritative C1 / C2 numbers for RFC 0001’s validated gates. Run. Dedicated baseline host (no CI run id): one ourios-bench --gates c1,c2 --hardware-kind baseline-8vcpu-32gib run at git 9a57ace; results JSON retained by the maintainer (2026-06-14T00-36-23.225Z-9a57ace.json). A1 was deliberately not run — it is diagnostic, not gating (RFC 0011); the §9.5 diagnostic A1 reading stands.

gateresultverdict
C11.000000 — 11,175,578 / 11,175,578 non-lossy rows reconstruct bit-identically; lossy ratio 4.6e-06 (51 rows)PASS
C2end template count 40 at 11.2 M lines (33 at 1 M); ratio 0.825 — sub-linear, formal gate applies (≥ 1 M, §3.4.3)PASS

Authoritative confirmation. The verdicts match §9.5’s local diagnostic run bit-for-bit — expected, since C1 (reconstruction fidelity) and C2 (template-count convergence) are deterministic functions of (corpus, miner) with no wall-clock or hardware-sensitive component (contrast A1’s writer-environment sensitivity, §9.4). The value of this run is the authoritative hardware_kind stamp on the two gates that, under RFC 0011, define RFC 0001’s validated: both PASS on a representative ≥ 1 M-line corpus on §1 baseline hardware.

9.7 Results — 2026-06-15 (authoritative, baseline-8vcpu-32gib) — D2 / D3 / B2-post (RFC 0009 compaction)

Hardware. baseline-8vcpu-32gib — the §1 baseline (8 dedicated vCPU, 32 GiB RAM, local SSD), provisioned for this run and torn down immediately after. These are the authoritative D2 / D3 / B2-post numbers for RFC 0009’s validated measure (RFC0009.7). Run. Dedicated baseline host (no CI run id): the ourios-bench compaction bench at git 4d52288. Two invocations — the band-scale one-shot (OURIOS_COMPACTION_BASELINE=1, FILES=32, ROWS=4800, BODY_BYTES=4096) for D2/D3, then the b2-post-compaction criterion group. Synthetic (no corpus): D2/D3 drive one partition of 32 small files (~485 MiB) through compact_partition; B2-post queries 32-files-vs-1-file with the result set held constant.

measureresultverdict
D2 compaction throughput32 files (485.2 MiB) → 1 in 2.91 s = 166.8 MiB/s; 153,600 rows conservedkeeps up — single-partition / single-threaded, ≫ any per-partition seal rate, so the backlog drains
D3 small-file size bandoutput 456.7 MiBIN the 256 MiB–2 GiB band; 0% of live files < 128 MiB (target < 5%)PASS
B2-post query latencytemplate query: uncompacted 12.78 ms (32 row groups, 33.5 MiB read, 32 files) → compacted 2.10 ms (1 row group, 1.05 MiB, 1 file) = 6.1×PASS

Reading. D3 is the headline: a band-scale compaction lands its output squarely in the H4 256 MiB–2 GiB target with zero sub-128 MiB files — the small-file problem, eliminated. D2 shows consolidation runs at ~167 MiB/s on one partition/thread, far above any plausible per-partition seal rate, so a backlog drains (the “keeps up” property). B2-post quantifies the query payoff that motivated RFC 0009 (the PR #92 B2 finding that per-file footer/metadata reads dominate): collapsing 32 files → 1 cuts the footer reads ~6× on this query. The structural reductions (32 → 1 files / row groups, rows conserved) are hardware-independent and also pinned in ourios-parquet’s rfc0009_1_* / compaction_conserves_every_row tests; these wall-clock figures are the baseline-hardware stamp for RFC 0009’s validated. The full sustained-ingest soak (D2’s “backlog returns to zero in a one-hour window at D1’s rate”) and D1 itself remain unrun — the throughput here is the RFC0009.7 D2 measure, not that soak.

9.8 Results — 2026-06-18 (authoritative, baseline-8vcpu-32gib) — ingest write-path + recovery (criterion) and real-corpus A1 / C1 / C2 + B1 / B2

Hardware. baseline-8vcpu-32gib — the §1 baseline (8 dedicated vCPU, 32 GiB RAM, local SSD), provisioned for this run and torn down immediately after. Two such hosts (one per invocation set), both at git d3f2cae. Run. (a) the self-contained ourios-bench criterion benches ingest_write_path (RFC 0014) and recovery (RFC0008.3) — synthetic, no corpus — at full criterion settings; (b) the ourios-bench binary --gates a1,c1,c2 against two real corpora, plus the b1/b2 criterion benches (--warm-up-time 1 --measurement-time 3, matching query-bench.yml) over those corpora. Corpora: LogHub HDFS_v1 (Zenodo record 8196385, md5 76a24b4d… — 11,175,629 lines / 1,577,982,906 raw bytes (1.47 GiB) of real Hadoop production logs, above §8’s ≥ 1 GiB canonical minimum) and the frozen OTel-Demo v1 (corpus/otel-demo-v1, 38,782 lines / 31.5 MiB). HDFS is fetched in-job and never redistributed (§1).

(a) Ingest write path + recovery — supportive wall-clock (criterion).

benchmedianthroughput
wal_append/batch — OTLP→WAL append + fsync (the WAL-before-ack unit)372 µs10.5 MiB/s
sink_write/1000 — WAL→Parquet emit + flush (RFC 0014)2.64 ms379 K rec/s
sink_write/1000012.24 ms817 K rec/s
recovery/{1,4,16} — WAL replay over N segments (RFC0008.3)169 µs → 507 µs → 1.87 ms~O(N), no amplification

Single-threaded micro-benches on synthetic records — supportive wall-clock (the structural sides are pinned by ourios-ingester’s RFC 0014 / ourios-wal’s RFC0008.3 tests), not gates. Dedicated hardware ran ~20–30% faster with much lower variance than the indicative ci-runner figures.

(b) Thesis gates A1 / C1 / C2 on real corpora.

corpusA1 (ourios vs zstd-19 → delta)C1 reconstructionC2 convergence
HDFS_v1 (11.18 M lines, 1.47 GiB)6.21× vs 16.0× → 0.386 — FAIL (diagnostic)1.000000 (11,175,578 / 11,175,578 non-lossy rows; lossy ratio 4.6e-06, 51 rows) — PASSratio 0.825, 40 templates — PASS
OTel-Demo v1 (38.8 K lines)14.6× vs 33.3× → 0.438 — FAIL (diagnostic)1.000000 (lossy ratio 0.0097) — PASSABSTAIN (< 1 M lines), 282 templates

C1 reconstructs every non-lossy row bit-for-bit across 11 M real production lines — the §3.3 invariant holds on real data at scale. C2 converges on HDFS (40 templates over 11 M lines; ratio 0.825 ≥ the threshold) — the template-mining thesis on a real corpus. A1 fails as expected: it is a recorded diagnostic, not a gate (RFC 0011) — template mining’s value is query pruning (B1/B2), not on-disk bytes beating a whole-stream codec.

(c) Query gates B1 / B2 on real corpora.

benchresulttimingpruning
b1/synthetic2000 rowsourios 2.93 ms vs zstd-grep ref 118 µspruned 1/2 row groups, read 7.8 KB
b2/synthetic/{2k,20k,100k}result held constant2.13 / 4.67 / 11.32 mssub-linear in corpus size
b2/real-corpus/HDFS (template 1, ubiquitous)1.72 M rows30.8 ms14/14 row groups (no prune — template is everywhere)
b2/real-corpus/HDFS windowed 1 h28,207 rows6.1 ms13/14 row groups pruned by the time window (~5× faster)

The windowed HDFS arm is the headline: a time-bounded query on the real 11 M-line corpus prunes 13 of 14 row groups via Parquet min/max statistics — the predicate-pushdown thesis (pillar #1) on real production data, ~5× faster than the unwindowed scan. (B1’s real-corpus arm skipped: OTel-Demo v1 has no error-band severity_text rows for the selectivity probe.) B1/B2’s structural pruning is the gate (pinned in ourios-querier); these are the baseline-hardware wall-clock stamp.

Not committed by the bench tooling — this is the curated narrative; the managed BENCH-RESULTS region above is for --update-benchmarks-md runs. The b1/b2 criterion timings use the reduced --warm-up-time 1 --measurement-time 3 (matching query-bench.yml); the structural pruning/template numbers are exact and criterion-setting-independent.

9.9 Results — 2026-07-03 (indicative, ci-runner) — B1 / B2 post-RFC 0022 (promoted attribute columns)

Purpose. The RFC 0022 §5 RFC0022.5 note: the promoted-attribute write path (per-key resource.<k> / attr.<k> columns + the two-arm predicate compile) must leave B1/B2 unchanged. This is the indicative re-run after RFC 0022 went green (#345–#348); the pruning counters are pinned structurally in crates/ourios-querier/tests/rfc0022_attr_columns.rs, this entry is the wall-clock stamp. Corpus. corpus/otel-demo-v4 (107,332 records → 735,377 mined rows / 5 files) and corpus/otel-demo-v5 (163,929 records, ~1.04 GB raw → 1,367,532 mined rows / 6 files). The LogHub HDFS_v1 arm did not run (fetch_hdfs off — memory-bound on the hosted runner). Hardware. ci-runner — indicative, not the §1 baseline. Run. query-bench.yml 28686650566 at git 6e3301b (the RFC 0022 green merge).

B1 — predicate pushdown vs zstdcat | grep (target: ≥ 10× at 1 GiB). Query: severity ERROR, full corpus span.

corpusrowsRGs scannedourios bytesreference bytes (zstd)ouriosreferencespeedup
v5113/6324,7731,403,0258.10 ms282.06 ms34.8×

Row count agrees exactly with the reference pipeline. v4 is skipped as in §9.3 (its capture has no error-band rows).

B1 verdict: PASS (indicative), no regression — 34.8× against §9.3’s 40.0× on the same corpus, comfortably inside hosted-runner noise and 3.5× above the bar. Same caveats as §9.3: ultra-thin error band, corpus just under the §8 minimum, not the §1 baseline.

B2 — template-exact latency ∝ result, not corpus.

benchresulttimingpruning
b2/real-corpus/corpus/v4 (template 45)89,382 rows8.71 ms5/5 row groups (full span)
b2/real-corpus/corpus/v5 (template 8)168,487 rows12.37 ms6/6 row groups (full span)
b2/real-corpus/corpus-window-1h/v412,854 rows5.46 ms1/5 — 4 row groups pruned by the time window
b2/real-corpus/corpus-window-1h/v517,632 rows6.71 ms1/6 — 5 row groups pruned by the time window
b2/synthetic/{2k,20k,100k}result held constant2.17 / 4.77 / 13.61 mssub-linear in corpus size

B2 verdict: PASS (supportive, indicative), no regression — the windowed latencies sit in the same flat few-ms band as §9.3/§9.8 while the full-span variants grow with corpus size, and everything is orders of magnitude under the 200 ms bar. The formal target speaks above ~10 GiB, which remains unmeasured on this runner class.

Assessment. The promoted-column machinery (extra column chunks per row group on the write side; the two-arm OR compile on the read side) shows no measurable drag on either gate. The RFC 0022 green → validated step still requires the authoritative baseline-8vcpu-32gib rerun per the standing bench policy (maintainer opt-in); this entry is its indicative precursor, curated by hand as in §9.3 — the workflow never writes §9.

9.10 Results — 2026-07-04 (authoritative attempt, baseline-8vcpu-32gib) — B1/B2 at 16 GiB: run blocked, miner finding

Purpose. The first run in the §8 10–100 GiB band: B2’s formal target speaks above ~10 GiB and had never been measured there. Corpus. LogHub HDFS_v2 (bench-time fetch, never redistributed): 31 files, 17,240,888,465 bytes ≈ 16.1 GiB raw, ~71 M lines of Hadoop daemon logs — the first corpus in our set whose shape (stack traces, multi-format node logs) differs qualitatively from HDFS_v1’s block events. Hardware. baseline-8vcpu-32gib, provisioned for the run and torn down after. Outcome: the run did not complete — it produced a product finding instead. The B2 store build was OOM-killed at 31.5 GiB RSS: the miner mints templates without bound on this corpus shape (template ids ≥ 56,199 by the 1.8 GiB subset mark, busiest template covering 0.67 % of 8.37 M rows; memory ~linear at ≈2× corpus bytes). Two bench-side pathologies were found and fixed en route — the eager corpus load (#350, now streaming: 1.3 GiB flat over hours) and a quadratic harness snapshot capture (#351, ~400× store-build speedup; gdb stacks exonerate the miner’s CPU path). RFC 0023 (bounded template memory) is the response; its RFC0023.7 criterion is this exact run completing.

What did land before the kill (recorded as diagnostic):

benchresulttimingpruning
b2/synthetic/{2k,20k,100k}result held constant2.72 / 6.33 / 19.7 mssub-linear in corpus size
b2/real-corpus (1.1 GiB subset)windowed 1 h → 1 row6.31 ms5/6 row groups pruned
b2/real-corpus (1.8 GiB subset)template 56199 → 55,751 rows full-span; windowed 1 hwindowed 6.31 ms10/11 row groups pruned by the window

B2’s shape — flat windowed latency, window-driven pruning — holds wherever memory allows; the fragmentation itself (56 k templates, busiest at 0.67 %) also means pillar #2’s logical reduction fails on this corpus shape, which is the same finding from the pruning side. B1 did not reach its arms (stopped before the reference build once the OOM trajectory was clear). No gate verdict is claimed from this entry; the §8-band verdict waits on RFC 0023 + the rerun.

9.11 Results — 2026-07-04 (authoritative, baseline-8vcpu-32gib) — B1 / B2 at 16 GiB + RFC0023.7

Purpose. The §8 10–100 GiB band’s first completed measurement (the §9.10 attempt OOM’d), doubling as RFC0023.7 (bounded mining must complete this exact corpus under 8 GiB peak RSS) and the first B1/B2 readings at ≥ 10 GiB — where B2’s formal target speaks. Corpus. LogHub HDFS_v2 (bench-time fetch): 31 files, 17,240,888,465 bytes ≈ 16.1 GiB, 71,116,785 mined rows → 21 files / 80 row groups. B2 ran under the §3.3 Fixed severity baseline; B1 under the opt-in OURIOS_CORPUS_SEVERITY=log4j extraction (#350), stated per the methodology rule. Hardware. baseline-8vcpu-32gib, provisioned for the run, torn down after. Git 19e0886 (RFC 0023 bounds + telemetry merged).

RFC0023.7 — bounded mining at scale: PASS. Peak RSS 1.73 GiB across both benches’ store builds (5 s sampler), vs the §9.10 OOM at 31.5 GiB on identical input — an 18× reduction, under the 8 GiB bar with 4.6× headroom. Both benches completed (B2 phase 35 min; B1 including its zstd-19 reference build ~2.8 h).

B1 — predicate pushdown vs zstdcat | grep (target: ≥ 10× at 1 GiB, widening to ≥ 100× at 100 GiB). Query: severity ERROR, full 16 GiB span.

corpusrowsRGs scannedourios bytesreference bytes (zstd)ouriosreferencespeedup
HDFS_v224,03054/8019,284,044548,344,798116.76 ms13.545 s116×

Row count agrees exactly with the reference pipeline.

B1 verdict: PASS (authoritative) — the ≥ 100× mark projected for 100 GiB is crossed at 16 GiB. With §9.8’s ~35–40× at ~1 GiB, the measured trajectory confirms the widening the target predicted: the reference’s cost grows with corpus bytes while Ourios’s grows with the matching row groups.

B2 — template-exact latency ∝ result, not corpus (formal target: ≥ 10 GiB, ≤ 200 ms for 10 k rows).

benchresulttimingpruning
b2/real-corpus windowed 1 h78 rows5.60 ms79/80 row groups pruned by the time window (21 partitions)
b2/real-corpus full span56,234,257 rows124.70 ms80/80 scanned (count over the dominant class)
b2/synthetic/{2k,20k,100k}result held constant1.92 / 3.70 / 10.3 mssub-linear in corpus size

B2 verdict: PASS (authoritative, first ≥ 10 GiB reading) — the windowed query answers in the same few-ms band as the ~1 GiB corpora (§9.3/§9.8/§9.9): latency tracks the result, not the 71 M-row corpus.

The fragmentation datum (§9.10’s open question, quantified). The “busiest template” is id 0 — NO_TEMPLATE: under the default 20 k ceiling, ~79 % of HDFS_v2’s rows took the §6.3 parse-failure path (bodies retained bit-faithfully; observable via ourios.miner.parse_failure.reason, RFC0023.6). Template mining contributes little on this corpus shape — and the B1/B2 numbers above show the floor it degrades to (first-class-column + time pruning over Parquet statistics) still clears every gate. Follow-up noted: the B2 bench’s busiest-template picker should exclude NO_TEMPLATE so the full-span arm measures a true template-exact query on such corpora.

Assessment. RFC 0023’s §5 is fully discharged (this entry is the .7 record); the RFC flips red → green alongside this entry. The §8-band thesis verdict on real, hostile-shaped production logs: pruning compounds with scale (B1), result-bound latency holds (B2), and the mining-fragmentation failure mode is now bounded, observable, and priced.

9.12 Results — 2026-07-09 (indicative, local M-series) — otel-demo v8 capture: C1 / C2

The run is dated 2026-07-09; its C2 verdict was re-scored under the per-service gate on 2026-07-10 (#444 / RFC 0006 §3.4.3), so the resolution dates below post-date the heading.

Corpus. corpus/otel-demo-v8 (published GitHub release): a 48-hour OTel-Demo 2.2.0 capture at 150 locust users with the adFailure + paymentFailure feature flags active — 690,355 OTLP LogsData batches / 4,948,596 log records / 2.96 GB uncompressed, the largest and most hostile real capture to date (deliberately injected failure modes, multi-service, long-horizon). Calibration manifest at testdata/calibration/otel-demo-v8.json (RFC 0024 §3.1).

C1 — bit-identical reconstruction: PASS, perfect. The corpus holds 4,948,596 records (the calibration manifest’s count); 17 of them (all kafka, 0.0003 %) took the §3.3 lossy-flag path with their bodies retained, and C1 = 1.000000 over the remaining 4,948,579 rows — the honesty contract holds at 4.9 M rows through failure-mode churn.

C2 — template-count convergence (bar: ratio ≥ 0.5 at 1 M lines, evaluated per service since #444): PASS. Under the per-service gate (RFC 0006 §3.4.3, amended 2026-07-10) the corpus passes: the only service that clears the 1 M-line evaluation floor is cart, which converges at ratio 1.000 with two templates. Every other service abstains for want of volume; the whole-corpus ratio (0.199, end template count 14,631, sample cadence 4,833) is retained below as a diagnostic — it is a category error to grade a multi-service corpus as one Drain stream (§3.4.3 rationale). The per-service decomposition (splitting on service.name and re-running the gates per service) localises the whole-corpus fragmentation completely:

servicelinesend templatesC2
cart2,756,3312ratio 1.000 PASS
recommendation971,49017abstain (< 1 M)
currency597,2591abstain (< 1 M)
ad486,7263abstain (< 1 M)
kafka136,79014,608abstain (< 1 M)

The gate folds over the gated services (those ≥ 1 M lines): cart is the sole such service and it passes, so the corpus passes. cart clears the formal gate at 2.76 M lines with two templates; the smaller services abstain below the 1 M-line floor, so they are not graded — though their observed counts (1–17 templates over 0.5–1.0 M lines) sit at the same near-flat convergence. The kafka broker, also abstaining, is the outlier: it mints 14,608 templates on 2.8 % of the lines. Mechanism (measured): kafka’s cleaner logs emit 3-token lines whose third token is a unique offset-bearing path (Deleted log /tmp/kafka-logs/…/00000000000000000429.log.deleted., 11,651 distinct) — one varying token in a 3-token line is similarity 2/3 ≈ 0.67, below the strict 0.7 threshold (§3.1 no-silent-merges), so each line mints a template; the 4-token siblings of the same family (0.75) merge fine. The failure-flag confound turned out to be a red herring. #444 settled how to handle the fragmentation (2026-07-10, maintainer-approved): of the three options — tokenizer masking, length-aware thresholding, and accept-and-scope-C2-per-service — option 3 shipped (the per-service gate, RFC 0006 §3.4.3, PR #451); masking is parked as a future strategic RFC (no commitment; a Collector transform or redaction processor can polish high-cardinality infra tokens upstream) and length-aware thresholding was rejected. The safety story held throughout (bounded memory per RFC 0023, per-service C1 perfect).

The per-service decomposition is now the first-class bench gate (ourios-bench --gates c2 prints it whenever any service bucket exists — distinct service.name values plus any <unknown>/<other>, so a single-service or plain-text corpus shows its one gated row too); template creation is a globally-monotonic event attributed to the minting service, so per-service creations partition the whole-corpus count exactly (2 + 17 + 1 + 3 + 14,608 = 14,631) in O(services) memory — no per-service id set. As of #444 (option 3) this decomposition is the gate: C2 is evaluated per service and folds over the services that clear the 1 M-line floor, with the whole-corpus ratio kept as a diagnostic (RFC 0006 §3.4.3).

What the fragmentation actually costs — B2 pricing (indicative, local M-series). Running the B2 windowed query on the fragmented (kafka) vs. converged (cart) service isolates the impact:

servicetemplates1 h-window queryrow groups pruned
cart23.66 ms48 / 49
kafka14,6083.40 ms48 / 49

The deployed time/column pruning floor is identical whether a service has 2 templates or 14,608 — a 1 h window prunes 48 of 49 row groups either way (reconfirming the RFC 0023 graceful-degradation result on a fresh corpus). Fragmentation does not cost query latency or pruning. What it costs is template-exact query precision: probing cart’s dominant template (id 1 in this run — a run-specific identifier, not a canonical one) recovers 1.78 M / 2.76 M rows (one template is most of the corpus) but only 11,523 / 136,790 on kafka, because kafka’s dominant event is scattered across ~11,651 ids — a single template_id probe recovers only that one id’s slice (11,523 rows), not the full dominant event. So the fragmentation is a query-capability / thesis-value tradeoff, not a performance one; the pruning path degrades to the first-class-column floor unharmed. #444 accepted that tradeoff on hostile infra logs: the per-service gate makes C2 acceptance honest without masking, and any future masking is deferred to an upstream Collector processor or a dedicated RFC.

9.13 Results — 2026-07-12 (indicative, ci-runner) — RFC 0031 comparative program vs Grafana Loki (runs #8–#18)

Purpose. The first recorded numbers for the RFC 0031 comparative program — Ourios against Grafana Loki, the incumbent CLAUDE.md §1 defines the project against. These are the §7 calibration inputs the RFC’s open questions ask for, not gate verdicts: the L-gate margins are the RFC’s proposed values (M_L1..M_L4 = 10, F_L6 = 3, wired as ComparativeMargins::default()), the §5 gate scenarios (RFC0031.2–.11) are still red stubs, and the harness reports each pair under its provisional margin rather than asserting it. Every “PASS”/“fail” below is provisional pending the §7 freeze — a maintainer step; the open inputs are enumerated in point (4) of the closing Assessment.

Corpus. corpus/otel-demo-v8 (the §9.12 capture): 4,948,596 log records, 2.96 GB uncompressed — the RFC 0031 §3.3 headline corpus (real OTLP, failure flags active, kafka fragmentation and all). Both systems ingest the identical OTLP stream; an OTLP partialSuccess in any push response fails the run, so neither side can silently drop lines. Reference system. grafana/loki:3.5.3, digest-pinned (sha256:3165cecce301ce5b9b6e3530284b080934a05cd5cafac3d3d82edcb887b45ecd), single-binary mode, fed over its native OTLP endpoint. Flag deviations from stock are documented below — all ingest-replay accommodations, all in Loki’s favour, per the §3.7 anti-strawman commitment. Hardware. ci-runnerindicative, not the §1 baseline; the authoritative baseline-8vcpu-32gib run remains a maintainer opt-in per RFC 0031 §3.2. Bytes-read, the primary channel, is CPU-insensitive by construction, but nothing here is quoted as authoritative. Runs. comparative-bench.yml dispatch runs (curated by hand as ever — no workflow writes §9), each with one harness delta under test. Counted runs are equivalence-gated passes over the full corpus; the two diagnostic failures (#11/#13) are listed with exactly what they carry:

runworkflow run iddelta under test
#829171354194honest-metric baseline (§3.6 amendment wired)
#929174022848+ single-pass count/materialize scan (#485)
#1029174342843+ late materialization (#486)
#1129186113326L3 diagnostic: Loki 0-rows, pre-salvage panic — no counted numbers
#1229188179299+ L3 trace pair (#487/#488)
#1329189430335L3 diagnostic recurrence (on the #489 branch): L3 timed out; the salvaged report’s other pairs are counted where tabulated
#1429190408893+ trace_id/span_id blooms (#489; pre-merge on the PR branch, since merged)
#1529192897795+ L1 template pair (#492; pre-merge, since merged)
#1629199815903+ selective-resource diagnostic, first picker (produced a vacuous duplicate of the L6 k=100 pair — the fix is what #493 merged; the run’s L1/L3 pairs measured and passed, so it counts toward the streaks)
#1729203804795+ selective-resource diagnostic pair, fixed picker (#493; pre-merge, since merged)
#1829210202343+ latency_p50 channel (#495; pre-merge, since merged) — bytes unchanged from #17; adds the §3.6 latency numbers below

In every counted run, RFC0031.1 result-set equivalence held on every pair: the two systems’ answers, keyed (timestamp_unix_nanos, body_bytes), were multiset-identical at 4.9 M-record scale. Runs #11/#13 were L3-flicker diagnostics (an ingester-visibility artifact, fixed in #490 — see the deviations list); their table rows above note exactly what each carries. Every dispatched run appears in the table, and the per-class tables below carry a row for every run in each quoted streak (L1: #15/#16/#17; L3: #14/#15/#16/#17), so the streaks audit from this entry alone.

The metric (§3.6 as amended 2026-07-12). The Ourios figure is the total bytes fetched from object storage per query: count scan + row materialization + template-registry derivation. Loki is reported on two channels: storage-side (query-stats compressedBytes + headChunkBytes — the conservative apples-to-apples counterpart of Ourios’s fetched compressed-Parquet bytes; the harness evaluates gates primarily on this) and totalBytesProcessed (decompressed engine-side work, which overstates Loki’s storage reads by the chunk compression ratio; reported as context). Which channel the frozen §7 gates ride is an open maintainer decision.

Program history — the biased ruler, retired. Runs #5–#7 predate the §3.6 measurement-fidelity amendment and measured the Ourios side as the count scan alone (e.g. run #7’s severity figure of 609,498 B and its “146.9×”-style ratios), silently excluding the row-materialization and registry IO while Loki’s counterpart figure includes delivering results. Those runs are program history only and are not citable; every number below is on the honest total.

L1 — template-exact lookup (must-win, the flagship class): provisional PASS, widest margins. Pair: template_id == 4323 (2 rows) vs the LogQL line-filter needle "Updated connection-accept-rate max connection creation rate to" over every stream — the picker proves the two select identical row sets before the pair counts. Loki has no template concept, so its honest equivalent is a substring scan of the whole corpus; Ourios rides the writer’s existing bloom filter on template_id.

runourios bytesloki storage-sideloki processedstorageprocessed
#151,358,683104,825,4282,468,065,72677.2×1,816.5×
#161,358,683105,191,9562,469,772,35277.4×1,817.8×
#171,358,683105,579,5102,474,713,32177.7×1,821.4×

Above the provisional M_L1 = 10 on both channels, in every run since the pair landed (third consecutive pass at #17). The Loki side is structural: no template id → nothing to prune with.

L3 — trace correlation (must-win, OTLP-native): provisional PASS after blooms. Pair: every log line for one trace_id (9 rows). trace_id is high-cardinality by construction, so it cannot be a Loki label (§3.3’s machine-checked disallowlist); Loki’s honest query is a structured-metadata filter over all streams.

runourios configourios bytesloki storage-sideloki processedstorageprocessed
#12no bloom — trace_id column scanned corpus-wide72,935,984102,835,8032,419,117,7831.41×33.2×
#14+ trace_id/span_id blooms (#489)4,812,668105,353,8372,476,749,58521.9×514.6×
#15reproduction4,812,668102,133,8662,404,486,16921.2×499.6×
#16reproduction4,812,668104,656,5702,456,853,96921.7×510.5×
#17reproduction4,812,668105,251,5472,465,855,69521.9×512.4×

Run #12 is the honest before-picture: without blooms Ourios itself had to fetch the trace_id column corpus-wide, and the storage-side ratio (1.41×) was nowhere near the margin. The blooms (implemented in #489; the RFC 0005 §3.6 amendment recording them, with this as its measured evidence, is #491) collapse the fetch 15×, and the pair has now passed the provisional margin on both channels three runs in a row. As with L1, Loki’s side is structural: a trace cannot be pre-narrowed to a label stream, so it scans and decompresses everything in the window.

L2 — severity predicate (must-win family): parity-plus storage-side, ~33× processed — not a provisional 10× pass. Pair: lowest-volume single-severity_text band on the highest-volume service, full corpus span, 1 row. The run series doubles as the read-path optimisation ledger (component split: count scan + materialize + registry):

runleverourios bytes (count + mat + reg)loki storageloki processedstorageprocessed
#8baseline4,270,091 (609,498 + 3,146,731 + 513,862)2,880,78489,184,7110.67×20.9×
#9single-pass scan (#485)3,660,593 (0 + 3,146,731 + 513,862)3,158,32398,114,7030.86×26.8×
#10late materialization (#486)2,549,129 (0 + 2,035,267 + 513,862)2,751,83485,261,7181.08×33.4×
#12reproduction (no L2 delta)2,549,1292,779,80086,255,9011.09×33.8×
#13reproduction2,549,1293,349,89798,253,3431.31×38.5×
#14reproduction2,549,1293,224,893100,044,0701.27×39.2×
#15reproduction2,549,1292,688,94283,216,8951.05×32.6×
#16reproduction2,549,1292,673,54582,919,2331.05×32.5×
#17reproduction2,549,1293,224,528100,198,4661.26×39.3×

(Run #8’s Loki side: 2,880,784 storage / 89,184,711 processed.) Across the later reproductions the storage-side ratio sits at 1.05–1.31× and processed at ~33–39×, the spread being entirely Loki-side wobble (below). Reading: on the honest metric Ourios went from losing the storage channel (0.67×) to parity-plus via two read-path fixes, and wins decisively on engine work — but this is not a 10× storage-side pass, and no amount of wobble makes it one. The remaining named levers: the constant 513,862 B template-registry derivation, 20–29 % of every small-answer query’s total (the RFC 0033 cached-template-map candidate), and write-side page/row-group sizing.

Time-window browses (L6 floor family): published loss on the storage channel. Pairs: all lines of the highest-volume service in a clean k-row window (the promoted-column bloom’s worst case), plus run #17’s diagnostic — the same shape scoped to the lowest-volume service (“ad”, ~34 s window), where the service.name bloom could in principle skip. Floor gate as reported here: a bytes-read floor analog (Ourios ≤ 3× Loki, i.e. ratio ≥ 0.33) — the harness applies the §7 F_L6 factor to this entry’s bytes channels. Note the §5 gate as written (RFC0031.7) defines the L6 floor on latency p50 — measured in run #18 (see the latency section below), where the gate as written passes on all three window pairs; the bytes framing here remains the conservative reporting channel pending the §7 freeze.

runpairourios bytesloki storage-sideloki processedstorage ratioprocessed ratio
#8k=1005,094,79016,25063,5950.003 fail0.012 fail
#8k=20009,736,28572,5241,809,5230.007 fail0.186 fail
#10k=1002,257,86716,25063,5950.007 fail0.028 fail
#10k=20004,528,42972,5241,809,5230.016 fail0.40 pass
#17“ad” k=100 (diagnostic)1,757,48931,616687,0430.018 fail0.39 pass

This is the honest loss the RFC’s L6 disposition anticipated, and it is published as §5 RFC0031.11 demands: on a browse-k-rows query Loki reads only the tiny chunk slice its label stream + time index point at, while Ourios pays fixed per-query costs (the registry constant plus row-group-granularity materialization) that dwarf a k-row answer. The #486 late-materialization fix halved the loss and lifted k=2000 past the processed floor; storage-side stays 0.007–0.018 vs the 0.33 floor on current code. Run #17’s diagnostic sharpens the why: scoping to a low-volume service improves Ourios only ~22 % and flips the processed floor to pass, but there is no bloom collapse — v8’s hour partitions each hold roughly one row group containing all services, so the promoted service.name bloom has nothing to skip. The tier-changing lever is write-side layout (service clustering / row-group sizing — hazard #4 territory, an RFC-level change), not query-side tuning.

Latency (§3.6 channel, run #18 — the program’s first). Median of 7 warm repetitions per pair per system, measured only on correctness-verified pairs; Ourios timed in-process, Loki over localhost HTTP (negligible at these magnitudes; stated because latency is corroborating, not sole-gating):

pairourios p50loki p50ratio (>1 = Ourios faster)
severity (1 row)82.0 ms875.0 ms10.7×
L3 trace (9 rows)74.6 ms24,101.9 ms323×
L1 template (2 rows)75.7 ms23,321.5 ms308×
window k=10040.2 ms13.8 ms0.34
window k=200085.9 ms294.8 ms3.43
selective-resource k=10038.8 ms51.2 ms1.32

Two findings this channel settles. First, the young-engine latency risk the RFC hedged against (“a latency loss + bytes-read win = sound architecture, young implementation”) did not materialize: Ourios answers every pair in 39–86 ms — a flat, fixed-cost-shaped profile — while Loki spans 13.8 ms to 24.1 s, and on the needle classes the wall-clock gap is interactive-vs-batch (75 ms vs 23–24 seconds). Second, scenario RFC0031.7 evaluated as written — on latency — PASSES on all three window pairs (0.34, 3.43, 1.32, all ≥ 1/3 at F_L6 = 3), and Ourios is outright faster on two of the three; the storage-channel loss published above is real as a bytes statement, but the RFC’s own L6 gate holds the floor. Which channel the frozen L6 gate uses is part of the §7 decision.

Determinism note. For repeated measurements of the same build and configuration, Ourios’s bytes are byte-identical (the store build is deterministic) — differences between runs are exactly the harness/optimisation deltas the table names, which is what lets the run series read as an optimisation ledger. Loki’s storage-side figure wobbles run to run (severity pair: 2.67–3.35 MB) with chunk boundaries and flush timing; ratios quoted against Loki carry that band.

Documented Loki flag deviations (all in Loki’s favour, per §3.7). The committed harness starts Loki with, and comments, exactly these deviations from stock:

  • -validation.reject-old-samples=false — the frozen corpus is weeks old; stock Loki would reject the replay outright.
  • -querier.query-ingesters-within=0 — stock Loki (default 3 h) skips ingesters for queries over weeks-old ranges, making rows still in unflushed low-volume chunks invisible (the run #11/#13 L3 flicker; diagnosed via ingester.totalReached: 0, fixed in #490). Disabling the cutoff means ingesters are always consulted — without it Loki’s answer to an old-range query is silently incomplete.
  • Raised ingestion + per-stream rate limits (-distributor.ingestion-rate-limit-mb=512, -distributor.ingestion-burst-size-mb=1024, -ingester.per-stream-rate-limit=512MB, -ingester.per-stream-rate-limit-burst=1GB) — replay is far faster than the capture’s real-time rate.
  • Raised internal gRPC message caps (-server.grpc-max-recv-msg-size-bytes=16777216, -server.grpc-max-send-msg-size-bytes=16777216) — runs #2–#4 failed on the same ~5.27 MB internal message regardless of our outer batch size: a single kafka-service LogsData line’s content alone inflates past Loki’s stock 4 MiB internal cap. Raising it (standard operator tuning) lets Loki accept the data at all, preserving the identical-ingest precondition the equivalence check requires.

Assessment. (1) The two classes the thesis stakes itself on hardest — L1 template lookup and L3 trace correlation — pass their provisional must-win margins on both channels, reproduced across three consecutive runs, and in both cases Loki’s cost is structural rather than tuning: no template concept, and no way to index a trace id. (2) L2 is parity-plus on storage and a ~33× processed win, honestly short of a 10× storage claim, with two named levers still on the table. (3) The window browses are a published storage-channel loss whose mechanism is understood (fixed per-query costs vs v8’s one-row-group-per-hour layout); the lever is write-side and RFC-sized. (4) Nothing here is frozen: the §7 inputs — the primary metric channel (storage-side vs processed), the must-win margins and floor factors, and whether the time-window pairs reclassify from gated floor to diagnostic — are open maintainer decisions, and this entry is the calibration evidence for them, not their resolution.

9.14 Results — 2026-07-13 (indicative, ci-runner) — comparative run #20: frozen gates on main, RFC 0033 acquisition

First dispatch on main after the §7 partial freeze and after the RFC 0033 cached template map merged (#511–#513). Job: run #20 (29255000054), exit 0.

Frozen gates. All asserting gates pass on mainM_L1/M_L3 storage margins and the F_L6 latency floors held; equivalence held on every pair. The dispatch is functioning as the regression gate the freeze intended (run #19 proved it on the branch; this run proves it on main).

RFC 0033 acquisition (the run’s purpose). Every pair reports:

template-map acquisition (RFC 0033): cold (audit fold, 513862 B; no artifact published)
  • The registry component is byte-identical to run #8’s baseline (513,862 B constant per body-rendering query): the cache regressed nothing, exactly as the advisory design promised.
  • But the write-through never published on this corpus, so no pair ever ran warm and the RFC0033.6 corpus gate (warm/cold ≤ 1/10) could not be measured.
  • The explanation consistent with the run’s outputs is §3.2’s size abstention: the artifact is uncompressed JSON carrying every (template_id, version) canonical template string, while the 513,862 B it must undercut is zstd-compressed Parquet of the same strings (plus their event history). On v8’s template set the JSON evidently meets or exceeds the fold, and the guard refuses a publish that would make warm acquisition cost more bytes than the fold it replaces. (A publish IO failure would leave the same “no artifact” label; the §3.7 publish-outcome telemetry distinguishes the two in a served process, but the bench harness does not export metrics — the amendment run should print the outcome explicitly.)

Consequences recorded.

  1. RFC 0033 status reverted green → red (this PR): RFC0033.6’s corpus arm is undischarged. The local-shape arm (55.8× on the 64-event fixture) stands.
  2. M_L2 stays frozen-deferred — §7’s unfreeze condition (the RFC 0033 warm measurement on the headline corpus) was not met.
  3. The lever is an artifact encoding amendment (format_version 2, compressed body). The same template strings zstd-compress into the 513,862 B audit Parquet with full event history alongside, so a compressed artifact is expected to land well below the fold size — to be measured, not assumed. Abstention semantics stay: publish only when the artifact beats the fold.

Roadmap to MVP

Living document. Refreshed at phase boundaries (§4) and whenever a merged PR materially changes the current state in §3. Last updated: 2026-06-15 — RFC 0013 (object storage, S3-compatible) drafted → specifiedred (first shipping-milestone spine; store module skeleton + §5 stubs landed); RFC 0009 (background compaction) flipped to validated (RFC0009.7 D2/D3/B2-post measured on baseline-8vcpu-32gib, §9.7); RFC 0005 (Parquet storage) and RFC 0010 (audit-stream / drift queries) flipped to green (RFC0005.6 row-group sizing landed; RFC 0010’s eight §5 drift scenarios all pass). Earlier, on 2026-06-14, RFC 0001, RFC 0008, and RFC 0011 flipped to accepted (maintainer sign-off). RFC 0001 reached validated first (C1/C2 pass authoritatively on the benchmarks.md §1 baseline hardware, §9.6; A1 is diagnostic per RFC 0011); RFC 0008’s validated is vacuous (no thesis gate); RFC 0011 is a tuning RFC. The §§4+ phase narrative below predates this and is not re-verified here (PR #41 RFC 0005, then PR-D through PR-G landed ourios-parquet end-to-end: schemas, writer, reader, audit stream). The deferred-capabilities table in §5 is unchanged: WAL durability and the OTLP wire endpoints stay post-MVP.

This document answers two questions in one place: what does “MVP” mean for Ourios, and how far are we from it. The artifact is parallel to hazards.md and benchmarks.md: hazards say what we mustn’t break, benchmarks say what success looks like, and this file says how we get from here to there.


1. What “MVP” means here

MVP for Ourios is thesis-proving, not production-ready.

The thesis (CLAUDE.md §2) claims that Parquet + Drain-derived template mining + DataFusion collapses the inverted index, the compression layer, the storage tier, and the query engine into one stack of off-the-shelf parts plus thin glue. That claim is falsifiable. The MVP is the smallest stack that lets us run the thesis-gate benchmarks in benchmarks.md on a real corpus and either confirm the claim or kill it.

Production-shape concerns — gRPC OTLP receiver, WAL durability, snapshot mechanism, Helm chart, the full §6.8 telemetry surface, the RFC 0002 query DSL — are deliberately out of MVP scope (§5). Each is a real shipping concern, but none of them changes the answer to “does the thesis hold.” We defer to keep the critical path as short and honest as possible.


2. The MVP gate: thesis benchmarks

Four gating [THESIS] goals in benchmarks.md define MVP-done. Hitting all four on a representative corpus means the thesis holds; missing any of them means a pillar (CLAUDE.md §2) is wrong and a PR won’t fix it — an RFC will.

GateWhat it measuresWhy it matters
B1Predicate-pushdown query latency on time/template/tenant filtersPillar 1 (footer reads + min/max stats skip row groups) actually skips
B2Template-exact query latency (where template_id = X)Pillar 2’s template_id column is a usable index, not a curiosity
C1Bit-identical reconstruction rate over the corpusThe hardest invariant (CLAUDE.md §3.3) holds in practice, not just in unit tests
C2Template-count convergence (Drain finds a small, stable number of templates)Pillar 2 (template mining) extracts the structure we believed was there

A1 (end-to-end compression vs. zstd-alone) was a fifth gating goal, but RFC 0011 (accepted) demoted it to a recorded diagnostic: it is refuted on every corpus class — including the maximally-templated one — for structural reasons (the more templated a corpus, the more a whole-stream byte codec captures the same redundancy), so template mining’s compression value is logical / query-pruning, captured by B1/B2, not on-disk bytes vs a codec. A1 is still measured and recorded (benchmarks.md §7/§9 — the columnar queryability premium + a codec-regression guard) but does not block MVP-done or any RFC’s validated.

A2, B3, C3, C4, D*, E* in benchmarks.md are relevant but not MVP-blocking — they’re tuning goals, honesty goals, or post-MVP shipping concerns.


3. Current state (as of 2026-06-15)

The thesis is proven on representative corpora. All four gating thesis-gates pass authoritatively on the benchmarks.md §1 baseline hardware (the §9.4 / §9.6 runs), so the MVP thesis-proving bar (§2) is met:

GateResultSource
B1 predicate-pushdownPASS — 34.2× / 25.4× vs zstdcat | grep at ~1 GB, exact row-count agreement§9.4
B2 template-exactPASS — windowed latency flat across 0.57→1.04 GB; flat on HDFS_v1 (11.2 M rows, 1/14 row groups)§9.4
C1 reconstructionPASS1.000000 on HDFS_v1 (11.2 M lines, authoritative)§9.6
C2 template convergencePASS — 40-template plateau, sub-linear, formal gate applies§9.6

A1 (compression vs zstd) fails, but RFC 0011 (accepted) reclassified it a recorded diagnostic, not a gate: the failure is structural and template mining’s value is logical / query-pruning, captured by B1/B2 (see benchmarks.md §2 / §7).

RFC ladder status:

RFCAreaStatus
0001Template mineraccepted
0002Query DSLgreen
0003OTLP receiver (gRPC + HTTP)green
0004Configuration policygreen
0005Parquet storagegreen — all 14 §5 scenarios pass; RFC0005.6 row-group sizing is the #[ignore]d tests/sizing.rs (manual cargo test -p ourios-parquet --ignored, not CI-gated per §7)
0006Bench harnessgreen
0007Querier (DataFusion + logs DSL)validated
0008WALaccepted
0009Background compactionvalidated — §5 RFC0009.1–.6 pass; RFC0009.7 D2/D3/B2-post measured authoritatively on baseline-8vcpu-32gib (§9.7: D3 in 256 MiB–2 GiB band, D2 166.8 MiB/s, B2-post ≈6.1×)
0010Audit-stream / drift queriesgreen — all 8 §5 scenarios pass (crates/ourios-querier/tests/drift.rs); discharges RFC 0001 H5.3; §9 items are accepted-gating; general audit aggregation deferred (§3.2)
0011A1 re-scopeaccepted
0013Object storage (S3-compatible)red — first shipping-milestone spine; store module skeleton in ourios-parquet (object_store direct dep, local() wired) + 8 #[ignore]d §5 stubs; crate-shape resolved (module, not a crate). green = S3 backend + conditional-PUT publish + consumer migration

Crates — all ten product crates are implemented (ourios-core, -miner, -wal, -parquet, -ingester, -querier, -server, -bench, -semconv, -telemetry):

  • ourios-miner — the Drain-derived miner, RFC 0001 accepted: (severity, scope) keying, three-zone confidence, widening + type-expansion with audit events, 256 B param-overflow spill, bit-identical reconstruction + the H7.3 render contract, structured-body canonical encoding, and §6.9 snapshot + v2 restore. Zero #[ignore]/todo!() acceptance stubs.
  • ourios-wal — RFC 0008 accepted: append/sync, crash recovery (the real-SIGKILL CI gate), snapshot-restore, segment rotation, group-commit batched fsync, checkpoint-driven truncation; §5 arms .1–.10 green.
  • ourios-parquet — RFC 0005 §3: atomic-publish writer + reader with the §3.9 compat contract, the §3.7 audit-event series, and the §3.6 encoding policy (dict + page index + template_id bloom filter).
  • ourios-ingester — RFC 0003 green: the OTLP gRPC + HTTP receiver with WAL-before-ack, per-ResourceLogs tenant derivation, the windowed group-commit coordinator, and the startup recovery driver; also hosts the RFC 0009 compaction runner.
  • ourios-querier — RFC 0007 validated / RFC 0002 green: the logs DSL over DataFusion with predicate + partition (time-window) pruning, alias resolution, and the RFC 0010 drift query.
  • ourios-bench — RFC 0006 green: drives the A1/B1/B2/C1/C2 measurements over OTLP-Demo + LogHub corpora and records results to benchmarks.md §9.
  • ourios-core / -semconv / -telemetry / -server — shared types + tenancy + record/audit shapes; the weaver-generated OTel name constants; the OTel metrics/export surface; the two-role binary.

The full cargo test --all-features suite is green in CI — the cargo test job gates every PR on the exact head; the coverage job runs alongside it but is informational (continue-on-error), not gating.

What remains is post-MVP shipping shape (§5 — Helm chart, the production deployment surface) and the items tracked in the RFCs’ §7/§9 open-questions (e.g. RFC 0009’s full D2 sustained-ingest soak + a measured D1, and the S3 atomic-swap primitive). RFC 0005 (green) and RFC 0009 (validated) are no longer open.


4. Path to MVP — three phases

Phase scope only; per-PR breakdown lives in the planning that opens each phase, not in this doc, so the file stays stable as mid-stream design decisions land.

Phase 1 — Finish the miner

Goal: the miner mines, audits, retains bodies, reconstructs. By the end of this phase the miner self-contained covers RFC 0001 §6.2 / §6.3 / §6.4 / §6.5 / §6.6 end-to-end and most §5 scenarios are green.

Capabilities to land:

  • Drain tree (root → length-N nodes → prefix nodes → leaves) with descend.
  • Best-candidate selection in MinerCluster::ingest via sim_seq (replaces the exact-match HashMap placeholder).
  • widen step + template_widened audit emission + type-expansion + template_type_expanded audit + degenerate- template guard.
  • Three-zone confidence branching (clean / lossy / parse-failure)
    • body retention in the lossy zone.
  • Separators preservation through the ingest pipeline + reconstruct() + lossy_flag semantics per §6.6.
  • Per-parameter byte-limit check + OVERFLOW marker + forced body retention.
  • MinerCluster::ingest consumes a structured OtlpLogRecord (per RFC 0001 §6.1 as amended), not a raw &str. The body_kind = String / body_kind = Structured fork lands with the §6.2 algorithm rewrite (a follow-on PR to the §6.1 amendment). Severity, scope, and the OTLP-canonical JSON encoding for structured bodies all flow through the miner from this phase forward.

Unblocks: thesis gates C1 (reconstruction) and C2 (template-count convergence). RFC 0001 §5 scenarios H1.*, H2.*, H5.*, H7.*, §3.3.1, RFC0001.* should mostly flip in this phase.

Phase 2 — Records to Parquet

Goal: mined records become Parquet files. By the end of this phase a corpus run produces on-disk Parquet that any DataFusion-aware reader can open.

Capabilities to land:

  • New crate ourios-parquet.
  • Record schema matching the amended RFC 0001 §6.1: identity + partitioning columns, the OTLP-derived columns (time_unix_nano, severity_number + severity_text, scope_name + scope_version, attributes, resource_attributes, trace_id + span_id + flags, event_name, dropped_attributes_count), and the body / miner-derived columns (body_kind, body?, params, separators, confidence, lossy_flag).
  • Writer: record batch → Parquet file (with row-group sizing from hazards.md H4 — target 128 MB–1 GB row groups).
  • Reader: Parquet file → record batch (for verification + the Phase 3 DataFusion path).
  • Audit-event Parquet stream (the contract called out in RFC 0001 §9 “Cross-RFC contracts pending”).

Unblocks: thesis gate A1 (compression ratio). The Parquet column codec earns its share of the 50–200× headline only once records actually land on disk in this format.

Out of MVP scope, parked here: background compaction (small-file problem, hazards.md H4) — corpus runs are bounded, a single Parquet file per phase is acceptable; production compaction is a post-MVP PR.

Phase 3 — DataFusion + bench

Goal: the thesis-gate benchmarks run.

Capabilities to land:

  • New crate ourios-querier — register the Phase 2 Parquet files with DataFusion and accept raw SQL. No DSL — RFC 0002’s surface is a post-MVP concern; the bench can use SQL directly.
  • New crate ourios-bench — corpus runner that reads pre-recorded OTLP LogsData test data into a stream of OtlpLogRecords, hands them to the miner, writes Parquet, runs the A1/B1/B2/C1/C2 measurements, and reports numbers that go into benchmarks.md §9 (Status). No network receiver in MVP — the bench reads OTLP from disk, not from a gRPC/HTTP listener (those stay post-MVP per §5).
  • testdata/corpus/ — anonymised real-log corpus committed to the repo (or a download script if size demands), serialised as OTLP LogsData (canonical JSON or protobuf) so the bench exercises the same record shape an OTel deployment would produce.

Unblocks: thesis gates B1 (predicate-pushdown latency) and B2 (template-exact latency). At the end of this phase, benchmarks.md §7 (the thesis-gate summary) has measured numbers for every [THESIS] row, and either the thesis holds or it doesn’t.


5. Deliberately out of MVP

Each item is a real production concern. The reason it’s deferred is “answering ‘does the thesis hold?’ doesn’t require it,” not “we don’t think it matters.”

CapabilityWhy deferred for MVPWhen it lands
Write-ahead log (ourios-wal)Corpus replay is bounded and reproducible; durability is irrelevant for thesis-provingFirst post-MVP shipping PR series — required before any non-corpus traffic
OTLP wire endpoints (gRPC + HTTP listeners)Bench reads OTLP from disk, not the network — see Phase 3. The wire-decode layer (tonic, axum, opentelemetry-proto) is independent of the record shape and adds no signal to thesis gatesFirst post-MVP shipping PR series — paired with WAL since both gate non-corpus ingest. RFC 0003 (forthcoming) specifies the wire-decode design
Snapshot mechanism (RFC 0001 §6.9)Corpus runs from cold start; replay budget mootAfter WAL — snapshots are an optimisation on top of WAL replay
Full §6.8 telemetry surfaceOne or two metrics suffice for the bench; the §3.1.2 mandatory set is a production observability concernAfter Phase 1 finishes — the metrics depend on the miner’s hot path being final. Implementation note (maintainer direction, 2026-05-19, updated 2026-06-03): instrument through the OpenTelemetry metrics API (meters create the instruments) and export the resulting metrics through the OTel SDK’s OTLP metric exporter (push), not the legacy prometheus client crate and not a /metrics scrape endpoint — any Prometheus compatibility is a downstream collector concern, keeping the project one metric-model end-to-end. The RFC 0001 §6.8 architecture amendment (2026-06-03) reframes the export model and terminology; the dotted-semconv name redesign (joining semconv/registry/, RFC 0009 §3.6) is a tracked follow-up
Query DSL (RFC 0002)Raw SQL through DataFusion serves the bench; DSL is operator UXPost-MVP — RFC 0002 already drafted but not specified
Multi-tenancy at runtime (rate limits, eviction, lifecycle)Bench uses one tenant; the type is in place but no orchestration around itPost-MVP, tied to operator-console RFC (see RFC 0001 §9 “Multi-tenancy and operational lifecycle”)
ourios-server binary + Helm chartBench is a binary in ourios-bench; full deployment shape is shipping concernPost-MVP, sequencing TBD
Perses dashboard integration (datasource plugin + possible CRDs)The data plane has to work first — a Perses plugin queries a query interface that doesn’t exist yet. A native datasource plugin is small and downstream-friendly once RFC 0002 stabilises the query API; CRDs / operator (PersesDashboard-style declarative pipeline + miner config) would extend Ourios into managed-service territory, which contradicts CLAUDE.md §1’s “Not a managed service” line. Splitting the concern: the plugin is an additive RFC against a stable query API; the CRDs/operator path is a charter change, not an RFC. Discussion captured 2026-05-18 (Grok prompt → maintainer review)Plugin: after RFC 0002 lands, as RFC 0010 — Perses datasource plugin, scoped to plugin-only and living in a separate repo. CRDs/operator: requires a meta: RFC against CLAUDE.md §1 first, no commitment to land

Note on OTLP scope. The pre-amendment roadmap listed “OTLP receiver (gRPC + HTTP)” as a single post-MVP item. PR #20 + #21 split that scope: the OTLP record shape (OtlpLogRecord consumption, the canonical JSON encoding, the OTLP-aligned Parquet schema) is in MVP — it’s a prerequisite for thesis-gate C2’s validity, because the template-count convergence the corpus measures has to be over records that look like real OTel traffic, not over flat-text caricatures of it. Only the wire endpoints — the actual gRPC/HTTP listeners that decode OTLP off the network — remain post-MVP, and that’s the row in the table above.


6. Update cadence

This file refreshes:

  • After every merged PR that materially changes §3 (current state) — the merging PR’s author (or their drafting assistant) updates the table and the §5 scenario count.
  • At phase boundaries (§4) — when Phase 1 finishes, §3’s current state and §4’s “blockers” tables are reconciled, and the next-phase opening planning PR is summarised here.
  • When a thesis-gate result lands in benchmarks.md §9 — this doc gets a one-line note in §3 acknowledging the result.

The doc is intentionally not refreshed on every spec edit — RFC patches and hazards.md edits don’t change the road map unless they change what MVP requires. If you find yourself updating §3 every PR, the doc has become an activity log; the fix is to be more selective, not to stop updating.

RFCs

Referenced from CLAUDE.md §5.1. This document is the minimum viable RFC process for Ourios. It will grow as the project does.

When an RFC is required

Per CLAUDE.md §5.1, an RFC precedes implementation for any change that touches:

  • An architectural pillar (CLAUDE.md §2).
  • An invariant (CLAUDE.md §3).
  • A hazard (CLAUDE.md §4 / docs/hazards.md).
  • The on-disk Parquet schema (CLAUDE.md §3.5).
  • A new crate (CLAUDE.md §7).

Bug fixes, dependency bumps, and internal refactors do not need RFCs. When in doubt, assume RFC.

File layout

  • Filename: NNNN-short-kebab-title.md, e.g. 0001-template-miner.md.
  • Numbers are assigned in merge order. Draft PRs may use the next free number provisionally; if two drafts collide, the later-merged one renumbers.
  • One file per RFC. Supersessions are recorded in the frontmatter of both the old and new RFC.

Required frontmatter

---
rfc: NNNN
title: Short descriptive title
status: drafted | specified | red | green | validated | accepted | rejected | superseded
author: Name <email>
drafting-assistance: Claude   # omit if no LLM drafted
created: YYYY-MM-DD
supersedes: —                 # or RFC NNNN
superseded-by: —              # or RFC NNNN
---

The maturity stages (drafted through validated) are gates an RFC moves through before it becomes binding; accepted is the terminal post-maintainer-signoff state; rejected and superseded are the off-ramps. See docs/verification.md §3.

Required sections

Every RFC has at least:

  1. Summary — 3–5 sentences. The commitment, not the rationale.
  2. Motivation — why this change now, and why at this layer.
  3. Proposed design — precise enough that two engineers would produce the same implementation.
  4. Alternatives considered — one paragraph each. “I have not heard of it” is not acceptable.
  5. Acceptance criteria — normative scenarios, one per invariant or hazard the RFC touches. Format: structured prose with Given / When / Then / And leading clauses; each scenario carries an id of the form H1.1, §3.4.2, or RFC<NNNN>.<m>, referenced from the test code so the mapping is greppable. See docs/verification.md §2.
  6. Testing strategy — mapped to CLAUDE.md §6.2; references the §5 scenario ids and names the technique (proptest, corpus, criterion) for each.
  7. Open questions — everything unresolved, as a checklist.
  8. References — paper citations, related RFCs, CLAUDE.md sections constrained.

Additional sections are welcome when they clarify. Do not pad for the sake of the template.

Lifecycle

The five-stage maturity model. An RFC moves through these stages before becoming binding; the status: frontmatter field tracks the current stage so reviewers and tooling see it without reading the body.

  1. Drafted — PR opened with status drafted. Sections §§1–4 and §§7–8 are filled. Discussion happens in PR review.
  2. Specified — §5 acceptance criteria are written, every invariant and hazard the RFC touches has at least one scenario, and review has confirmed the criteria are testable in principle.
  3. Red — test stubs exist and fail. Implementation may begin.
  4. Green — all acceptance criteria pass; unit + property + corpus tests green.
  5. Validated — thesis-gates in docs/benchmarks.md §7 pass on representative corpora. Maintainer flips status to accepted.

A regression detected after Validated either reopens the RFC (if a criterion is invalidated) or spawns a tuning RFC per benchmarks.md §7 (if a thesis-gate degrades). See docs/verification.md §3.

Two terminals reachable from any stage:

  • Superseded — a later RFC replaces part or all of this one. Both frontmatters are updated. The superseded RFC is not deleted.
  • Rejected — closed PR or status flipped to rejected. The file is kept for the record.

Diagrams

When an RFC needs a diagram (state machine, sequence flow, schema relationship, decision tree), it is authored in Mermaid, embedded as a fenced ```mermaid block in the markdown. Mermaid is chosen for the same reasons we chose markdown over a binary doc format: text-based source is reviewable in PR diffs, version-controllable, and lets the RFC itself remain a single self-contained file.

Lectures (docs/talks/) use a different convention: hand-drawn SVGs (Excalidraw export, or hand-authored to match) committed under docs/talks/img/. Lectures benefit from a “manuscript / blackboard” aesthetic that Mermaid does not provide; RFCs benefit from the diff-ability that Excalidraw does not provide. Do not mix the two conventions.

The mdBook build has the mdbook-mermaid preprocessor enabled (book.toml), with the Mermaid runtime vendored at the repo root (mermaid.min.js, mermaid-init.js) so the rendered book is self-contained. The CI book job and the Pages workflow install the mdbook-mermaid binary before building. To work on diagrams locally, cargo install mdbook-mermaid --locked (the preprocessor binary) — the vendored runtime is already committed.

Relationship to architecture docs

An accepted RFC is a contract for how something will be built. Once the subsystem is stable, the RFC graduates to docs/architecture/<subsystem>.md — a living document describing the system as it actually is. The RFC stays in place as the historical decision record; the architecture doc is what a new contributor reads first.

RFC 0001 — Template miner


rfc: 0001 title: Template miner (Drain-derived online log parsing) status: accepted author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-04-24 supersedes: — superseded-by: —

RFC 0001 — Template miner

Status note. accepted (2026-06-14, maintainer sign-off — the terminal ladder status per docs/rfcs/README.md). Reached validated the same day on the evidence below; accepted records the maintainer’s final sign-off on the template-mining pillar. The docs/verification.md §3 / docs/rfcs/README.md ladder reserves validated for every thesis-gate the RFC’s pillars touch passing on representative corpora (benchmarks.md §7). The template-mining pillar’s gates are C1 (reconstruction fidelity) and C2 (template-count convergence) — both pass on the representative LogHub HDFS_v1 corpus (≈ 1.47 GiB, 11.2 M lines — above benchmarks.md §8’s ≥ 1 GiB canonical floor, so representative; and well past C2’s ≥ 1 M-line formal-gate threshold, so that gate applies rather than abstains), authoritatively on the benchmarks.md §1 baseline hardware: C1 1.000000, C2 a 40-template plateau (diagnostic local run benchmarks.md §9.5, authoritative baseline-8vcpu-32gib rerun §9.6 — identical verdicts, as expected of deterministic gates). A1 (compression vs zstd) is a diagnostic, not a gate (RFC 0011, already encoded in the §7 gate table): it fails on every corpus class including the maximally-templated one, for structural reasons — template mining’s compression is logical/query-pruning (B1/B2), not on-disk bytes.

Reached green first (2026-06-13): all §5 acceptance criteria pass with live tests (zero #[ignore]/todo!() stubs) — miner-internal (tokenize/mask/sim-seq, the three-zone confidence model, fresh-leaf + widening + type-expansion with audit events, the (severity_number, scope_name) template key, the 256 B param-overflow spill + telemetry, bit-identical reconstruction + the H7.3 render contract, structured-body canonical encoding, the §6.9 snapshot + v2 restore) plus the relocated cross-crate criteria (query semantics RFC0001.5/.6, time-preserved RFC0001.10, §3.7.3 per-ResourceLogs tenant derivation, drift H5.3 via RFC 0010, the §6.7 alias index via RFC 0005 §3.7).

Terminal step: accepted is the maintainer’s final sign-off (docs/rfcs/README.md). NB the A1 re-scope’s own RFC (RFC 0011) is still drafted; the §7 gate table already reflects the demotion, but RFC 0011 should be accepted to fully ratify that chain.

How to read this document. §§1–4 are the design contract — the what and the why. §5 lists the normative Given / When / Then scenarios — the contract — grouped by parent (hazard, invariant, RFC-internal). §6 is the precise specification the ourios-miner crate is implemented against; its opening paragraphs name the gaps between the published algorithm and a production miner that §6.1–§6.9 then close. §7 records the alternatives we evaluated and rejected. §8 maps each §5 scenario to the technique that tests it.

Cross-references to CLAUDE.md sections are in square brackets, e.g. [§3.1], and name the invariant the section must preserve.

1. Summary

Ourios implements a Drain-derived online template miner (ourios-miner) that converts each ingested OTLP LogRecord into a structured Parquet record. The record shape is the OTLP LogRecord (with its inherited Resource and InstrumentationScope context) plus the miner-derived columns (template_id, template_version, params, separators, body_kind, body?, confidence, lossy_flag); see §6.1 for the full schema and the 2026-05-13 amendment that aligned it to OTLP. The miner is per-tenant by construction [§3.7], uses a three-zone confidence model that retains the original line in the lossy zone [§3.1], audits every template widening [§3.1], captures inter-token separators in a parallel array so that bit-identical reconstruction is the default rather than a property-test exception [§3.3], bounds parameter values at 256 B with overflow to a side body column [§3.2], and tracks template structural changes via a monotonic template_version so that schema drift across deploys is a first-class query rather than a silent count drop [§3.5]. The 50–200× figure is a logical reduction (lines → (template_id, params)), realised as query pruning (gates B1/B2), not on-disk bytes versus a byte codec — see RFC 0011, which demoted the compression-vs-zstd ratio (A1) to a diagnostic.

2. Motivation

This is the load-bearing pillar of the project [§2.2]. Three sub-questions justify it.

Why template mining at all. A typical service emits 10²–10⁴ distinct printf templates over its entire lifetime, but raw log volume is dominated by the parameters substituted into those templates. Storing the template once per tenant and the parameters per occurrence makes that redundancy explicit — and explicit redundancy stacks with byte-level codecs rather than fighting them. zstd over flat log text recovers ~10× on typical workloads; doing the structural work first leaves zstd a column of short, repetitive parameters that dictionary-encode well, where the codec then earns its keep again. The 50–200× headline (README.md, [§2.2]) is the product of these two layers, not a claim about either alone.

Why online vs. offline. Operators expect logs to be queryable within seconds of ingest, not minutes. Any batch clustering window long enough to do offline hierarchical clustering well is a window the operator is blind in. Drain’s fixed-depth tree gives O(d) lookup per line at the cost of being slightly less accurate than the best offline parsers — an acceptable trade because §3.1’s audit and confidence machinery surfaces the inaccuracy rather than hiding it.

Why this layer. The compression is structural, not statistical. Doing it before Parquet’s byte codecs means each Parquet column sees small, dictionary-friendly values; doing it after means we have already paid for storing the redundancy and zstd has to find it again from the bytes. The order matters.

3. Background: Drain as published

A restatement of He et al., ICWS 2017, in the notation this RFC uses downstream. Citations are by paper section/figure.

3.1 Tree structure (paper §3.2, Fig. 2)

A fixed-depth parse tree, depth d (default 4 in the paper). Three node kinds, in order from root:

  • Root. Single node; routes by token count.
  • Length-N node. One per observed token count N. Children are prefix nodes keyed by the first token of the line.
  • Token-prefix nodes at depths 2..=d. Each is keyed by the token at position (depth - 1) of the line.
  • Leaf log groups at depth d + 1. Each leaf holds a template — a sequence of N tokens, where each position is either a fixed string or the wildcard <*>.
                   root
                    │
        ┌───────────┼───────────┐
       len=4       len=5       len=6      ← length groups
        │           │           │
    ┌───┴───┐    ┌──┴──┐     ┌──┴──┐      ← prefix nodes (depth 1)
   "user"   …  "GET"  …    "INFO"  …
    │           │           │
   ┌┴┐         ┌┴┐         ┌┴┐
   …  …        …  …        …  …          ← prefix nodes (depth 2)
   │           │           │
 [leaf]      [leaf]      [leaf]           ← log groups

3.2 Similarity function (paper §3.3)

For a candidate line L = (t_1, …, t_N) and a leaf template T = (τ_1, …, τ_N):

simSeq(L, T) = (count of positions i where t_i == τ_i or τ_i is <*>) / N

Wildcards in the template count as matches. The line length and the template length are equal by construction (the length-N node selected the leaf candidates).

3.3 Threshold st (paper §3.4)

A configured value st ∈ (0, 1]. After computing simSeq against every leaf at the current parent, the leaf with the highest simSeq is the candidate. If simSeq(L, T_best) ≥ st, the line attaches to T_best; otherwise a new leaf is created. The paper reports st = 0.4 as a default; see §6.3 for why Ourios overrides this.

3.4 New-log-group creation vs. leaf update (paper §3.5)

If simSeq(L, T_best) < st, a new leaf is created at the parent prefix node, with L as its initial template (no wildcards yet). Otherwise T_best is updated: at every position where t_i ≠ τ_i, the template position is replaced with <*>. The template never becomes more specific over time, only more general; positions can become wildcards but cannot become fixed again.

3.5 Worked example

A fabricated illustration (no testdata/corpus/ exists yet; this example will be replaced with one drawn from the corpus once it lands).

Line A:  user 42 logged in from 10.0.0.1
Line B:  user 17 logged in from 10.0.0.2
Line C:  user 99 logged out from 10.0.0.7

After preprocessing (§4.2), numbers and IPs are masked, so the miner sees:

Line A:  user <NUM> logged in from <IP>
Line B:  user <NUM> logged in from <IP>
Line C:  user <NUM> logged out from <IP>

All three are length 6. They route to root → len=6 → "user".

A walks the prefix path further (depth 2: token at position 1 is the masked <NUM> placeholder, treated as a fixed token at this stage). It is the first line, so a leaf is created with template user <NUM> logged in from <IP>.

B walks the same path. The candidate leaf has simSeq(B, T_A) = 6/6 = 1.0 ≥ st. B attaches; the template is unchanged.

C walks the same path. The candidate leaf has simSeq(C, T_A) = 5/6 ≈ 0.833. With st = 0.7 (Ourios default, §6.3), 0.833 ≥ 0.7, so C attaches. Token position 4 (in vs out, 1-indexed against the masked sequence) becomes <*>. The template widens to user <NUM> logged <*> from <IP>. This is a template widening event and must emit an audit record per §6.4.

4. Background: Drain3 extensions (not in the paper)

Drain3 (logpai/Drain3) is the maintained Python implementation. It adds several capabilities beyond the 2017 paper. Each is recorded here as adopt, adopt with modification, or reject, with one sentence of rationale.

4.1 Persistent state — adopt with modification

Drain3 supports JSON snapshots to file, Redis, or Kafka. Ourios adopts the snapshot concept but commits to a file/object-storage backend; Redis and Kafka are out of scope (CLAUDE.md §3.6 names object storage as the source of truth). Snapshot target, cadence, and scope are open questions in §9.

4.2 Pre-tree-walk masking — adopt with modification

Drain3’s most important extension: regex-based masking of common parameter shapes (IPs, UUIDs, numbers, hex, timestamps, file paths) before the tree walk, so high-cardinality tokens never become tree branches. Without this, the tree explodes into one branch per IP address.

The Ourios modification: a masked token is not discarded. It becomes a typed parameter attached to the wildcard slot it created. The masking layer emits (type_tag, original_bytes) pairs; the tree walk treats the type tag as the token (so <NUM> matches <NUM> for tree-routing purposes) while the original_bytes flow into params so reconstruction can recover the line exactly. Paper-pure Drain loses the original token; Ourios retains it as a parameter. This is what makes [§3.3] reconstruction possible at all.

4.3 Variable-length wildcards — adopt with constraint

Drain3’s MaskingInstruction allows a single regex to match a variable-length run of tokens (e.g. a multi-token user-agent string). Ourios adopts this where the run is bounded at parse time and produces exactly one typed parameter in the output. Reject: unbounded variable-length wildcards, because they break leaf identity (two lines with the same template structure but different run lengths would land in different length-N nodes and never deduplicate).

4.4 Dynamic / adaptive threshold — reject

Drain3 supports auto-tuning the similarity threshold per leaf based on observed cluster sizes. Ourios rejects this. CLAUDE.md §3.1 fixes threshold ≥ 0.7 as a project-level invariant; auto-tuning would silently move the merge boundary across deploys, defeating the audit contract. Threshold tuning is a config decision per tenant, never a runtime decision per leaf.

4.5 Other Drain3 features

  • Parameter-naming hints. Drain3 lets users name <*> slots via the masking config (e.g. <IP:client_addr>). adopt — the type-tag mechanism in §4.2 already requires a slot name; using the Drain3 hint format keeps configs portable.
  • Built-in metrics surface. Drain3 exposes a set of state counters via callback. replace — Ourios exposes OTel metrics directly per §6.8 (instrumented via the meter API), with names that match [§3.1]’s required set rather than Drain3’s internal names.
  • Parameter masking after the fact. Drain3 has utilities to retroactively mask params in already-clustered lines. reject — Ourios masks once, at ingest, deterministically. Retroactive masking would invalidate already-written Parquet files.

5. Acceptance criteria

Per docs/verification.md §§2–3, every CLAUDE.md §3 invariant and every docs/hazards.md hazard this RFC touches has at least one numbered scenario below. Scenarios use the bold-leading-clause format (verification.md §2.1) and the id grammars (§2.2): H<n>.<m> for hazard-rooted, §3.<n>.<m> for invariant-rooted, RFC0001.<m> for design-internal commitments. Test code carries each id in a doc comment per §2.3 so grep -R "H1.1" . resolves bidirectionally between RFC and tests.

The hazards in scope are H1, H2, H5, H7; the invariants are §3.1, §3.2, §3.3, §3.5, §3.7. H3 (WAL durability) and H4 (small files) are owned by the ourios-wal and ourios-parquet RFCs; H6 (DSL) is owned by RFC 0002; §3.4 (WAL-before-ack) and §3.6 (object-storage-as-truth) are touched only via §6.9’s persistence direction and the primary obligation lives in those other RFCs.

5.1 Hazards

Scenario H1.1 — Semantically distinct templates do not silently merge

  • Given a corpus containing user logged in <*> and user logged out <*>
  • When similarity threshold is 0.7 (the default)
  • Then the two remain distinct template_ids
  • And any widening produces an audit event recording both old and new templates

Scenario H1.2 — Lossy-zone match retains body

  • Given a line whose best match has confidence in the lossy zone (floor ≤ x < threshold)
  • When the line is ingested
  • Then the body column contains the original line bytes
  • And the row carries lossy_flag = false (the flag is reserved for tokenizer / preprocessing failure per §6.6 — the lossy zone retains the body but reconstruction still succeeds)

Scenario H1.3 — Every widening emits an audit event

  • Given any sequence of inputs that triggers a template widening
  • When the widening completes
  • Then an audit event exists naming the old template, the new template, the tenant id, the timestamp, and the event_type

Scenario H1.4 — severity_number is part of the template key (no INFO/ERROR silent merge)

  • Given two OtlpLogRecords with identical body_kind = String bodies and identical scope_name, but severity_number = 9 (INFO) and severity_number = 17 (ERROR)
  • When both are ingested via MinerCluster::ingest
  • Then the emitted records carry distinct template_ids
  • And no widening or merge ever produces a single template_id covering both severity buckets
  • (Operationalises the §6.1 Template-key composition commitment that severity_number is part of the key regardless of body_kind.)

Scenario H1.5 — scope_name is part of the template key (no cross-scope silent merge)

  • Given two OtlpLogRecords with identical body_kind = String bodies and identical severity_number, but scope_name = Some("lib.auth") and scope_name = Some("lib.payments")
  • When both are ingested
  • Then the emitted records carry distinct template_ids
  • And no widening or merge ever produces a single template_id covering both scopes
  • And a third record with scope_name = None shares a template_id with neither (it lives in the (severity, None) bucket per §6.1)

Scenario H2.1 — Oversized parameter triggers OVERFLOW marker and forced body retention

  • Given a tenant configured with the default 256 B per-parameter byte limit
  • And a log line whose masked parameter value exceeds 256 B (e.g. an embedded stack trace)
  • When the line is ingested
  • Then the corresponding Param entry has type_tag = OVERFLOW carrying (length, sha256_prefix) instead of the original value
  • And the body column contains the original line bytes regardless of lossy_flag
  • And ourios.miner.params.overflow (attributes ourios.tenant, ourios.service) increments

Scenario H2.2 — Per-service overflow rate above 1% raises an alert

  • Given the ourios.miner.params.overflow.utilization gauge (attributes ourios.tenant, ourios.service) for some service
  • When the rolling rate exceeds 0.01
  • Then the documented alert rule fires (the rule ships alongside §6.5’s metric definition)

Scenario H5.1 — Wildcard widening increments template_version and emits template_widened

  • Given a leaf at (template_id = X, template_version = V)
  • When an attach widens a previously-fixed token at position i into <*>
  • Then the leaf’s template_version becomes V + 1
  • And an audit event with event_type = template_widened is emitted naming the new wildcard position(s)

Scenario H5.2 — Type expansion increments template_version and emits template_type_expanded

  • Given a leaf whose wildcard slot s has slot_types[s] = {NUM}
  • When an attach maps a typed parameter of type = STR into slot s
  • Then slot_types[s] becomes {NUM, STR}
  • And template_version increments
  • And an audit event with event_type = template_type_expanded is emitted naming the slot and the newly-added ParamType

Scenario H5.3 — Drift query returns templates that gained a version in window

  • Given the template_audit event stream contains template_widened and template_type_expanded events for templates A and B in the window [t1, t2]
  • When the §6.7 drift query runs against [t1, t2]
  • Then the result includes both A and B with their widening counts

Scenario H7.1 — Reconstruction property holds across the corpus

  • Given the committed testdata/corpus/ (anonymised, fixed)
  • When every line is ingested through the miner
  • Then for every emitted record r where r.lossy_flag = false, reconstruct(r) == r.ingested_bytes holds byte-for-byte
  • And property failure is a build break, not a regression

Scenario H7.2 — Tokenizer failure sets lossy_flag = true and retains body

  • Given a line containing an embedded NUL byte (or another tokenizer-failure mode listed in §6.6)
  • When the line is ingested
  • Then a parse-failure record is emitted
  • And the record’s lossy_flag is true
  • And the record’s body column contains the original line bytes

Scenario H7.3 — Reader emits body verbatim when lossy_flag is true

  • Given a record with lossy_flag = true
  • When the reader renders the row
  • Then the rendered bytes are the body column verbatim (byte-for-byte, no prefix or in-band marker)
  • And the rendered row carries the §6.6 reconstruction signal Reconstruction::RetainedVerbatim (the out-of-band warning marker the §6.6 Reader render contract defines)
  • And reconstruct() is NOT called for that row

Scenario H7.4 — Widened literal slot reconstructs via STR fallback

  • Given a leaf whose template gains a new <*> slot at position i via the §6.2 widening of an originally-literal token
  • When the triggering line is attached
  • Then the line’s record carries params[slot_for_i] = { type_tag: STR, value: L_tok[i] }
  • And reconstruct(record) == ingested_bytes holds

5.2 Invariants

Scenario §3.1.1 — Default similarity threshold is 0.7

  • Given a tenant configuration with no threshold override
  • When the miner is initialised for that tenant
  • Then the effective threshold is 0.7

Scenario §3.1.2 — Mandatory metric set is exposed

  • Given the mandatory set defined by §6.8’s table — the ourios.miner.* metric instruments in the semconv registry (semconv/registry/, surfaced as generated ourios_semconv constants) that the miner registers on the ourios.miner meter when it is constructed (the ourios.miner.alias.* counters are registered separately by the alias map, §6.7, and are out of this scenario’s scope)
  • When a small representative workload exercises every instrument (a normal line, a near-duplicate that widens a template, an oversized-param line, and a parse-failure line) and the meter is collected via an SDK in-memory reader
  • Then the collected metric stream contains every metric named in §6.8’s table — each appearing on its first real measurement, carrying the registry’s required attributes (no synthetic zero-traffic points) — (ourios.miner.template.count, ourios.miner.merges, ourios.miner.confidence, ourios.miner.confidence.p50, ourios.miner.confidence.p01, ourios.miner.body_retention.utilization, ourios.miner.parse_failures, ourios.miner.params.overflow, ourios.miner.params.overflow.utilization, ourios.miner.template.version_changes, ourios.miner.duration) with the instrument kinds and attributes listed there

Scenario §3.2.1 — Default per-parameter byte limit is 256

  • Given a tenant configuration with no per-parameter byte limit override
  • When the miner is initialised for that tenant
  • Then the effective limit is 256 bytes

Scenario §3.2.2 — Configured limit above 1 KiB is rejected at startup

  • Given a tenant configuration with param_byte_limit > 1024
  • When the miner is initialised
  • Then initialisation fails with an error citing the §3.2 ceiling
  • And the process refuses to start serving that tenant

Scenario §3.3.1 — Separators array captured on every successful tokenization

  • Given a line that tokenizes successfully
  • When the line is ingested
  • Then the emitted record’s separators.len() == tokens.len() + 1
  • And the per-row precondition for H7.1 holds (the reconstruction proptest then asserts byte equality)

Scenario §3.5.1 — Snapshot format carries a leading version byte

  • Given a serialised snapshot artefact written by the miner
  • When the artefact is inspected
  • Then byte 0 is the snapshot format version

Scenario §3.5.2 — Unknown snapshot version triggers full WAL replay

  • Given a snapshot artefact whose leading version byte is unknown to the running miner
  • When the miner loads the snapshot at startup
  • Then the snapshot is rejected
  • And the miner falls back to full WAL replay rather than misinterpreting the bytes

Scenario §3.5.3 — Known-version restore + tail replay is equivalent to a full rebuild (2026-06-12 amendment)

  • Given a tenant tree snapshotted at WAL high-water mark S, with further frames appended after S
  • When recovery restores the snapshot and replays only the frames above S
  • Then the recovered tree state (leaves, template_ids, template_versions, slot types, structured-template-id map) equals the control tree built by ingesting every record from scratch
  • And no frame at or below S reaches the miner (no double-apply — the v1 hazard that gated restore)

Scenario §3.5.4 — Stale snapshot degrades loudly, not silently (2026-06-12 amendment)

  • Given a snapshot at high-water mark S, a Parquet checkpoint at X > S, and a WAL whose surviving segments start above S but retain every frame above X (externally truncated — WAL segment files manually unlinked; the RFC 0008 §6.7 retain floor prevents this arising internally, and legitimate housekeeping never removes a frame above X)
  • When recovery runs
  • Then the snapshot is restored and the surviving frames are replayed under the per-consumer horizons (the data side is complete: every missing frame was ≤ X, hence already in Parquet)
  • And a structured warning is emitted naming the gap between S and the oldest surviving frame, so the possible template re-minting inside it is surfaced (hazard #5, observable via the RFC 0010 drift query) rather than silent

Scenario §3.7.1 — Tenants’ template trees never cross-pollinate

  • Given a MinerCluster ingesting interleaved lines from synthetic tenants A and B
  • When the corpus is fully ingested
  • Then no template mined under tenant A appears in tenant B’s tree
  • And no template mined under tenant B appears in tenant A’s tree
  • (Implements docs/benchmarks.md E2.)

Scenario §3.7.2 — Same structural template in two tenants gets distinct template_ids

  • Given tenants A and B independently emit the structurally identical template user <NUM> logged in from <IP>
  • When both are ingested
  • Then tenant A’s template_id for that template differs from tenant B’s template_id
  • And no template_id is shared across tenants
  • And template_ids are guaranteed unique across the entire cluster (not just per tenant)

Scenario §3.7.3 — Tenant derivation runs per ResourceLogs, not per export batch

  • Given a single OTLP ExportLogsServiceRequest carrying two ResourceLogs whose Resource.attributes resolve to distinct tenants A and B under the configured derivation rule
  • When the receiver fans the batch out per RFC 0003 §6.3 and the miner ingests both per-tenant streams
  • Then every LogRecord under ResourceLogs[0] is mined under tenant A
  • And every LogRecord under ResourceLogs[1] is mined under tenant B
  • And no record ever appears in the wrong tenant’s tree
  • (Operationalises the §6.1 Tenant derivation commitment that the derivation rule runs once per inherited Resource, not once per export batch.)

5.3 RFC-internal design commitments

Scenario RFC0001.1 — Fresh-leaf creation does not emit an audit event

  • Given a parent prefix node with no leaves yet
  • When a line creates the first leaf at that node
  • Then no event is appended to the audit stream for that creation
  • And ourios.miner.template.count increments to reflect the new leaf

Scenario RFC0001.2 — Degenerate-template guard rejects fully-wildcard widening

  • Given a leaf whose template, after a candidate widening, would have zero non-wildcard tokens
  • When the candidate widening is attempted
  • Then the widening is rejected
  • And the line is treated as a parse failure (confidence = 0, body retained, ourios.miner.parse_failures increments)
  • And an audit event with event_type = template_widening_rejected_degenerate records the rejection

Scenario RFC0001.3 — Tokenizer is Unicode whitespace only; punctuation stays in tokens

  • Given a line key=value, other=42 (no whitespace adjacent to the punctuation)
  • When the line is tokenized
  • Then it produces two tokens (key=value, and other=42)
  • And no token boundary is introduced at =, ,, :, ;, [, ], (, or )

Scenario RFC0001.4 — Confidence ratio = simSeq / threshold; decision boundary at 1.0

  • Given a tenant with threshold = 0.7
  • And a line whose simSeq against the best candidate is 0.7
  • When the line is ingested
  • Then the emitted record’s confidence == 1.0
  • And the line takes the clean-attach branch
  • And the same simSeq under threshold = 0.5 would yield confidence == 1.4 (the ratio reframes scale-invariantly across tenants)

Scenario RFC0001.5 — Bare template_id = X spans all versions of leaf X

  • Given leaf X with versions 1, 2, 3 attached over time
  • When a query runs where template_id = X
  • Then the result includes rows attached against (X, 1), (X, 2), and (X, 3)
  • And no alias resolution is involved (this is by-construction, since template_id is stable across widenings of one leaf)

Scenario RFC0001.6 — Bare template_id = X does NOT follow alias chains

  • Given two distinct leaves X and Y that the alias index records as semantically equivalent
  • When a query runs where template_id = X
  • Then only rows whose template_id == X are returned; rows with template_id == Y are NOT included
  • And where template_id.resolves_to(X) (RFC 0002 §5.4) is the explicit form that includes Y’s rows

Scenario RFC0001.7 — Combined widening + type-expansion increments version twice and emits two events in order

  • Given a leaf at version V where a single attach both introduces a new wildcard slot AND introduces a previously-unseen ParamType into an existing slot
  • When the attach completes
  • Then the leaf’s template_version == V + 2
  • And the audit stream contains two events for this attach: a template_widened event for the new wildcard, immediately followed by a template_type_expanded event for the type expansion (in that order)

Scenario RFC0001.8 — ourios.miner.confidence.p50 and ourios.miner.confidence.p01 are emitted as gauges

  • Given a running miner with a non-empty ourios.miner.confidence histogram for some (ourios.tenant, ourios.service)
  • When the miner’s meter is collected via an SDK in-memory reader
  • Then ourios.miner.confidence.p50 and ourios.miner.confidence.p01 (attributes ourios.tenant, ourios.service) are present as gauges
  • And each value matches the corresponding quantile of the same-attributed histogram (computed in-process on a short ticker per §6.8)

(The dotted-semconv rename landed in the 2026-06-08 amendment; the open fork is whether confidence.p50 / confidence.p01 become backend-derived quantiles over the exported histogram rather than in-process gauges. That is a contract change to the §3.1.2 mandatory set and would be made — possibly superseding this scenario — under its own review, not folded into the rename.)

Scenario RFC0001.9 — body_kind = Structured short-circuits to a structured-template id

  • Given an OtlpLogRecord whose body is Body::Structured(AnyValue) (any non-String AnyValue variant carried verbatim per RFC 0003 §6.4)
  • When the record is ingested
  • Then the §6.2 algorithm skips tokenize/mask/descend per step 0 and allocates or reuses the structured-template id for (severity_number, scope_name, BodyKind::Structured)
  • And the emitted record has body_kind = Structured
  • And the emitted record’s body carries the Ourios canonical body encoding of that AnyValue (per the §6.1 encoding rule)
  • And params and separators are empty
  • And confidence == 1.0 (the §6.1 sentinel)
  • And lossy_flag == false

Scenario RFC0001.10 — time_unix_nano is preserved verbatim from the wire

  • Given an OtlpLogRecord with time_unix_nano = 1_715_700_000_000_000_000
  • When the record is ingested and committed to Parquet
  • Then the emitted row has time_unix_nano == 1_715_700_000_000_000_000
  • And a query WHERE time_unix_nano BETWEEN 1_715_600_000_000_000_000 AND 1_715_800_000_000_000_000 returns the row
  • (Gates docs/benchmarks.md B1 — time-range queries — by making the underlying column measurable.)

Scenario RFC0001.11 — severity_number = 0 and scope_name = None are distinct key buckets

  • Given four OtlpLogRecords with identical body_kind = String body, varying only in (severity_number, scope_name) across (0, None), (0, Some("lib.x")), (9, None), (9, Some("lib.x"))
  • When all four are ingested
  • Then four distinct template_ids are emitted, one per key bucket
  • And no widening or merge ever coalesces the severity_number = 0 (UNSPECIFIED) bucket with any specified-severity bucket
  • And no widening or merge ever coalesces the scope_name = None bucket with any scope_name = Some(_) bucket
  • (Locks the §6.1 explicit edge-case rules: 0 = UNSPECIFIED is a valid OTLP severity that gets its own bucket, and absent scope is its own bucket.)

Scenario RFC0001.12 — Alias assertion is durably recorded and appears in the per-tenant map

  • Given tenant T with two distinct leaves A and B (A < B) and no existing alias set
  • When an operator asserts B is an alias of A
  • Then an alias_asserted audit event is durably recorded on the §6.4 stream under the §3.4 WAL-before-ack barrier before the assertion is acknowledged, naming tenant_id = T, the anchor representative_id = A, member_ids = [B], the actor, and the timestamp — so the asserted set is {A} ∪ {B} = {A, B}
  • And after the per-tenant projection rebuilds, tenant T’s alias map contains an equivalence class with members {A, B} whose derived canonical representative is A (the smallest member)

Scenario RFC0001.13 — resolves_to(rep) returns all members and excludes non-members

  • Given tenant T whose alias map records the set {A, B} (per RFC0001.12) and an unrelated leaf C in no set
  • When the querier compiles template_id.resolves_to(A) for tenant T
  • Then the predicate expands to template_id IN {A, B}
  • And resolves_to(B) expands to the same {A, B} (expansion is by the set, not the direction of assertion)
  • And resolves_to(C) expands to exactly {C}

Scenario RFC0001.14 — Cross-tenant isolation: an alias in tenant A never affects tenant B [§3.7]

  • Given tenant T1 whose alias map records {A, B} and tenant T2 that has the same template_ids A and B but no alias assertion
  • When the querier compiles template_id.resolves_to(A) once for T1 and once for T2
  • Then for T1 it expands to {A, B}
  • And for T2 it expands to exactly {A}
  • (Locks §3.7: alias sets are per-tenant; an assertion in one tenant is invisible to every other.)

Scenario RFC0001.15 — Retraction removes any member, including the canonical, and is itself audited

  • Given tenant T whose alias map records the equivalence class {A, B} (A < B, so A is the derived canonical)
  • When an operator retracts member A — the canonical / smallest member — from the class
  • Then an alias_retracted audit event is durably recorded (same WAL-before-ack barrier and field shape as RFC0001.12) whose asserted set names A (here as representative_id, the operator’s anchor) plus an empty member_ids, and the actor
  • And after the projection rebuilds, A is removed from the class, leaving {B} — a single member, which is no longer an alias set, so resolves_to(A) expands to exactly {A} and resolves_to(B) expands to exactly {B}
  • (Locks the representative-independent retraction rule: retracting any member is well-defined even when it is the canonical/smallest; the canonical is re-derived as min of the remainder, and a class that drops to one member ceases to be an alias set.)

Scenario RFC0001.16 — A non-aliased id resolves to itself

  • Given tenant T with leaf Z and no alias assertion naming Z
  • When the querier compiles template_id.resolves_to(Z)
  • Then the predicate expands to exactly {Z} — identical to the base-member behaviour and to bare template_id = Z (RFC0001.6)

6. Proposed design

The Ourios miner in detail. This is the section that the ourios-miner crate is implemented against; §5’s Acceptance criteria operationalise the commitments here, and §8 maps each §5 scenario to the technique that tests it.

Why §6 exists. Published Drain (§3) and Drain3 (§4) do not address the properties Ourios requires. Each row below is a gap this section closes:

Gap in published DrainOurios invariant that fills it§6 subsection
No confidence score on a match[§3.1] body retention below threshold§6.3
No audit trail on group merges[§3.1] merge audit events§6.4
No inter-token whitespace preservation[§3.3] bit-identical reconstruction§6.6
No per-parameter byte bound[§3.2] param length limit, overflow to body§6.5
No multi-tenant scoping of the tree[§3.7] per-tenant template trees§6.1
No template versioning / drift story[§3.5], hazard H5§6.7

6.1 Data model

Amendment 2026-05-13. Section rewritten to align the record schema with the OTLP LogRecord shape — the project’s stated ingest contract per docs/glossary.md (entry OTLP: “we do not invent our own format”). The investigation that surfaced the gap is docs/architecture/otlp-log-format.md. The pre-amendment schema treated logs as raw text strings; the amended schema treats every log as a structured OTLP record from the moment it enters the system. §6.2’s algorithm and its ingest signature were aligned to this amendment in a companion edit the same day (see §6.2’s amendment note below): the body.kind fork is at the top of the algorithm, the descent step incorporates the §6.1 template-key tuple, and the MinerCluster::ingest signature now takes a structured OtlpLogRecord rather than a raw &str.

The miner emits one record per ingested OTLP LogRecord. The record shape mirrors the wire shape of OTLP logs (the opentelemetry-proto LogRecord plus its inherited Resource and InstrumentationScope context) plus the miner-derived columns that template mining produces.

Record columns

The record carries three groups of columns. The OTLP-derived group preserves the structured shape the wire promised; the miner-derived group is what this RFC introduces; the reconstruction group exists only when the body was mineable (body.kind = String).

Identity and partitioning:

FieldRust type (informal)SourcePurpose
tenant_idTenantIdderived from Resource.attributesMulti-tenant scoping [§3.7]; default rule below
template_idu64miner-allocatedCluster-wide unique; see “Template identity”
template_versionu32miner-allocatedIncrements on widening; see “Template version”

OTLP-derived columns (faithful to opentelemetry-proto):

FieldRust type (informal)OTLP sourcePurpose
time_unix_nanou64LogRecord.time_unix_nanoEvent time at source; 0 = unknown. Required for thesis-gate B1 (time-range queries)
observed_time_unix_nanoOption<u64>LogRecord.observed_time_unix_nanoCollector observation time
severity_numberu8LogRecord.severity_numberOTLP SeverityNumber: 0 = UNSPECIFIED (a valid OTLP value for records that omit severity), 1..=24 = TRACE..FATAL with sub-levels. Part of the template key (see below); 0 is a distinct key value — UNSPECIFIED records cluster together, never with TRACE/INFO/etc.
severity_textOption<String>LogRecord.severity_textSource’s original severity string
scope_nameOption<String>InstrumentationScope.nameLibrary/module emitter; part of the template key (see below)
scope_versionOption<String>InstrumentationScope.versionDrift / debugging
attributesVec<KeyValue>LogRecord.attributesPer-occurrence structured context
dropped_attributes_countu32LogRecord.dropped_attributes_countTruncation indicator
resource_attributesVec<KeyValue>Resource.attributesSource identity (service.name, host.*, etc.)
trace_idOption<[u8; 16]>LogRecord.trace_idTrace correlation
span_idOption<[u8; 8]>LogRecord.span_idTrace correlation
flagsu32LogRecord.flagsLower 8 bits = W3C trace flags
event_nameOption<String>LogRecord.event_nameIdentifier for structured-event records

Amendment 2026-06-11 — the effective timestamp lives in RFC 0005, not here. RFC 0005 §3.2 (amendment of the same date) adds a writer-derived effective_time_unix_nano Parquet column — time_unix_nano when non-zero, else observed_time_unix_nano, else 0 — following the OTLP logs data model’s recommendation (“Use Timestamp if it is present, otherwise use ObservedTimestamp”). The record shape above is unchanged: the miner emits no new field, the Parquet writer computes the column from the two timestamp fields already listed, and the wire time_unix_nano is stored verbatim including 0 — scenario RFC0001.10 (verbatim preservation) remains intact and normative. Time partitioning and the DSL time window key off the derived column (RFC 0005 §3.4 / RFC 0002 §6.2).

Body and miner-derived reconstruction:

FieldRust type (informal)SourcePurpose
body_kindBodyKindderived from LogRecord.bodyDiscriminator: String | Structured (see “Body representation”)
bodyOption<String>LogRecord.bodyUTF-8 (the in-memory record type; the RFC 0005 Parquet column is BYTE_ARRAY). When body_kind = Structured: the Ourios canonical body encoding of the AnyValue (see “Body representation” for the rule). When body_kind = String lossy: the original line. When overflow: per §6.5.
paramsVec<Param>from maskingOne entry per <*> slot. Always empty when body_kind = Structured
separatorsVec<Separator>from tokenizetokens.len() + 1 entries. Always empty when body_kind = Structured
confidencef32miner-derivedsimSeq / threshold at attach time. 1.0 (sentinel) when body_kind = Structured
lossy_flagboolminer-derivedTrue iff reconstruct(record) ≠ ingested_body_bytes is possible. Always false when body_kind = Structured (the verbatim body column is the source of truth)

Where:

  • Param = { type_tag: ParamType, value: Bytes }. ParamType is one of IP, UUID, NUM, HEX, TS, PATH, STR, OVERFLOW. STR is the unmasked-wildcard fallback — used when a slot was created by template widening of a previously-fixed literal token (the literal itself becomes the param value); OVERFLOW carries (length: u32, sha256_prefix: [u8; 8]) instead of the original value (§6.5). params.len() == count(<*> in template), always (in the body_kind = String branch); §6.2 enforces this when a widening introduces new wildcard slots.
  • Separator is a small inline byte string (typically 1–3 bytes in practice). Encoding in Parquet is an implementation detail that does not affect this RFC.
  • KeyValue mirrors the OTLP KeyValue message: a key: String and a value: AnyValue. AnyValue is a discriminated union over string | bool | int | double | bytes | array | kvlist. Storing AnyValue faithfully in Parquet (rather than flattening to a string) is what keeps query expressions like attributes["client.address"] = "10.0.0.1" typed.
  • BodyKind is a two-variant enum (String, Structured) — not the full AnyValue discriminator. The body column carries the encoded AnyValue payload; body_kind is the cheap routing flag the query planner uses to decide whether reconstruction is defined for this row.

Body representation (AnyValue handling)

OTLP’s LogRecord.body is AnyValue — string, bool, int, double, bytes, array, or kvlist. The spec is explicit (Logs Data Model §Body): “Body MUST support AnyValue to preserve the semantics of structured logs emitted by the applications.” Real OTel emitters send structured Body routinely, not just text.

Ourios distinguishes two body shapes at ingest:

  • body_kind = StringLogRecord.body is AnyValue::String. The miner runs the §6.2 algorithm over the unwrapped string: tokenize, mask, descend the tree, attach to or create a leaf. params, separators, confidence, lossy_flag are populated per the existing semantics.
  • body_kind = StructuredLogRecord.body is any other AnyValue variant (kvlist, array, int, double, bool, bytes). The miner does not run the §6.2 algorithm. The body is encoded with the Ourios canonical body encoding (see The Ourios canonical body encoding below) and stored in the body column; no template is mined, no params/separators are emitted. template_id is allocated per the Template-key composition rule below — for this branch the key is (severity_number, scope_name, BodyKind::Structured), so all structured-Body records sharing a (severity, scope) share one template_id. The leaf the id points at carries the Structured marker and an empty body_template. confidence = 1.0 (sentinel), lossy_flag = false (the canonically-encoded body is authoritative; nothing is reconstructed from a template).

This is the conservative default. It preserves the structural content of the body (the Ourios canonical body encoding below makes [§3.3] reconstruction well-defined for the structured branch: stored_bytes ↔ AnyValue is bidirectional and byte-deterministic), it avoids inventing template structure for arbitrary AnyValue trees, and it sidesteps the spec ambiguity of “what is the template for {"msg": "x", "user_id": 42}.” A future opt-in mine-inner-field mode (e.g., mine body.kvlist["msg"] as the line if present) is a configurable knob, not the default; that decision lives with the maturity-stage move from redgreen once corpus evidence informs which inner-field conventions are worth specifying.

A third path — render-to-string + mine (canonicalise structured Body to JSON-ish text and run it through the §6.2 mining algorithm) — was rejected because mining over the JSON serialisation produces token templates that depend on the serialiser’s whitespace and field-ordering choices, which is both fragile (changing serialisers shifts every template) and defeats the §3.3 reconstruction guarantee for any record where the original wire form was protobuf rather than JSON. Storing the canonical encoding (without mining over it) is different from this rejected path: storage is faithful, it just doesn’t get a template extracted.

The Ourios canonical body encoding (body_kind = Structured).

Amendment 2026-06-09 (no canonical OTLP JSON exists). This paragraph previously called the encoding “the OTLP-canonical JSON encoding per the OTLP specification’s HTTP/JSON binding,” implying a spec-defined canonical form. There is none. Per the OTLP spec, the OTel common docs, and a maintainer answer (Josh Suereth, 2026-06-09): OTLP/JSON is the proto3 JSON mapping plus a short closed list of deviations (hex trace_id/span_id, integer enums, ignore-unknown-fields, lowerCamelCase) — with no normative rules on whitespace, key/field ordering, or number canonicalisation, and OTLP does not require lossless translation between formats. The text below is reframed to state the rule as an Ourios-local deterministic encoding, not an OTLP conformance point, and renamed to “the Ourios canonical body encoding.” No code and no RFC status change here; the encoder is ourios-core’s otlp::canonical (a separate follow-up PR aligns its doc comments).

Amendment 2026-06-11 (doubles round-trip bit-exactly — #130). The rule below previously left double precision implicit, and decode(encode(x)) drifted 1–2 ULP for ~12% of arbitrary finite f64. Investigating #130 located the loss on the decode side, not the encoder: the emitter already produces shortest-round-trip digits (serde_json’s Ryu f64 formatter — with-serde adds no custom double formatter), but serde_json’s default float parsing is approximate. The rule now pins both halves: doubles are emitted as shortest-round-trip JSON numbers and decoded with correctly-rounded float parsing (serde_json’s float_roundtrip feature, declared load-bearing in ourios-core), so the f64 round-trip is exact for every finite double — the faithfulness guarantee below holds for arbitrary doubles, not just “nice” ones. Non-finite doubles (NaN, ±∞) have no JSON-number form and encode as null — bytes that do not decode back; that pre-existing gap is explicitly out of scope here and stays open. No RFC status change.

The body column carries the Ourios canonical body encoding of the AnyValue: a proto3-JSON form, defined below. This is an Ourios-local deterministic convention, not an OTLP-mandated canonical form. OTLP defines no canonical or byte-deterministic JSON encoding. Its only normative JSON rules are the proto3 JSON mapping (per the protobuf spec) plus a short closed list of OTLP-specific deviations — trace_id / span_id as hex strings (not applicable to a body AnyValue, which carries no IDs), enum values as integers, ignore unknown fields, and lowerCamelCase field names. The spec is silent on whitespace, key/field ordering, and number canonicalisation, and OTLP does not require lossless translation between formats. There is therefore no “canonical OTLP JSON” to reference; the byte-stable encoding below is Ourios’s own, chosen so the body column is byte-deterministic (storage dedup) and the [§3.3] reconstruction guarantee is well-defined.

The concrete rule is the proto3 JSON mapping as emitted by opentelemetry-proto’s with-serde feature via serde_json:

  • field names in lowerCamelCase;
  • int64 / uint64 values as decimal strings (proto3 JSON’s canonical emit form; decoders accept a JSON number or string);
  • double values as JSON numbers in shortest-round-trip form, decoded with correctly-rounded float parsing — decode(encode(x)) is bit-exact for every finite f64 (#130; see the 2026-06-11 amendment above);
  • bytes as base64;
  • KvlistValue and ArrayValue element order preserved as received — not sorted (this is explicitly not RFC 8785 / JCS canonical JSON);
  • byte-deterministic because the proto types have a fixed serde field order and serde_json serialisation is deterministic.

Canonical byte examples: {"intValue":"-42"}, {"doubleValue":2.71}, {"boolValue":true}, {"bytesValue":"<base64>"}, {"arrayValue":{"values":[…]}}, {"kvlistValue":{"values":[{"key":"…","value":{…}}]}}.

“Deterministic” here means byte-identical. Re-encoding the same in-memory AnyValue with this encoder yields byte-for-byte identical output (within a fixed opentelemetry-proto / serde_json version). This is the byte-level reading, not a weaker struct-level one: it is what lets the body column be deduplicated and lets two receivers handling the same logical AnyValue produce the same stored bytes. The receiver path: OTLP/gRPC (protobuf wire) decodes to an in-memory AnyValue and re-encodes here; OTLP/HTTP+JSON decodes the incoming JSON to an in-memory AnyValue and re-encodes the same way, so the stored bytes do not depend on the producer’s whitespace, field order, or int64-as-number-vs-string choice.

The faithfulness guarantee — stored_bytes decode back to the original in-memory AnyValue — is an Ourios guarantee delivered by this encoder/decoder pair, not an OTLP lossless promise (OTLP makes none). lossy_flag = false for structured rows rests on this Ourios guarantee, not on any OTLP conformance claim.

Duplicate keys. OTLP KvlistValue is a repeated KeyValue that the data model treats as a map with unique keys; the data-model map equality is order-insensitive, but OTLP does not define wire-order equality, which is why preserving received order (above) is the safe, spec-permitted choice. A KvlistValue carrying duplicate keys is non-conforming OTLP input with no defined semantics. Ourios does not silently dedup or reorder such input: it preserves the entries verbatim in the encoding (so the round-trip stays faithful) and makes no map-semantic guarantee for it, rather than inventing one.

Template-key composition

A template’s identity (the discriminator the Drain tree uses to decide “is this the same template?”) depends on the body shape:

  • body_kind = String — key tuple is (severity_number, scope_name, masked_body_tokens).
  • body_kind = Structured — key tuple is (severity_number, scope_name, BodyKind::Structured). All structured-Body records sharing a (severity_number, scope_name) share one template_id. This intentionally forfeits structured-body shape clustering — the rationale is that the structured-Body branch’s value comes from the faithful preservation of attributes and the canonically-encoded body, not from grouping similar AnyValue shapes. Operators who need shape-level clustering can opt into a future body_shape_fingerprint column (a stable hash over the AnyValue’s structural skeleton — kvlist key-set, nested shape, leaf-type sequence; values ignored) as a reserved extension; the gate for adding it is “we have a concrete consumer,” not “it might be useful.”

The bullet rationale below applies to both branches:

  • severity_number is part of the key because INFO and ERROR versions of the same body text are semantically distinct events. “user logged in” at INFO is a routine signal; “user logged in” at ERROR is an alarm (or an emitter bug) — collapsing them to one template_id would surface either as the other on query, which is a [§3.1] “no silent merges” violation in disguise. The OTLP-spec-valid severity_number = 0 (UNSPECIFIED) is a distinct key value, not coalesced with any specified severity.
  • scope_name is part of the key because the same body text emitted from two different instrumentation scopes (myapp.login vs myapp.checkout) describes two different events. The scope is the OTel-canonical “which code path emitted this,” directly analogous to the package/logger name in traditional logging frameworks. Records with no scope (scope_name = None) cluster as their own (severity, None) bucket.
  • resource_attributes are NOT part of the key. They identify who sent the record (service, host, k8s pod), not what event was emitted. The tenant_id derivation (below) already encodes the partition decision over Resource. Folding Resource into the template key would explode template cardinality proportionally to the deployment fleet size without adding semantic discrimination — the same myapp.login template from two replicas of service.name = api is the same template.
  • event_name is not in the key today but is reserved as a candidate addition. RFC 0001 stays at the OTLP-canonical severity+scope key; promoting event_name into the key is a follow-up RFC patch once corpus evidence justifies it.

The Drain tree’s implementation of this tuple (extra prefix levels above length-N, tuple-keyed leaf lists, separate trees per (severity, scope), etc.) is §6.2 implementation territory and may be revisited based on cardinality observations from the corpus benchmark. The RFC pins only the semantic key.

Tenant derivation

tenant_id is derived per ResourceLogs group, not per OTLP export batch. Each ResourceLogs carries its own Resource.attributes, and a single OTLP export can contain multiple ResourceLogs groups from different sources — so one export can route records to multiple tenants. The derivation runs once per inherited Resource; the resulting tenant_id applies to every LogRecord under that ResourceLogs group (across all its ScopeLogs), and the receiver fans the records out into per-tenant streams.

The default per-Resource rule:

tenant_id := resource.attributes["service.name"]   if present
          ?: <operator-required fallback rule>

service.name is the conventional OTel unit of “what application emitted this,” and it maps directly onto Ourios’s per-tenant template-tree partitioning ([§3.7]). Operators with a different multi-tenant model (per-namespace, per-customer-id-attribute, composite of multiple attributes) configure an alternative rule; the receiver does not invent a tenant identity that the operator hasn’t declared.

If a ResourceLogs group’s Resource resolves to no tenant under either the default rule or the operator’s fallback, the receiver rejects the entire export batch with a controlled error (no panic, no silent assignment to a “default” tenant; the sender sees the failure and either fixes its emitter or its deployment). Per-Resource rejection within an otherwise-valid batch is not supported in this RFC — the all-or-nothing failure mode is simpler to reason about for the sender, and OTLP’s batch-level acknowledgement model fits all-or-nothing more naturally than partial-success. The receiver-side specification of this rejection path (and any future opt-in for partial acceptance) lives in RFC 0003 — OTLP receiver (forthcoming).

Template identity

template_id is a cluster-wide unique monotonic u64 (with each tenant seeing a monotonic subsequence), allocated when a new leaf is created and never reused or reassigned. The id space is shared across tenants so that the same u64 value never refers to two different leaves; the per-tenant subsequence guarantee preserves [§3.7] by making each tenant’s allocation order observable in isolation. Cross-tenant content identity is intentionally not guaranteed — two tenants emitting the structurally identical template (same (severity_number, scope_name, masked_body_tokens) tuple) will have different template_ids, so a template_id alone never links structurally-equivalent templates across tenants. (The u64 value itself is cluster-wide unique, per the previous paragraph; what is not guaranteed is that the same template across two tenants resolves to the same id.) This preserves [§3.7] (per-tenant template trees) by construction; cross-tenant analytics that need content identity (deduplication across tenants for storage savings, shared template dashboards) are an opt-in concern and are not provided by the miner. A future template_fingerprint side column may carry a canonical content hash over (severity_number, scope_name, masked_body_tokens) for opt-in cross-tenant use; the gate for adding it is “we have a concrete consumer,” not “it might be useful.”

Template version. template_version starts at 1 when the template is created and increments by 1 on every widening event: either a new wildcard slot opens (a previously fixed token at position i becomes <*>), or an existing wildcard’s typed parameter set changes (e.g. a <NUM> slot starts seeing <STR> values). To detect the second case, every leaf carries — alongside its template — a slot_types: Vec<HashSet<ParamType>> indexed by wildcard slot, recording every ParamType observed in that slot. A type expansion is the addition of a ParamType to one of these sets. The pair (template_id, template_version) uniquely identifies one structural state of a template. Queries against template_id = X return all versions; queries against (template_id, template_version) = (X, V) return only the named state. The DSL surface is RFC 0002’s concern, not this RFC’s, but the data model must support both.

Why two integers and not a content hash. A content hash makes identity global by construction; in a multi-tenant backend that is a tenant-isolation leak rather than a feature. A content hash also makes template_version redundant — once the canonical template string changes, the hash changes, so versioning collapses into alias-mapping between hashes. Per-tenant monotonic ints with an explicit version field are smaller in the Parquet column, easier to reason about under [§3.7], and keep (template_id, template_version) as a meaningful compound key.

6.2 Algorithm

Amendment 2026-05-13. Rewritten to take a structured OTLP LogRecord rather than a raw &str, in line with the §6.1 amendment. The algorithm now opens with the body.kind fork from §6.1’s Body representation: AnyValue::String runs the Drain mining steps (the prior algorithm, preserved verbatim below); every other AnyValue variant short-circuits to the structured emit per §6.1’s Template-key composition fork. Step 3’s descent now incorporates (severity_number, scope_name) into the tree key, again per §6.1 — the implementation choice (extra prefix layers, tuple-keyed leaf lists, separate trees per (severity, scope)) stays in §6.2 as the algorithm’s responsibility, but the semantic key is pinned by §6.1. The ingest signature on MinerCluster becomes ingest(record: &OtlpLogRecord); pre-amendment callers were ingest(tenant_id, raw: &str).

The miner sees an already-tenant-resolved (tenant_id, record: OtlpLogRecord) pair. The receiver (RFC 0003) is responsible for resolving tenant_id per ResourceLogs and fanning records into per-tenant streams before the miner sees them; §6.1’s Tenant derivation pins that contract.

For each ingested OTLP LogRecord:

0.  match record.body.kind:

      AnyValue::String(s):
          # Continue with the Drain mining algorithm in steps
          # 1–5 below, treating `s` as the `L_raw` of the prior
          # spec. body_kind = String.

      AnyValue::Bool | Int | Double | Bytes | Array | KVList:
          # Structured short-circuit per §6.1 *Body
          # representation*. The miner does NOT run the Drain
          # mining steps. body_kind = Structured.
          encoded = encode_canonical_body(record.body)
              # Ourios canonical body encoding (a proto3-JSON form;
              # lowerCamelCase fields, int64/uint64 as decimal
              # strings, bytes as base64, kvlist/array order
              # preserved — NOT sorted). This is an Ourios-local
              # deterministic convention, NOT an OTLP-mandated
              # canonical form: OTLP defines no canonical JSON and
              # requires no lossless translation. For records over
              # OTLP/gRPC the receiver decodes protobuf and
              # re-encodes here; for OTLP/HTTP+JSON it decodes to
              # the in-memory AnyValue and re-encodes the same way,
              # so stored bytes are byte-identical regardless of the
              # producer's whitespace / field order / int64 form.
              # The lossy_flag = false promise rests on this Ourios
              # round-trip guarantee — see §6.1 for the why.
          template_id = allocate_or_reuse_structured_template_id(
              record.severity_number,
              record.scope_name,
          )
              # Per §6.1 *Template-key composition*, the
              # structured-Body key is (severity_number,
              # scope_name, BodyKind::Structured). All structured
              # records sharing a (severity, scope) share one
              # template_id. The leaf the id points at carries the
              # `Structured` marker and an empty body_template.
          attach_structured(record, encoded, template_id,
                            confidence = 1.0,
                            lossy_flag = false)
              # confidence = 1.0 sentinel; lossy_flag = false
              # because the canonicalised body is authoritative,
              # nothing is reconstructed from a template.
          return

1.  L_tok, separators = tokenize(L_raw)
        # tokenize splits on Unicode whitespace only — every
        # codepoint matching `char::is_whitespace()` (ASCII space,
        # tab, CR, LF, plus the broader Unicode whitespace classes
        # U+0085, U+00A0, U+1680, U+2000–U+200A, U+2028, U+2029,
        # U+202F, U+205F, U+3000). Every other byte (including
        # punctuation such as `=`, `:`, `,`, `;`, `[`, `]`, `(`,
        # `)`) stays inside a token; structured separators are the
        # masking layer's responsibility (§4.2 / step 2). The
        # captured whitespace runs go into `separators` so that
        # reconstruction (§6.6) is byte-identical.
        # On failure (malformed UTF-8, embedded NUL, line longer
        # than max-line-bytes): emit a parse-failure record and
        # increment ourios.miner.parse_failures. Skip the rest.
        # Note: an empty-after-whitespace string (the AnyValue
        # carries `""` or only whitespace) is not a parse failure
        # — it has zero tokens and the miner short-circuits with
        # the cluster's `NO_TEMPLATE` sentinel rather than
        # descending the tree. The pre-amendment cluster code
        # already routes this case; the spec just records it.

2.  L_masked, typed_params = mask(L_tok)
        # mask applies the configured masking rules in order;
        # any token matching a rule is replaced with its type
        # tag (e.g. <IP>) and the original bytes are pushed
        # into typed_params with that tag. Unmasked tokens
        # remain literal.

3.  parent = tree.descend(record.severity_number,
                           record.scope_name,
                           len(L_masked),
                           L_masked[0..d-1])
        # Per §6.1 *Template-key composition*, the discriminator
        # for "is this the same template?" is the tuple
        # (severity_number, scope_name, masked_body_tokens).
        # Step 3 incorporates severity_number and scope_name into
        # the descent key alongside the masked-token prefix used
        # by published Drain. The implementation may layer extra
        # prefix levels above the length-N node, key leaf lists
        # by (severity, scope), or maintain separate trees per
        # (severity, scope) — the choice is cardinality-driven
        # and revisitable from corpus observations. The
        # severity_number = 0 (UNSPECIFIED) and scope_name = None
        # cases are valid distinct key positions; they cluster as
        # their own buckets, never coalesced with any specified
        # severity or named scope.
        # if a node along the path does not exist, create it.

4.  candidate = argmax over leaf in parent.leaves of
                  simSeq(L_masked, leaf.template)
    if candidate is None:
        # no leaves under parent yet; create one. Creation does not
        # emit an audit event — `ourios.miner.template.count` already reflects
        # leaf allocation, and §6.4 reserves the audit stream for
        # widening events whose semantics need cross-referencing.
        leaf = new Leaf(template = L_masked)
        parent.leaves.push(leaf)
        # On fresh-leaf creation the template is L_masked verbatim,
        # so every <*> in it came from mask(); params == typed_params.
        attach(L_masked, typed_params, separators, leaf,
               confidence = 1.0, lossy_flag = false)
        return

5.  similarity = simSeq(L_masked, candidate.template)
    confidence = similarity / threshold

    if similarity >= threshold:
        # clean or lossy attach; widen the template if needed.
        # widen() returns:
        #   widened           — the new template (existing fixed
        #                       positions that mismatched L_masked
        #                       become <*>)
        #   new_wildcards     — the set of positions that just
        #                       became <*> (the audit payload)
        widened, new_wildcards = widen(candidate.template, L_masked)
        if new_wildcards > 0:
            candidate.template = widened
            candidate.version += 1
            emit_audit(event_type = template_widened,
                       template_id = candidate.id,
                       old_version, new_version = candidate.version,
                       positions_widened = new_wildcards.positions,
                       ...)
            ourios.miner.merges.inc()

        # Build the params array. One entry per <*> in the (possibly
        # just-widened) template, in template order. For each slot:
        #   - if the slot existed before this attach AND mask() emitted
        #     a typed_params entry for it, use that entry verbatim.
        #   - if the slot is a fresh wildcard from this widening (the
        #     position held a literal token in candidate.template before
        #     the widen call), the original literal at that position in
        #     L_tok is captured as { type_tag: STR, value: L_tok[pos] }.
        # Without this step §6.1's "one entry per <*> slot" invariant
        # is violated and §6.6's reconstruct() has no value to insert
        # at the freshly-widened position.
        params = build_params(candidate.template, typed_params,
                              L_tok, new_wildcards)

        # Type-expansion: if any wildcard slot now sees a typed param
        # whose type tag is not already in that slot's observed-type
        # set, widen the slot's type set, bump the version, and
        # audit. The leaf carries `slot_types: Vec<HashSet<ParamType>>`
        # alongside its template (data model in §6.1).
        new_types = update_slot_types(candidate, typed_params)
        if not new_types.is_empty():
            candidate.version += 1
            emit_audit(event_type = template_type_expanded,
                       template_id = candidate.id,
                       old_version, new_version = candidate.version,
                       slots_expanded = new_types,
                       ...)

        attach(L_masked, params, separators, candidate,
               confidence,
               lossy_flag = false)  # §6.6: lossy_flag is set only on
                                    # tokenizer/preprocessing failure,
                                    # not on confidence < 1.0
        return

    if similarity >= floor:
        # lossy zone: the line is "close" but doesn't meet
        # threshold. Create a new leaf rather than force-merging.
        # Body retention is unconditional in this branch.
        leaf = new Leaf(template = L_masked)
        parent.leaves.push(leaf)
        # As in the candidate-is-None branch, the new leaf's template
        # is L_masked verbatim, so params == typed_params.
        attach(L_masked, typed_params, separators, leaf,
               confidence,
               lossy_flag = false,
               body = L_raw)  # forced body retention
        ourios.miner.body_retention.utilization.observe(retained = true)
        return

    # similarity < floor: parse failure
    ourios.miner.parse_failures.inc()
    emit_failure_record(L_raw, reason = "no candidate above floor")

Branching invariants:

  • Step 0’s structured short-circuit never enters the Drain mining steps (1–5). Structured-Body records do not widen, do not emit template_widened or template_type_expanded audit events, do not contribute to ourios.miner.merges, and never carry params/separators. The structured branch’s [§3.1] preservation is vacuous: no template merge happens, so no silent merge is possible.
  • The tree only deepens on first observation of a (severity_number, scope_name, length, prefix tokens) shape (the §6.1 template-key tuple, anchored at this section’s step 3).
  • Leaves are split (new leaf created) when the best candidate is in the lossy zone; they are never split when the candidate is clean.
  • A leaf is widened (wildcards introduced) when a clean attach would otherwise mismatch positions. Every widening emits an audit event (§6.4).
  • A leaf’s wildcard slot is type-expanded when an attach maps a typed parameter whose ParamType is not already in that slot’s slot_types[slot] set. Type expansion increments template_version and emits a template_type_expanded audit event (§6.4).
  • A single attach can trigger both wildcard-widening and type-expansion in the same leaf; in that case template_version increments twice and two audit events are emitted, in that order.
  • The leaf’s template_version only increments on widening or type-expansion, not on a clean attach. Structured-Body leaves are never widened or type-expanded; their template_version stays at 1 for the lifetime of the leaf.

6.3 Confidence scoring [§3.1]

confidence = simSeq / threshold. The ratio framing makes the decision boundary land at confidence == 1.0 regardless of the configured threshold, which gives ourios.miner.confidence.p50 and ourios.miner.confidence.p01 ([§3.1] required metrics) a stable interpretation across tenants with different thresholds: the p01 value tells you how close the bottom 1% of attaches are to the merge boundary. A collapsing p01 means many lines are barely passing — a tuning signal even though the threshold itself has not moved.

Three zones, with concrete defaults:

  • confidence ≥ 1.0 (i.e. simSeq ≥ threshold): clean attach. No body retention.
  • floor / threshold ≤ confidence < 1.0: lossy zone. The line attaches to a freshly created leaf rather than being force-merged into the candidate (see §6.2 step 5). body is retained unconditionally; lossy_flag follows the §6.6 rule (set only on reconstruction failure, not on lossy zone alone — the body is available either way).
  • confidence < floor / threshold: parse failure. ourios.miner.parse_failures increments; the line is written to a failure record with the original bytes intact.

Defaults. threshold = 0.7, floor = 0.4. The threshold floor is fixed by [§3.1] (“threshold ≥ 0.7, lowering requires an RFC, not a config change”); the lossy-zone floor is a tuning knob between threshold and 0. floor = 0.4 matches the paper’s reported default threshold, on the reasoning that lines below the paper’s own bar are likely genuinely different events. Tuning the floor is a per-tenant config decision; it is not load-bearing for any invariant.

6.4 Merge policy [§3.1]

A template widening (per §6.2 step 5) is the operation that [§3.1] calls a “merge.” Every widening emits an audit event with the schema:

{
  event_type: AuditEventType,  # enum:
                               #   template_widened
                               #   template_type_expanded
                               #   template_widening_rejected_degenerate
  tenant_id: TenantId,
  template_id: u64,
  old_version: u32,
  new_version: u32,
  old_template: String,        # canonical form, with <*> for wildcards
  new_template: String,
  triggering_line_hash: [u8; 16],  # blake3 of L_raw, for cross-ref
  triggering_line_sample: Option<String>,  # first 256 B of L_raw
  positions_widened: Vec<u16>, # token positions that became <*>
                               # (empty for template_type_expanded)
  slots_expanded: Vec<SlotExpansion>,
                               # slot index + newly added ParamType(s)
                               # (empty for template_widened)
  timestamp: SystemTime,
}

event_type is the field §6.7’s drift-detection query filters on. ourios.miner.merges increments on every event whose event_type is template_widened or template_type_expanded (the two structural widenings); template_widening_rejected_degenerate is recorded but does not increment ourios.miner.merges. The audit stream is written to the same WAL as the data records and ends up in a dedicated audit Parquet file per tenant per compaction window (schema in ourios-parquet’s RFC, not this one).

Default policy: strict. Widening is permitted whenever the clean-attach path in §6.2 would otherwise mismatch positions. The audit event is mandatory — no widening, of any reason, ever proceeds without one. Code paths that would emit a widening without emitting an audit event are blocked at PR review per hazards.md H1.

WAL durability ordering of audit events. A single attach may emit two audit events in order (RFC0001.7: template_widened immediately followed by template_type_expanded) and one data record. The contract this RFC requires from the future ourios-wal RFC is an ordering-plus-durability-barrier: a data record carrying template_version = V must not become durable before every audit event justifying the leaf’s progression to V is durable. Crash recovery may then observe some prefix of [event_1, event_2, …, data_record], but never a state in which the data record exists without the events that caused its version stamp. Any framing strategy that satisfies this — a composite multi-record frame, batched-fsync ordering, a two-phase write-then-link, anything else — is acceptable; the framing is ourios-wal’s choice, the ordering barrier is this RFC’s requirement. Without it, replay would bump template_version fewer times than the in-memory leaf did and the surviving data records would reference a version the audit stream cannot substantiate.

Degenerate template guard. If a widening would leave the template with zero non-wildcard tokens (the entire template becomes <*> <*> … <*>), the widening is rejected, the line is treated as a parse failure (confidence = 0, retain body, increment ourios.miner.parse_failures), and an audit event with event_type = template_widening_rejected_degenerate records the rejection. A fully-wildcard template provides no parsing value and would swallow arbitrary lines.

6.5 Parameter handling [§3.2]

Per-parameter byte limit. Default 256 B, configurable up to 1 KiB (the [§3.2] ceiling). Above 1 KiB requires an RFC.

Overflow behaviour. When a parameter value (post-masking) exceeds the configured limit, the parameter slot is replaced by an OVERFLOW marker:

Param {
  type_tag: ParamType::OVERFLOW,
  value: encode(length: u32, sha256_prefix: [u8; 8]),
}

The original line L_raw is captured into the body column unconditionally (overflow forces body retention, regardless of lossy_flag). The 8-byte SHA-256 prefix lets queries “find rows where this exact long parameter occurred” without storing the long value in the columnar data. Reconstruction honours overflow: reconstruct(record) falls back to body when any param has type_tag == OVERFLOW.

Telemetry. Two metrics for [§3.2] and hazard H2:

  • ourios.miner.params.overflow (counter, attributes ourios.tenant, ourios.service): increments per overflow.
  • ourios.miner.params.overflow.utilization (gauge, attributes ourios.tenant, ourios.service): rolling overflow rate. Alert at > 0.01 per service per [§3.2].

6.6 Body reconstruction [§3.3]

Amendment 2026-06-08 (reader render contract). H7.3 (§5) referenced “the §6.6 warning marker,” but §6.6 defined no such marker — the prose Reader behaviour paragraph it replaced described one only informally. This amendment adds the Reader render contract subsection below, defining the marker as a structured, out-of-band per-row Reconstruction signal (Faithful | RetainedVerbatim) the reader attaches to the rendered row — never a mutation of the body bytes — and pinning the lossy short-circuit H7.3 requires (return body verbatim, do not call reconstruct). The clean-path read-time template lookup (a registry mapping (template_id, template_version) → tokens at read time) is explicitly out of scope and deferred to the querier’s reader-materialisation story (RFC 0007). RFC 0001 stays specified; this clarifies the §6.6 contract, it does not change the on-disk schema or the mining algorithm.

Capture, always. Every successful tokenization in §6.2 step 1 populates the separators array with the bytes between adjacent tokens (and the leading and trailing bytes of the line). The array length is tokens.len() + 1. There is no whitespace heuristic and no “is this whitespace trivial” decision — the bytes are captured verbatim. Storage cost is bounded (typical separator is one space; the array dictionary-encodes well in Parquet) and the implementation has no fuzzy boundary that could decide to drop bytes silently.

Reconstruction function.

fn reconstruct(record: &Record) -> Bytes {
    if record.lossy_flag {
        return record.body.expect("lossy implies retained body");
    }
    if record.params.iter().any(|p| p.type_tag == OVERFLOW) {
        return record.body.expect("overflow implies retained body");
    }
    let template = lookup(record.template_id, record.template_version);
    let mut out = BytesMut::new();
    out.extend_from_slice(&record.separators[0]);
    for (i, token) in template.tokens.iter().enumerate() {
        match token {
            Token::Fixed(s) => out.extend_from_slice(s),
            Token::Wildcard(slot) => {
                out.extend_from_slice(&record.params[slot].value)
            }
        }
        out.extend_from_slice(&record.separators[i + 1]);
    }
    out.freeze()
}

lossy_flag semantics. Set to true if and only if reconstruction is not guaranteed to equal the ingested bytes:

  • The tokenizer failed (malformed UTF-8 inside a token, embedded NUL, line exceeded the configured max_line_bytes cap before tokenization completed).
  • A preprocessing rule explicitly rejected the line.

The lossy zone in §6.3 (low confidence) does not automatically set lossy_flag: the body is retained either way, and reconstruction from template + params + separators is still expected to match. The flag is reserved for the cases where the record genuinely cannot be reconstructed.

Reader render contract

The functions above run at write time: reconstruct is the property-test oracle and the in-process renderer the miner exercises while the template is in hand. The reader — the read-side path that materialises a stored Parquet row back into the effective original line for a query result — is a distinct caller, and H7.3 pins the contract it must honour. The contract below covers String-body rows (body_kind = String); structured bodies are out of scope (see the end of this subsection).

For a String-body row, the render result is (bytes, reconstruction). Rendering yields two things: the effective original line bytes and a per-row reconstruction signal

#![allow(unused)]
fn main() {
enum Reconstruction {
    Faithful,         // bytes == ingested line, reconstructed from template
    RetainedVerbatim, // bytes are the retained `body` column, not reconstructed
}
}

The Reconstruction signal is the “§6.6 warning marker” that H7.3 references. It is structured, out-of-band metadata attached to the rendered row — not a mutation of the body bytes. A consumer (the DSL output layer, RFC 0007; a UI) renders RetainedVerbatim as a “rendered from the retained body bytes, not reconstructed” warning beside the row, exactly as it would render any other per-row annotation.

A body-byte annotation is explicitly rejected as the marker. Prefixing the body with a sentinel string, wrapping it in a marker character, or otherwise editing the bytes to carry the warning would break the verbatim guarantee: the whole point of the lossy path is that an operator asking “show me what was actually logged” gets the ingested bytes back unchanged [§3.3]. The marker therefore lives beside the bytes, never inside them.

Lossy path (H7.3). For a row with lossy_flag = true — the tokenizer-failure / explicit-rejection cases enumerated under lossy_flag semantics above — the reader returns the body column verbatim with Reconstruction::RetainedVerbatim, and does not invoke reconstruct: no template lookup, no token walk. The same short-circuit applies to a String-body row carrying an OVERFLOW param (§6.5): its retained body is returned verbatim with Reconstruction::RetainedVerbatim. reconstruct’s own lossy_flag / OVERFLOW early returns remain in place as a defensive guard for callers that reach it anyway; the reader’s contract is to short-circuit before that call, so the guard is belt-and-braces, not the primary mechanism.

Structured bodies are out of scope of this amendment. A body_kind = Structured row renders its body column from the Ourios canonical body encoding (the §6.1 rule, exercised by the RFC0001.9 structured short-circuit). This amendment defines the Reconstruction marker for the implemented String path only; how a structured render maps to a Reconstruction signal is left open here, to be settled when structured-body rendering is wired.

Clean path. For a faithful row (lossy_flag = false, no OVERFLOW param, template available) the reader invokes reconstruct(record) and attaches Reconstruction::Faithful. This path requires resolving (template_id, template_version) → tokens against a template registry available at read time. That registry — how the reader obtains the template a stored row was mined against, given that the miner’s in-memory tree is an ingest-side structure — is a separate concern and out of scope of this amendment. Today reconstruct is exercised only where the template is already in hand (the write-side property test H7.1, and H7.4); the read-time lookup mechanism is future work, tracked with the querier’s reader-materialisation story (RFC 0007). This amendment pins the render contract and the lossy path; it does not specify a template-registry design.

The reader never silently substitutes one rendering for the other: every rendered String-body row carries its Reconstruction signal, and the lossy/clean branch is selected solely by the row’s lossy_flag (and the §6.5 OVERFLOW case), never inferred from the bytes.

Property test. For every row r in the corpus where r.lossy_flag == false:

reconstruct(r) == ingested_bytes(r)

Failure is a build break, not a regression — [§3.3] and hazard H7 both name this as the property test that gates merges.

6.7 Template versioning and drift [§3.5], hazard H5

A template’s structural state changes over time as widenings (§6.4) and parameter-type expansions accrue. Each change increments template_version and emits an audit event of type template_widened or template_type_expanded. ourios.miner.template.version_changes counts these.

Two distinct cross-cutting questions. “Same leaf, different structural snapshots” and “different leaves that mean the same thing” are separate problems, with separate query forms:

  • Cross-version (within one leaf). A leaf’s template_id is stable across every widening of that leaf (§6.1, “Template identity”); only template_version advances. So a literal predicate where template_id = X already returns rows from every version of leaf X by construction — no alias resolution required. To pin to a single structural snapshot, query where (template_id, template_version) = (X, V).
  • Cross-alias (across leaves). When a deploy changes a log line enough that the miner allocates a new leaf instead of widening the existing one, the operator has two template_ids for what is semantically the same template. Resolving “all rows for the thing X represents” then requires walking an alias set that spans leaves. RFC 0002 §5.4 exposes this as where template_id.resolves_to(X); bare where template_id = X does not follow alias chains.

The data model in §6.1 supports both shapes: cross-version is free because template_id is stable across widenings; cross-alias is served by a separate alias index that maps a representative template_id to the equivalence class of template_ids the operator (or a future inference layer) considers semantically the same template.

Alias index lifecycle. Cross-alias is structurally distinct from cross-version: widening is intra-leaf and increments template_version (one template_id, several versions); aliasing is inter-leaf and groups template_ids the miner allocated separately (different template_ids, the operator asserts they mean the same thing). template_widened events therefore do not populate the alias index — they live on the cross-version axis.

Alias write path: operator-driven and audited [§3.1]. The alias index is operator-driven, never silently inferred. An alias assertion — “leaf B is the same template as leaf A” — is an explicit operator action recorded as an audited, durable event, exactly as §3.1 requires of any merge (“every merge emits an audit event; explicit”). Automatic inference is the precise failure mode §3.1 forbids: an auto-aliased cross-semantic merge is a silent merge by another name. The amendment below replaces the previous “no creation event / produced out of band” deferral with the mechanism.

Amendment (alias write path, 2026-06-07). Resolves the §9 open question “Alias index creation mechanism.” The alias index is produced by operator-driven, audited, reversible assertions on the §6.4 audit stream; automatic inference is deferred to a possible future propose → operator-confirm layer (proposals never enter the active index unconfirmed). Adds the alias_asserted / alias_retracted audit events, the per-tenant alias-map projection the querier reads, and §5 scenarios RFC0001.12–RFC0001.16. The RFC re-enters the ladder at specified until those scenarios land (precedent: the RFC 0003 served-binary amendment).

The alias model. An alias set is an equivalence class of template_ids within one tenant [§3.7]. Membership — which template_ids are in the class — is the only thing that carries contract weight: resolves_to expands by membership and nothing else (RFC0001.13). The class also has a canonical representative, defined as the numerically smallest member of the materialized set. The canonical representative is a derived display/identity convenience, not what defines membership: it gives the set a stable name and is deterministic regardless of assertion order, but it plays no part in deciding who belongs to the class. This derivation rule is an evolvable implementation detail, not a contract — it may change (for example, letting an operator designate a preferred representative) without changing alias-set semantics, precisely because resolves_to expands by membership regardless of which member is canonical. (This is distinct from the event-level representative_id below, which is merely the operator’s anchor id for an assertion and need not equal the derived canonical.) Membership is cross-leaf only: it groups template_ids the miner allocated as separate leaves. It never crosses the cross-version axis — every version of a single leaf already shares one template_id (§6.1, “Template identity”), so template_version is not an alias concern and the alias index holds no template_version field. The two axes stay disjoint: widenings move a leaf along template_version; aliasing groups distinct template_ids.

The assertion event. Aliasing is expressed by two new AuditEventType variants on the §6.4 audit stream, carrying an alias-specific payload:

{
  event_type: AuditEventType,  # alias_asserted | alias_retracted
  tenant_id: TenantId,
  representative_id: u64,       # operator's anchor id for this
                               # assertion — names one member of the
                               # asserted set; carries no contract
                               # weight beyond that and need not equal
                               # the set's derived canonical (smallest)
  member_ids: Vec<u64>,        # the other ids grouped by / removed
                               # from the set in this assertion
  actor: ActorId,              # operator / API principal that
                               # issued the assertion — aliasing is
                               # never anonymous (§3.1 "explicit")
  reason: Option<String>,      # operator-supplied justification
                               # (e.g. "deploy 2026-06 re-split the
                               # login template"), <= 256 B
  timestamp: SystemTime,
}

The asserted set of an event is the full union {representative_id} ∪ member_idsrepresentative_id is one named member of that set, never excluded from it. An alias_asserted event groups its entire asserted set into one equivalence class; an alias_retracted event removes every id in its asserted set from their class. Membership is therefore defined purely by the union of ids in the event, independent of which id the operator chose as the anchor.

These events flow through the same audit stream as template_widened (§6.4) and inherit its durability contract: they are written to the WAL and become durable under the §3.4 WAL-before-ack barrier before the assertion is acknowledged to the operator. An assertion that has not hit the WAL is not acknowledged — there are no in-memory-only aliases. Unlike widenings, alias events are not emitted on the ingest hot path; they originate from an explicit operator/control-plane call, so they do not gate attach latency. They do not increment ourios.miner.merges (that counter is reserved for the two structural widenings, §6.4); alias activity is counted separately as the ourios.miner.alias.assertions / ourios.miner.alias.retractions counters enumerated in §6.8’s telemetry table (mandatory, ourios.tenant attribute), keeping operator-driven aliasing first-class telemetry per [§3.1] / §6.3 alongside ourios.miner.merges.

Materialization and storage. The durable alias event log (the alias_asserted / alias_retracted stream above) is the source of truth; the queryable per-tenant alias map is a projection built by folding that log per tenant. Each alias_asserted unions its full asserted set ({representative_id} ∪ member_ids) into one equivalence class, merging any pre-existing classes that share a member so that overlapping assertions converge on a single class regardless of arrival order; each alias_retracted removes its asserted set’s ids from their class. The canonical representative of each materialized class is then derived as min(members) — so it re-derives automatically when membership changes and never depends on which id any event named as its anchor. A class that drops to a single member is no longer an alias set (that lone id resolves only to itself, RFC0001.16). The folded result is persisted as a per-tenant artifact (one map per tenant, not per partition) that the querier reads at compile time — note: that persisted artifact is the deferred cache of the 2026-06-12 amendment below; in v1 the querier folds the map directly from the audit stream and no artifact exists yet. Three venues were considered:

  • Per-tenant projection from the audit/alias event log (chosen). Aliases are a tenant-scoped projection rebuilt from the durable event log and persisted as a small per-tenant alias-map artifact under the tenant root. This reuses the §6.4 audit infrastructure end-to-end (no new write plane), matches the tenant scope of the data (§3.7), and keeps the truth (the event log) append-only and replayable while the map is a cache that can always be rebuilt by re-folding the log.
  • Tenant-root aliases.parquet / JSON written directly (rejected as the source of truth). A directly-mutated file has no audit trail of its own; it would either duplicate the event log or become an unaudited mutation point, violating §3.1’s “every merge is audited.” It survives only as the serialization format of the projection above — a storage-layer detail (RFC 0005), not the model.
  • Extending the partition Manifest (rejected). The manifest is partition-scoped (Manifest { generation, files }, one per partition); alias sets are tenant-global. Putting a tenant-global structure in a partition-local manifest would fragment one logical map across every partition and force N-partition fan-in on every query. Poor fit.

Eventual consistency / read staleness. The querier and the ingester/control-plane run in separate processes (§6.6 names the same seam for the live template registry). The alias map the querier reads is therefore eventually consistent with the latest assertion: an alias asserted or retracted at t becomes visible to queries once the projection is rebuilt and republished, not instantaneously. This is the same staleness window the §6.6 querier↔registry seam already accepts. Staleness is bounded in both directions by the projection refresh / snapshot cadence:

  • A not-yet-visible assertion makes resolves_to(X) return a subset of the eventual membership — it never returns rows from a set the operator did not yet assert, so it can only temporarily under-include.
  • A not-yet-visible retraction leaves a stale projection still expanding to the old, larger set, so resolves_to(X) can temporarily over-include a member the operator already removed.

Both are transient and self-correcting on the next projection rebuild, and neither cross-contaminates across tenants (§3.7) or fabricates a grouping no operator ever asserted — the over-inclusion is always a previously asserted membership, never a phantom one. The bound on the window (snapshot cadence) is a storage/serving-layer knob, deferred to the RFC 0005 storage decision (see §9).

Amendment 2026-06-12 — the storage decision is made (v1), by the RFC 0005 line. alias_asserted / alias_retracted persist as event_kind 4 / 5 on the RFC 0005 §3.7 audit stream, and in v1 the querier derives the per-tenant alias map at query-compile time by scanning the tenant’s audit stream for those kinds and folding them through this section’s projection semantics (RFC 0005 §3.7.1) — there is no persisted map artifact yet, so “the projection is rebuilt and republished” above reads, in v1, “the audit events are durably written and flushed”; the staleness bound is audit-flush visibility rather than a snapshot/rebuild cadence, with the same bounded under-/over-inclusion directions. The cached per-tenant artifact (file/format/cadence) stays deferred behind the RFC 0009 §3.4 manifest fork; because the event log remains the source of truth, adding the cache later changes no query-visible semantics — the same v1-full-replay-now / accelerate-later shape as §6.9’s snapshot.

Reader / query contract. RFC 0002’s template_id.resolves_to(X) (RFC0002.9, §5.4) loads the requesting tenant’s alias map at compile time and expands X to its alias-set membership: template_id IN {X} ∪ members(set containing X). With no assertions for the tenant, or for an X in no set, the membership is exactly {X} — identical to today’s base-member stub and to bare template_id = X for that id (RFC0001.6 still holds: bare equality never follows alias chains). Expansion is by the set, not by direction: passing any member of a set (representative or not) resolves to the whole set.

Reversibility. An operator can retract an alias; the retraction is itself an alias_retracted audit event with the same durability and isolation guarantees, and the projection drops the retracted membership on its next rebuild. Aliasing and un-aliasing are both explicit, both audited, never silent — closing the loop with §3.1.

sequenceDiagram
    participant Op as Operator / control plane
    participant WAL as WAL (§3.4 barrier)
    participant Log as Alias event log (§6.4 stream)
    participant Proj as Per-tenant alias-map projection
    participant Q as Querier (resolves_to)
    Op->>WAL: assert alias {rep, members, actor, reason}
    WAL-->>Op: ack (only after fsync — §3.4)
    WAL->>Log: append alias_asserted (durable)
    Log->>Proj: fold per tenant (rebuild + publish)
    Q->>Proj: load tenant alias map at compile
    Q->>Q: resolves_to(X) -> template_id IN members(set with X)
    Note over Op,Proj: retraction is the symmetric alias_retracted event

Future work — automatic inference. A later layer may propose aliases from a post-deploy heuristic (e.g. a burst of template_widened / fresh-leaf allocations correlated with a deploy timestamp). Such proposals are never written to the active alias index directly; they enter a review queue and become real only via the same operator-confirmed alias_asserted event specified above. This RFC does not specify that layer — see §9.

Drift detection as a first-class query. “Templates that gained a new version in the window [t1, t2]” is a query against the audit event stream:

SELECT template_id, MIN(old_version), MAX(new_version),
       COUNT(*) AS widening_count,
       MIN(timestamp), MAX(timestamp)
FROM template_audit
WHERE event_type IN ('template_widened', 'template_type_expanded')
  AND timestamp BETWEEN $t1 AND $t2
GROUP BY template_id
ORDER BY widening_count DESC

(SQL shown for spec clarity; the user-visible form is the RFC 0002 DSL, not raw SQL — see hazard H6.) Operators use this query after deploys to spot templates whose structure changed; a sudden cluster of template_widened events correlated with a deploy timestamp is exactly the H5 detection signal.

6.8 Telemetry [§3.1], §6.3

Amendment 2026-06-03. Telemetry export is realigned from a Prometheus client/scrape model to the OpenTelemetry SDK (the maintainer direction recorded against RFC 0009 §3.6 and the roadmap §5 note). This amendment fixes the export architecture and the Prometheus-era terminology (registry → meter provider, scrape → OTLP push, labels → attributes) throughout §§6.8–6.9 and the §5 scenarios.

Amendment 2026-06-08 (dotted-semconv migration — landed). The metric and attribute names are now the dotted-ourios.miner.* scheme, defined in the semconv/registry/ weaver registry alongside the compaction set (RFC 0009 §3.6) and consumed through the generated ourios-semconv constants. The table below lists the registry names. Instrument kinds are unchanged from the original set; the confidence.p50 / confidence.p01 gauges remain in-process views of the confidence histogram (RFC0001.8) — the question of whether they become collector-/backend-derived quantiles over the exported histogram is a genuine contract change to the §3.1.2 mandatory set and stays deferred to its own review, not folded into this rename.

The registry names were audited against the OpenTelemetry semantic-conventions naming rules (the canonical docs/general/{naming,metrics}.md plus the weaver registry policies): counters drop the Prometheus _total suffix and take singular {annotation} units; the two fraction-of-total gauges use the conventional .utilization segment (unit 1) rather than a bespoke .ratio; and the per-line elapsed-time histogram is ourios.miner.duration (UCUM s), the conventional segment for a discrete operation’s elapsed time, not latency.

Export architecture (OTel SDK + OTLP)

Metrics are instrumented through the OpenTelemetry meter API and exported via the OTel SDK’s OTLP metric exporter (push, over OTLP to a collector / endpoint). There is no prometheus client crate and no /metrics scrape endpoint; any Prometheus compatibility is a downstream collector concern, not Ourios’s.

The dependency split follows the standard OTel layering so the heavy SDK and transport crates do not leak into every library:

  • Instrumented crates (ourios-miner, ourios-parquet, ourios-ingester, ourios-querier) depend only on the lightweight opentelemetry API crate and resolve instruments through global::meter("ourios.<subsystem>"). No SDK, no OTLP, no transport dependency in a library crate.
  • A new ourios-telemetry crate owns the heavy deps — the opentelemetry_sdk and opentelemetry-otlp crates (the upstream package names, underscore and hyphen respectively) plus the OTLP transport. It exposes an init() that builds the OTLP push MeterProvider (periodic-reader export, interval configurable), installs it as the process-global provider, and returns a guard whose shutdown() flushes pending metrics on exit. The binary (ourios-server) calls init() once at start-up; benches and integration tests call the same entry point or substitute an in-memory reader. Adding this crate extends the CLAUDE.md §7 target layout; the new-crate commitment is blessed here, in this RFC, per §7’s rule.

Dimensions are OTel attributes, not Prometheus labels, and OTel splits them in two: resource attributes identify the telemetry producer and are set once on the MeterProvider; data-point attributes vary per measurement. Ourios’s own identity — service.name = ourios-<role> (e.g. ourios-ingester, ourios-querier, matching the role the ourios-telemetry crate initialises the provider for; with service.version, etc.) — is a resource attribute: per the semantic conventions it MUST be set once on the provider’s Resource and MUST NOT be repeated on individual data points.

The per-measurement dimensions in the table below — among them ourios.tenant, the originating service of the ingested logs, and per-metric dimensions like event_type — are data-point attributes. A single ingester multiplexes many tenants and many source services, and [§3.1] / [§3.2] require per-(tenant, service) breakdowns — notably the §6.5 / H2.2 per-service overflow alert — which a single producer-level resource attribute could not provide. The service dimension here is the log’s source service (the value §6.1’s tenant derivation reads), distinct from Ourios’s own service.name — it must not reuse that reserved resource key. It is exported under the dedicated ourios.service attribute key; the tenant dimension is ourios.tenant and the merges change-kind is ourios.miner.template_change (registry enum widened / type_expanded). All three are defined in semconv/registry/attributes.yaml and consumed through the generated ourios-semconv constants.

The mandatory set is defined by the semconv registry: the ourios.miner.* entries in semconv/registry/, surfaced as the generated ourios_semconv::OURIOS_MINER_* constants, are the source of truth for which metrics the miner must expose. Each is registered as an instrument on the ourios.miner meter when the miner is constructed.

OTel’s metric model is collect-on-read: a reader / exporter sees the data points produced during a collection cycle, and an instrument contributes a data point on its first real measurement. The miner emits no synthetic zero-traffic points — so every exported series carries the registry’s required attributes, with no sentinel attribute value to collide with a real tenant / service or violate the template_change enum. §3.1.2 is verified by exercising every instrument with a small representative workload and collecting the metric stream (an SDK in-memory reader in tests): the registry pins the mandatory set; the collection proves each instrument is registered and emits real data under the required attributes.

The metrics enumerated in [§3.1] are mandatory. Full set (the dotted-ourios.miner.* registry names; the dimensions shown are exported as attributes, not labels — tenant is ourios.tenant, service is ourios.service):

MetricInstrument kindAttributesSource invariant / hazard
ourios.miner.template.countgaugetenant[§3.1]
ourios.miner.mergescountertenant, template_change[§3.1], H1
ourios.miner.alias.assertionscountertenant[§3.1], §6.7, H5
ourios.miner.alias.retractionscountertenant[§3.1], §6.7, H5
ourios.miner.confidencehistogramtenant, service[§3.1], §6.3
ourios.miner.confidence.p50gaugetenant, service[§3.1]
ourios.miner.confidence.p01gaugetenant, service[§3.1]
ourios.miner.body_retention.utilizationgaugetenant[§3.1], [§3.3]
ourios.miner.parse_failurescountertenant, service[§3.1]
ourios.miner.params.overflowcountertenant, service[§3.2], H2
ourios.miner.params.overflow.utilizationgaugetenant, service[§3.2], H2
ourios.miner.template.version_changescountertenant[§3.5], H5
ourios.miner.durationhistogramtenanthot-path budget (D1)

ourios.miner.confidence.p50 and ourios.miner.confidence.p01. The ourios.miner.confidence histogram is the source of truth; the two gauges are convenient named views derived from it in-process. The miner recomputes them on a short ticker (default 10 s, configurable; the cost is one quantile evaluation over the histogram per tenant per service per tick — negligible relative to the hot path) and caches the value between ticks so a metric export cycle never blocks on recomputation. The gauges exist so alerting rules and runbooks can name them directly per [§3.1] rather than spelling out a histogram_quantile(...) expression at every reference.

The histogram bucket boundaries are tuned to straddle the decision boundary at 1.0 (see §6.3): default buckets [0.1, 0.3, 0.5, 0.7, 0.9, 0.95, 1.0, 1.05, 1.2, 1.5, 2.0, +Inf].

6.9 Persistence and recovery

Amendment 2026-06-10 (snapshot store / cadence / scope resolved). The three §9 open questions deferred from this section — target store, cadence, and scope — are now pinned. The snapshot is a rebuildable recovery-acceleration cache, not durable state (the WAL is the truth per [§3.4]), which is what licenses the choices: local disk, WAL-adjacent (object storage deferred, see §9); per WAL-segment-rotation cadence, recording the WAL high-water mark; per-tenant scope. The format is a leading u8 version byte then a payload; recovery dispatches on byte 0. In v1, recovery replays the full WAL in both the known- and unknown-version branches, because the resume-from- high-water-mark optimisation needs the RFC 0008 §6.7 checkpoint / replay-from-offset API, which is not yet implemented; the format records the high-water mark so the optimisation can be switched on later without a format change. This makes the §3.5.1 / §3.5.2 acceptance criteria buildable. The matching §9 entries are marked RESOLVED.

Amendment 2026-06-12 (v2 — restore switched on). The RFC 0008 §6.7 checkpoint / offset-carrying-sink API this section was gated on is now specified to land (RFC 0008’s same-day §6.1/§6.7 amendment is the other half of this design), so the known-version branch of the recovery algorithm below restores the tree and replays only the WAL tail above the snapshot’s recorded high-water mark S — exactly as written in step (2), with no format change (the mark has been in the payload since v1). Three rules complete the design. Per-consumer horizons: RFC 0008’s replay delivers every surviving frame with its offset; the recovery driver suppresses per consumer — the Parquet path consumes only frames above the RFC 0008 checkpoint X (below it they are already published), the miner only frames above S (below it they are already folded into the snapshot; re-feeding would double-apply — the v1 hazard, now resolved by routing rather than by refusing to restore). The rule covers both orderings: in the steady state S ≥ X the miner consumes a suffix of what Parquet consumes; with a lagging snapshot (S < X) the miner additionally consumes the (S, X] frames the floor retained, closing its state gap while Parquet suppresses them. Truncation floor: the ingester passes the latest durable snapshot’s S to Wal::housekeeping as a retain floor, so the WAL never unlinks a frame no snapshot has captured (RFC 0008 §6.7 — closes the S < X template-drift hole, hazard #5). Stale-snapshot fallback: if recovery nevertheless finds the WAL truncated past S (external mutation — segment files manually unlinked from wal_root; the floor prevents the gap arising internally), it restores the snapshot, replays the surviving frames above S, and emits a structured warning naming the gap. The data side is complete provided the truncation did not exceed X — legitimate housekeeping never unlinks a frame above the checkpoint, so everything missing is in Parquet; manual deletion beyond X would be unrecoverable acknowledged-data loss, which is exactly why segment removal is reserved to housekeeping and never an operator action. Templates first seen inside the (S, X] gap may re-mint (drift surfaced via RFC 0010, not silent). New acceptance criteria: §3.5.3 (restore-equivalence), §3.5.4 (stale-snapshot fallback); the end-to-end driver contract is RFC 0008’s RFC0008.10.

Hot path. The per-tenant tree lives in process memory on the ingester. Tree operations (descend, simSeq, attach, widen) are hot-path; persistence does not happen synchronously per line.

Durability via WAL replay. [§3.4] (WAL-before-ack) means every line that reached the miner is in the WAL before the ingester acknowledged it. The tree state is therefore derivable from the WAL: a cold start with no snapshot replays the WAL in order through the miner and reconstructs the trees. This is correct but slow at scale; the snapshot mechanism is an optimisation on top.

Replay mode. Cold-start replay re-walks attach, widen, and expand_slot_types against the same code path live ingest uses. Doing so naively would re-fire every counter increment, every histogram observation, and every gauge update for the entire replay window, polluting steady-state metrics for the post-restart horizon (a 10-minute replay on a high-volume tenant could shift ourios.miner.merges by orders of magnitude in a few seconds). The miner therefore runs in replay mode until the WAL cursor reaches the live tip: domain events are processed and tree state is mutated exactly as in live ingest, but updates to the §6.8 metrics are suppressed (counters do not increment, histograms do not observe, gauges retain their previous value or, if the miner has never served live traffic, their zero / empty initialisation value). Suppressing the update path means the replay window contributes no data points — each instrument still surfaces on its first live measurement once replay completes (§3.1.2’s registry-defined set is satisfied by instrument registration plus real post-replay traffic, not by replay-window points). A single wal_replay_progress gauge (attribute ourios.tenant, value: fraction of the tenant’s replay window completed in [0.0, 1.0]) is exposed during replay so operators can see the cold-start curve and confirm replay finished. This metric is replay-only and is not part of the §3.1 mandatory set; it is documented here, not in §6.8’s table.

Snapshot mechanism. A snapshot is a rebuildable recovery-acceleration cache, not durable state. The WAL is the durable truth ([§3.4]); the snapshot exists only to shorten cold-start replay. A lost, absent, or corrupt snapshot is never a data-loss event — it degrades to a full WAL replay (the same path a miner that never wrote a snapshot takes). This framing is what licenses the store and recovery choices below: because the snapshot is cache, it may live on local disk, and a reader that cannot trust it may discard it without ceremony.

Target store: local disk (WAL-adjacent); object storage deferred. Snapshots are written to a local artefact next to the WAL (e.g. under the WAL root), not to object storage. [§3.6] makes local disk legitimate here precisely because the snapshot is cache, not truth — the constraint [§3.6] imposes is that no feature rely on local disk being durable beyond the WAL horizon, and snapshot recovery never does: anything the snapshot would have accelerated is still in the WAL. Object-storage snapshots are explicit future work (see §9); they would couple to the RFC 0009 §3.4 atomic-publish manifest to define a durable, multi-writer publish point, and are deferred for that reason.

Scope: per-tenant. One snapshot artefact per tenant tree, matching [§3.7]’s per-tenant trees. Recovery loads the latest snapshot per tenant independently; there is no cluster-wide combined artefact.

Cadence: per WAL-segment rotation. A snapshot is taken at WAL-segment-rotation boundaries. The snapshot records the WAL high-water mark — the WalOffset (RFC 0008 §6.1) up to which its tree state reflects appended frames — so that a future optimisation can resume replay from there rather than from the start of the log.

Format: a leading u8 version byte, then the payload. Byte 0 is the snapshot format version; the remaining bytes are that version’s serialised payload. The payload captures the per-tenant state needed to reconstruct the miner: the tree leaves (template token sequence, template_id, template_version, the (severity_number, scope_name) template key of §6.1, and the per-slot slot_types of §6.1), the structured-template-id map allocated in §6.2’s structured short-circuit, and the WAL high-water mark above. The concrete payload codec is an implementation detail behind the version byte — the version byte is what makes format evolution safe, so this RFC pins the framing, the captured state, and the rule that the reader dispatches on byte 0, and deliberately does not pin a specific serialisation codec.

Recovery algorithm. On ingester restart, per tenant:

  1. Load the latest snapshot artefact for the tenant, if one exists.
  2. If byte 0 is a known version: deserialise the payload, restore the tree, then replay only the WAL tail above the snapshot’s recorded high-water mark S — the driver delivers each replayed frame to the miner only when its offset is > S (per-consumer routing, RFC 0008 §6.6; active as of the 2026-06-12 v2 amendment above). If the surviving WAL no longer reaches back to S, apply the stale-snapshot fallback of the v2 amendment: restore, replay what survives, warn.
  3. If byte 0 is an unknown version, or the snapshot is absent or corrupt: discard it and replay the full WAL via Wal::replay (RFC 0008 §6.1 API, RFC 0008 §6.6 recovery procedure), rebuilding the tree from scratch.

v1 scope — rebuild from a full replay; do not restore yet. (Superseded by the 2026-06-12 v2 amendment above — restore is now switched on; this paragraph is retained as the record of why v1 refused to restore.) The restore-then-replay-the-tail path in step (2) requires the RFC 0008 §6.7 checkpoint / replay-from-offset API (Wal::checkpoint and the CHECKPOINT sidecar), which was not yet implemented at the time. Restoring a tree from a snapshot and then replaying the full WAL (the only replay available without offset support) would double-apply every frame the snapshot already captured, corrupting the tree. So until offset-resume landed, recovery ignored the snapshot payload and rebuilt the tree from a full Wal::replay in both branches — the known-version branch did not restore. What landed in v1 was the snapshot format (the leading version byte and the recorded high-water mark) and the version-dispatch + WAL-fallback contract; v2 switches the restore path on with no format change, exactly as planned. v1 fully satisfied §3.5.1 (the artefact carries a leading version byte) and §3.5.2 (an unknown version is rejected and falls back to full WAL replay).

Snapshot-load telemetry. The wal_replay_progress gauge (above) remains the replay-only signal. A snapshot-load-outcome signal — distinguishing “snapshot restored,” “unknown version → full replay,” and “absent/corrupt → full replay” — is named here in prose; its concrete metric and attribute names go through the semconv weaver registry when the slice is implemented (§3.1.2), and are not invented as flat names in this RFC.

Migration. When the in-memory data model in §6.1 changes (new field, retired field, semantic change), the snapshot format’s version byte increments. Old snapshots are read-compatible only if the change is additive (new optional fields tolerated). For breaking changes, snapshots from the prior version are discarded and the tree is rebuilt from WAL replay. [§3.5]’s schema-change discipline applies: the change goes through an RFC.

7. Alternatives considered

Alternatives to Drain itself, evaluated as primary algorithms. Each is rejected for the reason given; some have a possible secondary role noted.

Spell (LCS-based online parser)

Spell uses longest-common-subsequence to compare a new line against existing templates. Per-line cost is O(template_count × line_length) without depth bounding, which is several orders of magnitude slower than Drain’s O(d) tree walk at the template counts we expect (10²–10⁴ per tenant). LCS also makes parameter positions ambiguous on lines where the same token recurs, because the LCS alignment can shift; Drain’s positional matching gives unambiguous parameter slots. Rejected as the primary algorithm.

IPLoM (iterative partitioning)

IPLoM does three passes over the entire log, each splitting clusters by a different criterion (token count, position, token uniqueness). This requires the full log up front and is offline by design. Rejected as the primary algorithm. Possible secondary role: a periodic offline reconciliation pass could use IPLoM to detect template fragmentation that Drain’s online structure missed (e.g. two leaves that should have been one because their discriminating token was spurious). This is a follow-up RFC topic, not a §6 commitment.

LenMa (length-based clustering)

LenMa groups lines by token-count length, then finds templates within each length group via a similarity-based second pass. The length-only initial grouping is close to Drain’s first level, but the absence of the token-prefix tree leads to more spurious merges within a length group (any two same-length lines are candidates, not just same-length-and-same-prefix lines). Drain’s tree is a strict refinement of LenMa’s grouping. Rejected as the primary algorithm — Drain dominates on the same workload.

LogPPT / LILAC / LLM-based parsers

Transformer-based parsers achieve higher accuracy on benchmark corpora (LogPAI scores) but require model inference per line. At the D1 hot-path budget (≥ 100k lines/s/core), per-line transformer inference is infeasible without specialised hardware that contradicts §1’s “single Rust binary” framing. Rejected as the primary algorithm. Possible secondary role: offline labeling-aid on the testdata/corpus/ to bootstrap a labeled set for confidence calibration; or as a periodic reconciliation pass similar to IPLoM. Both are deferred to follow-up RFCs.

Offline clustering (e.g. nightly hierarchical agglomerative)

Quality is high; latency is unacceptable. Logs ingested at 14:00 would not be queryable until the next clustering window completes. This contradicts §2’s online motivation. Rejected as the primary algorithm. Possible secondary role: the same reconciliation pass mentioned under IPLoM and LLM-based could use offline clustering to validate Drain’s online output and surface drift; a follow-up RFC if and when reconciliation becomes a real concern.

8. Testing strategy

Mapping to [§6.2]. Each technique below names the §5 scenarios it operationalises; the test code carries the matching id in a doc comment per docs/verification.md §2.3 so grep -R "H1.1" . resolves bidirectionally between RFC and tests.

  • Unit tests for tree operations: tokenize, mask, descend, simSeq, widen, attach, build_params. Each operation tested in isolation against fabricated inputs. Covers: RFC0001.3 (tokenizer whitespace-only), RFC0001.4 (confidence ratio + decision boundary), RFC0001.7 (combined widening + type-expansion in one attach).

  • proptest for §6.6 reconstruction: for every generated line shape (length, separator distribution, masking outcome), reconstruct(mine(line)) == line or mine(line).lossy_flag == true. Property failure blocks merge. Covers: H7.1, H7.4, §3.3.1.

  • Corpus tests on testdata/corpus/ (fixed, anonymised; see docs/benchmarks.md §1): assert bounds on ourios.miner.template.count, ourios.miner.merges, reconstruction accuracy, parameter overflow rate. Regressions are build failures, not warnings. Covers: H1.1 (login/logout corpus arm), H7.1 (corpus arm).

  • Confidence calibration test: on a labelled subset of the corpus, verify the three-zone classification in §6.3 against the human labels. Covers: H1.2.

  • Merge-audit assertion (negative + positive): no widening or type-expansion completes without a matching audit event, and fresh-leaf creation does not emit one. Runs on every corpus pass and on the synthetic widening fixtures. Covers: H1.3, H5.1, H5.2, RFC0001.1 (negative — no event on creation), RFC0001.2 (rejection event for degenerate widening), RFC0001.7 (event ordering arm).

  • Multi-tenant isolation (negative test): interleave lines from two synthetic tenants through a single MinerCluster; assert that templates mined under tenant A never appear in tenant B’s tree and vice versa. Implements docs/benchmarks.md E2. Covers: §3.7.1, §3.7.2.

  • Per-ResourceLogs tenant derivation (miner-side stub): assert that when records carrying distinct derived tenant_ids arrive in the same ingest sequence, each lands in its derived tenant’s tree. The receiver-side test — that the wire-decode layer actually derives tenant_id per ResourceLogs.resource rather than per ExportLogsServiceRequest — is owned by RFC 0003 (see RFC 0003 §6.3); RFC 0001 owns only the miner-side contract. Covers: §3.7.3.

  • OTLP-aligned template-key tests: hand-curated OtlpLogRecord fixtures exercising the §6.1 Template-key composition tuple. Assert that varying only severity_number produces distinct template_ids, varying only scope_name produces distinct template_ids, the severity_number = 0 (UNSPECIFIED) and scope_name = None edge buckets are each their own key value, and body.kind != AnyValue::String short-circuits per §6.2 step 0 with the §6.1 sentinel confidence = 1.0, lossy_flag = false. The time_unix_nano round-trip is a small unit test against the §6.1 record schema. Covers: H1.4, H1.5, RFC0001.9, RFC0001.10, RFC0001.11.

  • Drift detection test: ingest a corpus where a template deliberately drifts mid-stream; assert that the drift query in §6.7 returns the drifted template within the expected window. Covers: H5.3.

  • Crash recovery test (snapshot + WAL replay): SIGKILL the ingester between snapshot writes; assert that recovery reconstructs the same tree state that was acknowledged before the kill. Also corrupt the snapshot’s leading version byte and assert WAL fallback. This is [§3.4]’s crash-recovery test extended to cover the miner’s persistence layer. Covers: §3.5.1, §3.5.2.

  • Restore-equivalence test: snapshot a tree at high-water mark S, append further frames, recover via restore-plus-tail-replay, and assert tree-state equality against a from-scratch control (the recovered state is compared field-by-field via the §6.9 snapshot payload of both trees, so the comparison itself can’t hide drift). A counter on the test sink asserts no frame ≤ S reached the miner. The stale-snapshot arm deletes the segments holding (S, tail]’s prefix, recovers, and asserts the structured warning names the gap while the surviving frames still fold. Covers: §3.5.3, §3.5.4 (the end-to-end driver half is RFC 0008’s RFC0008.10).

  • Configuration tests: assert default values and the rejection of out-of-bounds settings at startup. Covers: §3.1.1 (default threshold = 0.7), §3.2.1 (default param byte limit = 256), §3.2.2 (limit > 1 KiB rejected).

  • Metric collection test: assert the mandatory set equals the generated ourios_semconv::OURIOS_MINER_* constants (the registry is the source of truth), then construct a miner, ingest a small representative workload that exercises every instrument, collect its meter (global::meter("ourios.miner")) via an SDK in-memory reader, and assert the collected stream contains every §6.8 metric name (each appearing on its first real measurement, with the required attributes), with the instrument kinds and attributes in §6.8’s table, and that the ourios.miner.confidence.p50 / ourios.miner.confidence.p01 gauges track the same-attributed ourios.miner.confidence histogram quantiles. Covers: §3.1.2, RFC0001.8.

  • Data-model contract tests: small unit tests against the template_id query semantics that RFC 0002’s DSL compiles to. These cover the cross-version vs. cross-alias distinction at the data-model layer; the DSL surface itself is tested in RFC 0002. Covers: RFC0001.5, RFC0001.6.

  • Alias write-path tests: assert that an operator alias assertion emits a durable alias_asserted audit event under the §3.4 barrier and that folding the event log produces the expected per-tenant alias map; that resolves_to expands by the set (representative or member) and to {X} for an un-aliased id; that a retraction emits alias_retracted and drops membership on rebuild; and that an alias asserted in one tenant is invisible to another. The resolves_to DSL surface itself is exercised in RFC 0002 (RFC0002.9); these tests own the §6.7 write-path and per-tenant-map contract. Covers: RFC0001.12, RFC0001.13, RFC0001.14, RFC0001.15, RFC0001.16.

  • Reader behaviour test: assert the §6.6 Reader render contract — for a lossy_flag = true row the reader returns the body bytes verbatim (no in-band prefix/marker) carrying Reconstruction::RetainedVerbatim, and does not call reconstruct(); for a faithful row it calls reconstruct() and carries Reconstruction::Faithful. The reader never silently substitutes one rendering for the other, and never mutates the body bytes to carry the marker. (The clean-path read-time template-registry lookup is out of scope of this scenario per §6.6.) Covers: H7.3.

  • Overflow-path tests: synthesize a parameter exceeding the configured byte limit; assert the OVERFLOW marker, forced body retention, and metric increments. Wire the alert-rule fixture for the >1% rate trigger. Covers: H2.1, H2.2.

  • Tokenizer-failure tests: feed lines with embedded NULs, malformed UTF-8, and over-cap lengths; assert the parse-failure path retains the body and sets lossy_flag = true. Covers: H7.2.

  • Benchmark (criterion): per-line miner latency (target: median ≤ 10 µs/line on the §1 hardware baseline), ingest throughput (target: ≥ 100k lines/s/core, per docs/benchmarks.md D1). No §5 scenario; satisfies thesis-gate D1 directly at the Validated stage.

9. Open questions

Decisions explicitly deferred. Each must be resolved before this RFC’s status flips to accepted.

Persistence (from §6.9) — RESOLVED (2026-06-10). The three sub-questions are pinned in §6.9; the resolutions are recorded here and the remaining future work is the two items below them.

  • Snapshot target storeRESOLVED: local disk (WAL-adjacent); object storage deferred. The snapshot is a rebuildable recovery-acceleration cache, not durable state (the WAL is the truth per [§3.4]), so it lives next to the WAL on local disk. [§3.6] permits this because recovery never relies on the snapshot surviving — a lost snapshot degrades to a full WAL replay. See §6.9.
  • Snapshot cadenceRESOLVED: per WAL-segment rotation. A snapshot is taken at segment-rotation boundaries and records the WAL high-water mark (the WalOffset it was taken at). See §6.9.
  • Snapshot scopeRESOLVED: per-tenant. One snapshot artefact per tenant tree, matching [§3.7]; recovery loads the latest snapshot per tenant. See §6.9.
  • Object-storage snapshots (remaining future work). Pushing snapshots to object storage would couple to the RFC 0009 §3.4 atomic-publish manifest for a durable, multi-writer publish point; deferred until that line settles.
  • Resume-from-high-water-mark replayRESOLVED (2026-06-12): switched on as §6.9 v2. The RFC 0008 §6.7 checkpoint / offset-carrying-sink API is specified (RFC 0008’s same-day amendment); the known-version branch restores and replays only the tail above the snapshot’s high-water mark, with per-consumer routing, a housekeeping retain floor, and a stale-snapshot fallback. No format change was needed — exactly as this entry predicted. Acceptance: §3.5.3 / §3.5.4 + RFC0008.10. See the §6.9 v2 amendment.

Algorithm tuning (open until corpus exists).

  • Floor default 0.4 — confirm against the corpus. If the lossy zone is too wide (many lines retained that “should have” been parse failures), tighten; if too narrow (too many parse failures on lines a human would accept), loosen. This is per-tenant tunable; the question is the out-of-the-box default.
  • Tree depth d. Paper default 4; Drain3 default 4. Open question: do any of our representative corpora benefit from d = 3 or d = 5?
  • Max children per node. Drain3 caps at 100; the cap acts as a safety against unbounded fan-out from a bad masking rule. Confirm 100 is right for our corpora, or motivate a different number.

Edge cases.

  • Lines that contain a literal <*> (the wildcard sentinel we use in template strings) — escape on tokenize, or replace with a non-collision character (e.g. U+E000)?
  • Multi-line log entries (stack traces). Paper assumes single-line. Ourios position: deferred to RFC TBD on the OTLP receiver, since multi-line reassembly happens before the miner sees the line.

Multi-tenancy and operational lifecycle.

  • Tenant lifecycle. §3.7 commits to per-tenant trees but does not name when a tree is allocated (lazily on first ingest? eagerly via a control-plane command?), nor whether tenants can be paused, evicted under memory pressure, or deleted. Likely deferred to a future operator-console RFC, but the bookend events (TenantInitialised, TenantPaused, TenantDeleted) need to exist somewhere before §3.7 is operationally complete.
  • Per-tenant fairness and back-pressure. A noisy tenant can monopolise WAL bandwidth, blow up the tree, and starve well-behaved tenants. RFC 0001 has no rate-limit or back-pressure event in scope; this overlaps with the OTLP receiver’s responsibility and likely lives in a future ourios-ingester RFC.
  • Alias index creation mechanism (from §6.7) — RESOLVED (2026-06-07). Of the three candidates (operator-driven, automatic-inference, deferred entirely), the maintainer chose operator-driven + audited: an alias is an explicit, audited, reversible operator assertion on the §6.4 stream, never silently inferred (§3.1). The write path, the alias_asserted / alias_retracted events, the per-tenant alias-map projection the querier reads, and the eventual-consistency semantics are specified in §6.7 (“Alias write path”); the acceptance criteria are RFC0001.12– RFC0001.16 in §5.3. RFC 0002’s template_id.resolves_to(X) now has a defined backing index. Remaining future work: automatic inference is deferred to a possible propose → operator-confirm layer (proposals never enter the active index unconfirmed); see the §6.7 “Future work” note. The physical alias-map file/format and snapshot cadence are a storage decision owned by the RFC 0005 line, not RFC 0001 — RFC 0001 owns the model, the write path, and the criteria (sibling to the issue #147 split). Update 2026-06-12: the RFC 0005 line has made the v1 half of that decision — alias events persist as kinds 4–5 on the RFC 0005 §3.7 audit stream, and the querier derives the map by folding that stream at compile time (RFC 0005 §3.7.1; §6.7 amendment of the same date). The cached per-tenant artifact remains deferred behind the RFC 0009 §3.4 manifest fork.

Cross-RFC contracts pending.

  • Querier ↔ live template registry (from §6.6). Reconstruction’s lookup(template_id, template_version) is called by ourios-querier, which runs in a separate process from the ingester that owns the live tree. Candidates: querier reads snapshots from object storage (eventually consistent with live), querier asks the ingester via RPC at query time (couples query latency to ingester health), or templates ride a separate Parquet side-stream alongside records (eventually consistent, no RPC, new data plane). RFC 0002 needs the answer before its DSL can compile; this RFC names the seam.
  • Audit-event Parquet schema (from §6.4). The Rust audit struct is specified in §6.4; the on-disk Parquet column layout for template_audit belongs to a future ourios-parquet RFC. The §6.7 drift query assumes the schema exposes event_type, template_id, old_version, new_version, and timestamp as columns suitable for predicate pushdown.

Deferred to follow-up RFCs.

  • Reconciliation pass (IPLoM / offline clustering / LLM-based labeling) — if real-world drift turns out to be more than §6.4’s online widening can handle, a periodic offline pass becomes interesting. RFC at that point.
  • Cross-tenant template_fingerprint side column — only if a concrete consumer materialises (storage dedup across tenants, shared dashboards). Until then, do not add.

10. References

  • He, P., Zhu, J., Zheng, Z., Lyu, M.R. “Drain: An Online Log Parsing Approach with Fixed Depth Tree.” ICWS 2017.
  • Drain3: https://github.com/logpai/Drain3 (specific commit pinned in this RFC at the Specified-gate PR).
  • LogPAI logparser benchmark: https://github.com/logpai/logparser
  • CLAUDE.md §§ 2, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 4, 6.2, 6.3, 6.6.
  • docs/hazards.md H1, H2, H5, H7.
  • docs/benchmarks.md C1, C2, C3, C4, D1, E1, E2.
  • docs/rfcs/0002-query-dsl.md §5.4 (template primitives in the DSL surface; required to expose drift detection).
  • docs/verification.md §§ 2, 3, 6 (the maturity model and the acceptance-criteria contract this RFC will inherit at the Specified gate).
  • Future: docs/architecture/miner.md (this RFC graduates there on acceptance).

RFC 0002 — Query DSL


rfc: 0002 title: Query DSL — the Ourios logs query language (Branch B, surface β) status: green author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-04-24 supersedes: — superseded-by: —

RFC 0002 — Query DSL

Status note. The prior decision (§3) is resolved: the predicate sublanguage takes Branch B (distance from OTTL), on the β (pipe-composable) top-level surface. Decided 2026-06-07 from the audience analysis in §3.6 (primary: Perses dashboard authors; future: MCP agents). This RFC is now green — all 11 §5 acceptance criteria (RFC0002.1–.11) have passing tests (crates/ourios-querier/tests/rfc0002_dsl.rs), landed across PRs #143 (this spec) and #144–#154 (the red gate + implementation): the Branch-B parser + structured surface → one IR, the IR→DataFusion compile, YAML-embeddability + the structured JSON Schema, and resolves_to alias-set expansion via the RFC 0001 §6.7 operator alias map. §6 gives the design, §7 the grammar, §5 the criteria. Per the docs/rfcs/README.md ladder, validated and finally accepted (a maintainer flip) follow the §9 validation. Hazard 6 (CLAUDE.md §4 — no DataFusion/SQL leakage) constrains the whole design.

1. Summary

Ourios exposes a logs query DSL that does not leak DataFusion/SQL to users (CLAUDE.md §4 hazard 6). This RFC specifies it:

  • Predicate sublanguage — Branch B (distance from OTTL). An Ourios-native, query-ergonomic syntax over the OTel data model (the ingest contract): bare top-level fields (body, severity, trace_id), resource. / attr. prefixes, bare-identifier severity (severity >= error), first-class template + OTel-canonical primitives.
  • Top-level surface — β (pipe-composable). A predicate followed by pipe stages: … | range(-1h, now) | count by template_id | sort count desc | limit 10. Compact, single-line, and embeddable as a YAML scalar in Perses dashboards.
  • Two front-ends, one core. The string DSL (for humans, esp. Perses YAML) and a structured JSON surface (for MCP agents + programmatic clients) parse to the same query IR and compile to the same DataFusion LogicalPlan. Agents emit JSON, not syntax.

The design rests on ourios-querier (RFC 0007), whose execution layer (predicate pushdown, tenant isolation, QueryStats) is already implemented and tested (RFC 0007 §5 criteria all live; the RFC itself stays specified pending this DSL); this RFC adds the user-facing language in front of it.

2. Motivation

2.1 Why a DSL at all?

CLAUDE.md §4 hazard 6 commits Ourios to a DSL that does not leak DataFusion SQL. The reasons are stability (evolve the backend without breaking user queries), safety (full SQL exposes cross-tenant joins, unbounded scans, recursive CTEs we cannot audit), and fit (logs are a narrow domain; a narrow DSL is more ergonomic than a general one). This is branch-agnostic.

2.2 Why the prior decision mattered

“OTTL-inspired” was not a free decision. Borrowing OTTL syntax in a query context promises OTTL-literate users that their mental model transfers; if the syntax looks the same but behaves differently (OTTL mutates; a query filters), the surface actively misleads. §3 records how that decision was made.

3. The prior decision (resolved): distance from OTTL

Both positions were defensible; §3.1–3.4 keep the honest case for each for the record. §3.5 records the resolution; §3.6 the reasoning.

3.1 The case for borrowing (Branch A) — not chosen

  • Positive transfer for Collector-literate SREs. Engineers who write Collector/OTTL pipelines reuse that mental model at zero onboarding.
  • Reduces bikeshed surface. A pinned external spec inherits decisions rather than re-litigating them.
  • Ecosystem alignment. Diverging on surface syntax in the OTel orbit can read as gratuitous.
  • OTTL’s path grammar is correct about the data model, which any alternative must address anyway.

3.2 The case for distancing (Branch B) — chosen

  • The OTTL-literate population is a minority of OTLP users — most emit logs via an SDK and never touch OTTL.
  • Collector ergonomics become query verbosity. resource.attributes["service.name"] == "api" is loud in a query.
  • Shared syntax + different semantics misleads. Unfamiliar syntax is a safer failure mode than almost-familiar-but-wrong.
  • No evolving external spec to track (OTTL has had breaking changes).
  • Design freedom for query-context idioms (severity >= error, attr.foo).

3.3 What is shared regardless of branch

  • The OTel data model is the schema of log records (the ingest contract, not a design choice): attributes, resources, severity, body, timestamps, trace context.
  • The template + correctness primitives (template_id, confidence, lossy; drift-alias membership via resolves_to) are first-class (§6.3).
  • The compilation target is a DataFusion LogicalPlan, no SQL leakage (§6.5).

3.4 Consequences

DimensionBranch A (borrow)Branch B (distance)
Onboarding for Collector-literate SREsNear-zeroMild (new syntax, familiar semantics)
Onboarding for SDK / dashboard usersSame (OTel data model)Same
Maintenance costTrack pinned OTTL, amend on bumpsOwn the grammar
Same-syntax/different-meaning confusionRealAvoided
Spec sizeSmallerLarger (owned)
Ecosystem signallingAligned with OTelIndependent (in the data model: still aligned)
Design freedomConstrained by OTTLFree within the OTel data model

3.5 Resolution

Branch B (distance from OTTL), surface β (pipe-composable). Decided 2026-06-07 by the maintainer, on the audience analysis in §3.6 in lieu of the formal user research originally gated here (§9 now scopes that research to the accepted gate, not specified).

3.6 Why — the two audiences

The decision turns on two audiences that re-weight §3.1–3.4:

  1. Primary — Perses dashboard authors (declarative YAML/CRDs). Queries live as string scalars in versioned YAML. Brevity and low bracket/quote density win (readable scalars, clean diffs); the audience thinks in dashboard query languages (PromQL/LogQL), not OTTL. Branch B’s flat syntax + the β pipe surface embed cleanly on one line; Branch A on surface α would be multi-line and bracket-heavy.
  2. Future — MCP agents. Borrow-but-diverge (Branch A + the §6 divergence list it required) is the worst case for LLMs: strong public-OTTL priors pull a model toward real-OTTL constructs we do not support → plausible-but-invalid queries. A small, self-owned grammar (Branch B) has no priors to fight, is cheaper to embed in an MCP tool schema, and is enforceable with grammar-constrained decoding. And — decisively — agents need not generate syntax at all: they target the structured surface (§6.4).

The one strong case for Branch A (onboarding + signalling for Collector-literate SREs) lands on the audience that is not primary here, while its costs (semantic-confusion in the overlap zone; an externally-driven breaking cadence against long-lived dashboards + cached agent schemas) land squarely on these two. Distancing on surface syntax costs little ecosystem goodwill because we stay faithful to the OTel data model (§3.3) and because bespoke query syntax is the norm (LogQL, PromQL, CloudWatch Insights all diverge from any transformation language).

The full audience analysis is the drafting-assistance recommendation that informed this decision; its three OTel-ecosystem questions (is there an OTel query language to align with? is OTTL the expected querying surface? Perses+OTel query conventions?) are folded into §9.

4. Design principles

  1. Familiarity beats cleverness. A first-time reader understands a query within 30 seconds without a reference. No heavy sigils.
  2. No DataFusion/SQL leakage (CLAUDE.md §4 hazard 6). If explaining a surface form requires naming a DataFusion type, the form is wrong.
  3. Predicate, then pipeline. A query is a predicate (the where) followed by ordered stages (range, aggregate, sort, limit, project). Each reads independently.
  4. Template + OTel-canonical fields are first-class vocabulary, not pseudo-columns: template_id, confidence, lossy (drift-alias membership via resolves_to); service, trace_id, span_id, scope (the primary correlation/query dimensions per OTel maintainer guidance, §6.2).
  5. Every query has a time range — explicit range(...) or a tenant-configurable default window. Never an unbounded scan.
  6. One core, two surfaces. The string DSL and the structured surface are equivalent front-ends over one IR (§6.4); neither can express a query the other cannot.
  7. YAML-embeddable. A query is expressible as a single-line scalar that survives a YAML round-trip — a first-class constraint for the Perses audience, not an afterthought.
  8. The grammar is owned and versioned by this RFC (§7), not “inspired by” anything. Compatibility pledges are written, not implied.

5. Acceptance criteria

Given/When/Then, ids greppable from tests: each test carries the docs/verification.md §2.2 doc-comment form — /// Scenario RFC0002.<n> — <title>. plus /// See docs/rfcs/0002-query-dsl.md §5.. These specify the parser + compiler that front-ends the (already-implemented, RFC 0007 §5) execution layer.

  • RFC0002.1 — A Branch-B predicate parses and compiles to a filter [CLAUDE.md §4 hazard 6]

    • Given a Branch-B predicate (e.g. template_id == 42 and severity >= error)
    • When it is parsed and compiled
    • Then it yields the query IR and an internal DataFusion Filter (a private compilation artifact — never surfaced through the public API, RFC0002.3). Predicates over RFC 0007 §4.3’s pushdown keys prune the scan per that section’s split — template_id skips row groups (B1), time_unix_nano prunes partitions and row groups, tenant_id prunes partition directories (not row groups); for the subset the current ourios_querier structured request can express (template + time) the DSL result is identical to it. Severity compiles via the §6.2/RFC0002.5 severity_number mapping (the column is RFC 0005’s severity_number), not the severity_text equality the current request supports, and predicates over non-indexed fields (service, attr.*) compile to a correct Filter with no row-group-pruning claim (indexed service.name pushdown would be a future RFC 0005 §3.6 amendment).
  • RFC0002.2 — String DSL and structured surface compile to the same plan [§6.4]

    • Given a query expressed both as a β string and as the structured JSON surface
    • When both are compiled
    • Then they produce the same query IR (and hence the same LogicalPlan) — the one-core/two-surfaces invariant.
  • RFC0002.3 — No DataFusion/arrow/SQL leakage [CLAUDE.md §4 hazard 6]

    • Given the public DSL API (parse, compile, error types)
    • When a query parses, compiles, or fails
    • Then no datafusion/arrow/SQL type or message appears in any public signature or error string (compile- and string-level boundary test, mirroring RFC0007.3).
  • RFC0002.4 — A query without an explicit range gets the tenant default window [§4 P5]

    • Given a query with no range(...) stage
    • When it is compiled in a tenant context with a default window W
    • Then the plan carries a time-column filter equal to W — never an unbounded scan.
  • RFC0002.5 — Bare-identifier severity maps to its SeverityNumber [§6.1]

    • Given severity >= error (and warn, info, debug, trace, fatal)
    • When compiled
    • Then each maps, case-insensitively, to the §6.1 SeverityNumber for that level (error → 17, etc.) and compiles identically to the numeric form (severity >= 17). The name→number mapping is the documented §6.1 one (Ourios’s, aligned with the OTel ranges) — not an OTel-standardised threshold.
  • RFC0002.6 — First-class OTel-canonical fields resolve correctly [§6.2]

    • Given service, trace_id, span_id, scope used as bare fields
    • When compiled
    • Then each resolves to the RFC 0001 §6.1 column / resource-attribute it names (serviceresource["service.name"]), with no string-flattening required of the user.
  • RFC0002.7 — Parse/serialise round-trip is idempotent

    • Given any well-formed query (property-generated)
    • When parsed → serialised → parsed
    • Then the second parse equals the first (AST idempotence).
  • RFC0002.8 — A malformed query yields a specific, leak-free error

    • Given a syntactically or semantically invalid query
    • When parsed/compiled
    • Then it returns a specific error citing the offending token/clause and the §7 grammar — never a panic, never a DataFusion message.
  • RFC0002.9 — Template primitives compile [§6.3]

    • Given template_id == 42, resolves_to(42), lossy == true, confidence < 0.7
    • When compiled
    • Then each compiles to the documented plan (resolves_to expands to the alias-set membership of RFC 0001 §6.7), without leaking the underlying representation.
  • RFC0002.10 — A query is a YAML-safe single-line scalar [§4 P7]

    • Given the canonical serialisation of any well-formed query
    • When embedded as a YAML scalar and round-tripped through a YAML parser
    • Then the recovered string parses to the same query (the Perses- embedding guarantee).
  • RFC0002.11 — The structured surface validates against its published schema [§6.4]

    • Given the structured (MCP) query surface
    • When a request is validated against the published JSON schema
    • Then well-formed requests pass and compile; malformed ones are rejected by the schema before reaching the planner.

6. Design

6.1 Predicate sublanguage (Branch B)

A predicate is a boolean expression over paths, operators, and literals against the OTel log data model. The bare literal true is the match-all predicate (for queries that filter only by range/other stages); false matches nothing.

Paths.

  • Top-level fields are bare identifiers mapping to the OTel log data-model fields: body (Body — an OTel AnyValue: string, bool, int, double, bytes, array, or kvlist/map), severity (SeverityNumber), ts (Timestamp), observed_ts (ObservedTimestamp), trace_id (TraceId), span_id (SpanId), scope (InstrumentationScope name), flags (TraceFlags). (Backend treatment of structured body vs attr.* is not uniform across the ecosystem; the DSL keeps the split explicit rather than flattening.)
  • Resource attributes: resource.<key> where <key> is the OTel attribute key taken literally including dots (resource.service.name → resource attribute "service.name"). Bracketed form resource["..."] for any key not expressible as dotted bare identifiers — characters outside the bare-identifier set, a segment starting with a digit, or a reserved-word collision (resource["k8s.pod.name"], resource["3rd.party"]).
  • Log-record attributes: attr.<key> (attr.http.status_code → attribute "http.status_code"); bracketed attr["..."] for the same non-bare-identifier cases.
  • Severity: severity compares against a bare severity name (severity >= error), case-insensitive, or a numeric form (severity >= 17). All severity comparisons — including ordering (</<=/>/>=) — are defined on the OTel SeverityNumber, never on the free-form severity_text (per the OTel comparing severity guidance). Bare names map to the floor of the matching OTel SeverityNumber range: trace→1, debug→5, info→9, warn→13, error→17, fatal→21. The spec standardises the ranges and says to compare on SeverityNumber; this name→number mapping is Ourios’s, aligned with those ranges, not separately mandated by OTel.

Operators. Comparison: ==, !=, <, <=, >, >=, =~ (regex match), !~ (regex non-match). Boolean: and, or, not, with terse aliases &&, ||, !; grouping with ().

Literals. Double-quoted strings ("api"), numbers (500, 0.7), booleans (true/false), null, duration literals (30s, 1h, 1d, 1w), and RFC 3339 timestamps.

Functions (read-only, bespoke names tuned for queries) — boolean predicate terms: matches(path, regex), contains(path, s), starts_with(path, s), ends_with(path, s). They require a string operand: applying one to a non-string path (severity, a numeric/bool attribute, lossy, ts) is a compile-time type error (RFC0002.8), not a silent coercion. (Scalar-returning functions such as len(path) are deferred: the grammar admits a call only as a boolean term, so a numeric len(...) > n would need a scalar-comparison form — added under a future minor version when a need surfaces.)

Worked predicate.

service == "api" and severity >= error and attr.http.status_code == 500

6.2 First-class OTel-canonical fields

Per OpenTelemetry maintainer guidance (the primary dimensions a log backend is judged on), these get named, bare surface rather than hand-written attribute lookups, resolving the last open question of the prior draft:

SurfaceResolves to (RFC 0001 §6.1)
serviceresource["service.name"]
trace_id, span_idthe dedicated columns (log↔trace correlation)
scopescope_name
severityseverity_number (via the §6.1 mapping)
tstime_unix_nano (the verbatim event timestamp)
observed_tsobserved_time_unix_nano

Amendment 2026-06-11 — range(...) filters the effective timestamp. This table previously noted that ts / time_unix_nano is “what range(...) filters”. Per RFC 0005 §3.2 (amendment of the same date), the time window shall compile against the derived effective_time_unix_nano column — time_unix_nano when non-zero, else observed_time_unix_nano.unwrap_or(0) (RFC 0005 §3.2 is the normative derivation; a record with neither timestamp stays at 0). The implementing slice follows this amendment; until it lands, the querier filters time_unix_nano directly. The change makes records whose source timestamp is unknown (time_unix_nano = 0 — ~15 % of real OTel-Demo corpora, per the OTLP logs data model’s “Use Timestamp if it is present, otherwise use ObservedTimestamp” recommendation) addressable by time. The bare ts field is unchanged — it still resolves to time_unix_nano, the verbatim wire value (RFC 0001 scenario RFC0001.10). For files written before the column existed the window applies effective := time_unix_nano (the RFC 0005 §3.9 documented default — exactly the pre-amendment behaviour), not the absent-OPTIONAL-column ⇒ predicate-false convention. The window bounds are half-openrange(from, to) selects from <= effective < to. The half-open shape is what the querier already implements today (over time_unix_nano) and matches RFC 0010’s locally-pinned [from, to) (which noted this RFC had not pinned boundary semantics; it now does).

trace_id / span_id literals are hex strings (32 and 16 hex digits respectively, no separators), parsed case-insensitively so uppercase OTLP/JSON ids are accepted; the canonical/serialised form is lowercase. The compiler hex-decodes them to match the stored byte columns — the OTLP/JSON id convention, consistent with RFC0003.6.

6.3 Template + correctness primitives

First-class vocabulary — Ourios-specific extensions (RFC 0001 §6.3/§6.7), not OpenTelemetry log-data-model fields; they live in the Ourios schema + query layer alongside the OTel-canonical fields of §6.2:

  • template_id == 42 — exact template; resolves to the template_id column.
  • resolves_to(42)X plus its drift aliases (the RFC 0001 §6.7 drift question); compiles to alias-set membership over template_id.
  • confidence — miner confidence (e.g. < 0.7); the confidence column.
  • lossy — the lossy-reconstruction flag; resolves to the RFC 0001 / RFC 0005 lossy_flag column (lossy == true).
  • render (pipe stage, §6.5) reconstructs the original line, honouring lossy.

The drift question is answered by resolves_to (alias membership). A bare drift predicate (“has this template drifted?”) is deferred: per RFC 0001 §6.7 drift is an audit-stream property, not a column in the RFC 0005 data files, so it needs an audit-stream query path — a future capability, not a row predicate in this grammar.

6.4 Two front-ends, one core

flowchart LR
  A["string DSL (β)<br/>Perses YAML, humans"] --> P[parser]
  B["structured surface<br/>JSON, MCP agents + clients"] --> V[schema validate]
  P --> IR[query IR]
  V --> IR
  IR --> C["compiler<br/>(no SQL leakage)"]
  C --> LP["DataFusion LogicalPlan<br/>(RFC 0007 execution layer)"]
  • String DSL (surface β) is the human surface (esp. Perses YAML). A query is a predicate optionally followed by |-separated stages:

    service == "api" and severity >= error | range(-1h, now) | count by template_id | sort count desc | limit 10
    

    A predicate-only / “no filter” query uses the match-all atom true, e.g. true | range(-1h, now) | limit 100.

    Stages: range(from, to) (each bound a relative duration, the now keyword, or an RFC 3339 timestamp — the §7 time form; defaults per §4 P5), count [by <field, …>] (comma-separated, per the §7 field_list) and other aggregations (sum, min, max, avg over a path), sort <field-or-aggregate> [asc|desc] (the §7 sort_key — a field or an aggregate output like count), limit <n>, project <field, …> / render. The whole query is expressible on one line as shown (whitespace around | is optional) — the §4 P7 YAML constraint.

  • Structured surface is the machine contract (MCP tool schema + programmatic clients): a top-level object { "predicate": <node>, "stages": [ <stage>, … ] } (stages optional, default []). A field is structured (no DSL path syntax for agents to build or escape): a bare top-level name string ("service", "severity", "body", "trace_id", …) or an attribute object { "resource": "<key>" } / { "attr": "<key>" } (<key> the raw OTel attribute key, e.g. "k8s.pod.name"). An op is a §7 cmp_op string ("==", ">=", "=~", …); a value is a JSON primitive (string / number / bool / null), with durations and timestamps carried as their §7 lexical strings ("1h", RFC 3339). A <node> is a comparison node { "field": …, "op": …, "value": … }, a call node { "call": "<fn>", "args": [ … ] } whose args follow the §7 typed signatures — matches/contains/starts_with/ends_with take [ <field>, <string> ] (<field> as above), resolves_to takes [ <number> ], a constant node { "const": true | false } (the §7 bool_lit match-all / match-none — { "const": true } is the “no filter” predicate), or a boolean node ({ "and": [ <node>, … ] } / { "or": [ <node>, … ] } with a child array; { "not": <node> } unary, per §7). Each <stage> is a tagged object covering the full §7 stage set — range/count/sum/min/max/avg/sort/limit/project/render. Its JSON Schema is published and versioned with the parser (snapshot- tested like the §7 grammar; RFC0002.11), and it compiles to the same IR as the string surface (RFC0002.2). It is the formalised, extended successor to the existing ourios_querier::QueryRequest (the RFC 0007 structured API) and is the stable surface agents target — no grammar generation required.

Both parse/validate to the same query IR and compile identically (RFC0002.2). The tenant is not expressed in either surface — it is supplied by the executing context (CLAUDE.md §3.7 multi-tenancy; enforced per RFC0007.5); a query without a tenant is an API usage error, not a cross-tenant scan.

6.5 Compilation target

Every construct compiles to a DataFusion LogicalPlan:

DSL constructDataFusion logical node
implicit from logsTableScan on the tenant’s log table
predicate / rangeFilter (range → time-column predicate)
count / aggregationsAggregate
sortSort
limitLimit
projectProjection
rendercustom projection honouring the three-zone reconstruction model
resolves_to(42)custom node expanding to alias-set membership

All but render and resolves_to are DataFusion’s built-in algebra; those two are the only Ourios extensions, both surface-independent.

6.6 Stability and versioning

The grammar (§7) is owned and versioned by this RFC. Additions (new functions, new first-class fields) are minor versions. Behavioural changes that could alter a query’s result set are major versions, require an amending RFC + a deprecation window, and — because the Perses/MCP audiences persist queries (git-versioned dashboards, cached agent schemas) — ship with a documented migration. There is no external spec to shadow, so major versions are deliberate, not inherited.

7. Grammar specification (owned by this RFC)

A compact EBNF; the canonical machine-readable grammar lives beside the parser and is snapshot-tested (§8). Kept small and regular so it doubles as a constrained-decoding grammar for the MCP surface (§3.6).

query        = predicate , { "|" , stage } ;
predicate    = or_expr ;
or_expr      = and_expr , { ("or" | "||") , and_expr } ;
and_expr     = unary , { ("and" | "&&") , unary } ;
unary        = [ "not" | "!" ] , ( comparison | call | bool_lit | "(" , predicate , ")" ) ;
bool_lit     = "true" | "false" ;   (* match-all / match-none; a bare `true` = no filter *)
comparison   = severity_cmp | scalar_cmp ;
severity_cmp = "severity" , ord_op , ( severity_name | number ) ;
scalar_cmp   = scalar_path , cmp_op , literal ;
ord_op       = "==" | "!=" | "<" | "<=" | ">" | ">=" ;   (* no regex — severity is numeric *)
cmp_op       = ord_op | "=~" | "!~" ;
call         = str_fn , "(" , path , "," , string , ")"
             | "resolves_to" , "(" , number , ")" ;
str_fn       = "matches" | "contains" | "starts_with" | "ends_with" ;
path         = field | "resource" , key_tail | "attr" , key_tail ;
scalar_path  = nonsev_field | "resource" , key_tail | "attr" , key_tail ;
field        = nonsev_field | "severity" ;
nonsev_field = "body" | "ts" | "observed_ts" | "trace_id" | "span_id"
             | "scope" | "flags" | "service" | "template_id"
             | "confidence" | "lossy" ;
key_tail     = ( "." , dotted_key ) | ( "[" , string , "]" ) ;
dotted_key   = ident , { "." , ident } ;
stage        = "range" , "(" , time , "," , time , ")"
             | "count" , [ "by" , field_list ]
             | agg_fn , "(" , path , ")" , [ "by" , field_list ]
             | "sort" , sort_key , [ "asc" | "desc" ]
             | "limit" , integer
             | "project" , field_list
             | "render" ;
agg_fn       = "sum" | "min" | "max" | "avg" ;
field_list   = field , { "," , field } ;
sort_key     = field | ident ;          (* ident = an aggregate output, e.g. count *)
literal      = string | number | boolean | "null" | duration | timestamp ;
severity_name = "trace" | "debug" | "info" | "warn" | "error" | "fatal" ;  (* case-insensitive; only as a `severity` RHS *)
time         = "now" | ( [ "-" ] , duration ) | timestamp ;   (* e.g. now , -1h *)
integer      = digit , { digit } ;
(* lexical: ident = letter , { letter | digit | "_" } ;
   string = '"' , { char | escape } , '"' ;
   char   = any Unicode scalar except '"' , '\' , or a line terminator
            (a literal newline must be written as the \n escape — queries
            are single-line, §4 P7 / RFC0002.10) ;
   escape = '\' , ( '"' | '\' | "n" | "t" | "r" | ( "u" , 4 * hex ) ) ;
   number = integer | float ;  float = integer , "." , digit , { digit } ;
   boolean = "true" | "false" ;
   duration = integer , ( "s"|"m"|"h"|"d"|"w" ) ;  timestamp = RFC 3339 ;
   digit = "0".."9" ;  letter = "a".."z" | "A".."Z" ;
   hex = digit | "a".."f" | "A".."F"
   — strings are double-quoted with backslash escapes; YAML embedding
   (RFC0002.10) wraps the whole query in a single-quoted YAML scalar so
   these double quotes need no YAML-level escaping *)

8. Testing strategy

Mapping to CLAUDE.md §6.2 and docs/verification.md §3 (red→green two-loop: #[ignore]’d stubs first, implementations second).

  • Unit tests — every grammar production has a positive and negative parse test.
  • Property tests — generate well-formed queries; assert the §5 round-trip idempotence (RFC0002.7) and that every generated query is a YAML-safe single-line scalar (RFC0002.10).
  • Compilation golden tests — every construct has a golden LogicalPlan (debug-rendered) checked in; the no-leakage boundary (RFC0002.3) is a compile + string test.
  • Equivalence tests — string vs structured surface compile to the same IR (RFC0002.2); a DSL query and the equivalent ourios_querier structured request return identical results + QueryStats (RFC0002.1).
  • Grammar snapshot — the EBNF / parser grammar is committed and snapshot-tested so changes are PR-visible (Branch B owns its grammar).
  • End-to-end — against the docs/benchmarks.md §1 corpora, pinned expected results for a query set spanning each construct.

9. Open questions

Narrowed by the §3 resolution. Must be resolved before accepted.

  • Pre-accepted validation. The §3.6 audience analysis stands in for instinct, not for evidence: before accepted, run a readability pass on 10–20 sample queries with non-author reviewers, and a migration sketch from LogQL/Insights into β. (Replaces the prior §9 user-research gate; not required for specified.)
  • OTel ecosystem alignment Resolved: OpenTelemetry defines the logs data model + API/SDK but no standard query/read language, and OTTL is a Collector transformation language, not a querying surface (see the OTTL README and the OTel logs spec linked in §11 References). There is no canonical OTel read syntax, and no Perses-specific query convention, to align to. Bespoke query syntax over the OTel data model is the norm (LogQL, PromQL, CloudWatch Insights), so Branch B carries no ecosystem-divergence cost — the alignment that matters is at the field semantics, which §6.1/§6.2 honour (ts/observed_ts/trace_id/span_id/flags/body/scope/ severity → canonical data-model fields; severity ordering on SeverityNumber).
  • --sql advanced-mode escape hatch — gated + sandboxed, or never? (Currently: never; reconsider under a separate RFC.)
  • Custom user functions — out for v1 (sandboxing is its own project).
  • params[N] positional access vs named parameters via the template schema.
  • In-path query cost estimator (“this will scan 400 GB”) before run.
  • Pagination / streaming surface for large result sets (mirrors RFC 0007 §8).

Resolved by this RFC (were open in the draft): branch (B), top-level surface (β), severity-text casing (case-insensitive, §6.1), agent- friendliness (the structured surface, §6.4), and first-class OTel- canonical fields (§6.2).

10. Alternatives considered

Alternatives that would replace the whole design, not just one branch.

  • Pure SQL (DataFusion dialect) — zero parser cost, but violates CLAUDE.md §4 hazard 6 (cross-tenant joins, unbounded scans) and binds the user surface to DataFusion. Rejected as default; possible future gated, sandboxed escape hatch under a separate RFC.
  • LogQL clone — label selectors are less expressive than the OTel log record; adopting them flattens structure and lies about the ingest contract. Rejected as the full DSL; its top-level shape survives as the chosen β surface.
  • CloudWatch Insights clone — proprietary, no open spec; attribute model differs from OTel. Rejected; its verb-per-line readability is the γ alternative we did not pick.
  • Branch A (borrow OTTL) on any surface — see §3; not chosen for the Perses/MCP audiences.

11. References

  • OpenTelemetry log data model: https://opentelemetry.io/docs/specs/otel/logs/data-model/
  • OpenTelemetry severity text conventions: https://opentelemetry.io/docs/specs/otel/logs/data-model/#field-severitytext
  • OTTL (reference-only under Branch B): https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/pkg/ottl
  • LogQL: https://grafana.com/docs/loki/latest/query/
  • CloudWatch Logs Insights: https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html
  • Perses (CNCF dashboards-as-code): https://perses.dev/
  • Apache DataFusion logical-plan documentation.
  • RFC 0001 §6.1/§6.3/§6.7 (the columns + template/drift primitives); RFC 0007 (the execution layer this DSL targets); CLAUDE.md §4 hazard 6 (no-leakage hazard) and CLAUDE.md §3.7 (multi-tenancy).

RFC 0003 — OTLP receiver


rfc: 0003 title: OTLP receiver — gRPC and HTTP wire endpoints for OpenTelemetry log ingest status: green author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-05-13 supersedes: — superseded-by: —

RFC 0003 — OTLP receiver

How to read this document. Sections §§1–4 are the design contract — the what and the why. §5 lists the normative Given / When / Then scenarios — the contract the receiver crate is implemented against and tested for. §6 is the precise specification the receiver crate is implemented against. §7 records the alternatives we evaluated and rejected. §8 maps each §5 scenario to the technique that tests it. §9 lists open questions; §10 the references.

Cross-references to CLAUDE.md sections are in square brackets, e.g. [§3.4], and name the invariant the section must preserve. Cross-references to RFC 0001 use its section numbers directly (e.g. RFC 0001 §6.1).

1. Summary

The Ourios OTLP receiver accepts OpenTelemetry log batches over gRPC and HTTP, decodes them per the official opentelemetry-proto schema, derives a tenant_id per ResourceLogs group via an operator-configured rule (RFC 0001 §6.1 Tenant derivation), materialises each LogRecord.body into the Body::String(String) | Body::Structured(AnyValue) fork (the decoded AnyValue rides through verbatim — canonicalisation happens once, at ingest, inside the miner, per the amended §6.4), fans the batch out into per-tenant streams of OtlpLogRecord, hands each stream to ourios-miner, and acknowledges the OTLP request only after the WAL-before-ack invariant [§3.4] is satisfied. The default wire stack is tonic (gRPC) + axum/hyper (HTTP) against the official opentelemetry-proto Rust crate; the alternatives considered and rejected are embedding rotel as a library and running the OTel Collector out-of-process.

This RFC is the wire-decode contract that the §6.1 amendment of RFC 0001 (PR #21) and the §6.2 algorithm rewrite (PR #23) both implicitly require: the miner takes a structured OtlpLogRecord that something must produce. RFC 0003 is that something.

2. Motivation

2.1 The OTel-native commitment is not yet implemented

docs/glossary.md (entry OTLP) commits Ourios to OTLP as the sole ingest contract: “we do not invent our own format.” RFC 0001’s pre-amendment §6.1 record schema and the MinerCluster::ingest(_, raw: &str) signature treated logs as flat text strings, which the investigation in docs/architecture/otlp-log-format.md (PR #20) showed to be incompatible with that commitment. PRs #21 and #23 amended the miner’s data model and algorithm to consume structured OtlpLogRecords. No code yet produces those records. This RFC specifies the producer.

2.2 The receiver is the boundary that decides what “OTLP” means in practice

OTLP carries a structured LogRecord whose body is AnyValue (string, bool, int, double, bytes, array, kvlist), whose attributes are typed, whose Resource lives one container level up (per ResourceLogs), and whose timestamps and severity are first-class. Where in the pipeline these wire-level facts become the in-memory OtlpLogRecord the miner sees is a load-bearing decision: the receiver is where:

  • The wire format (protobuf vs JSON, gRPC vs HTTP) collapses to a single in-memory representation.
  • tenant_id is derived per ResourceLogs (RFC 0001 §6.1 Tenant derivation) and the batch fans out into per-tenant streams.
  • body.kind = Structured records have their AnyValue body carried verbatim into Body::Structured(AnyValue) — per the amended §6.4 the receiver never canonicalises; the miner encodes the tree to the Ourios canonical body encoding at ingest, whose round-trip stored_bytes ↔ AnyValue per RFC 0001 §6.1 Body representation makes the lossy_flag = false promise meetable.
  • The acknowledgement-after-durability sequencing ([§3.4]) is enforced.

Specifying these decisions in one place — and pinning them explicitly against the OTel spec rather than reinventing them — is what this RFC does.

2.3 Roadmap context

docs/roadmap.md §5 (post-#22) lists “OTLP wire endpoints (gRPC + HTTP listeners)” as post-MVP: the bench reads OTLP from disk (a corpus of pre-recorded LogsData), not from the network, so wire-decode is not on the C2 thesis-gate path. The record shape is in MVP — the miner consumes OtlpLogRecord from the corpus reader. This RFC is the spec for the post-MVP wire layer; landing the spec now (rather than after the bench) settles the design while the OTLP record shape is being implemented in the miner, so the receiver’s eventual implementation has nothing to redesign.

3. Background — OTLP wire formats

3.1 The OTLP message hierarchy

An OTLP log export is a single ExportLogsServiceRequest message carrying one or more ResourceLogs. (LogsData is the file-format equivalent message in logs.proto and shares the same resource_logs: ResourceLogs[] field shape; this RFC uses ExportLogsServiceRequest throughout, since that is the wire type both transports decode into.)

ExportLogsServiceRequest
└── resource_logs: ResourceLogs[]
    ├── resource: Resource           # per-source attributes (service.name, host.*, ...)
    ├── schema_url: string
    └── scope_logs: ScopeLogs[]
        ├── scope: InstrumentationScope     # name, version, attributes
        ├── schema_url: string
        └── log_records: LogRecord[]        # the actual log entries

A single export request can carry records from multiple sources (multiple ResourceLogs groups), each with its own Resource, and within each Resource multiple instrumentation scopes. The mapping from this hierarchy to per-tenant streams of records is the receiver’s responsibility (§6.4 below).

3.2 Two transports, three encodings

OTLP is defined for two transports:

  • OTLP/gRPC — the canonical transport. Service is opentelemetry.proto.collector.logs.v1.LogsService, method Export. Wire encoding: protobuf over HTTP/2.
  • OTLP/HTTP — POST against the /v1/logs path. Wire encoding chosen by the client per the Content-Type header:
    • application/x-protobuf (recommended by the spec; the same protobuf message as gRPC)
    • application/json (the proto3 JSON mapping with OTLP overrides — hex trace_id/span_id, base64 bytes)

The receiver MUST support both transports and all three encodings. The OTel emitter ecosystem is split: SDKs ship with gRPC by default, but the HTTP transport is widely used in constrained environments and as a Collector exporter. Refusing either transport reduces the receiver to a non-compliant subset.

3.3 Backpressure and partial-success in the OTLP response

The OTLP spec defines a partial-success response shape:

ExportLogsServiceResponse
└── partial_success: ExportLogsPartialSuccess (optional)
    ├── rejected_log_records: int64
    └── error_message: string

When set, this signals that the receiver accepted some records but rejected others (e.g., due to rate limiting, validation failures, etc.). The full-failure case uses a transport-level error (gRPC status code, HTTP non-2xx) rather than partial-success.

§6.7 below discusses how Ourios uses (or defers using) this field. For the initial design, the receiver uses all-or- nothing batch semantics — full-success or transport-level error — and reserves partial-success for a future RFC.

4. Background — Existing Rust OpenTelemetry ecosystem

4.1 opentelemetry-proto

The official Rust crate carrying generated bindings for every opentelemetry-proto message. Tracks upstream proto. Suitable as the in-memory representation between wire-decode and the miner. Trivially compatible with both tonic (gRPC) and prost (raw protobuf, used over HTTP).

4.2 tonic

The de-facto Rust gRPC framework: production-grade, async (tokio), supports the metadata, deadlines, and streaming features OTLP relies on. Standard choice for any Rust gRPC service. The LogsService server trait is generated by the tonic-build codegen step from the OTLP .proto files.

4.3 axum and hyper

axum is the conventional Rust HTTP framework for service endpoints, built on hyper and tower. Suitable for the OTLP/ HTTP transport. The endpoint handler decodes the request body (protobuf or JSON, dispatched on Content-Type) into the same in-memory ExportLogsServiceRequest representation tonic produces, and the two transport paths converge into a single business-logic layer.

4.4 rotel

A Rust-implemented OpenTelemetry Collector. Mature (production deployments exist), covers receivers, processors, exporters. Interesting as a possible library to embed (taking just its OTLP-receiver component) rather than as a separate process — see §7 for the build-vs-embed analysis. Note: rotel’s public API is collector-shaped (full pipeline), not “just the receiver” shaped, which complicates embedding.

4.5 OTel Collector (Go)

The reference collector implementation. Often deployed as a sidecar or daemonset that buffers, batches, and forwards telemetry to backends. For an Ourios deployment, a fronting Collector would terminate OTLP at the Collector and forward to Ourios via some other transport (or via OTLP again). §7 discusses this as a deployment option, not a code dependency.

5. Acceptance criteria

Each scenario carries an id of the form RFC0003.<m> that is referenced verbatim from each test’s leading doc comment (e.g. /// Scenario RFC0003.1 — WAL-before-ack.) so the spec↔test mapping is greppable (per docs/rfcs/README.md Required sections and docs/verification.md §2.3 — function names are not part of the contract, the doc-comment line is). Scenarios .1.11 cover the invariants and hazards the §6 design touches; .12.15 pin behaviour the OTLP spec mandates and that the §9 enrichments surfaced (empty request, compression, default path, concurrency).

Scenario RFC0003.1 — WAL-before-ack [§3.4]

  • Given a Receiver wired to a real Wal (opened with defaults) and a single OTLP ExportLogsServiceRequest carrying ≥ 1 LogRecord
  • When the receiver runs its accept path
  • Then the transport-level success response (gRPC OK / HTTP 2xx) is emitted only after the Wal::sync call covering the batch’s frame returns Ok(_) — measured by an AtomicBool set after sync returns Ok(_) (mirroring RFC0008.1; the probe inside sync would already be true mid-call). The response-writer asserts the flag is true before sending
  • And the pre-sync points (decode, tenant_derive, body_materialise, append) all observe the flag as false
  • And the WAL contains a single FrameKind::OtlpBatch frame (per RFC 0008 §3.2 + §6.2.3) whose payload decodes (via prost) to the input ExportLogsServiceRequest — verified post-response by shutting down the receiver (which drops its Wal handle, per RFC 0008 §3.1’s single-writer architecture — enforced by crates/ourios-wal/src/lib.rs:162) and then opening a second Wal to replay via Wal::replay, asserting one new frame whose payload round-trips via prost to the input request. This And is a content/existence check; the before-the-ack ordering is established by the AtomicBool probe in the preceding Then + And clauses, not by the replay (byte equality of the payload to any specific encoding is not required — protobuf has multiple wire encodings that decode to the same message; see RFC0003.2)
  • And the §6.5 step-5 miner-acceptance precondition for ack also holds: every record in the batch has been handed to MinerCluster::ingest and accepted before the ack fires (an instrumented MinerCluster stub records each ingest call; the response-writer asserts the per-batch accepted-count equals the batch’s record-count before sending)

Scenario RFC0003.2 — Crash-before-ack: at-least-once with retry tolerance [§3.4]

  • Given a receiver wired to a real Wal, an OTLP client that retries on transport timeout per the OTLP spec retry semantics, and a SIGKILL injected after Wal::sync returns Ok(_) but before the success response reaches the wire — i.e. anywhere in the §6.5 window between step 4 (fsync return) and step 6 (ack); both the step-4/5 and step-5/6 gaps reduce to the same duplicate-on-retry contract since the records are already durable
  • When the receiver process restarts, Wal::replay runs, and the client retries the timed-out export
  • Then the post-restart WAL contains the OtlpBatch frame the killed process had fsync’d before the kill — its payload decodes (via prost) to an ExportLogsServiceRequest semantically equivalent to the killed process’s input (the RFC0008.2 guarantee this RFC consumes; byte equality of the wire payload is not required, see the second And below for why)
  • And the client’s retry is accepted and produces a second OtlpBatch frame whose payload decodes to an ExportLogsServiceRequest semantically equivalent to the first (same resource_logs after prost decode — the wire bytes need not match, since the client may re-encode on retry: JSON field-ordering / whitespace, switched compression, etc.). This duplication is the at-least-once contract per the OTLP spec’s duplicate-data section (“duplicate data is a deliberate tradeoff for telemetry data”); the receiver implements no de-duplication in this RFC
  • And no special “retry” marker is appended; the receiver has no dedup key (§9 reserves any future dedup mechanism for a follow-up RFC) and cannot distinguish a retry from an independent batch carrying the same records

Scenario RFC0003.3 — Tenant fan-out [§3.7]

  • Given an OTLP batch containing exactly two ResourceLogs groups R_A (service.name = "svc-a") and R_B (service.name = "svc-b"), and an operator-configured tenant-derivation rule keyed on service.name
  • When the receiver processes the batch
  • Then the (tenant_id, OtlpLogRecord) pairs accepted by an instrumented MinerCluster stub for tenant_id_a are exactly those derived from R_A and contain no record derived from R_B
  • And the symmetric assertion holds for tenant_id_b
  • And each emitted OtlpLogRecord’s resource_attributes reflects the originating Resource verbatim — the receiver does not mix Resource attribute sets across the fan-out

Scenario RFC0003.4 — Tenant resolution failure rejects the entire batch [§3.7]

  • Given an OTLP batch where at least one ResourceLogs.resource lacks the attribute named by the operator’s tenant-derivation rule
  • When the receiver processes the batch
  • Then the receiver emits a transport-level error (gRPC INVALID_ARGUMENT / HTTP 400) whose payload names the failing ResourceLogs index and the missing attribute key
  • And no OtlpBatch frame from the batch is appended to the WAL (asserted by shutting down the receiver — dropping its single Wal handle per RFC 0008 §3.1’s single-writer architecture (enforced by crates/ourios-wal/src/lib.rs:162) — and then opening a second Wal and observing via Wal::replay that frame count and segment offsets are unchanged from the pre-batch snapshot)
  • And no record from the batch reaches MinerCluster::ingest — per-Resource partial acceptance is reserved per §6.3

Scenario RFC0003.5 — gRPC ≡ HTTP/protobuf decode equivalence

  • Given a byte-equal ExportLogsServiceRequest protobuf payload
  • When the payload is decoded via the tonic gRPC handler and via the axum HTTP handler with Content-Type: application/x-protobuf independently
  • Then the two resulting in-memory ExportLogsServiceRequest values are structurally equal (PartialEq), and every derived OtlpLogRecord from each path is field-for-field equal — including body, attributes, resource_attributes, trace_id, span_id, and dropped_attributes_count

Scenario RFC0003.6 — HTTP/JSON ↔ gRPC/protobuf equivalence with OTLP-JSON encoding rules

  • Given an ExportLogsServiceRequest carrying non-trivial trace_id and span_id bytes, a record with a bytes-typed AnyValue attribute, and at least one record whose severity_number exercises a non-default enum value
  • When the payload is serialised as gRPC + protobuf and as HTTP + application/json per the OTLP-JSON mapping (hex-encoded traceId / spanId, base64-encoded bytes, integer-encoded enums, lowerCamelCase field names) and each is independently decoded by the receiver
  • Then the two derived OtlpLogRecord sequences are equal at the AnyValue tree level — no byte-level canonicalisation is asserted at this layer (byte-level equivalence under the Ourios canonical body encoding is the miner’s ingest contract per the amended §6.4)
  • And the JSON decoder accepts whitespace and field- ordering variation (insignificant per proto3-JSON)
  • And the JSON decoder ignores unknown fields anywhere in the request body (top-level, nested, repeated) per the OTLP spec’s “receivers MUST ignore unknown fields” rule (forward-compatibility)

Scenario RFC0003.7 — Body::Structured carries the decoded AnyValue verbatim

  • Given a LogRecord whose body is an AnyValue of a non-string_value variant (kvlist_value, array_value, int_value, double_value, bool_value, or bytes_value)
  • When the receiver materialises the record via ourios_core::otlp::Body::from_any_value from either transport
  • Then the resulting OtlpLogRecord.body is Some(Body::Structured(av)) where av is structurally equal to the wire’s AnyValue (no canonicalisation, no reshape, no dropped fields)
  • And the same equality holds across the three transports, since RFC0003.5 and RFC0003.6 make the per-transport decodes equivalent at the AnyValue level

Scenario RFC0003.8 — Body::String reaches the miner as the unwrapped L_raw

  • Given a LogRecord whose body is AnyValue { value: Some(string_value(s)) }
  • When the receiver materialises the record
  • Then the resulting OtlpLogRecord.body is Some(Body::String(s)) where s is the original UTF-8 string (no wrapping, no quoting, no escaping)
  • And the value handed to MinerCluster::ingest equals s byte-for-byte (asserted by an instrumented MinerCluster stub that records each ingest call’s body argument — the receiver’s contract here is the pass-through, not anything about how the miner indexes or short-circuits on it)

Scenario RFC0003.9 — Edge OTLP fields pass through unchanged

  • Given a LogRecord with severity_number = 0 (UNSPECIFIED), no scope_name on its enclosing InstrumentationScope, and observed_time_unix_nano = 0 (proto3’s scalar default for an unset field — OTLP’s log-record section spells this out as “the value of 0 indicates unknown”)
  • When the receiver materialises the record
  • Then the derived OtlpLogRecord carries severity_number = 0 (kept as 0 because UNSPECIFIED is an explicit OTLP value per RFC 0001 §6.1, not absence), scope_name = None, and observed_time_unix_nano = None — the receiver applies the wire-0None rule for observed_time_unix_nano specifically (the Option<u64> typing in RFC 0001 §6.1 exists for this conversion; this scenario is the contract that owns the rule)
  • And the record is accepted by MinerCluster::ingest without rejection, coalescing, substitution, or any downcast to a “default” value

Scenario RFC0003.10 — dropped_attributes_count preserved verbatim

  • Given a LogRecord whose dropped_attributes_count is 42 on the wire
  • When the receiver materialises the record
  • Then the resulting OtlpLogRecord.dropped_attributes_count is exactly 42
  • And the receiver does not recompute the field — it reflects the wire-level claim only, even if a future receiver-side per-attribute truncation step would have dropped further attributes (a hypothetical such step is tracked as a §9 open question)

Scenario RFC0003.11 — Transport-level errors are controlled, not panics

  • Given any of:
    • a malformed protobuf payload (random bytes that fail prost::Message::decode),
    • an over-size request body exceeding the receiver’s configured request-size limit,
    • an HTTP request with an unrecognised Content-Type,
    • an HTTP POST to a path other than the configured /v1/logs (covered jointly with RFC0003.14),
    • or a gRPC client cancellation mid-decode
  • When the receiver handles the request
  • Then the receiver emits a controlled transport-level error — gRPC INVALID_ARGUMENT / RESOURCE_EXHAUSTED / CANCELLED as appropriate, or HTTP 400 / 413 / 415 / 404 as appropriate
  • And no part of the receiver panics or restarts; the process remains alive (each arm of the test asserts this after the request)
  • And no OtlpBatch frame is appended to the WAL (the rejected batch never reaches §6.5 step 3, so the persistence unit — the per-export frame — never lands)

Scenario RFC0003.12 — Empty ExportLogsServiceRequest returns success without WAL write

  • Given an ExportLogsServiceRequest that carries zero LogRecords — covered shapes are (i) resource_logs empty, (ii) resource_logs[i].scope_logs empty for every i, (iii) every resource_logs[i].scope_logs[j].log_records empty. All three shapes are tested
  • When the receiver processes the request via either transport
  • Then the receiver emits a transport-level success response carrying an ExportLogsServiceResponse with partial_success unset (per the OTLP spec’s otlpgrpc-response and otlphttp-response sections: “servers SHOULD treat empty as success”)
  • And the receiver does not invoke Wal::sync, no frame is appended (asserted via a test wrapper around the Wal handle that counts append and sync calls), and no record reaches MinerCluster::ingest

Scenario RFC0003.13 — Compression over HTTP: identity and gzip MUST be supported

  • Given an HTTP request whose body is the byte-equal ExportLogsServiceRequest payload of RFC0003.5, transported with Content-Encoding: identity (or absent) and with Content-Encoding: gzip independently
  • When the receiver processes each request
  • Then the two derived OtlpLogRecord sequences are equal — the OTLP spec mandates both encodings, and the receiver’s decode produces semantically identical results
  • And a request with an unsupported Content-Encoding (e.g. zstd, br) is rejected with HTTP 415 and a controlled error message; zstd support is deferred per §9

Scenario RFC0003.14 — Default /v1/logs path with configurable override

  • Given the HTTP listener bound with the default path configuration
  • When a POST arrives at /v1/logs
  • Then the receiver handles it via the OTLP/HTTP code path defined in §6.2
  • And a POST to any other path returns HTTP 404 (the “wrong path” arm of RFC0003.11)
  • And when the operator configures an override path (e.g. /otlp/v1/logs), it replaces /v1/logs as the accepted path without changing any other receiver behaviour (the configurability matches the Collector’s OTLP-receiver path knob, so deployments that need a non-standard prefix don’t have to front Ourios with a reverse proxy)

Scenario RFC0003.15 — Concurrent Export calls each obey WAL-before-ack independently [§3.4]

  • Given N ≥ 2 concurrent gRPC Export unary calls submitted to the receiver from independent client connections
  • When each call’s batch independently traverses the §6.5 sequence
  • Then each call’s ack is emitted only after its own batch’s Wal::sync returns Ok(_) and its own batch’s records have all been accepted by MinerCluster::ingest — the §3.4 AtomicBool of RFC0003.1 is per in-flight call, not process-global; a per-call probe records both the sync-completion and miner-acceptance ordering before the response-writer sends
  • And the WAL contains exactly one OtlpBatch frame per concurrent call (no call’s batch is lost to concurrency, asserted by shutting down the receiver — dropping its single Wal handle per RFC 0008 §3.1’s single-writer architecture (enforced by crates/ourios-wal/src/lib.rs:162) — and then opening a second Wal whose Wal::replay yields N frames whose payloads round-trip to the N input ExportLogsServiceRequests)
  • And the test does not assert any cross-call ordering — concurrent batches may interleave in the WAL as the tokio runtime chooses, which is consistent with the OTLP spec’s recommendation to support concurrent unary Export calls for throughput

Amendment (served-binary slice, post-green). Scenarios RFC0003.1–.15 are implemented and were green (exercised in-process: axum/tonic handlers via direct call / oneshot, the pipeline + WAL directly). This amendment adds RFC0003.16 — the end-to-end served-binary contract, which the §9 Receiver process model resolution settles — and re-enters the ladder at specified until RFC0003.16 lands.

Scenario RFC0003.16 — Served binary: both transports bind, a client export round-trips, graceful shutdown [§3.4]

  • Given ourios-server started with the receiver role enabled (config-toggled per the §9 resolution), the gRPC listener bound on its configured port (default 4317) and the HTTP listener bound on its configured port (default 4318), both sharing one IngestPipeline over a single Wal
  • When a real OTLP client exports a non-empty batch (resolvable tenant) over each bound socket — gRPC Export and HTTP POST /v1/logs (application/x-protobuf) — and receives each transport response, and only then is the server signalled to shut down (this scenario pins the steady-state export→ack→shutdown path; in-flight-during- shutdown behaviour is out of scope here)
  • Then each client receives transport-level success (gRPC OK / HTTP 200) only after its batch is durable — the §6.5 WAL-before-ack contract holds end-to-end over a real socket, not just in-process
  • And the shutdown signal stops the listeners and exits the process cleanly, releasing the single Wal handle — without dropping it mid-fsync, and no already-acked batch is lost on the way out
  • And after that clean exit frees the single-writer handle (RFC 0008 §3.1), opening the WAL and running Wal::replay recovers each batch’s OtlpBatch frame — the durability check necessarily follows shutdown, since the WAL cannot be reopened while the server holds it

6. Proposed design

6.1 Overall shape

The receiver is a single Rust crate (ourios-ingester per the target layout in CLAUDE.md §7) exposing two listeners — gRPC on its own port, HTTP on its own port — that share a single business-logic layer. The business-logic layer accepts a decoded ExportLogsServiceRequest and:

  1. Iterates ResourceLogs[], deriving tenant_id per Resource via the operator-configured rule (RFC 0001 §6.1 Tenant derivation).
  2. For each ResourceLogs, iterates ScopeLogs[] and LogRecord[], materialising one OtlpLogRecord per record. The OtlpLogRecord is the in-memory shape RFC 0001 §6.1’s amended record table mirrors; it carries the inherited Resource attributes and the InstrumentationScope name and version as fields, so downstream code never needs to walk back up the OTLP hierarchy.
  3. For each LogRecord, materialises body into the Body::String(String) | Body::Structured(AnyValue) fork per ourios-core::otlp::Body::from_any_value. No canonicalisation runs at the receiver — the structured branch carries the decoded AnyValue verbatim per the amended §6.4.
  4. Hands each per-tenant stream to ourios-miner (one MinerCluster per process; the cluster routes internally per tenant_id).
  5. After the batch has been written to the WAL as a single OtlpBatch frame with fsync AND every record accepted by the miner, returns a transport-level success.

6.2 Wire stack defaults

  • gRPC: tonic + the opentelemetry-proto crate’s generated LogsServiceServer trait.
  • HTTP: axum on hyper. A single /v1/logs POST handler dispatches on Content-Type:
    • application/x-protobufprost::Message::decode into the same ExportLogsServiceRequest type the gRPC path produces.
    • application/json → proto3-JSON decode into ExportLogsServiceRequest. The decode handles whitespace and field-ordering variation natively (proto3-JSON spec); no separate canonicalisation pass — the Body::Structured(AnyValue) carried downstream is transport-agnostic at the AnyValue level.
  • Both listeners spawn off the same tokio runtime, share a single instance of the business-logic layer, and bind on operator-configured ports (defaults 4317 for gRPC and 4318 for HTTP, per the OTel convention; configurable). The receiver is a role of the ourios-server binary, enabled by config and sharing that binary’s tokio runtime alongside the other roles (e.g. the compaction daemon) — the §9 Receiver process model resolution. The served-binary contract is RFC0003.16.

6.3 Tenant fan-out

Per RFC 0001 §6.1 Tenant derivation, tenant_id is derived per ResourceLogs group, not per export batch. The receiver:

  • Resolves the tenant rule once per ResourceLogs.resource.
  • Groups the resulting OtlpLogRecords by tenant_id (a single batch can produce multiple per-tenant groups).
  • Hands each group to the miner via MinerCluster::ingest, which is already per-tenant-routed internally.

If any ResourceLogs.resource fails to resolve to a tenant under the configured rule, the receiver rejects the entire batch with a transport-level error naming the failing ResourceLogs index (the offset in the export’s resource_logs[]) and the missing attribute key. Per-Resource partial acceptance is reserved for a future RFC (see §9).

6.4 AnyValue canonicalisation happens once, at ingest

Amendment (PR introducing ourios-core::otlp::OtlpLogRecord). This subsection originally pinned the receiver as the place that canonicalises structured AnyValue bodies into OTLP-canonical JSON, with the in-memory record carrying pre-cached Bytes. The amended position carries the AnyValue itself on the in-memory record and defers canonicalisation to the storage layer (Parquet writer, when it lands).

Amendment 2026-06-10 (canonicalisation happens at ingest). The amendment above predated the implementation and placed the single canonicalisation pass at Parquet-write time. The merged implementation runs it at ingest: the miner’s ingest_structured encodes the AnyValue the receiver delivered with the Ourios canonical body encoding (RFC 0001 §6.1 The Ourios canonical body encoding), and the mined record carries those bytes from there — WAL, flush, and the Parquet writer (RFC 0005 §3.3) persist them verbatim. What the amendment above got right is preserved: the receiver still does not canonicalise, and the “mine inner field” optionality is intact because the miner receives the decoded tree — the encode point sits after any future inner-field hook would run. This note reconciles the text below to the implemented behaviour; the rationale is rewritten accordingly.

The receiver hands the miner an OtlpLogRecord whose body, when present and structured, carries the decoded AnyValue verbatim (Body::Structured(AnyValue)) — unchanged from the first amendment. The miner’s §6.2 step-0 short-circuit dispatches on the discriminator alone; only after taking the structured branch does ingest_structured encode the tree, once, via ourios_core::otlp::canonical::encode_any_value (infallible for every AnyValue the type system admits) into the Ourios canonical body encoding per RFC 0001 §6.1 Body representation. The record carries the encoded bytes in its body field from that point on; the Parquet writer stores them verbatim in the RFC 0005 §3.3 body column.

Rationale:

  • Optionality is not lost. RFC 0001 §6.1 reserves a future “mine inner field” mode (e.g. mine body.kvlist["msg"] as the line if present) gated on corpus evidence. That mode needs the structured tree — and ingest_structured receives the structured tree: the receiver hands Body::Structured(AnyValue) through untouched, so the exact place such a mode would hook in still sees the AnyValue. Only the stored form is the canonical bytes; encoding at ingest forecloses nothing.
  • Single canonicalisation pass. Whether the body arrived as gRPC-protobuf or HTTP-JSON, exactly one encode runs — once per structured record, at ingest. There is one transport-agnostic encoder (ourios-core’s otlp::canonical, operating on the decoded AnyValue); neither the receiver nor the writer needs to know a second strategy, and the writer’s contract shrinks to “persist the bytes.”
  • Miner hot path is unchanged. The §6.2 step-0 short-circuit still inspects only the discriminator (Body::Structured(_) vs Body::String(_)) before branching; no AnyValue walking decides the dispatch. The encode cost scales with body size, but it is paid exactly once per structured record regardless of which layer pays it — moving it to write time would buy no work back, while costing a rework of MinedRecord, the miner’s snapshot serialisation (RFC 0001 §6.9), and the render path (RFC 0001 §6.6), all of which carry the encoded body today. That churn would purchase only a mode with no RFC and no named consumer.

For Body::String(s), no canonicalisation is ever needed; the unwrapped string is passed through as L_raw.

6.5 WAL-before-ack sequencing

[§3.4] requires the receiver to acknowledge a non-empty batch only after the batch’s OtlpBatch frame is durably written. (The empty-batch fast path of RFC0003.12 is the explicit exception: no WAL write occurs, and success is returned without an OtlpBatch frame.) Concrete contract for the non-empty case:

  1. Receiver accepts the request and decodes to ExportLogsServiceRequest.
  2. Receiver fans out to per-tenant OtlpLogRecord streams (§6.3); body canonicalisation does not happen here, per the amended §6.4.
  3. Receiver appends the request as a single FrameKind::OtlpBatch frame (per RFC 0008 §3.2 + §6.2.3) whose payload is a protobuf-encoded ExportLogsServiceRequest decodable via prost — semantically equivalent to the input, but byte-equal to the wire payload is not required (per RFC0003.1 + .2 the contract is “you can recover the input message,” not “you get the bytes back”). For the gRPC and HTTP/protobuf paths the receiver MAY store the wire bytes verbatim; for the HTTP/JSON path no incoming protobuf bytes exist and the receiver MUST encode the decoded message.
  4. Receiver fsyncs the WAL segment(s) touched.
  5. Receiver hands records to the miner for templating.
  6. Receiver returns transport-level success.

The fsync-then-template ordering matters: a crash between (4) and (5) is recoverable (records replay from the WAL; the miner state is reconstructed); a crash between (3) and (4) loses those records but the client retries (no ack was sent); a crash between (5) and (6) is the “the server did the work and the client never heard about it” case, where client retries produce duplicates. This RFC implements no de-duplication: duplicates on retry are the explicit at-least-once contract per RFC0003.2 and §9 #1 (resolved by reference to the OTLP spec’s duplicate-data section). Any future content-hash or request-id dedup is purely additive on top of this baseline.

The receiver itself is post-MVP per roadmap.md §5 — the MVP bench reads OTLP from the on-disk corpus, bypassing this component entirely. The receiver therefore cannot be enabled until ourios-wal lands, and there is no MVP code path that acks a network request before durability. The append-then-fsync-then-ack sequence above is the only contract; no “WAL no-ops” mode exists, since that would violate [§3.4].

6.6 The OtlpLogRecord in-memory shape

Amendment (PR introducing ourios-core::otlp::OtlpLogRecord). Body now carries the decoded AnyValue rather than its OTLP-canonical JSON encoding (see amended §6.4). body_kind is derived from body rather than stored on the record, since the §6.2 step-0 fork only needs to read the discriminator.

Amendment 2026-06-11 — the effective timestamp is derived downstream, not here. RFC 0005 §3.2 (amendment of the same date) adds a writer-derived effective_time_unix_nano Parquet column (time_unix_nano when non-zero, else observed_time_unix_nano.unwrap_or(0) — RFC 0005 §3.2 is the normative derivation). The receiver’s contract is unchanged: time_unix_nano is carried verbatim from the wire including 0 (RFC 0001 scenario RFC0001.10), and the wire-0None rule for observed_time_unix_nano stands. No effective-timestamp field is materialised on OtlpLogRecord; the derivation happens at the Parquet writer from the two fields below, and never overwrites either.

The receiver materialises each wire-level LogRecord (plus its inherited Resource and InstrumentationScope context) into a single owned struct. The authoritative definition lives in the ourios-core::otlp module; the sketch below mirrors that module:

struct OtlpLogRecord {
    // Identity / partitioning
    tenant_id: TenantId,

    // OTLP-derived (per RFC 0001 §6.1)
    time_unix_nano: u64,
    observed_time_unix_nano: Option<u64>,
    severity_number: u8,
    severity_text: Option<String>,
    scope_name: Option<String>,
    scope_version: Option<String>,
    attributes: Vec<KeyValue>,            // opentelemetry-proto KeyValue
    dropped_attributes_count: u32,
    resource_attributes: Vec<KeyValue>,   // opentelemetry-proto KeyValue
    trace_id: Option<[u8; 16]>,
    span_id: Option<[u8; 8]>,
    flags: u32,
    event_name: Option<String>,

    // Body — None when the wire delivered no body
    body: Option<Body>,
}

enum Body {
    String(String),
    Structured(AnyValue),                 // opentelemetry-proto AnyValue
}

// `body_kind()` is a method on OtlpLogRecord that returns
// `Option<BodyKind>` derived from `body`; the discriminator
// is never stored.
enum BodyKind { String, Structured }

The Rust types are informal here; the precise definition lives in the ourios-core::otlp module — owning the type in ourios-core (rather than ourios-ingester) lets the miner take it without depending on the receiver crate, since the receiver doesn’t yet exist. The shape mirrors RFC 0001 §6.1 column-for-column so the Parquet writer can serialise a slice of these directly without a translation layer.

6.7 Backpressure (deferred)

The receiver does not apply rate limiting in this initial design. If the miner or the WAL is the bottleneck, the receiver holds the request open until the per-tenant queue drains, then acks. In practice this means OTLP clients see backpressure as elevated request latency rather than as partial_success.rejected_log_records. Whether to upgrade this to explicit partial-success is reserved for a future RFC (see §9). The full-failure path (transport error) covers the unresolvable-tenant and malformed-batch cases per §6.3 and §3.2.

6.8 Out of scope for this RFC

  • Metrics + traces ingest. OTel Collector and OTLP define endpoints for both; Ourios is a logs-only backend per CLAUDE.md §1. Receiver MAY accept metric/trace requests at the transport layer (returning a deliberate Unimplemented response) but this RFC does not specify that path.
  • mTLS / authn / authz. Production deployment concerns, out-of-band of the OTLP wire contract. A future RFC covers the authentication model (likely token-based per request with the resolved identity feeding the tenant-derivation rule).
  • Schema URL handling. ResourceLogs.schema_url and ScopeLogs.schema_url are separate OTLP fields and do not appear on the OtlpLogRecord shape in §6.6 — the receiver currently drops them. Rationale: RFC 0001 §6.1’s record schema does not include columns for them, no consumer references them yet, and Ourios does not interpret OTel semantic conventions. Whether to add resource_schema_url / scope_schema_url fields (or a Parquet column) is tracked as an open question in §9; until then the drop is deliberate, not an oversight.
  • Compactor / WAL implementation. Specified in the forthcoming ourios-wal RFC; this RFC’s contract with the WAL is just the append-then-fsync-then-ack sequence in §6.5.

7. Alternatives considered

7.1 Embed rotel as a library

rotel is a production-quality Rust OTel collector. Embedding it would give us a known-good OTLP receiver implementation without us building one. Rejected because:

  • rotel’s public API is collector-shaped (the full receivers→processors→exporters pipeline), not “just the receiver” shaped. Embedding it means embedding the entire pipeline machinery, then building Ourios as one of its exporters. That’s a deployment shape (out-of-process collector) wearing the costume of a code dependency, with the worst of both worlds: the dependency footprint of a full collector and the integration friction of an in- process one.
  • The OTel-receiver pieces of rotel are themselves built on tonic + opentelemetry-proto — the same primitives we would use directly. Embedding rotel adds a layer without removing one.
  • Build-vs-embed parity: our wire-decode layer is small (~a few hundred lines, almost all glue against generated protobuf bindings). The reuse argument doesn’t carry the weight it would for a complex piece of infrastructure.

7.2 Run the OTel Collector out-of-process and have it forward to us

Common deployment shape: a Collector terminates OTLP at the network edge, batches, and forwards to a backend. Rejected as the default because:

  • The Collector ACKs the OTLP client before our backend sees the data, breaking the WAL-before-ack contract [§3.4]. The only way to recover the contract is for our forwarding protocol from the Collector to be itself durable + ack- after-fsync — at which point that protocol is what we needed to spec, and we are back to writing a receiver.
  • Adds a deployment dependency (operator must install and configure the Collector) for no signal beyond what a direct receiver provides.
  • Configuration drift between the Collector’s input validation and ours becomes a real source of “works in one place, fails in the other” bugs.

That said: the Collector is a perfectly fine deployment option for operators who already run one (e.g., for trace sampling). The receiver in this RFC accepts OTLP from any source, including a Collector forwarder, so the deployment shape is not foreclosed; it just isn’t the default and doesn’t get to be on the WAL-before-ack path.

7.3 Hand-roll the protobuf without opentelemetry-proto

Writing our own protobuf bindings against the OTLP .proto files. Rejected because the official crate tracks upstream faithfully and is the canonical Rust binding for the OTLP messages. Re-implementing risks drift, especially on the JSON-encoding overrides (hex IDs, base64 bytes) which are spec-defined but easy to get wrong.

7.4 HTTP-only or gRPC-only

Supporting only one of the two transports. Rejected because the OTel ecosystem is split: SDK defaults are gRPC, but HTTP is widely used in constrained environments and is the standard exporter target for the Collector’s otlphttp exporter. Refusing either transport reduces the receiver to a non- compliant subset of OTLP and forces a class of operators to front Ourios with a converter (e.g., the Collector) — which re-introduces the WAL-before-ack problem of §7.2.

7.5 Synchronous AnyValue canonicalisation in the miner or the receiver

Amendment 2026-06-10 (canonicalisation happens at ingest). The conclusion this section originally reached — “canonicalise at the storage layer (Parquet writer)” — was superseded by the implementation; see the amended §6.4. The grounds on which variant (a) was rejected dissolved once RFC 0001 §6.1’s 2026-06-09 amendment pinned a single transport-agnostic encoder over the decoded AnyValue (ourios-core’s otlp::canonical): the miner needs no transport knowledge, and the encode cost is once per structured record regardless of which layer pays it. The original text is preserved below as the record of the evaluation.

Two related alternatives evaluated together:

(a) Canonicalise in the miner. Rejected because the miner’s hot path benefits from a constant-time write in the body_kind = Structured short-circuit (RFC 0001 §6.2 step 0); doing serialisation work there scales with body size on every structured record. The miner would also need to know the source transport (the two transports need different canonicalisation strategies), which is a layering inversion. (Superseded — see the amendment note above: this is the implemented design.)

(b) Canonicalise in the receiver before materialising OtlpLogRecord. This was the original §6.4 stance and was the basis on which §7.5(a) was rejected. Reversed by the §6.4 amendment: receiver-side canonicalisation forecloses the future “mine inner field” mode (RFC 0001 §6.1) which needs the structured tree, not pre-cached bytes; it also splits canonicalisation knowledge across two transports unnecessarily. (Still rejected — the receiver continues to hand the decoded AnyValue through verbatim. Only the “canonicalise at the storage layer” conclusion that this paragraph originally drew is superseded, per the amendment note above.)

8. Testing strategy

Mapped to the §5 scenarios. Each technique below names the scenario ids it covers; each test’s leading doc comment references the same id verbatim (/// Scenario RFC0003.1 — WAL-before-ack. etc., per docs/verification.md §2.3) so the spec↔test mapping is greppable.

  • WAL-before-ack and concurrency (RFC0003.1, RFC0003.15): integration tests against a real Wal (defaults), with an AtomicBool ordering probe mirroring RFC0008.1 — set after Wal::sync returns, asserted true by the response-writer and false by every pre-sync stage. RFC0003.15 spawns N ≥ 2 concurrent Export calls and uses a per-call probe so the invariant is checked independently per in-flight call.

  • Crash-before-ack (RFC0003.2): a child-process harness mirroring wal_crash_fixture (PR #126) runs a receiver binary wired to a real Wal, the parent SIGKILLs between Wal::sync return and ack-emit, the parent restarts the child and re-issues the export, and the assertion is that the post-restart WAL contains two OtlpBatch frames whose payloads each decode (via prost) to an ExportLogsServiceRequest semantically equivalent to the input (byte-equality is not required — see RFC0003.2 — but the second frame must round-trip to the same logical request) — the at-least-once contract per the OTLP spec’s duplicate-data section. The test explicitly does not assert dedup; RFC0003.2’s contract is “no loss + safe retry,” not exactly-once.

  • Tenant fan-out (RFC0003.3, RFC0003.4): unit tests with a hand-curated two-Resource batch and an instrumented MinerCluster stub that records every accepted (tenant_id, OtlpLogRecord) pair. A proptest strategy over tenant-derivation rules asserts the cross-contamination-free invariant for any rule that returns Some for both Resources. RFC0003.4 uses a hand-curated batch where one Resource lacks the rule’s attribute key.

  • Wire-decode equivalence (RFC0003.5, RFC0003.6): a proptest strategy generates ExportLogsServiceRequest payloads across the proto’s value space; each is serialised to gRPC + protobuf, HTTP + protobuf, and HTTP + JSON, decoded by the receiver, and the three resulting OtlpLogRecord sequences are asserted equal at the AnyValue level. The RFC0003.6 OTLP-JSON encoding-rule clauses (hex IDs, base64 bytes, integer enums, ignore unknown fields) use hand-curated payloads, since the proptest generator can’t reliably exercise spec-mandated forward-compatibility behaviour.

  • Body fork (RFC0003.7, RFC0003.8): table-driven tests over all seven AnyValue variants, each asserting that Body::from_any_value routes string_value to Body::String(s) (unwrapped) and every other variant to Body::Structured(av), where av is structurally equal to the input AnyValue and the inner oneof is moved, not cloned.

  • Edge OTLP cases (RFC0003.9, RFC0003.10): hand-curated LogRecords exercising severity_number = 0, scope_name = None, observed_time_unix_nano = 0, and non-zero dropped_attributes_count. Assertions pin the pass-through semantics on the derived OtlpLogRecord.

  • Transport-level errors + empty request (RFC0003.11, RFC0003.12): table-driven tests over each error arm (malformed protobuf, oversize, unrecognised Content-Type, wrong path, mid-decode cancellation) and the empty-request success arm. Each assertion pins the response status code, that no OtlpBatch frame is appended to the WAL and no record reaches the miner, and that the receiver process is still alive afterwards.

  • Compression and path (RFC0003.13, RFC0003.14): the gzip arm of RFC0003.13 uses flate2 to construct the Content-Encoding: gzip body; the unsupported-encoding arm asserts HTTP 415. RFC0003.14’s path arm covers the default /v1/logs, a wrong-path 404, and an operator-configured override path producing equivalent behaviour.

  • Conformance fuzzing (additive, not bound to a single scenario): proptest strategies derived from the proto definitions feed random valid batches through the receiver; the only assertion is “no panic; response is either success or a controlled transport-level error” — a backstop against decode paths the hand-curated cases miss.

  • Benchmarks (criterion, in ourios-bench): end-to-end latency from request arrival to ack-fires, for both transports, at batch sizes (1, 100, 1 000, 10 000 records per batch). RFC0003.15 throughput at N = 8 concurrent callers. Regressions block merges per CLAUDE.md §6.2.

  • Served binary (RFC0003.16): an integration test boots the ourios-server receiver role bound on ephemeral ports (127.0.0.1:0, reading back each OS-assigned port), exports a non-empty batch over each transport with a real client — a tonic gRPC client and an HTTP client (reqwest/hyper) — and asserts transport success for each. It then signals shutdown and waits for the server task to join cleanly, which releases the single Wal handle (RFC 0008 §3.1’s single-writer rule — the WAL cannot be reopened while the server holds it). Only after that join does the test open the WAL and Wal::replay it, confirming each batch’s OtlpBatch frame is durable — WAL-before-ack over a real socket, with no acked batch lost on the way out. Unlike RFC0003.1–.15 (in-process: direct handler call / oneshot), this is the only scenario that crosses a real socket.

docs/verification.md §3’s two-loop Red gate applies: the §5 scenarios become #[ignore]d test stubs at red stage, then get implementations as the receiver crate is built (the same two-loop pattern RFC 0008 §5 used to drive its red-gate scenarios — #[ignore]’d stubs first, implementations second).

9. Open questions

  • Retry-induced duplicate suppression. Resolved by §5 / RFC0003.2: a crash between miner-attach (step 5) and ack (step 6) in §6.5 produces duplicates on client retry, and that is the contract. The OTLP spec’s duplicate-data section (“the client may re-send … which may result in duplicate data on the server side. This is a deliberate choice and is considered to be the right tradeoff for telemetry data”) explicitly accepts at-least-once with duplicates; the Collector’s WAL guidance carries the same caveat. The receiver implements no de-duplication in this RFC. If a future RFC introduces a dedup mechanism (content-hash idempotency key, OTel SDK request-id header), it is purely additive — the at-least-once baseline is the floor, not a stop-gap.
  • ResourceLogs.schema_url / ScopeLogs.schema_url preservation. §6.8 records that schema URLs are currently dropped because no consumer references them and RFC 0001 §6.1’s record schema has no column for them. If a semantic-conventions-aware feature lands later (e.g., schema URL → attribute key mapping), OtlpLogRecord and the Parquet schema will need the two fields added. Tracked here so a future RFC does not re-derive the question.
  • Where exactly does canonicalisation cost land? Resolved (2026-06-10 §6.4 amendment, reconciling to the implementation): canonicalisation runs at ingest — the miner’s ingest_structured encodes the decoded AnyValue with the Ourios canonical body encoding (RFC 0001 §6.1) and the record carries the bytes from there; the Parquet writer (RFC 0005 §3.3) persists them verbatim. The receiver carries the decoded AnyValue verbatim and never canonicalises. The cost is once per structured record either way; placing it at ingest keeps MinedRecord, the snapshot format, and the render path on a single stored form.
  • dropped_attributes_count semantics on truncation. Preserve verbatim from the wire (current §6 design), sum across records, or recompute if the receiver itself drops attributes (e.g., for being over the 256-byte limit per RFC 0001 §3.2)? Current design says preserve; a future receiver- side truncation step would need to either recompute or use a separate column.
  • Receiver process model. Resolved (served-binary amendment): the receiver is a role of the ourios-server binary, enabled by config and sharing that binary’s tokio runtime alongside the other roles (e.g. the compaction daemon) — not a separate sidecar. Default ports 4317 (gRPC) / 4318 (HTTP) per §6.1; the end-to-end served contract (bind + client round-trip + graceful shutdown) is RFC0003.16.
  • Partial-success response semantics. Resolved (OTLP review): the all-or-nothing batch contract (§6.3 / RFC0003.4) is spec-compliant. OTLP mandates only 400 Bad Request + no client retry for permanently-bad/undecodable input (OTLP/HTTP Bad Data) and does not require accepting a valid subset; partial_success.rejected_log_records is supported but optional. We keep whole-batch rejection and defer partial_success to a future RFC if a concrete operator need surfaces (e.g. one failing tenant in a large multi-tenant batch). On full success partial_success stays unset — the normal OK path.
  • Authentication and tenant binding. If the receiver authenticates the client (mTLS, token), does the authenticated identity feed into the tenant_id derivation rule (e.g., as a constraint), or is it purely an access- control check decoupled from tenancy? A future authentication RFC settles this; the open question is flagged here so the tenant-derivation rule’s interface can grow into it.
  • Multi-line / non-UTF-8 body handling for String bodies. The miner’s tokenize step (RFC 0001 §6.2 step 1) has explicit failure modes (malformed UTF-8, embedded NUL, oversize). Should the receiver pre-validate and reject at the transport level, or pass through and let the miner emit a parse-failure record? Current design: pass through, per-record granularity is the miner’s concern.
  • Compression (gzip / zstd over HTTP). Resolved by §5 / RFC0003.13: the OTLP spec mandates that servers support identity and gzip; both are required acceptance criteria. zstd and br are out of scope for this RFC — a request carrying an unsupported encoding is rejected with HTTP 415. A future RFC may add zstd if operator demand surfaces; until then the 415 response is the contract.
  • Receiver-side OTel telemetry (eating our own dog food). The receiver should itself emit metrics about request rates, decode failures, fan-out latency. Specified where? Likely in the same RFC as the §6.8 telemetry surface (RFC 0001 §6.8); flagged here for tracking.

10. References

  • OTLP logs.proto: https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/logs/v1/logs.proto
  • OTLP logs_service.proto: https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/collector/logs/v1/logs_service.proto
  • OTLP common.proto (AnyValue, KeyValue): https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/common/v1/common.proto
  • OpenTelemetry Logs Data Model spec: https://opentelemetry.io/docs/specs/otel/logs/data-model/
  • OTLP transport spec (gRPC, HTTP, encodings): https://opentelemetry.io/docs/specs/otlp/
  • tonic: https://github.com/hyperium/tonic
  • opentelemetry-proto Rust crate: https://crates.io/crates/opentelemetry-proto
  • axum: https://github.com/tokio-rs/axum
  • rotel: https://github.com/streamfold/rotel
  • OpenTelemetry Collector: https://github.com/open-telemetry/opentelemetry-collector
  • Ourios investigation finding: docs/architecture/otlp-log-format.md
  • RFC 0001 §6.1 (record schema this RFC produces records for): docs/rfcs/0001-template-miner.md
  • CLAUDE.md §1 (Ourios is logs-only), §3.4 (WAL-before-ack), §3.7 (multi-tenancy not bolted on), §4 (hazards).

RFC 0004 — Configuration policy


rfc: 0004 title: Configuration policy — tunables vs invariants status: green author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-05-18 supersedes: — superseded-by: —

RFC 0004 — Configuration policy: tunables vs invariants

1. Summary

Ourios exposes a small, deliberately bounded configuration surface to its operators. This RFC pins the line between tunables — knobs that can be set globally and overridden per tenant — and invariants — the CLAUDE.md §3 commitments that define what Ourios is. Tunables let an organisation place themselves on the accuracy-vs-compression spectrum without taking the whole product with them. Invariants are not configurable — every tenant gets the same [§3] guarantees, no matter what. The RFC names the current four tunables, the boundary they sit inside, and the escalation path for anyone who wants to cross it.

2. Motivation

2.1 Different organisations sit at different points

Dev clusters care about cheap ingest and aggressive compression and tolerate noisier templates. Production caps the noise and pays the storage. Some customers run high-cardinality logging from legacy apps; others run carefully structured loggers. A backend that bakes one trade-off into the algorithm is rigid and harder to adopt; a backend that lets users tune the trade-off within a guaranteed safety net is exactly Ourios’ thesis-shaped use case.

2.2 But the safety net is the product

CLAUDE.md §1 lists what Ourios is and is not. CLAUDE.md §3 lists the load-bearing invariants — strict thresholds, no unbounded params, bit-identical reconstruction, WAL-before-ack, schema migrations through RFC, single-source-of-truth in object storage, multi-tenancy from day one. Each of those is the answer to a specific failure mode (silent template merges, cardinality blow-ups, lossy reconstruction, lost acked data, …). If any of them is configurable per tenant, the product becomes configurable per tenant: query semantics, audit trail, storage guarantees all vary based on a knob a future operator forgot they flipped. The cognitive surface alone is a hazard.

2.3 Why pin this in an RFC

The boundary is a recurring question (it has already come up in maintainer discussion 2026-05-18; see docs/roadmap.md §5 for the Perses-integration variant of the same instinct). Pinning the two-class model now means:

  • New PRs that propose a tunable can be reviewed against a written rule rather than a half-remembered convention.
  • Future RFCs that want to break an invariant know they need a meta: RFC (per CLAUDE.md §6.2 precedent), not a runtime toggle.
  • Contributors reading the MinerConfig rustdoc see the category of each knob, not just its type.

3. Proposed design

3.1 Two-class model

Every operator-visible knob is exactly one of:

  • Tunable. Configurable globally; overridable per tenant. Validated at process startup; tenants whose override fails validation never serve traffic (RFC 0001 §3.2.2 already pins this contract for param_byte_limit; this RFC generalises it to all tunables).
  • Invariant. Not configurable. The same value applies to every tenant. Encoded as an algorithmic property of the code, not a field on MinerConfig. A change requires an RFC against CLAUDE.md §3; a waiver requires a meta: RFC.

There is no third category. A “default but overridable in production” knob is a tunable; a “default for now, may make configurable later” knob is an invariant — configurability is opt-in, never an implicit consequence of “we exposed a field.”

3.2 The current tunables (four)

These are the knobs MinerConfig exposes, with the current defaults and the RFC §3 invariant each lives inside:

TunableDefaultValidated rangeInside invariant
similarity_threshold0.7 (RFC 0001 §3.1.1)(0, 1]§3.1 — strict-by-default, RFC required to change the default below 0.7
similarity_floor0.4 (RFC 0001 §6.3)(0, similarity_threshold]§3.1 — bounds the §6.3 lossy zone; body retention in that zone is invariant
prefix_depth2 (Drain paper §3.2)0..=8 (RFC 0001 §6.1 — “configurable cap of ~8 is the realistic ceiling”)§3.1 — affects tree quality, not safety
param_byte_limit256 (RFC 0001 §3.2.1)1..=1024 (PARAM_BYTE_LIMIT_CEILING, RFC 0001 §3.2.2)§3.2 — bounds cardinality; overflow spilling is invariant

The §3 invariant column is load-bearing: a tunable that walks outside its validated range is rejected at startup, not mapped to a clamped value, because clamping silently moves a tenant onto a trade-off point the operator didn’t pick.

3.3 The invariants (not tunable)

These come from CLAUDE.md §3 and RFC 0001 §6.1 / §6.4 / §6.6 — they’re enforced in code, not exposed as fields:

  • Widening fires on every Fixed mismatch with a TemplateWidened audit event (§6.4). There is no allow_widening toggle; turning off widening means turning off the §3.1 audit signal and the miner’s compression story together. If a tenant doesn’t want template merging, they shouldn’t use a template-mining backend.
  • severity_number and scope_name are part of the §6.1 template-key composition. There is no respect_severity toggle; merging INFO and ERROR "user logged in" records is hazard H1.4 by construction.
  • Body is retained on every §6.3 lossy-zone and parse-failure attach. There is no LossyMode::Aggressive toggle; CLAUDE.md §3.1 reads “MUST retain the original body. No exceptions.”
  • Reconstruction is bit-identical on every record with lossy_flag = false. There is no accept_lossy_reconstruction toggle; CLAUDE.md §3.3 reads “rendering … must equal the original line byte for byte, or the line must be flagged lossy.”
  • Mining is per-tenant. There is no enable_cross_tenant_dedup toggle; CLAUDE.md §3.7 reads “every code path that touches data takes a tenant ID.”

The list is closed in the sense that any new knob that touches one of these areas is an invariant proposal, not a tunable proposal — the PR adding it goes through the §6 RFC process, not review.

3.4 Per-tenant override mechanism

MinerConfig is Clone + Copy + 'static and its docstring already says “per-tenant miner configuration.” The cluster holds a cluster default plus an optional per-tenant override; overrides are seeded before the tenant is first observed (or default-resolved at lazy TenantState allocation when no override exists). The algorithm code reads &MinerConfig from TenantState on every ingest — no global flag, no implicit “current tenant.”

Implementation detail (specified in the follow-up PR, not this RFC): seeding API on MinerCluster is with_tenant_config( tenant_id, config) or equivalent; the lookup is state.config inside the per-tenant store the cluster already maintains. No hot-path overhead beyond the existing &self.config deref.

3.5 Escalation path

If a future RFC proposes promoting an invariant to a tunable, the escalation is:

  1. A meta: RFC against CLAUDE.md §3 explaining why the invariant should no longer be load-bearing. Majority maintainer approval (the precedent is CLAUDE.md §6.2’s 2026-05-13 amendment).
  2. Only after the meta: RFC accepts does the implementation RFC propose the MinerConfig field and the validation bounds.

Going the other direction — promoting a tunable to an invariant — follows the same path: the meta: RFC justifies the loss of flexibility, the implementation RFC removes the field.

This is the only path. A PR that adds a “small, just-for-now” field that touches an invariant area is rejected.

4. Alternatives considered

4.1 Single flat config bag

Stuff everything (tunables + algorithmic constants) into one Config struct with no internal classification. Rejected: the cognitive surface concern in §2.2 — readers can’t see at a glance which fields are safe to override. Future PRs that add knobs have no anchored rule to be reviewed against.

4.2 Inline classification on each field via a marker trait

Tag each field with Tunable or Invariant via a Rust trait. Rejected: invariants aren’t fields at all — they’re algorithmic properties (widening fires, severity participates in the key, body retains). Marking them as fields-with-a-trait would imply the field is the source of truth, which it isn’t. The closed-set rustdoc in §3.2 / §3.3 is a stronger contract than a marker.

4.3 A DrainConfig separate from MinerConfig

External LLM proposal 2026-05-18 (Grok session — link in maintainer’s memory under reference_grok-design-conversations). Rejected: MinerConfig already exists and already covers three of the four tunables. A second config type duplicates the validation surface, splits the per-tenant override mechanism, and introduces a new boundary type to maintain. The naming convention “<subsystem>Config is the tunables surface, invariants live in code” is the simpler shape.

4.4 RFC the implementation, not the policy

Skip this RFC; let the implementation PR add prefix_depth to MinerConfig. Rejected: the boundary keeps coming up (docs/roadmap.md §5 Perses row, Grok DrainConfig, future CRD proposals); a one-shot implementation PR doesn’t give those recurrences an anchor to be reviewed against. The RFC is the artifact, the PR is the action.

5. Acceptance criteria

Scenario RFC0004.1 — Every tunable validates at startup

  • Given a MinerConfig constructed via try_new_full with a value outside the §3.2 ranges for any field
  • When the constructor is called
  • Then it returns Err(MinerConfigError::*) naming the offending field
  • And no MinerConfig instance is produced

Scenario RFC0004.2 — Per-tenant override is honoured

  • Given a MinerCluster with a default MinerConfig and a per-tenant override for tenant T that differs from the default in at least one tunable
  • When tenant T ingests a line that exercises the differing knob’s decision boundary
  • Then the cluster’s behaviour matches the per-tenant override, not the default

Scenario RFC0004.3 — No invariant-breaking field exists

  • Given the MinerConfig type as defined by this RFC
  • When cargo doc is rendered or the type is grep’d in CI
  • Then there is no allow_widening, respect_severity, lossy_mode, enable_cross_tenant_dedup, or accept_lossy_reconstruction field — adding one is a compile-time visible change that fails this scenario
  • And the implementation PR adds a test that pins the tunable-set against this RFC

6. Testing strategy

  • RFC0004.1 — exhaustive unit tests on try_new_full per failure variant (one test per MinerConfigError arm). Already partially in place; the follow-up implementation PR adds the PrefixDepthTooLarge variant + test.
  • RFC0004.2 — integration test in crates/ourios-miner/tests/ ingesting the same line through two tenants with different similarity_thresholds and asserting different template-allocation outcomes.
  • RFC0004.3 — a “tunable-set pin” test that uses a match against MinerConfig’s public fields (exhaustive on a struct pattern); adding a new field forces the test author to think through which side of the boundary it sits on, and reviewers see the change as part of the RFC against §3.

7. Open questions

  • Should the per-tenant override mechanism allow dynamic reconfiguration (operator API at runtime), or only at startup? RFC defers to the implementation PR’s preference; current proposal is startup-only because TenantState is allocated lazily and config is captured at allocation.
  • Does the documentation route stop at MinerConfig’s rustdoc, or does it also need a page under docs/architecture/? Defer until the implementation PR lands.

8. References

  • CLAUDE.md §1 (project charter), §3 (invariants), §3.7 (multi-tenancy from day one), §5.1 (RFC process), §6.2 (tests as specifications, 2026-05-13 meta: amendment).
  • RFC 0001 §3.1.1 (similarity_threshold default), §3.2.1 (param_byte_limit default), §3.2.2 (startup rejection contract), §6.1 (template-key composition, prefix-depth cap), §6.3 (three-zone model + floor default), §6.4 (widening + audit), §6.6 (reconstruction).
  • docs/roadmap.md §5 (deliberately-out-of-MVP table — Perses row is a related “is/is-not” discussion).
  • docs/hazards.md H1 (silent merges), H2 (cardinality blow-up), H7 (reconstruction).
  • Drain paper §3.2 (prefix tree, prefix-depth convention).

RFC 0005 — Parquet storage


rfc: 0005 title: Parquet storage — schema, writer, reader, audit stream status: green author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-05-19 supersedes: — superseded-by: —

RFC 0005 — Parquet storage: schema, writer, reader, audit stream

Status note. green (2026-06-15) — every RFC0005 §5 acceptance criterion has a live, passing test. The prior drafted label was stale: the storage layer (schema, writer, reader, audit stream) landed early (PR #41 + the PR-D..G ourios-parquet series), and the ladder label was never advanced; this flip records reality. Scenario → test: .1 round-trip of every §3.2 column (rfc0005_1_*), .2/.3/.4 missing-OPTIONAL / unknown-column / missing-REQUIRED reader tolerance (rfc0005_2/3/4_*), .5 partition layout incl. non-ASCII tenant (rfc0005_5_*), .6 row-group size inside the H4 band (rfc0005_6_*, see below), .7 audit as a separate file series (rfc0005_7_*), .8 no body/params dictionary (rfc0005_8_*), .9 unknown ParamTypeUnknown (rfc0005_9_*), .10 schema is greppable / immutable (rfc0005_10_*), .11 row-vs-path validation on data + audit (rfc0005_11_*), .12 compaction audit round-trip (rfc0005_12_*), .13 effective-timestamp fallback (rfc0005_13_*, parquet + querier), .14 alias audit events back the v1 map (rfc0005_14_*).

RFC0005.6 is an #[ignore]d heavyweight test (tests/sizing.rs): it pushes >256 MiB through the production writer and asserts every non-final row group’s uncompressed total_byte_size ∈ [128 MiB, 1 GiB] per §3.5 / H4. Per §6 it is not run by CI (the project has no schedule: trigger — §7 open question); verify it manually with cargo test -p ourios-parquet --ignored (~7 s dev / ~1 s release).

Open for follow-up (§7, non-gating): compression-codec tuning (pending A1), bloom-filter FPR (pending B2), audit-event retention, and a scheduled-CI cadence for the slow sizing test.

1. Summary

Pins the on-disk Parquet contract that the ourios-parquet crate implements. The contract has four parts: (a) the data-file schema — a column-by-column mapping of RFC 0001 §6.1’s record schema (the planned MinedRecord Rust type — see §3.0) onto Parquet types, with tenant_id and time as Hive-style partition keys; (b) the audit-event file schema — a parallel file series carrying the TemplateWidened / TemplateTypeExpanded / TemplateWideningRejectedDegenerate records named in RFC 0001 §6.4; (c) the writer’s row-group / file sizing, compression codec, and encoding policy, all anchored to docs/hazards.md H4 and the CLAUDE.md §3.2 cardinality invariant; (d) the reader’s forward-compatibility contract (unknown columns ignored, missing columns surface as documented defaults). Together these are the §3.5 schema baseline: every column added after this RFC lands goes through an incremental amendment, every column removed requires the §3.5 migration path.

2. Motivation

2.1 Phase 2 needs an RFC, not a stub crate

docs/roadmap.md §4 opens Phase 2 with one capability — “mined records become Parquet files.” CLAUDE.md §3.5 reads “All schema changes go through the schema RFC process,” and docs/rfcs/README.md lists the on-disk Parquet schema in the “RFC required” set. A ourios-parquet crate that lands without a schema RFC immediately takes a schema commitment without going through the gate the project’s own rules require. RFC 0005 is that gate.

2.2 The schema is the contract with future data

Operators who run Ourios accrue Parquet files. A subsequent PR that adds a non-OPTIONAL column, renames a column, or changes a column’s type breaks every reader that opens an older file — and breaks every emitter against a deployment that hasn’t upgraded. Treating the schema as a written contract from PR-one forward prevents the silent format drift that turns a working backend into “redeploy and lose six months of logs.” It is also what makes CLAUDE.md §3.6 (“object storage is the source of truth”) durable: the truth has to be readable a year from now by code we haven’t written.

2.3 The Parquet pillar earns its compression here

Pillar 1 in CLAUDE.md §2 (“Parquet as the on-disk format”) is load-bearing for the thesis-gate A1 compression ratio. The encoding decisions in this RFC — which columns dictionary-encode, which carry bloom filters, which page indexes are enabled, what the row-group target is, how body is not dictionary-encoded because the CLAUDE.md §3.2 cardinality invariant forbids it — are where A1’s 50–200× promise gets paid. Pinning them in an RFC means those decisions are reviewable independently of the writer’s implementation and stable across PRs that touch the writer for unrelated reasons.

2.4 Why this is one RFC, not three

A natural split would be RFC 0005 (schema), RFC 0006 (writer), RFC 0007 (reader, audit). Rejected: the schema, the writer’s sizing/encoding policy, and the reader’s forward-compatibility contract are co-designed. Splitting them into three RFCs optimises for short documents but loses the cross-cutting constraints (e.g. “no dictionary on body” is a schema rule and a writer rule and a reader expectation). The RFC 0001 §6.8 telemetry surface and the eventual compaction policy are real post-MVP concerns and get their own RFCs.

3. Proposed design

3.0 Terminology note

This RFC uses MinedRecord as the planned Rust type name for the per-row record the miner emits, the same shape RFC 0001 §6.1 specifies but without yet naming a type. The §6.1 amendment uses “the record” / “the miner emits one record”; this RFC chooses MinedRecord for the type that backs the writer’s input and the reader’s output, and uses it consistently below. A follow-on PR to RFC 0001 may adopt the same name in §6.1; until then, treat the two terms as synonyms.

3.1 Scope and what this RFC pins

This RFC pins:

  • The Parquet logical schema (column names, types, repetition, nullability) for both the data-file series and the audit-event file series.
  • The on-disk partition layout (Hive-style: tenant_id=…/ year=…/month=…/day=…/hour=…/).
  • The writer’s row-group target, file-size target, compression codec, and per-column encoding policy (dictionary, page index, bloom filter).
  • The reader’s forward- and backward-compatibility contract.
  • The AnyValue encoding rule for OTLP attribute and body payloads.
  • The schema-evolution rules anchored to CLAUDE.md §3.5.

This RFC does not pin:

  • Background compaction (deferred per docs/roadmap.md §4 Phase 2 “Out of MVP scope, parked here” — a separate RFC after MVP).
  • Query-engine plumbing (DataFusion table provider registration, predicate-pushdown wiring) — that’s Phase 3 / RFC 0002 territory.
  • The wire-format receiver (gRPC / HTTP) — RFC 0003.
  • The body_shape_fingerprint and template_fingerprint reserved extensions named in RFC 0001 §6.1 — those gate on “we have a concrete consumer.”
  • A typed Parquet representation of AnyValue’s array / kvlist branches — see §3.3 (rejected for MVP; future RFC).

3.2 Data-file Parquet schema

The mapping below is the normative column set. Field order is the Parquet schema’s declared order; readers MUST address columns by name, not by ordinal.

tenant_id is row-level, the partition path is an index over it. tenant_id is a REQUIRED row-level column in every data file, listed in the schema table below. It is also replicated as the leading Hive partition key (§3.4) so DataFusion / Arrow can prune by tenant without opening files. Per docs/talks/0001-template-miner.md (“tenant_id is present on every row, not on every file … we never trust the file to tell us the tenant; we trust the row”) the row-level value is authoritative: the reader resolves tenant_id from the row, treats the partition path as a partition-pruning index, and errors on row-vs-path mismatch (§3.9). The time-bucket parts (year, month, day, hour) are pure-partition pseudo- columns derived from the effective timestamp (§3.4; equal to time_unix_nano whenever that is non-zero) rendered as UTC; they are not stored row-level and their schema-evolution contract follows §3.4 (the partition layout), not §3.8 (the row schema).

Identity (RFC 0001 §6.1 “Identity and partitioning”):

ColumnParquet logical typePhysical typeRepetitionNotes
tenant_idSTRINGBYTE_ARRAYREQUIREDAuthoritative tenant identifier; also replicated in the partition path (§3.4) for predicate-pushdown convenience. Row value wins on row-vs-path mismatch per §3.9
template_idINTEGER(64, signed=false)INT64REQUIREDMonotonic; bloom-filter coverage (§3.6)
template_versionINTEGER(32, signed=false)INT32REQUIREDStarts at 1; bumped on RFC 0001 §6.4 events

OTLP-derived columns (RFC 0001 §6.1 “OTLP-derived columns”):

ColumnParquet logical typePhysical typeRepetitionNotes
time_unix_nanoTIMESTAMP(NANOS, isAdjustedToUTC=true)INT64REQUIRED0 = unknown (OTLP convention); preserved verbatim from the wire (RFC 0001 scenario RFC0001.10). The time partition key derives from the effective timestamp (§3.4; equal to this column whenever it is non-zero). See “u64 → i64 overflow contract” below
observed_time_unix_nanoTIMESTAMP(NANOS, isAdjustedToUTC=true)INT64OPTIONALSame overflow contract as time_unix_nano
effective_time_unix_nanoTIMESTAMP(NANOS, isAdjustedToUTC=true)INT64OPTIONALWriter-derived (amendment 2026-06-11, §3.8 rule 1): time_unix_nano when non-zero, else observed_time_unix_nano, else 0. Drives the time partition key (§3.4) and the DSL time window (RFC 0002 §6.2). Never overwrites the wire time_unix_nano. Absent-column default is the row’s time_unix_nano (§3.9), not None
severity_numberINTEGER(8, signed=false)INT32REQUIREDOTLP SeverityNumber 0..24; part of template key
severity_textSTRINGBYTE_ARRAYOPTIONAL
scope_nameSTRINGBYTE_ARRAYOPTIONALPart of template key
scope_versionSTRINGBYTE_ARRAYOPTIONAL
attributesSTRING (canonical JSON)BYTE_ARRAYREQUIREDUTF-8 canonical JSON per §3.3 (mirrors RFC 0001’s Vec<KeyValue> — always present, possibly empty). For a record with no attributes, the writer emits the canonical empty array [] (two bytes — repetitive across no-attribute records so ZSTD compression collapses it). NULL is not a valid encoding; the round-trip rule is Vec::new()[]
dropped_attributes_countINTEGER(32, signed=false)INT32REQUIREDMostly zero
resource_attributesSTRING (canonical JSON)BYTE_ARRAYREQUIREDSame contract as attributes: REQUIRED, UTF-8 canonical JSON, empty Vec[], NULL not valid
trace_id(no logical type)FIXED_LEN_BYTE_ARRAY(16)OPTIONALOTLP / W3C Trace Context trace_id is 16 opaque bytes — not an RFC 4122 UUID. Parquet’s UUID logical type is deliberately not applied: downstream consumers (Arrow, DataFusion, ParquetTools) treat it as a typed UUID with RFC 4122 validation and formatting, which would misrepresent OTLP’s opaque-byte semantics
span_id(no logical type)FIXED_LEN_BYTE_ARRAY(8)OPTIONALSame opaque-byte contract as trace_id; no Parquet logical type exists for 8-byte opaque ids
flagsINTEGER(32, signed=false)INT32REQUIREDLower 8 bits = W3C trace flags
event_nameSTRINGBYTE_ARRAYOPTIONAL

Amendment 2026-06-11 — effective_time_unix_nano (derived event-or-observed timestamp). Measured across the OTel-Demo corpora (v5: 205,155 records; v6: 202,484), ~15 % of records carry timeUnixNano absent/0 — and 100 % of those carry observedTimeUnixNano (verified by sampling). Under the pre-amendment contract those records are unaddressable by time: the DSL window filters time_unix_nano, so they fall outside every real query window, and the bench’s zero-timestamp guard correctly refuses such corpora — blocking B1, the last unmeasured thesis gate. The OTLP logs data model anticipates exactly this case. Its Timestamp field definition reads:

Time when the event occurred measured by the origin clock, i.e. the time at the source. This field is optional, it may be missing if the source timestamp is unknown.

and its ObservedTimestamp field definition reads:

Time when the event was observed by the collection system. […] This field SHOULD be set once the event is observed by OpenTelemetry.

For converting OpenTelemetry log data to formats that support only one timestamp or when receiving OpenTelemetry log data by recipients that support only one timestamp internally the following logic is recommended:

  • Use Timestamp if it is present, otherwise use ObservedTimestamp.

This amendment adopts that recommendation as a derived, additive column, per the maintainer decision of 2026-06-11 (option 1: ingest-side, derived — not overwriting the wire value):

  1. Derivation rule. effective_time_unix_nano := time_unix_nano if time_unix_nano != 0 else observed_time_unix_nano.unwrap_or(0). The Parquet writer computes it from the row’s two existing timestamp fields when serialising — the same rule the §3.4 partition derivation already runs, now stored so queries can use it. MinedRecord (RFC 0001 §6.1) is unchanged; no new miner or receiver field exists, and the column is therefore outside the RFC0005.1 round-trip surface (derivable, not carried — its own assertions live in RFC0005.13). Both source fields are already covered by the §3.2 u64i64 overflow contract, so the derived value is always in-range.
  2. Derived, never overwriting. The wire time_unix_nano is stored verbatim, including 0 — RFC 0001 scenario RFC0001.10 (verbatim preservation) is explicitly intact.
  3. Storage. A new OPTIONAL column per §3.8 rule 1 (additive; old files lack it, the §3.9 default applies). Post-amendment writers always populate it (required-by-convention; 0 means genuinely timeless, mirroring the time_unix_nano sentinel); NULL appears only in pre-amendment files. The redundancy costs ≈ 8 B/row before encoding and almost always equals time_unix_nano, so DELTA_BINARY_PACKED + ZSTD collapse it (§3.6). A real column is what makes the window predicate prunable: a query-time fallback expression (CASE WHEN time_unix_nano != 0 THEN time_unix_nano ELSE observed_time_unix_nano ENDtime_unix_nano is REQUIRED with 0 as the unknown sentinel, so a plain coalesce would never fall back) would defeat row-group min/max pruning, which is the B1 mechanism.
  4. Partitioning. The §3.4 time-fallback derivation is this rule; the partition tuple and the stored column never disagree. Records with neither timestamp still land under the 1970 epoch partition exactly as before — only genuinely timeless records remain there.
  5. Query semantics. The DSL time window (range(...)) filters effective_time_unix_nano (RFC 0002 §6.2, amended the same date). The bare ts field still resolves to time_unix_nano, the verbatim wire value.
  6. Old-file read rule (the migration story). Files written before this amendment lack the column; the reader’s documented default (§3.9 rule 2) is effective := time_unix_nano — exactly the pre-amendment behaviour, so historical files keep answering time-window queries identically. No file rewrite is needed.
  7. Bench follow-up. The B1 zero-timestamp guard subsequently keys off the effective span — a code follow-up, not part of this amendment.

This resolves the measured v5/v6 corpus blocker. Acceptance is pinned by scenario RFC0005.13 (§5).

Body and miner-derived columns (RFC 0001 §6.1 “Body and miner-derived reconstruction”):

ColumnParquet logical typePhysical typeRepetitionNotes
body_kindINTEGER(8, signed=false)INT32REQUIRED0 = String, 1 = Structured
body(no logical type)BYTE_ARRAYOPTIONALOriginal bytes when retained per RFC 0001 §6.3 (lossy-zone retention) / RFC 0001 §6.5 (overflow forces retention); canonical-JSON AnyValue when body_kind = Structured; absent on clean-zone String rows. Intentionally no STRING logical type — the column carries raw bytes (potentially non-UTF-8 log lines or non-JSON binary), not text
paramsLIST<STRUCT<type_tag: INT32, value: BYTE_ARRAY>>as schemaREQUIREDAlways written (mirrors RFC 0001’s Vec<Param>); the list is empty (zero elements) when body_kind = Structured. NULL is not a valid encoding
separatorsLIST<BYTE_ARRAY>as schemaREQUIREDAlways written (mirrors RFC 0001’s Vec<Separator>); tokens.len() + 1 elements when body_kind = String, zero elements when body_kind = Structured. NULL is not a valid encoding
confidenceFLOATFLOATREQUIRED1.0 sentinel when body_kind = Structured
lossy_flagBOOLEANBOOLEANREQUIREDAlways false when body_kind = Structured

params’ nested struct uses the standard Parquet 3-level LIST encoding (list.element.<field>); separators uses the same 3-level shape with BYTE_ARRAY elements. The params.type_tag integer enum is 0..=7 matching RFC 0001’s ParamType ordering: IP, UUID, NUM, HEX, TS, PATH, STR, OVERFLOW. Adding a new variant is a §3.5 schema amendment (additive, but readers MUST know how to surface unknown variants — see §3.9).

u64i64 overflow contract for nanosecond timestamps. OTLP defines time_unix_nano and observed_time_unix_nano as uint64 nanoseconds-since-Unix-epoch; Parquet’s TIMESTAMP(NANOS) is backed by INT64. The 63-bit physical range tops out at i64::MAX ≈ 2^63 − 1 ns, which corresponds to 2262-04-11T23:47:16.854775807Z UTC. The writer rejects any record whose time_unix_nano or observed_time_unix_nano exceeds i64::MAX with a hard error naming the offending record and the offending field; no silent saturation, no wrap- around to negative values. The reader, conversely, never encounters out-of-range values (the file format itself can’t hold them), so reads are infallible on this axis. Operators running Ourios past year 2262 will need a schema migration (per §3.5 / §3.8) to either widen the physical type or re-base the epoch; that’s a future-RFC concern, not a post-MVP gap to plug here.

3.3 AnyValue encoding rule

OTLP’s LogRecord.attributes and resource_attributes are Vec<KeyValue> where each value is an AnyValue discriminated union (string | bool | int | double | bytes | array | kvlist). Recursive (array, kvlist) variants do not map cleanly onto Parquet’s flat-nested schema — Parquet supports LIST and STRUCT but the recursion depth has to be unrolled into the schema declaration, which means no fixed-depth schema can faithfully describe arbitrary AnyValue trees.

Amendment 2026-06-09 (no canonical OTLP JSON exists). This section previously called the encoding “OTLP-canonical JSON,” implying a spec-defined canonical form. Per an OTel-spec answer (no canonical OTLP JSON; OTLP requires no lossless translation), RFC 0001 §6.1 now frames the rule as the Ourios canonical body encoding — an Ourios-local deterministic proto3-JSON convention, not an OTLP conformance point. This section is reworded to defer to that rule and to drop the “canonical OTLP JSON” overclaim. No schema bytes and no status change.

Decision. attributes, resource_attributes, and the body column when body_kind = Structured are stored as a single BYTE_ARRAY carrying the Ourios canonical body encoding — RFC 0001 §6.1 (“The Ourios canonical body encoding”) is the single source of truth for the rule; this section does not restate it. In short it is a proto3-JSON form (lowerCamelCase fields, int64/uint64 as decimal strings, bytes as base64, kvlist/array order preserved — not sorted), and it is an Ourios-local deterministic convention, not an OTLP-mandated canonical form (OTLP defines no canonical JSON). The same rule applies to all three columns so operators don’t have to remember three encodings.

The rationale is on three legs:

  1. Faithfulness. The encoding is bidirectional — stored_bytes ↔ AnyValue round-trips byte-deterministically (the normative [§3.3] reconstruction guarantee for the structured branch). This is an Ourios guarantee delivered by RFC 0001 §6.1’s encoder, not an OTLP lossless promise (OTLP makes none).
  2. Schema simplicity. A single BYTE_ARRAY column versus a recursive STRUCT<string_value, int_value, ..., array_value: LIST<...>, kvlist_value: LIST<STRUCT<...>>> pseudo-schema with unrolled recursion depth.
  3. Query consumer absence. Phase 3’s thesis-gate B1/B2 queries are predicate-pushdown on template_id, tenant_id, and time_unix_nano — none of those require typed AnyValue predicates. The typed-attribute query path is a future RFC gated on a concrete consumer.

A reserved future amendment may add a parallel typed-attribute column set (likely a flattened attributes_str: MAP<STRING, STRING> for the common string-valued case, leaving complex values in the JSON column). The gate is “we have a concrete consumer,” not “it might be useful.”

Amendment 2026-07-03 (the consumer arrived). The reservation above is discharged by RFC 0022 (queryable attribute columns): the RFC 0002 DSL’s service / resource.<key> / attr.<key> predicates are the concrete consumer (#147). RFC 0022 chooses per-key promoted OPTIONAL columns over the MAP sketch (a map’s statistics and bloom filters are not key-scoped, so it cannot prune — see RFC 0022 §4) and extends the §3.6 encodings table when it lands. This section’s JSON columns remain the source of truth; no schema bytes change before RFC 0022’s green slices land (at red only failing stubs exist).

3.4 Partition layout on disk

Data files live at:

<bucket>/data/tenant_id=<tenant_id>/year=YYYY/month=MM/day=DD/hour=HH/<flush_uuid>.parquet

Audit-event files live at:

<bucket>/audit/tenant_id=<tenant_id>/year=YYYY/month=MM/day=DD/<flush_uuid>.parquet

The partition path segment is tenant_id= (not tenant=) so the Hive-style partition-discovery convention (column name = path segment key) resolves it to the same column name the row-level schema declares; the reader’s row-vs-path validation (§3.9) compares values across the two surfaces unambiguously.

Where:

  • <tenant_id> is the percent-encoded TenantId per RFC 3986 §2.1, with two project-specific overrides:
    • The input is the TenantId’s UTF-8 byte sequence (the TenantId newtype wraps a Rust String, which is already UTF-8). No Unicode normalisation is applied before encoding — the bytes are taken verbatim. This is deterministic and independent of the host’s locale.
    • The unreserved set (A-Za-z0-9, -, _, ., ~) is passed through unchanged. Every other byte is percent-encoded (%XX with upper-case hex digits). In particular / (path separator), = (partition key/value delimiter), and % (the escape introducer) are always escaped, regardless of whether RFC 3986 would treat them as reserved or unreserved in another context.
    • Decoding is the inverse; partition values that contain a malformed percent escape (e.g. %XY with non-hex digits) are a hard read error. Both writer and reader use this exact algorithm; the RFC0005.5 acceptance criterion’s non-ASCII sub-test pins it.
  • year / month / day / hour are derived from the effective timestamp (the next bullet; equal to time_unix_nano whenever that is non-zero) rendered as UTC. Audit-event partitioning stops at day=DD because audit volume is far lower than data volume; an hour-level partition for audit would produce many tiny files for no win.
  • time_unix_nano = 0 (OTLP “unknown” sentinel). The writer derives the partition tuple by first checking time_unix_nano; if it is 0, the writer falls back to observed_time_unix_nano. This derivation is the effective timestamp of the 2026-06-11 §3.2 amendment; the writer stores the same value in the effective_time_unix_nano column, so the partition tuple and the stored column never disagree. If observed_time_unix_nano is also absent or 0, the record is placed under the epoch partition year=1970/month=01/day=01/hour=00/ — operators see “unknown-time records cluster under 1970-01-01” as the documented signal, and an emitter-side investigation is the proper response. Rejecting the record was considered and rejected: §3.5 records are end-of-pipeline (the wire-decode receiver already accepted them), and a hard-reject here would silently drop data the WAL already acknowledged. Row-vs-path validation (§3.9) uses the same derivation rule, so a row at time_unix_nano = 0 placed under the 1970 partition validates cleanly.
  • <flush_uuid> is the writer’s flush identifier, pinned to UUIDv7 (RFC 9562). UUIDv7 places a millisecond-precision Unix timestamp in its high bits, so files in a partition sort naturally by creation time when listed lexicographically. This is normative — the writer MUST emit UUIDv7. Operators inspecting a bucket can rely on sort-order = creation-order for tooling like “show me the latest file in this partition.”

This is the production layout. The MVP corpus runner (ourios-bench in Phase 3) is allowed to emit all records to a single file under a degenerate partition path (tenant_id=corpus/year=2026/month=04/day=02/hour=10/) because corpus runs are bounded and producing 24 small files would distract from the thesis-gate measurements. The H4 file-sizing target (§3.5) is enforced on the production path; the corpus path is exempt.

3.5 Row group, file size, compression codec

Anchored to docs/hazards.md H4 and the small-file-problem detection threshold (file count must grow sub-linearly with bytes ingested):

  • Row-group size target. 128 MiB – 1 GiB uncompressed bytes per row group (binary units; the H4 target is written as “128 MB – 1 GB” but the operational detection threshold is in MiB, and Parquet byte counts in metadata are unprefixed binary bytes — RFC 0005 standardises on MiB/GiB throughout to avoid the ambiguity). The writer flushes a row group when its in- memory buffer crosses 128 MiB; row groups never exceed 1 GiB (the next row starts a new row group). Below 128 MiB only on the final row group of a file.
  • File size target. 256 MiB – 2 GiB compressed bytes post-compaction. The writer’s job is to land at the bottom of this range or below on its own (1024 MiB target uncompressed → typical 3–8× compression → ~128–340 MiB compressed file); compaction is deferred.
  • Compression codec. ZSTD level 3 for every column. ZSTD-3 is the Apache Arrow / DataFusion default and gives the best ratio-vs-throughput balance Ourios cares about; the thesis-gate A1 measurements will test whether the choice holds. Compression is orthogonal to per-column encoding (dictionary, RLE for booleans, RLE-encoded repetition / definition levels in LIST columns — all standard Parquet shapes that apply regardless of the chosen compression codec); §3.6 specifies the encoding policy.
  • Page size target. Default 1 MiB pages (Arrow default). Bloom filters and page index live on a per-column basis (§3.6).

The targets are floors and ceilings, not exact numbers. A writer flush forced by a time-based segment rotation (e.g. producing the audit-event file at end-of-day) may emit a small-row-group file; that’s an acknowledged corner case the compaction PR will sweep up. Steady-state production traffic must produce files inside the §3.5 range; the H4 detection metric (“fewer than 5 % of files below 128 MiB at steady state”) is the operational check.

3.6 Encoding policy

Per-column encoding decisions, anchored to query patterns (thesis-gate B1/B2) and the CLAUDE.md §3.2 cardinality invariant:

ColumnDictionaryPage indexBloom filterRationale
tenant_idyesnonoExactly one distinct value per file in valid data (§3.4 places each file under a single tenant_id=… partition, §3.9 errors on row-vs-path mismatch); dictionary encoding collapses the column to a one-entry dictionary plus an indexed RLE stream
template_idyesyesyesB2 (where template_id = X) is bloom-friendly; high cardinality but small relative to row count
template_versionyesyesnoAlways small per template
time_unix_nanonoyesnoDELTA_BINARY_PACKED Parquet encoding (the writer’s default for monotonic INT64 timestamps) plus ZSTD compression; min/max per page is what the window predicate prunes on in pre-amendment files (the §3.9 absent-column fallback) — effective_time_unix_nano below is the primary window column since the 2026-06-11 amendment
observed_time_unix_nanonoyesnoSame encoding/compression as time_unix_nano; the observation timeline is also broadly monotonic, so delta encoding pays
effective_time_unix_nanonoyesnoSame encoding/compression as time_unix_nano, which it almost always equals — DELTA_BINARY_PACKED collapses the redundancy. Min/max per page is what makes the B1 time-window predicate prunable on this column (amendment 2026-06-11)
severity_numberyesyesno0..24 — dict alone is enough
severity_textyesyesnoBounded set in practice
scope_nameyesyesnoBounded per deployment
scope_versionyesyesnoBounded per deployment
attributesnononoJSON BYTE_ARRAY, high entropy, dict would balloon
resource_attributesyesnonoRepetitive across rows of one tenant; dict pays
trace_idnoyesyesNear-random ids defeat min/max pruning, so dict loses and the page index’s column-index half is inert — it stays enabled for the offset index, which page-selective reads under filter pushdown need to fetch just the matched rows’ pages; the bloom is what makes the exact-id lookup prunable at all (amendment 2026-07-12, below)
span_idnoyesyesSame
flagsyesyesnoBounded
event_nameyesyesnoBounded
body_kindyesyesnoTwo values
bodynononoCLAUDE.md §3.2 invariant: bodies are unbounded by design. Dictionary encoding would balloon — overflow is the safety valve, dict is the failure mode
params (list values)nononoPer-row entropy too high
separators (list values)yesnonoAlmost always a single space — dict crushes it
confidencenoyesnoFloat, narrow range, page-index sufficient
lossy_flagn/ayesnoBoolean, RLE handles it
dropped_attributes_countyesyesnoAlmost always zero

Amendment (2026-07-12): bloom filters on trace_id and span_id. This table originally said “dict and bloom both lose” for the trace-context ids — right about dictionaries, measurably wrong about blooms. The two judgments conflate different costs: dictionary encoding loses because near-random values don’t repeat, but a bloom filter’s value is not compression — it is the ONLY pruning mechanism an exact-id lookup has, precisely because near-random ids defeat min/max statistics. RFC 0031 comparative run #12 (otel-demo-v8, 4.9 M records) measured the cost of the original decision: a 9-row trace lookup read 72,935,984 bytes — the trace_id column scanned corpus-wide. With blooms (run #14): 4,812,668 bytes, a 15.2× collapse, and the RFC 0031 L3 must-win passes at 21.9× storage-side / 514.6× processed-bytes against the reference system. Blooms are optional Parquet column-chunk metadata, not a schema element: files written without them remain readable, readers that don’t consult them are simply unaccelerated, and no migration exists to plan.

The body row is the only one bolded end to end (the lone bold cells elsewhere mark bloom decisions that carry their own rationale text): a writer that quietly enables dictionary encoding on body because Arrow’s default does so violates CLAUDE.md §3.2 (“Drain assumes parameters are short, variable bits. Reality: a params slot may capture an entire stack trace, request body, or base64 blob. Unbounded values destroy Parquet’s dictionary encoding and bloat files.”). The RFC 0001 §6.5 OVERFLOW marker is the design response in params; the body column is where retained originals land, and those are unbounded by construction.

3.7 Audit-event file schema

The audit stream carries the template events that RFC 0001 §6.4 names — TemplateWidened, TemplateTypeExpanded, TemplateWideningRejectedDegenerate — plus, per the 2026-06-03 amendment below, the Compaction event of RFC 0009 §3.6, and, per the 2026-06-12 amendment below, the alias_asserted / alias_retracted operator events of RFC 0001 §6.7, each with a kind tag and a timestamp. The contract from RFC 0001 §9 (“Cross-RFC contracts pending”) is fulfilled by this file series.

As in §3.2, tenant_id is a row-level REQUIRED column on the audit record (also replicated as the leading Hive partition key, §3.4); the time-bucket parts (year, month, day) are pure- partition pseudo-columns derived from timestamp. The reader’s row-vs-path validation (§3.9) applies identically here.

Event-kind mapping and dual-column storage. RFC 0001 §6.4 refers to these audit events by snake_case event_type strings; this RFC stores both an event_kind INT32 ordinal (compact, dictionary-encodes to a few bytes) and an event_type STRING column carrying the canonical string from the mapping table below (RFC 0001 §6.4 for the template kinds, RFC 0009 §3.6 for compaction). The string column is what RFC 0001 §9 names as the predicate-pushdown surface for the RFC 0001 §6.7 drift query; the ordinal is what the writer and reader use internally. Both columns are REQUIRED and the writer must keep them in sync per the mapping table — divergence is an implementation bug, not a degree of freedom. The normative mapping:

event_kind ordinalevent_type stringRust variantSource
0template_widenedTemplateWidenedRFC 0001 §6.4
1template_type_expandedTemplateTypeExpandedRFC 0001 §6.4
2template_widening_rejected_degenerateTemplateWideningRejectedDegenerateRFC 0001 §6.4
3compactionCompactionRFC 0009 §3.6 (amendment 2026-06-03)
4alias_assertedAliasAssertedRFC 0001 §6.7 (amendment 2026-06-12)
5alias_retractedAliasRetractedRFC 0001 §6.7 (amendment 2026-06-12)

Adding a new ordinal is a §3.8 additive amendment; the mapping table is the source of truth and a new ordinal lands as a new row plus a new event_type string in the same PR. Renumbering an existing ordinal or renaming an event_type string is forbidden in-place (§3.8 rule 3: column-type changes go through add-new-column / migrate / drop).

Amendment 2026-06-03 — compaction audit events. RFC 0009 §3.6 routes a compaction audit event through this same stream (the “nothing happens silently to stored data” stance applied to file lifecycle, CLAUDE.md §3.1). A compaction event shares the common envelope (tenant_id, timestamp, event_kind = 3, event_type = "compaction") but has no template identity (and leaves reason NULL — the facts live in the compaction_* columns). Two changes accommodate it, both backward-compatible:

  1. The template-specific columns (template_id, old_version, new_version, old_template, new_template, positions_widened, slots_expanded, triggering_line_hash) are relaxed to OPTIONAL (§3.8 rule 6). They stay required-by-convention for the template event kinds (0–2) — the writer MUST populate them there, enforced in code/tests, so the template-event contract is unchanged — and are NULL for compaction. Existing audit files keep their (non-null) values, so no data migration is needed.
  2. New OPTIONAL compaction_* columns (below) carry the file set / generation / row count (§3.8 rule 1). They are NULL for the template kinds.

The RFC 0009 §7 fork (structured reason vs additive columns) is resolved here in favour of explicit columns: they are first-class queryable columns where a JSON blob in reason would be opaque to the query engine. The low-cardinality scalars (compaction_partition, compaction_generation) support predicate-pushdown — row-group skipping via min/max, e.g. “which compaction committed generation N”. compaction_output_file and the compaction_input_files LIST are high-entropy UUID names: queryable first-class (equality / array-containment filters) but not stats-pushdown-indexed, consistent with their no-dictionary / no-index encoding policy below — still far better than being unparseable inside a reason blob.

Amendment 2026-06-12 — alias audit events (issue #148). RFC 0001 §6.7 (amendment 2026-06-07) routes operator alias assertions through this same stream and its §9 resolution hands the storage half to “the RFC 0005 line”. This amendment is that half: the events get a home here, and §3.7.1 below pins how the querier turns them into the per-tenant alias map in v1. Two new kinds, alias_asserted (4) and alias_retracted (5), join the mapping table (§3.8 rule 1 territory — the ordinals match the constants ourios-core::audit already pins). An alias event shares the common envelope (tenant_id, timestamp, event_kind, event_type) and carries the RFC 0001 §6.7 payload in new OPTIONAL alias_* columns (§3.8 rule 1), following the compaction amendment’s pattern of kind-prefixed first-class columns rather than overloading the template columns or packing a blob into reason:

  • alias_member_ids is a LIST<INTEGER(64, signed=false)>, not canonical JSON. The §3.3-style canonical-JSON Utf8 alternative was considered and rejected on the same grounds the 2026-06-03 amendment rejected a structured reason: a list of ids is first-class queryable (equality / array-containment — “which assertions ever touched template X”) where a JSON blob is opaque to the query engine, and the §3.7 precedent for set-valued payload fields of scalars is already LIST (positions_widened, compaction_input_files). Canonical JSON earns its keep only for nested values (attributes, the template token arrays); a flat id set is not one. Schema evolution is unaffected either way — the column is OPTIONAL per §3.8 rule 1, so old files simply lack it and read back as None.
  • representative_id gets its own column (alias_representative_id) rather than reusing template_id. template_id’s contract is “the leaf the event applies to”, and the 2026-06-03 convention pins the template columns as required-by-convention for kinds 0–2 / NULL otherwise; stretching that to “non-null for alias kinds too, with anchor semantics” would fork the column’s meaning by kind. The kind-prefixed column keeps each kind’s payload→column mapping uniform: every kind populates exactly its own prefix plus the envelope.
  • reason is reused, not duplicated: it is already the generic OPTIONAL justification/diagnostic column. For alias kinds it carries the operator-supplied justification (RFC 0001 §6.7, ≤ 256 B); the in-memory empty-string-when-none convention maps to NULL on disk (round-trip rule: "" ↔ NULL).

The semantic value of an alias row is the asserted set {alias_representative_id} ∪ alias_member_ids (RFC 0001 §6.7); the writer stores the event’s member_ids verbatim (no sort/dedup normalization — round-trip is exact) and consumers fold it as a set, so element order and duplicates carry no meaning. An empty list is valid and distinct from NULL (member_ids: vec![] on a single-id retraction ↔ empty list; NULL means “not an alias row”), mirroring the positions_widened empty-list convention. Alias rows leave every template-specific and compaction_* column NULL; conversely the alias_* columns are NULL for all other kinds and required-by-convention non-null for kinds 4–5 (alias_member_ids possibly empty, reason per the operator’s optional input) — the §3.8 rule 6 convention, writer-enforced and test-pinned (RFC0005.14).

Unknown-event_kind tolerance. Today’s AuditReader hard-errors on an ordinal outside the mapping table (AuditReaderError::UnknownEventKind), with a documented deferral of the catch-all decision “until a real new variant lands”. Kinds 4–5 are that variant, so the rule is now pinned: a reader encountering an event_kind ordinal above its known range MUST NOT fail the file — it surfaces the row as an opaque unknown-kind event (envelope only), the ParamType::Unknown / §3.9 discipline applied to the kind enum, so every future §3.8 ordinal addition stays non-breaking for readers. Tolerance is not semantics: a fold defined over named kinds (the §3.7.1 alias fold reads kinds 4–5; the RFC 0010 drift query filters event_type strings) ignores unknown kinds by construction, and a future kind that participates in an existing fold must amend that fold’s spec. For already-deployed readers (which still hard-error) the exposure is bounded by §3.8 rule 6’s version-together argument: rows with kinds 4–5 are written only by post-amendment writers, so no previously-deployed reader is expected to encounter them. The implementation slice for this amendment (issue #148) extends the reader’s ordinal match to kinds 4–5, lands the tolerance rule, and retires the writer’s interim AliasEventNotYetPersistable rejection.

The row-level audit columns are:

ColumnParquet logical typePhysical typeRepetitionNotes
tenant_idSTRINGBYTE_ARRAYREQUIREDSame contract as data-file tenant_id: row authoritative, replicated in partition path, mismatch → reader error
timestampTIMESTAMP(NANOS, isAdjustedToUTC=true)INT64REQUIREDCluster clock at emit time (matches RFC 0001 §6.4 timestamp)
event_kindINTEGER(8, signed=false)INT32REQUIREDOrdinal per the mapping table above
event_typeSTRINGBYTE_ARRAYREQUIREDCanonical snake_case string per the mapping table above (RFC 0001 §6.4 for template kinds; RFC 0009 §3.6 for compaction); predicate-pushdown surface for the RFC 0001 §6.7 drift query
template_idINTEGER(64, signed=false)INT64OPTIONAL†The leaf the event applies to
old_versionINTEGER(32, signed=false)INT32OPTIONAL†Pre-event template version
new_versionINTEGER(32, signed=false)INT32OPTIONAL†Post-event template version (equal to old_version for the rejection variant)
old_templateSTRING (canonical JSON)BYTE_ARRAYOPTIONAL†The token sequence of the pre-event template (matches RFC 0001 §6.4’s non-optional old_template: String). For TemplateTypeExpanded and TemplateWideningRejectedDegenerate (variants where the template tokens don’t change), old_template == new_template
new_templateSTRING (canonical JSON)BYTE_ARRAYOPTIONAL†The token sequence of the post-event template (matches RFC 0001 §6.4’s non-optional new_template: String). Always set: TemplateWidened carries the post-widen template; TemplateTypeExpanded and TemplateWideningRejectedDegenerate carry the unchanged template (equal to old_template)
positions_widenedLIST<INT32>as schemaOPTIONAL†Written for template kinds; the list is empty for TemplateTypeExpanded (no positions involved) and TemplateWideningRejectedDegenerate (the would-be widening was rejected). For TemplateWidened, the positions that gained <*>. Mirrors RFC 0001 §6.4 positions_widened: Vec<u16>
slots_expandedLIST<STRUCT<slot_index: INT32, types_added: LIST<INT32>>>as schemaOPTIONAL†Written for template kinds; the list is empty for TemplateWidened and TemplateWideningRejectedDegenerate. For TemplateTypeExpanded, one element per slot whose type set grew, each carrying the wildcard-slot ordinal plus the ParamType ordinals added (RFC 0001 §6.4 slots_expanded: Vec<SlotExpansion>; SlotExpansion = { slot_index, types_added })
triggering_line_hash(no logical type)FIXED_LEN_BYTE_ARRAY(16)OPTIONAL†Blake3 hash of the raw triggering line L_raw (RFC 0001 §6.4 triggering_line_hash: [u8; 16]); enables cross-referencing the audit event with the data record that caused it
triggering_line_sampleSTRINGBYTE_ARRAYOPTIONALFirst 256 bytes of L_raw, UTF-8 lossy-decoded if necessary (RFC 0001 §6.4 triggering_line_sample: Option<String>); NULL when the sample was redacted for retention policy
reasonSTRINGBYTE_ARRAYOPTIONALThe degenerate-template guard’s diagnostic string for TemplateWideningRejectedDegenerate; the operator-supplied justification (≤ 256 B, RFC 0001 §6.7; "" ↔ NULL) for the alias kinds (4–5); NULL otherwise (NULL for compaction — the compaction_* columns carry the facts)
compaction_partitionSTRINGBYTE_ARRAYOPTIONALCompaction only. The compacted data partition, as the canonical year=…/month=…/day=…/hour=… key under the row’s tenant_id (RFC 0009 §3.4). NULL for all other kinds
compaction_input_filesLIST<STRING>as schemaOPTIONALCompaction only. The input file names that were merged away (RFC 0009 §3.6 ourios.compaction.files). NULL for all other kinds
compaction_output_fileSTRINGBYTE_ARRAYOPTIONALCompaction only. The consolidated output file name (the sole live file after the commit). NULL for all other kinds
compaction_generationINTEGER(64, signed=false)INT64OPTIONALCompaction only. The manifest generation the consolidation committed at (RFC 0009 §3.4). NULL for all other kinds
compaction_rowsINTEGER(64, signed=false)INT64OPTIONALCompaction only. Rows in the consolidated file — equal to the total input rows, the conserved count (RFC0009.2). NULL for all other kinds
alias_representative_idINTEGER(64, signed=false)INT64OPTIONALAlias kinds (4–5) only. The operator’s anchor id for the assertion/retraction — one member of the asserted set, not the set’s derived canonical (RFC 0001 §6.7). NULL for all other kinds
alias_member_idsLIST<INTEGER(64, signed=false)>as schemaOPTIONALAlias kinds (4–5) only. The other ids in the asserted set (RFC 0001 §6.7 member_ids: Vec<u64>), stored verbatim; the semantic value is the set {alias_representative_id} ∪ alias_member_ids. Empty list is valid (single-id retraction) and distinct from NULL. NULL for all other kinds
alias_actorSTRINGBYTE_ARRAYOPTIONALAlias kinds (4–5) only. The principal that issued the assertion — aliasing is never anonymous (RFC 0001 §6.7 actor: ActorId, non-empty). NULL for all other kinds

OPTIONAL† marks columns relaxed from REQUIRED by the 2026-06-03 amendment (§3.8 rule 6). They are required-by-convention for the template event kinds (event_kind 0–2): the writer MUST populate them there and a test asserts it, so the template-event contract is unchanged; they are NULL for compaction (kind 3) and, per the 2026-06-12 amendment, the alias kinds (4–5). Existing audit files keep their non-null values and read back as Some — no data migration.

The canonical-JSON encoding of old_template / new_template is ["lit0", "<NUM>", "lit2", ...] — the same shape the miner’s in-memory Vec<OwnedToken> produces.

Audit encoding policy (parallel to §3.6’s data-file table; the audit stream is low-volume so page indexes and bloom filters are unnecessary defaults, but the policy needs to be explicit under §3.1’s “RFC pins per-column encoding policy” commitment):

ColumnDictionaryPage indexBloom filterRationale
tenant_idyesnonoBounded per cluster
timestampnoyesnoDELTA_BINARY_PACKED Parquet encoding plus ZSTD compression (same shape as data-file time_unix_nano); page index supports time-range pruning on drift queries
event_kindyesyesnoA small bounded set (six ordinals today), plus future ordinals
event_typeyesyesnoSame bounded set as event_kind; predicate-pushdown surface for the RFC 0001 §6.7 drift query
template_idyesyesnoBounded by tenant template count; bloom filter is unnecessary at audit volume
old_version, new_versionyesnonoSmall per template
old_template, new_templatenononoPer-tenant repetitive but variable-length JSON; defer the dict decision until bench data exists
positions_widened (list values)yesnonoSmall INT32s
slots_expanded (list / struct values)yesnonoSame
triggering_line_hashnononoNear-random 16 bytes, dict loses
triggering_line_samplenononoHigh-entropy text, dict loses
reasonyesnonoGuard diagnostic strings plus, since the alias kinds, operator-supplied justifications — free text but rare and ≤ 256 B, so dict still pays at audit-event volumes
compaction_partitionyesyesnoBounded per tenant; page index supports range pruning on the compacted partition
compaction_input_files (list values)nononoUUID file names, near-random — dict loses
compaction_output_filenononoUUID file name, near-random — dict loses
compaction_generationyesnonoSmall monotonic integers per partition
compaction_rowsnononoHigh-cardinality counts; neither dict nor index earns its keep
alias_representative_idyesyesnoBounded by tenant template count — same shape as template_id
alias_member_ids (list values)yesnonoSame bounded id space; list volume is tiny (rare operator actions)
alias_actoryesnonoA small set of operators / API principals per tenant

Compression codec follows §3.5 (ZSTD-3 across every column). Anything not in the table above takes the writer’s defaults; the table covers every row-level column declared in §3.7.

Audit files are flushed independently of data files: a single write to the cluster’s audit sink does not force a data flush, and vice versa. The writer guarantees no audit event is lost across crashes by routing audit events through the same WAL path as data records (a contract that lands with the post-MVP ourios-wal crate; until then audit-event durability is in-memory and the corpus bench accepts that).

3.7.1 v1 reader-side alias-map derivation (amendment 2026-06-12)

In v1 there is no persisted per-tenant alias-map artifact: the audit stream is the alias store, and the querier derives the requesting tenant’s alias map at query-compile time. The derivation:

  1. Scan the tenant’s audit/ partition subtree for rows with event_kind ∈ {4, 5} — pruned by the tenant_id partition key plus the event_kind / event_type dictionary and page-index columns (the same partition-pruned scan shape as the RFC 0010 drift query). Alias events are rare operator actions, not ingest-volume data, so the scan is small by construction.
  2. Fold the matching events in timestamp (event-time) order through the RFC 0001 §6.7 projection semantics — each alias_asserted unions its asserted set into one equivalence class (merging classes that share a member), each alias_retracted removes its asserted set’s ids, canonical representative derived as min(members). Those semantics are owned by RFC 0001 §6.7 and implemented by ourios-core::alias::AliasMap; this RFC references them and does not restate them. The fold order is total and deterministic: (timestamp, file path lexicographic, within-file row index) — same-nanosecond ties within one file fold in row order (the sink’s append order), and ties across files break on the lexicographic file path (audit file names are unique per flush, so the order is stable across re-scans). The control plane is the single writer of alias events, so ties are not expected in practice; only an assert/retract pair over the same ids in the same nanosecond would be sensitive to the tiebreak.
  3. Hand the folded map to the RFC 0002 resolves_to compilation (RFC0002.9), which expands by set membership exactly as before — the derivation changes where the map comes from, not what it means.

Consistency bound. The derived map reflects exactly the alias events durably written and flushed to the audit stream at scan time. This is the eventual-consistency stance RFC 0001 §6.7 already takes (bounded under-inclusion for a not-yet-visible assertion, bounded over-inclusion for a not-yet-visible retraction, never cross-tenant, never a phantom grouping); in v1 the staleness window is audit-flush visibility rather than a snapshot/projection-rebuild cadence.

The cached artifact is deferred, not designed away. A materialized per-tenant alias-map file would be a pure recovery/latency cache over this derivation — its file format, publish point, and refresh cadence ride the RFC 0009 §3.4 atomic-publish manifest fork (issues #94 / #147) and are not pinned here. Because the audit stream remains the source of truth either way, introducing the cache later changes no query-visible semantics — the same “v1 full-replay now, accelerate later, no format change” shape RFC 0001 §6.9 pinned for the miner snapshot.

3.8 Schema-evolution policy

The §3.5 invariant from CLAUDE.md is normative: “All schema changes go through the schema RFC process.” RFC 0005 establishes the baseline schema; subsequent changes follow these rules:

  1. Adding a column. Always OPTIONAL. An amendment to this RFC names the column, its type, its default behaviour for readers that haven’t been upgraded, and its source/derivation. No data-migration is required — old files lack the column, readers surface None (or the documented default), new files include it.
  2. Renaming a column. Forbidden in-place. The path is: add the new name as a new optional column, dual-write for one release, deprecate the old name in a later RFC, drop the old name in the release after that.
  3. Changing a column’s type. Forbidden in-place. Add a new column (<name>_v2 or a semantically meaningful new name), migrate, drop. The amendment RFC pins the migration plan.
  4. Removing a column. Requires an RFC against CLAUDE.md §3.5. The migration plan accompanies the RFC: either every historical file is rewritten, or queries against the removed column become a documented error.
  5. Changing a column’s encoding policy (e.g. enabling dictionary on body, dropping a bloom filter). Permitted in an RFC patch — encoding is not part of the logical schema, so readers don’t break, but a benchmark must show the change doesn’t regress A1/B1/B2.
  6. Relaxing a column REQUIREDOPTIONAL. Permitted via an amendment that names the columns and the writer invariant that keeps them required-by-convention for the event/record kinds that always carry them (enforced by a test). No data- migration is required: existing files wrote the column for every row, so it reads back as Some everywhere; only new rows of a new kind may write NULL. The forward-compat caveat — a reader predating the amendment reads a relaxed column as REQUIRED and would mishandle a NULL — is bounded because (a) Ourios versions reader and writer together and (b) the rows that exercise the NULL belong to a kind introduced by the same amendment, so no previously-deployed reader is expected to read them. The reverse (OPTIONALREQUIRED, a tightening) is forbidden in-place — older files may already store NULL, which a REQUIRED column cannot represent — and, like rules 2 and 3, takes the add-new-column / migrate / drop path. First applied by the 2026-06-03 compaction-audit amendment (§3.7).

The PR description that touches the schema must explicitly call out which rule above applies, mirroring the CLAUDE.md §4 convention for hazard-touching PRs (“the PR description must explicitly address how the change preserves the invariant”).

3.9 Reader contract

The reader has three normative requirements:

  1. Unknown columns are silently ignored. A file produced by a future writer that adds columns the current reader doesn’t know about must read successfully; the unknown columns are dropped on the floor. This is what makes amendment-by-addition (§3.8 rule 1) cheap.
  2. Missing columns surface as documented defaults. A file produced by an earlier writer that lacks columns the current reader expects must read successfully; the missing columns default to:
    • OPTIONAL columns → None. Per §3.8 rule 1, every amendment-added column is OPTIONAL, and per §3.8 rule 6 a column relaxed REQUIREDOPTIONAL is read the same way — None when a row stores NULL (e.g. the template-specific columns on a compaction row), Some for the non-null values older files wrote. Together these cover the entire amendment surface; there is no “REQUIRED-added-in-amendment” case to default.

      Exception — effective_time_unix_nano (amendment 2026-06-11): the documented default when the column is absent (a file written before the amendment) is the row’s time_unix_nano, not None — i.e. effective := time_unix_nano, which is exactly the pre-amendment behaviour, so historical files keep answering time-window queries identically. Consumers that compile predicates over this column (the RFC 0002 §6.2 time window) MUST apply this substitution per-file; the querier’s general absent-OPTIONAL-column ⇒ predicate-false convention (RFC 0007 / RFC0007.4) does not apply to the time-window filter — compiling the window to false on old files would silently hide all pre-amendment data from every query.

    • The baseline REQUIRED columns still declared REQUIRED — the reader errors if they are missing. A file missing a baseline REQUIRED column (the common envelope: tenant_id, timestamp, event_kind, event_type) is corrupted or written by an incompatible writer; falling through to a made-up default would corrupt downstream query results.

  3. Row-vs-path partition validation. For every row read under a partition-aware path (i.e. via Reader::open_partition or the DataFusion ListingTable integration that feeds a partition tuple in), the reader compares the row-level tenant_id against the partition path’s tenant_id segment and the row’s derived UTC year / month / day / hour against the path’s time-bucket segments. The derivation algorithm is identical to the writer’s in §3.4: prefer time_unix_nano if non-zero, else fall back to observed_time_unix_nano if present and non-zero, else the 1970-01-01T00 epoch. Using the same algorithm on both sides guarantees that a row written under one bucket validates under the same bucket. Mismatch is a hard read error that names the offending row and the partition path. The row value is authoritative (the talk and RFC 0001 §6.1’s row-as-source-of-truth rule); the path is the partition- pruning index. A diagnostic Reader::open_file helper that opens a single file without a partition tuple skips this validation and surfaces records as-stored — that mode is not exposed through the production query path.

Unknown ParamType ordinals (i.e. a value the reader doesn’t know about) are surfaced as ParamType::Unknown — a reserved catch-all variant. Queries against records carrying unknown variants pass through to the application layer to decide what to do (the RFC 0001 §6.6 reconstruction path treats unknown variants as lossy and falls back to the body column, which is why RFC 0001 §6.5’s overflow-forces-body-retention rule is paired with this).

3.10 Crate shape

crates/ourios-parquet/ per the §7 target layout in CLAUDE.md. The public surface is intentionally small:

  • Schema — a singleton describing the data-file schema; one function per amendment that gates an additive column.
  • AuditSchema — the parallel singleton for the audit stream.
  • Writer — opens a file at a partition path, appends rows in the §3.2 column order, rotates row groups at the §3.5 threshold.
  • Reader — opens a file (or a directory of files; partition discovery is part of the reader’s job), surfaces records as MinedRecords with the §3.9 contract.
  • AuditWriter / AuditReader — same shapes for the audit series.

No trait abstraction over Writer or Reader until a second implementation is named in an RFC. Pre-abstracting when only one consumer exists picks an axis for the trait before the shape of the second consumer is visible, and an extracted trait that turns out to fit only one consumer is harder to re-shape than the concrete type would have been. Phase 3’s DataFusion table provider is one consumer of Reader; the bench is another; both are concrete, neither demands a trait.

4. Alternatives considered

4.1 Apache Iceberg or Delta Lake on top of Parquet

A table-format layer (Iceberg, Delta) would give us schema evolution, snapshots, and time-travel queries for free. Rejected for MVP: both pull in a large dependency surface (metastore plumbing, transaction logs, manifest files) for features (snapshots, time-travel) the thesis gates don’t need. A future RFC can adopt Iceberg as a layer over the Parquet files defined here — Iceberg is additive on top of Parquet, so the §3.2 schema doesn’t need to change. Adopting it now would multiply the dependency footprint without moving the thesis.

4.2 Apache Arrow IPC files instead of Parquet

Arrow IPC is faster to read into Arrow memory but lacks Parquet’s row-group pruning, page index, and bloom filters — the exact features Pillar 1 of CLAUDE.md §2 names as load-bearing for thesis-gate B1. Rejected for the same reason Parquet was chosen in the first place.

4.3 Typed STRUCT encoding of AnyValue

Encode the OTLP AnyValue discriminated union as a recursive Parquet STRUCT, with one optional field per variant and explicit recursion-depth unrolling for array / kvlist. Rejected for MVP: Parquet’s flat-nested model doesn’t support true recursion; any encoding caps recursion depth at the schema declaration, which is a hard limit operators can’t override without a schema change. Canonical JSON in a BYTE_ARRAY is unambiguously faithful and defers the typed-attribute query story to a future RFC with a named consumer.

4.4 One concatenated file series (data + audit)

Carry audit-event rows in the data file with a discriminator column. Rejected: audit volume is orders of magnitude smaller than data volume; co-locating them defeats partition pruning for both (“give me all widening events” would have to scan the data partition, “give me all log records at time T” would scan through audit rows). The two-file-series shape is the natural operational separation.

4.5 Compaction in MVP

Background compaction (small-file consolidation) was considered for Phase 2. Rejected: docs/roadmap.md §4 Phase 2 explicitly parks it post-MVP, on the rationale that corpus runs are bounded and a single Parquet file per phase is acceptable. Production deployments accumulating sustained traffic will need compaction before the H4 file-size detection threshold fires; that’s a post-MVP RFC.

4.6 Apache Avro for the audit-event stream

Avro is a natural fit for sparse event streams. Rejected: Pillar 1 commits the project to Parquet end-to-end; running two file formats in one bucket doubles the operational surface (reader libraries, schema-registry-shape, partition-discovery code) for the marginal benefit of slightly better encoding of a column the bench won’t measure.

5. Acceptance criteria

Scenario RFC0005.1 — Round-trip preserves every §3.2 row-level column

  • Given a MinedRecord populated with every row-level column in §3.2 (every OPTIONAL field set to Some, every variant of body_kind exercised across a batch — including the row-level tenant_id)
  • When the batch is written to a Parquet file by the writer and read back by the reader via Reader::open_partition (the production query path)
  • Then for every column whose Rust type in MinedRecord is a raw byte container (trace_id: Option<[u8; 16]>, span_id: Option<[u8; 8]>, body: Option<Bytes>), the recovered bytes equal the original bytes byte-for-byte
  • And for every typed column (integers, floats, booleans, timestamps, enum ordinals, plain strings, the params and separators lists), the recovered value equals the original under the column’s Rust-level equality — UTF-8 equality for String, numeric equality for integers/floats/timestamps, element-wise equality for Vec<T>
  • And for the canonical-encoded structural columns (attributes: Vec<KeyValue> and resource_attributes: Vec<KeyValue> — encoded with the Ourios canonical body encoding as a BYTE_ARRAY on disk per §3.3), the recovered Vec<KeyValue> equals the original under structural equality (the encoding is bidirectional and byte-deterministic per RFC 0001 §6.1, so structural equality is the testable property at the MinedRecord boundary; byte equality on the encoded bytes follows as a corollary but is not the primary assertion)
  • And the round-trip equality assertion does not include the pure-partition pseudo-columns (year, month, day, hour); those are covered by RFC0005.5 (partition layout) and RFC0005.11 (row-vs-path validation)

Scenario RFC0005.2 — Missing column tolerance (old-file reader path)

  • Given a Parquet file produced by a hand-rolled writer that omits an OPTIONAL column the current schema declares
  • When the current reader reads the file
  • Then records surface with None for the absent column
  • And no error is raised

Scenario RFC0005.3 — Unknown column tolerance (forward compatibility)

  • Given a Parquet file produced by a hand-rolled writer that includes a column the current reader’s schema does not declare
  • When the current reader reads the file
  • Then the unknown column is silently ignored
  • And every declared column reads through correctly
  • And no error is raised

Scenario RFC0005.4 — Baseline REQUIRED column missing → reader errors

  • Given a Parquet file produced by a hand-rolled writer that omits one of the §3.2 baseline REQUIRED columns
  • When the current reader attempts to read it
  • Then the reader returns an error naming the missing column
  • And no records are surfaced

Scenario RFC0005.5 — Partition layout follows §3.4

  • Given a record stream spanning two tenants, three hours, and one of the records carries a tenant id with non-ASCII characters
  • When the writer flushes records to the bucket
  • Then files are placed under data/tenant_id=<tenant_id>/year=YYYY/month=MM/day=DD/hour=HH/<flush_uuid>.parquet, where <tenant_id> is the percent-encoded TenantId per §3.4 and <flush_uuid> is the UUIDv7 flush identifier per §3.4
  • And every record inside a file shares the partition tuple

Scenario RFC0005.6 — Row-group size lands inside H4 target

  • Given a corpus run producing more than 256 MiB of mined records under the production writer (not the corpus-mode single-file path)
  • When the writer flushes Parquet files
  • Then every emitted row group’s total_byte_size (the uncompressed size field on RowGroup in the Parquet metadata — equal to the sum of its column chunks’ total_uncompressed_size) is at least 128 MiB and at most 1 GiB
  • Except the final row group of a file, which may be smaller

Scenario RFC0005.7 — Audit-event stream is a separate file series

  • Given a corpus run that triggers at least one RFC 0001 §6.4 event_type = template_widened event (the Rust variant is TemplateWidened)
  • When the cluster’s audit sink flushes
  • Then audit events land under audit/tenant_id=<id>/..., not interleaved with the data file series
  • And the emitted audit record is populated for every row- level column declared in §3.7’s audit-schema table, with NULL appearing only on the explicitly-OPTIONAL columns documented for the variant (e.g. reason is NULL for template_widened; slots_expanded is an empty list)

Scenario RFC0005.8 — body column carries no dictionary encoding

  • Given a corpus run that retains at least 100 unique high- entropy body strings (e.g. via RFC 0001 §6.3 lossy-zone or RFC 0001 §6.5 overflow)
  • When the writer flushes the Parquet file
  • Then the body column chunk’s compression codec is ZSTD (Parquet CompressionCodec field)
  • And the body column chunk’s encodings list does NOT include PLAIN_DICTIONARY or RLE_DICTIONARY (Parquet Encoding enum)
  • And the body column chunk’s dictionary_page_offset is unset (None) in the column-chunk metadata — there is no dictionary page on disk for this column

Scenario RFC0005.9 — Unknown ParamType ordinal surfaces as Unknown

  • Given a Parquet file with a params.type_tag value that the current reader’s ParamType enum doesn’t recognise (e.g. ordinal 99)
  • When the reader reads it
  • Then the resulting Param.type_tag is ParamType::Unknown
  • And the record’s reconstruct call surfaces it as lossy (consistent with RFC 0001 §6.6’s fallback path)

Scenario RFC0005.10 — Schema declaration is greppable and immutable

  • Given the Schema singleton defined in ourios-parquet
  • When the test suite extracts the column list from Schema and compares it against the column list pinned in this RFC
  • Then the two lists are equal in name, type, and repetition, in declared order

Scenario RFC0005.11 — Row-vs-path validation on partition mismatch

  • Given a Parquet file whose row-level tenant_id, or the row’s UTC year / month / day / hour as derived by the §3.4 algorithm (prefer time_unix_nano if non-zero, else observed_time_unix_nano if non-zero, else the 1970 epoch), disagrees with the partition-path segments the file lives under
  • When the reader opens the file via Reader::open_partition
  • Then the reader returns a hard error naming the offending row, the row’s value, and the partition path’s value
  • And no records are surfaced from the file
  • And a row with time_unix_nano = 0 and a non-zero observed_time_unix_nano placed under a partition path derived from the observed-time fallback validates cleanly (the same algorithm runs on both sides)

Scenario RFC0005.12 — Compaction audit event round-trips (amendment 2026-06-03)

  • Given a compaction audit event (event_kind = 3, event_type = "compaction") carrying a partition key, an input file set, an output file, a manifest generation, and a row count
  • When it is written to the audit stream and read back
  • Then the common envelope (tenant_id, timestamp, event_kind, event_type) and the compaction_* columns are populated with those values
  • And every template-specific column (template_id, old_version, new_version, old_template, new_template, positions_widened, slots_expanded, triggering_line_hash) reads back as None / null
  • And a template_widened event written to the same stream still populates all of those template columns and reads back its compaction_* columns as None — i.e. the writer keeps each kind’s required-by-convention columns non-null (§3.8 rule 6)

Scenario RFC0005.13 — Effective-timestamp fallback (amendment 2026-06-11)

  • Given a record with time_unix_nano = 0 and observed_time_unix_nano = T (non-zero)
  • When the writer flushes it and a time-window query whose window contains T runs over the store
  • Then the stored effective_time_unix_nano equals T
  • And the file lands under the partition tuple derived from T (§3.4)
  • And the query returns the row — the time window filters effective_time_unix_nano (RFC 0002 §6.2)
  • And the stored time_unix_nano is still 0 — the wire value is never overwritten (RFC 0001 scenario RFC0001.10)
  • And given a pre-amendment file lacking the effective_time_unix_nano column, the same time-window semantics apply with effective := time_unix_nano (§3.9) — i.e. exactly the pre-amendment behaviour, no error, no hidden rows

Scenario RFC0005.14 — Alias audit events round-trip and back the v1 map derivation (amendment 2026-06-12)

  • Given an alias_asserted event (event_kind = 4, event_type = "alias_asserted") carrying a representative id, a member-id set, an actor, and a reason, written through the audit sink
  • When the tenant’s audit stream is read back
  • Then the event round-trips with its full asserted set, actor, and reason intact (reason round-trips "" ↔ NULL; an empty member_ids reads back as an empty list, not NULL)
  • And every template-specific and compaction_* column reads back as None / null, and a template_widened event in the same stream reads its alias_* columns back as None (§3.8 rule 6, per kind)
  • And given a stream carrying alias_asserted(A, {B}) followed by the matching alias_retracted for tenant T, when the querier derives T’s alias map at compile time (§3.7.1), then resolves_to(A) reflects exactly the folded state per RFC 0001 §6.7 (assert-then-retract → {A})
  • And a second tenant’s alias events contribute nothing to T’s derived map (CLAUDE.md §3.7; RFC 0001 scenario RFC0001.14 at the storage layer)

6. Testing strategy

  • RFC0005.1 — property test in crates/ourios-parquet/tests/roundtrip.rs using proptest to generate MinedRecords spanning every column variant; asserts byte-equality after a round trip through the writer and reader. Corpus integration test in the same file drives the H7.1 corpus through writer → reader and asserts the same property end-to-end.
  • RFC0005.2, RFC0005.3, RFC0005.4 — schema-evolution tests in crates/ourios-parquet/tests/evolution.rs. Each test builds a Parquet file with the parquet crate directly (not through the project’s writer), exercising a specific shape: missing-OPTIONAL, unknown-column, missing-REQUIRED. Asserts the §3.9 reader contract.
  • RFC0005.5 — integration test in crates/ourios-parquet/tests/partition.rs that drives the writer with a synthetic multi-tenant, multi-hour stream and asserts the bucket layout via filesystem inspection. The non-ASCII tenant id case is a sub-test.
  • RFC0005.6 — corpus integration test in crates/ourios-parquet/tests/sizing.rs. Generates ≥256 MiB of records, flushes through the writer, parses each emitted file’s Parquet footer, asserts row-group sizes inside the H4 range. Marked #[ignore] by default (slow); contributors run it manually via cargo test --ignored. Scheduling it on a CI cadence is an open question (§7) — the project’s CI workflow has no schedule trigger today, so the RFC does not commit to one.
  • RFC0005.7 — integration test in crates/ourios-parquet/tests/audit.rs that wires the audit sink to the writer’s audit path, triggers a widening through the miner, flushes, and reads back the audit file. Asserts the §3.7 column set.
  • RFC0005.8 — Parquet-metadata inspection test in crates/ourios-parquet/tests/encoding.rs. Drives 100+ unique bodies through the writer, opens the resulting file’s footer via the parquet crate’s column-chunk metadata, asserts the body column’s compression is ZSTD and its encodings list does not include PLAIN_DICTIONARY or RLE_DICTIONARY (the two distinct Parquet-metadata fields per RFC0005.8).
  • RFC0005.9 — unit test in crates/ourios-parquet/src/reader.rs with an in-memory Parquet file built directly from arrow arrays carrying a forged 99 in the type_tag list.
  • RFC0005.10 — unit test in crates/ourios-parquet/tests/schema_pin.rs that holds a const expected-column-list and compares against Schema::columns(). This is the “schema-as-spec” pin: adding a column to Schema without updating the expected list (and, by implication, this RFC) fails the test, mirroring the RFC0004.3 pattern.
  • RFC0005.11 — integration test in crates/ourios-parquet/tests/partition_validation.rs that builds Parquet files at deliberately mismatched partition paths (row says tenant_id = a, path segment says tenant_id=b) and asserts the reader’s hard-error path fires with the documented diagnostic. Sub-tests cover the four time-bucket parts (year/month/day/hour).
  • RFC0005.12 — round-trip test in crates/ourios-parquet/tests/ lands with the audit-schema code change: write a compaction audit event and a template_widened event through AuditWriter, read them back via AuditReader, and assert each kind’s columns are populated / null per §3.7 (the relaxed template columns non-null only for template kinds; compaction_* non-null only for compaction).
  • RFC0005.13 — integration test spanning crates/ourios-parquet (writer derivation + the §3.9 absent-column default) and crates/ourios-querier (the time-window filter): write a time_unix_nano = 0 record with observed_time_unix_nano set, assert the stored column, the partition path, the window hit, and the verbatim zero; then build a pre-amendment-shaped file (no effective_time_unix_nano column) with the parquet crate directly, per the RFC0005.2 pattern, and assert the window filter behaves as effective := time_unix_nano.
  • RFC0005.14 — lands with the issue-#148 implementation slice. Round-trip test in crates/ourios-parquet/tests/audit.rs per the RFC0005.12 pattern: write alias_asserted / alias_retracted and a template_widened event through AuditWriter, read back via AuditReader, assert each kind’s columns populated / null per §3.7 (including the "" ↔ NULL reason rule and the empty-vs-NULL alias_member_ids distinction). Derivation test in crates/ourios-querier: fold a written assert/retract stream into the tenant’s AliasMap per §3.7.1 and assert resolves_to over the result, with a second tenant’s events on disk to pin isolation. The unknown-kind tolerance rule is pinned by extending the existing forged-ordinal reader test (audit_reader.rs) from expect-error to expect-opaque-event.

Criterion benchmarks (in ourios-bench, Phase 3 territory) will measure A1 (compression ratio) and B1/B2 (predicate-pushdown latency) against the schema this RFC specifies; those numbers are normative for the maturity-stage move from green to validated.

7. Open questions

  • Compression codec. ZSTD-3 is the default per §3.5; ZSTD-22 trades CPU for ratio. The A1 measurement decides whether to add zstd_level as a tunable per RFC 0004. Defer until A1 numbers exist.
  • Bloom filter sizing. §3.6 names template_id as the one column with a bloom filter; the false-positive rate is a Parquet writer parameter (Arrow default is 1%). Lower FPR trades file size for query selectivity. Defer until B2 numbers exist.
  • Audit-event retention. Audit events have a different retention policy than log records (audits should outlive the data they audit, for forensics). The retention plumbing is post-MVP (no compaction = no expiry in MVP); the RFC notes the asymmetry but does not pin a policy.
  • Partition-discovery API on the reader. The reader has to enumerate files under a <bucket>/data/ prefix and decode the Hive partition values to apply predicate-pushdown. Whether this is in-crate (Reader::open_partition) or delegated to DataFusion’s ListingTable is a Phase 3 wiring decision; for the standalone reader tests the bench will use whichever is simplest.
  • Concurrent writers per partition. Two writers writing to the same tenant_id=…/hour=HH/ simultaneously is fine (UUIDv7 prevents filename collision), but readers that enumerate partitions during an active write may see partial files. The reader contract assumes a file is either complete or absent. The atomic-publish convention (write to a temp path, rename on close) is the writer’s responsibility; the reader does not need to do anything special. Defer the writer PR to nail this down.
  • Scheduled CI cadence for the slow tests. RFC0005.6 (row-group sizing) and any future criterion benchmarks are marked #[ignore] and rely on cargo test --ignored / manual invocation. Adding a GitHub Actions schedule: trigger (e.g. nightly at 03:00 UTC) so these run automatically is a follow-up workflow PR, not part of this RFC. The RFC notes the gap; the workflow PR will land alongside the Phase 3 ourios-bench benchmark implementation (docs/roadmap.md §4 Phase 3).

8. References

  • CLAUDE.md §1 (project charter), §2 (architectural pillars — Parquet, template miner, DataFusion), §3.2 (no unbounded cardinality in params), §3.5 (Parquet schema changes require a migration plan), §3.6 (object storage is the source of truth), §3.7 (multi-tenancy from day one), §5.1 (RFC process), §7 (target repository layout — ourios-parquet is the named crate).
  • RFC 0001 §6.1 (MinedRecord data model, OTLP-derived columns, body representation including the Ourios canonical body encoding rule), §6.4 (widening events that this RFC’s audit-event stream carries), §6.5 (OVERFLOW marker + forced body retention — the source of unbounded values in the body column), §6.6 (reconstruction — the consumer of the schema’s params / separators / lossy_flag columns), §6.7 (template versioning; the 2026-06-07 alias write path whose alias_asserted / alias_retracted events the §3.7 stream persists and whose projection semantics §3.7.1 folds), §9 (cross-RFC contracts pending — audit-event Parquet stream).
  • RFC 0002 (query DSL, drafted) — Phase 3 consumer of the reader.
  • RFC 0003 (OTLP receiver, drafted) — Phase 3 producer of records that feed this schema.
  • RFC 0004 (configuration policy) §3 (tunables-vs-invariants — this RFC’s encoding policy choices are not tunables; they are RFC-amendment territory).
  • docs/hazards.md H1 (silent template merges — audit-event stream is the operational signal), H4 (small-file problem — the row-group and file-size targets in §3.5), H5 (template schema evolution — the schema-evolution rules in §3.8).
  • docs/benchmarks.md A1 (compression ratio — gated on this RFC’s encoding policy), B1 (predicate-pushdown latency — gated on this RFC’s page index / partition layout), B2 (template-exact query latency — gated on this RFC’s bloom filter on template_id).
  • docs/roadmap.md §4 Phase 2 (the capability set this RFC opens), §5 (deliberately out of MVP — compaction, the post-MVP follow-up RFC named here).
  • Apache Parquet Format specification (file format, page index, bloom filter, LIST encoding) — project site https://parquet.apache.org/; the normative format spec lives in the repository at https://github.com/apache/parquet-format.
  • OpenTelemetry Logs Data Model — AnyValue, normative source at https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md.
  • OpenTelemetry Protocol (OTLP) specification — the proto3-JSON mapping (plus OTLP’s closed list of deviations) that the Ourios canonical body encoding for body_kind = Structured builds on lives at https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md (see the “OTLP/HTTP” section). OTLP defines no canonical / byte-deterministic JSON form and requires no lossless translation; the byte-stable encoding is Ourios-local — see RFC 0001 §6.1.

RFC 0006 — Bench harness


rfc: 0006 title: Bench harness — A1 / C1 / C2 thesis-gate measurement status: green author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-05-22 supersedes: — superseded-by: —

RFC 0006 — Bench harness: A1 / C1 / C2 thesis-gate measurement

1. Summary

Pins the contract for ourios-bench: a binary that drives the shipped ourios-miner + ourios-parquet pipeline against a corpus on disk, computes the three writer-side thesis-gate numbers (A1 compression, C1 reconstruction, C2 template-count convergence) per docs/benchmarks.md §2 / §4, and writes results into docs/benchmarks.md §9 in a diff-reviewable shape. The RFC fixes the methodology — what counts as a raw byte, what counts as a Parquet byte, when plateau is plateau, what equals what in reconstruction — before any code is written, because the difference between “the thesis holds” being a real claim and a vibe lives in those definitions. B1 and B2 (predicate-pushdown and template-exact query latency) are excluded: they need the DataFusion querier (ourios-querier, RFC 0007) and therefore landed in follow-up extensions once the querier was live — both are now measured authoritatively (docs/benchmarks.md §9.4; RFC 0007 is validated).

2. Motivation

2.1 The honesty contract collapses without measurement

CLAUDE.md §1 declares the project’s central claim and §2 names the three pillars that have to hold for the claim to be true. docs/benchmarks.md §7’s escalation rule is the load-bearing consequence: if two thesis-gates fail on any representative corpus, we pause implementation and revisit the pillars. That rule is a no-op as long as no thesis-gate has been measured. The §9 status line as of merge of RFC 0005 reads “no benchmark has been run; all targets are aspirational” — which is fine for the storage layer’s RFC, but cannot stay true through the rest of MVP. RFC 0006 is the gate that flips §9 from aspirational to measured.

2.2 Why bench-first, before the querier

docs/roadmap.md §4 Phase 3 names two crates: ourios-bench and ourios-querier. Either could go first. Three of the five thesis-gate goals (A1, C1, C2) need only the bench — the writer and reader shipped through PR-D…PR-G are everything those gates require on the storage side. The other two (B1, B2) need DataFusion plumbing on top. Bench-first means three thesis-gate signals land before any DataFusion code is written; querier-first defers all five signals until the querier is green.

The asymmetric value also runs the other direction: the methodology RFC is the kind of document that tends to surface gaps in the writer / reader contract while the storage code is still fresh, when those gaps are cheaper to fix. Writing it after the querier lands risks discovering A1-affecting writer bugs at the same time we’re debugging predicate pushdown.

2.3 Why an RFC and not just a PR

docs/rfcs/README.md requires an RFC for any new crate, which covers ourios-bench mechanically. The methodology section is the deeper reason: A1 in particular has subtle definitional choices (“what does bytes(raw_corpus) mean for a corpus that the miner wraps in OTLP envelopes?”, “do we include the audit-stream files in bytes(parquet)?”, “is zstd-alone the codec or the codec plus the comparable defaults the Drain paper uses?”) that are much easier to argue about in markdown than in code review. Pinning them in an RFC means the resulting numbers are not only reproducible but meaningful — the §9 Results section that grows out of this work cites the RFC by section, and changes to the methodology require an amendment.

2.4 Why this is one RFC, not three

A natural split would be RFC 0006 (bench crate shape) / RFC 0007 (A1 methodology) / RFC 0008 (C1+C2 methodology). All three are co-designed: the crate shape exists to compute the measurements, the A1 plain-text-vs-OTLP corpus decision affects which loader the crate exposes, and C1/C2 share the per-line ingest loop that A1 also runs to produce its Parquet output. Splitting them optimises for short documents and loses the cross-cutting constraints. The querier (and the B1/B2 methodology it carries) is a genuinely separate concern with no shared code path and lives in RFC 0007 (since shipped and validated).

3. Proposed design

3.1 Scope and what this RFC pins

This RFC pins:

  • The ourios-bench crate’s shape: a binary plus a small set of supporting modules (corpus loader, ingest harness, result writer).
  • The corpus input format for v1 — plain-text *.txt files under testdata/corpus/, one line per row, UTF-8, the same on-disk shape testdata/corpus/README.md documents and the existing H7.1 property test in crates/ourios-miner/tests/hazards.rs reads. The bench reuses the on-disk format, not the test’s OtlpLogRecord fixture defaults (see §3.3 for the bench-specific tenant / severity / scope envelope). Amendment (PR-K2, 2026-05-28): the OTLP-LogsData migration has landed — the loader also reads *.jsonl / *.json files in the OTel File Exporter format (one LogsData per line). The measurement formulas are unchanged; the §3.3 plain-text envelope defaults still apply to text input.
  • The A1 / C1 / C2 measurement formulas — what is divided by what, where the byte counts come from, what equality means.
  • The “hardware baseline annotation” rule: every result line carries the machine kind the measurement ran on so deltas across hardware classes don’t masquerade as code regressions.
  • The output format: a per-run JSON results file under benchmarks/results/<UTC-RFC3339-ms-colon-free>-<git-sha7>.json (filename colons replaced by -; see §3.6), and a human-readable summary appended to docs/benchmarks.md §9 under a date-stamped sub-heading.
  • The invocation surface: cargo run -p ourios-bench -- or just thesis-bench, with CLI flags pinning corpus selection, result-file output, and the optional “annotate-only mode” that runs measurements but does not write benchmarks.md. The recipe is not named just bench — that name is already taken by the criterion-micro-benchmark recipe in justfile; see §3.7.

This RFC does not pin:

  • B1 / B2 measurement — both need ourios-querier (RFC 0007, where they since landed; authoritative results in docs/benchmarks.md §9.4).
  • The OTLP-LogsData corpus migration (docs/roadmap.md §4’s “OTLP LogsData (canonical JSON or protobuf)” goal). Landed in PR-K2 (2026-05-28). The loader now reads *.jsonl / *.json files in the OTel File Exporter format alongside the plain-text *.txt path. As predicted, the measurement formulas were unchanged; only the loader’s parse step grew. The follow-up that swaps in the protobuf (*.binpb) LogsData decode (instead of JSON) remains out of scope for this RFC.
  • criterion micro-benchmarks for the miner / writer hot paths. criterion is the right tool for sub-measurements (e.g. per-line tokenize cost), but the thesis-gate harness is end-to-end. A follow-up may add a crates/ourios-bench/ benches/ directory; this RFC does not specify it.
  • A Validated-stage flip for any RFC — this RFC lands green (test stubs exist, measurements compile and run on the existing seed corpus), with hardware-and-corpus-specific validation happening in a follow-up benchmarking session.

3.2 Crate shape

crates/ourios-bench/
├── Cargo.toml
└── src/
    ├── main.rs        # CLI entry point, argument parsing
    ├── lib.rs         # public surface for integration tests
    ├── corpus.rs      # *.txt loader (mirrors ourios-miner's
    │                  # tests/hazards.rs but factored for reuse)
    ├── harness.rs     # ingest loop, per-line measurement
    │                  # callbacks (lines into miner, records
    │                  # into Parquet writer, samples C2)
    ├── a1.rs          # A1 compression-ratio computation
    ├── c1.rs          # C1 reconstruction-rate computation
    ├── c2.rs          # C2 template-count-convergence
    │                  # computation, including plateau detection
    └── report.rs      # JSON serialisation + benchmarks.md §9
                       # appender

lib.rs is non-empty so integration tests under tests/ can drive the bench without going through main.rs argument parsing. The binary’s main() is thin: parse args, configure harness, call harness.run(), hand the result to report.

No trait abstraction over Harness or Corpus until a second consumer exists. The crate is internal to the project; SemVer applies to it only via the report::ResultsFile shape under benchmarks/results/<...>.json.

3.3 Corpus format

For v1, the bench reads plain-text *.txt files under testdata/corpus/ per the format convention in testdata/corpus/README.md (one log line per row, UTF-8, empty rows skipped). Each non-empty line becomes one OtlpLogRecord with Body::String(line), a default tenant (bench-tenant), severity (9 / INFO), and scope (None / None); the in-memory shape matches what MinerCluster::ingest expects for body_kind = String records.

The bench reuses the same corpus files and one-line-per-record shape as the H7.1 loader in crates/ourios-miner/tests/hazards.rs, but intentionally differs on pipeline defaults: H7.1 uses tenant "corpus" and severity 0 (unspecified), while the bench uses "bench-tenant" and severity 9 (INFO). The divergence is deliberate — H7.1 exercises the miner’s body-reconstruction invariant where tenant/severity are irrelevant, whereas the bench exercises the full write path where a realistic severity aids coverage of the Parquet writer’s field encoding. Both loaders produce Body::String records from the same *.txt files; they are not code-shared because their purposes and default-filling strategies differ.

Time stamps for the synthesised records are deterministic: time_unix_nano starts at a fixed RFC 0005-friendly baseline (1_775_127_480_000_000_000, i.e. 2026-04-02T10:58:00 UTC, matching the existing test fixtures) and advances by a fixed 1 ms per line. The advancement is artificial; this RFC accepts the artificiality because A1 / C1 / C2 are time-insensitive (no gate measures throughput or query latency against a time range). The RFC 0007 measurement extension to B1/B2 revisited time-stamp synthesis as anticipated, since predicate-pushdown latency depends on the time-range distribution: the B1/B2 real-corpus arms window on the records’ real timestamps.

The default tenant means every record lands in the same partition. This is a simplification — the writer’s atomic publish, row-group rotation, and §3.9 row-vs-path contract have all been exercised on the multi-partition path through PR-E2 / PR-F / PR-G. A1 / C1 / C2 are tenant-distribution neutral. Multi-tenant bench scenarios land with future multi-tenant integration work.

Amendment (PR-K2, 2026-05-28): OTLP-LogsData corpus support has landed. The loader dispatches on file extension: *.txt → the plain-text path above; *.jsonl / *.json → OTLP/JSON Lines (one LogsData per line, the OTel File Exporter format), parsed via serde_json::from_str against the opentelemetry-proto types (the with-serde feature gives the OTLP/JSON spec mapping for free). Each wire LogRecord maps to one OtlpLogRecord per the RFC 0003 §6.6 shape — severity (clamped to OTLP’s 0..=24), scope, attributes, resource attributes (copied per record), trace context (length-validated [u8;16] / [u8;8]), body (StringValueBody::String, anything else → Body::Structured(AnyValue) per RFC 0003 §6.4). Both formats may coexist in the same corpus directory. Wire timestamps are honoured for OTLP records (file-static = run-reproducible); the §3.3 deterministic baseline still drives the text path. The follow-up that decodes the protobuf (*.binpb) LogsData form remains out of scope for this RFC.

3.4 Measurement methodology

The load-bearing section of this RFC. The §5 acceptance criteria assert each formula and the §9 status line cites this section by sub-heading.

3.4.1 A1 — Compression ratio

Per docs/benchmarks.md §2 / A1, the formula is:

ourios_ratio = bytes(raw_corpus) / bytes(ourios_output)
zstd_ratio   = bytes(raw_corpus) / bytes(zstd_corpus)
A1_delta     = ourios_ratio / zstd_ratio

Targets: A1_delta ≥ 3.0 on every corpus in benchmarks.md §1; ≥ 10.0 on well-templated services.

Pinned definitions:

  • bytes(raw_corpus): sum of std::fs::metadata(p).len() for every corpus file the loader consumed — recursively under the corpus directory. The loader dispatches on extension: *.txt (the §3.3 plain-text path), or *.jsonl / *.json (the §3.1 OTLP/JSON Lines path landed in PR-K2). *.binpb protobuf-encoded LogsData is reserved for a future follow-up and not counted today. No transformation: this is the byte count an operator measures with find testdata/corpus/ \( -iname '*.txt' -o -iname '*.jsonl' -o -iname '*.json' \) -exec stat --printf='%s\n' {} + | awk '{s+=$1}END{print s}' (or the platform equivalent). For OTLP/JSON corpora the byte count includes the envelope (camelCase keys, base64 bytes), so A1 ratios are not directly comparable across formats — a directory holding a mix of *.txt and *.jsonl produces one aggregate number that conflates both encodings. The §3.6 results JSON’s corpus.directory field lets consumers locate the corpus and inspect its contents to interpret the result; cleanly comparable runs need a corpus directory of one encoding only. A per-format byte breakdown on the results JSON is a future enhancement (see §9 open questions). bytes(zstd_corpus) (below) covers the same extension set so the §3.4.1 math invariant — both sides processing the same input — holds across formats.
  • bytes(ourios_output): sum of std::fs::metadata(p).len() for every *.parquet file under the bench’s output bucket directory, including the audit-event file series (audit/...). The audit stream is part of what Ourios stores about the corpus — excluding it would understate the on-disk footprint and inflate the ratio. The pre-rename *.parquet.tmp files are skipped (the writer’s atomic-publish contract per RFC 0005 §7 means an open *.parquet.tmp indicates an in-flight write, not a durable artefact).
  • bytes(zstd_corpus): sum of std::fs::metadata(p).len() for every *.zst file produced by running zstd -19 --no-progress against each consumed input file individually — same extension set as bytes(raw_corpus) above (*.txt + *.jsonl + *.json). The two byte counts must cover identical input files; broadening one without the other would break the §3.4.1 math invariant (zero bytes(zstd_corpus) on an OTLP-only corpus would produce zstd_ratio = 0 and an undefined A1 delta). Level 19 (not 3) matches the Drain paper’s published comparison and is the strictest competent byte codec; using ZSTD-3 would make Ourios’s A1 trivially pass and is dishonest. The --no-progress flag suppresses the progress bar so the bench is deterministic on reinvocation.
  • A1_delta is the ratio of ratios; it has no units. Reported to three significant figures (3.21×, 12.4×, etc.) and rounded down to that precision so reported numbers err pessimistic.

The bench logs bytes(raw_corpus), bytes(ourios_output), bytes(zstd_corpus), ourios_ratio, zstd_ratio, and A1_delta for each corpus directory it processes. The §9 table summarises by corpus name + hardware kind.

3.4.2 C1 — Bit-identical reconstruction rate

Per docs/benchmarks.md §4 / C1, the formula is:

C1 = count(records WHERE !lossy_flag AND reconstruct == bytes)
   / count(records WHERE !lossy_flag)

Target: C1 = 1.000 (100.000%) on every corpus. lossy_flag = true rows are excluded from both numerator and denominator — that’s the definition of “non-lossy reconstruction rate”. A non-lossy row that reconstructs wrong is a CLAUDE.md §3.3 violation and a blocker per §4 / benchmarks.md C1; the bench reports such rows as a hard failure (non-zero exit code) rather than a degraded gate.

Amendment (PR-K4, 2026-05-29): BodyKind::Structured rows are also excluded from the C1 denominator. Per RFC 0001 §6.4 / RFC 0003 §6.4, reconstruction for structured bodies is a storage-layer round-trip (decode the stored AnyValue bytes) — not a template + params reconstruction — so the template-based equality C1 measures doesn’t apply to them. Structured ≠ lossy (the two are independent axes; a structured record can be high-confidence). The harness symmetrically skips the templates_for() snapshot lookup for those records, because RFC 0001 §6.1 assigns them a sentinel template id outside the Drain tree (no leaf to find).

Pinned definitions:

  • reconstruct(record, template) is the function exposed by ourios_miner::reconstruct::reconstruct, signature fn reconstruct(record: &MinedRecord, template: &[OwnedToken]) -> Vec<u8> — same function RFC 0001 §6.6 specifies and the H7.1 property test in crates/ourios-miner/tests/hazards.rs already exercises at unit scale. The function takes the emitted record and the leaf’s template token slice at the record’s emit-time (template_id, template_version); template snapshots have to be captured separately because a later attach can widen the same leaf and rewrite the live template.
  • Template-snapshot capture mirrors the H7.1 pattern: after each MinerCluster::ingest, the harness walks cluster.templates_for(tenant) and records the current template tokens into a HashMap<(template_id, template_version), Vec<OwnedToken>> via or_insert_with (so the first observation of a (id, v) pair wins and later widenings produce (id, v+1) entries without clobbering). At C1 evaluation time, each record’s (template_id, template_version) looks up its emit-time-active snapshot. A record whose key is not in the map is a contract violation — the harness exits with non-zero before reporting C1.
  • bytes is the original line bytes the loader handed MinerCluster::ingest, captured by the harness alongside each MinedRecord. The bench MUST capture the input line before MinerCluster::ingest borrows or transforms it; the comparison happens against the exact bytes the miner saw.
  • Equality is byte-for-byte == between reconstruct(record, template) (a Vec<u8>) and line.as_bytes(). No trailing-newline normalisation, no case folding, no whitespace trimming.
  • Reported as a fraction with six decimal places (1.000000 / 0.999998). C1’s 100.000% target makes three-decimal precision insufficient — a single failing reconstruction out of 100 000 records is the difference between green and a blocker.

The bench also reports lossy_flag_ratio = count(lossy=true) / count(all) as a quality signal per benchmarks.md C1, with the ≤ 5% / ≤ 20% targets surfaced but not gating.

3.4.3 C2 — Template-count convergence

Per docs/benchmarks.md §4 / C2, the gate is “template count grows sub-linearly and plateaus within 2× of its steady-state value by 1 M lines”. The formula needs three things pinned: when to sample, what counts as plateau, and what counts as “steady-state value”.

The benchmarks.md C2 phrasing — “template count grows sub-linearly and plateaus within 2× of its steady-state value by 1 M lines” — operationalises to: at the 1 M-line mark, the template count is at least half of the count the curve eventually converges to. Since template count is monotonic non-decreasing (the miner does not unmerge templates), this is the cleanest formulation; if count(1M) ≥ SS / 2, the curve cannot have more than doubled between 1 M lines and end-of-corpus, i.e. it is within 2× of its steady-state value. The phrasing reading where SS is defined as max(samples) and the comparison is plateau_value ≤ 2 × max is tautological — plateau_value ≤ max by definition — and was rejected after the first copilot review of this RFC.

Pinned definitions:

  • Sample cadence: every N lines, where N = max(1, ceil(lines_in_corpus / 1024)). The cadence uses ceiling division so the curve never exceeds 1024 samples regardless of corpus size; a 1 M-line corpus samples every 977 lines, a 10 k-line corpus samples every 10 lines. Sampling indices: the curve records template count after processing line indices N-1, 2N-1, 3N-1, … (i.e. after every N-th line, zero-indexed). The final sample is always taken at total_lines - 1 (the last line), regardless of whether it falls on a cadence boundary. The sample count is therefore ceil(total_lines / N) — at most 1024 entries.
  • Steady-state value (SS): the template count at the last sample (line index = total_lines - 1; always included by the final-sample rule above). Operationally, “where the curve ended up”. Not the running max — see the rationale paragraph above.
  • Count at 1 M lines: the template count at the sample whose line index is closest to 999_999 (the millionth line, zero-indexed). When two samples are equidistant, the earlier one wins (floor tie-break). Defined only on corpora of ≥ 1_000_000 lines.
  • Convergence ratio: count_at_1m / SS, defined only when SS > 0. By monotonicity (count_at_1m ≤ SS) it is ≤ 1.0; it is 0.0 when no template has been minted as of the sample nearest the 1 M-line mark (count_at_1m == 0, SS > 0) — count_at_1m is that nearest sample, not the exact millionth line — so the defined range is [0.0, 1.0]. It is undefined (null, paired with a null count_at_1m) when SS == 0 — a ≥ 1 M corpus that mints no templates at all, a 0/0 ratio.
  • Pass condition (gate) — per service (amended for #444, maintainer-approved 2026-07-10): C2 is defined over “a corpus from a single stable service”, so on a multi-service corpus the gate is evaluated per service.name, not on the whole corpus. Each service’s ratio is count_at_1m / SS over that service’s lines, with count_at_1m taken at that service’s exact millionth line (not the whole-corpus nearest-sample; template creation is a globally-monotonic event attributed to the minting service, so per-service creations partition the whole-corpus template count exactly). A corpus passes iff every service with ≥ 1_000_000 lines has ratio ≥ 0.5 — with one exception: a service that mints zero templates over its ≥ 1 M lines (SS == 0, an undefined 0/0 ratio) passes trivially, since a flat-zero count is the strongest possible convergence (C2’s falsifier is linear growth; an all-NO_TEMPLATE service is a body-retention / parse-failure concern, caught by §3.1’s counters, not a convergence failure). It fails if any ≥ 1 M service has a defined ratio below 0.5; it abstains (c2.pass = null) when no service reaches 1 M lines. A single-service corpus — including the plain-text <unknown> bucket (no service.name) — is gated on that one service’s ratio, measured at its exact millionth line. That reproduces the pre-amendment whole-corpus verdict for every historical converged corpus (whose ratio sits far from the 0.5 boundary); it is not bit-identical to the whole-corpus convergence_ratio, which is sampled at the nearest curve point (cadence granularity) and is now only a diagnostic. Only multi-service OTLP corpora change verdict. Rationale: running one whole-corpus ratio over a multi-service capture (e.g. the OTel-Demo) is a category error — it conflates a noisy infra service (a broker emitting high-cardinality offset/path tokens) with clean application services, so the whole-corpus number fails even when every application service converges perfectly (v8 §9.12). The whole-corpus convergence_ratio is retained as a diagnostic (the by_service breakdown is the gate basis). Note: token-level polishing of high-cardinality infra logs is an OTel Collector concern (a transform/redaction processor upstream), not the miner’s — consistent with “format parsing is the Collector’s job”. Cardinality cap: the decomposition holds at most MAX_SERVICES = 1024 distinct service.name buckets (an O(services) memory guard mirroring §3.2); beyond that, further services fold into one <other> bucket and c2.services_truncated is set. A real OTLP capture carries tens of services, so the cap is not expected to bind; if it does, the folded <other> bucket mixes services and its per-service ratio is no longer strictly single-service — services_truncated flags that the run should be re-scoped (the truncation is surfaced, never silent).
  • Plateau-detection diagnostic (not a gate): the curve is “plateaued” at the sample where the trailing K = 64 samples all lie within ± 5% of the SS. The diagnostic is useful for understanding where the curve actually flattens (often well before 1 M lines), but it does not gate the RFC — the gate is the 2× rule above.

Reported as: template_count_at_1m_lines (integer; null for corpora < 1 M lines or a ≥ 1 M corpus with SS == 0), template_count_at_end (integer; this is SS), convergence_ratio (three-decimal float; null under the same two conditions). These two form a matched pair — both null or both set, never mixed — which the report layer relies on (report.rs errors on a mixed pair). pass (bool or null), corpus_at_least_1m (bool).

v1 records the convergence curve in the results JSON (as c2.convergence_curve, an array of {"lines": N, "template_count": M} objects at the sample cadence) but does not plot it. A future RFC may add a plot artefact so the §9 Results section can include visualisations.

3.5 Hardware baseline and annotation

docs/benchmarks.md §1 pins the hardware baseline: “commodity cloud VM, 8 vCPU, 32 GiB RAM, gp3-class SSD.” Every bench run captures the host’s --hardware-kind=<tag> CLI argument (required; defaults to unknown only when explicitly opted in via --allow-unknown-hardware) and writes it into the results JSON. The §9 Results table cites the hardware tag on every row; a comparison across rows with different tags is a delta between hardware and code, not code alone.

Hardware tags this RFC pins as known: baseline-8vcpu-32gib (the §1 reference), dev-laptop, ci-runner. New tags can be added without an RFC amendment — the value is operator discipline, not a closed vocabulary — but unknown tags require the explicit --allow-unknown-hardware opt-in so a forgotten --hardware-kind doesn’t silently land in §9 as unknown.

3.6 Result format

Each bench invocation writes one results JSON to:

benchmarks/results/<UTC-RFC3339-ms-colon-free>-<git-sha7>[-N].json

The name embeds the run’s millisecond-precision RFC3339 timestamp with the : separators replaced by - (so 2026-05-22T14:30:00.123Z becomes 2026-05-22T14-30-00.123Z). The colon substitution is required: : is illegal in filenames on Windows and awkward for shell / tooling elsewhere, so the on-disk name is colon-free even though the timestamp field inside the JSON keeps canonical RFC3339 (colons included). Two runs on the same commit in the same wall-clock second still produce distinct names via the millisecond component.

Even at millisecond precision two runs can theoretically collide on a fast machine. The writer creates each candidate with an atomic create_new (“create iff absent”) open and, on AlreadyExists, appends a numeric suffix (-1, -2, …) until it finds a free name — rather than re-deriving the timestamp. This closes the check-then-write race against a concurrent run and never clobbers an existing file; if the suffix budget is exhausted the write fails loudly rather than overwriting. The directory benchmarks/ will be created at the repo root by the implementation PR that lands the ourios-bench crate. That same PR adds a .gitignore entry ignoring benchmarks/results/ except for a .gitkeep and the specific runs the maintainer chooses to commit (the §9 Results section then cites those by file path).

The JSON shape is pinned by report::ResultsFile and looks like:

{
  "rfc": "RFC 0006",
  "rfc_version": "v1",
  "timestamp": "2026-05-22T14:30:00.123Z",
  "git_sha": "abc1234",
  "hardware_kind": "baseline-8vcpu-32gib",
  "corpus": {
    "directory": "testdata/corpus/",
    "total_lines": 1234567,
    "total_files": 2,
    "raw_bytes": 98765432
  },
  "ourios": {
    "data_parquet_bytes": 56789,
    "audit_parquet_bytes": 1024,
    "total_parquet_bytes": 57813
  },
  "zstd": {
    "level": 19,
    "compressed_bytes": 312345
  },
  "a1": {
    "ourios_ratio": 13.6,
    "zstd_ratio": 3.95,
    "delta": 3.44,
    "target_delta": 3.0,
    "pass": true
  },
  "c1": {
    "non_lossy_total": 12000,
    "non_lossy_reconstruct_ok": 12000,
    "rate": 1.000000,
    "lossy_flag_ratio": 0.0279,
    "pass": true
  },
  "c2": {
    "sample_cadence": 1206,
    "total_lines": 1234567,
    "template_count_at_1m_lines": 142,
    "template_count_at_end": 145,
    "convergence_ratio": 0.979,
    "convergence_curve": [
      {"lines": 1206, "template_count": 14},
      {"lines": 2412, "template_count": 27}
    ],
    "pass": true,
    "corpus_at_least_1m": true
  }
}

The temp-directory paths the bench actually uses (the Writer’s bucket root) are intentionally not in the JSON. They’re an implementation detail that differs across runs and would otherwise break the §5 RFC0006.7 reproducibility scenario. The byte counts are what downstream analysis cares about; the paths are debug-only and logged to stderr when --keep-parquet is passed. The field relationship: total_parquet_bytes = data_parquet_bytes + audit_parquet_bytes, and total_parquet_bytes is the value §3.4.1 calls bytes(ourios_output). data_parquet_bytes is the sum of *.parquet sizes under data/…; audit_parquet_bytes is the sum under audit/…. The split is recorded for diagnostic transparency (understanding how much of the footprint is audit overhead) but the A1 formula operates on the total.

Gate sections are nullable. The a1, c1, and c2 keys are always present at the top level but their values are null when the corresponding gate is skipped (via --gates per §3.7) or abstains (e.g. c2 on a corpus of < 1 M lines — see §3.4.3). The example above shows all three populated (the “all gates ran, all gates pass” case); a --gates c1 run produces "a1": null, "c2": null while "c1": { ... } carries the populated payload. Downstream analysis MUST handle the null case (rather than assuming the object shape) — the §5 RFC0006.6 scenario asserts the behaviour.

rfc_version is a literal "v1" and tracks RFC 0006 amendments; bumping it requires an RFC amendment, and downstream analysis tooling refuses unknown versions with a hard error. This is the bench’s own forward-compatibility policy — the results JSON is a closed schema, unlike RFC 0005 §3.9’s Parquet reader which ignores unknown columns and surfaces unknown ordinals as ParamType::Unknown.

A human-readable summary is appended to docs/benchmarks.md §9 as a sub-heading per run, with the same numbers in a markdown table. Repeated bench runs on the same (git-sha, hardware-kind) pair update the existing sub-heading rather than appending duplicates — the bench reads the §9 section, finds the matching heading, and rewrites it in place.

3.7 Invocation

The CLI has two output-path concepts and they are spelled differently to avoid the §3.4.1 “output bucket directory” ambiguity:

  • --results-dir is where the JSON results file from §3.6 lands. Default: benchmarks/results/.
  • --bucket-dir is the bucket_root passed to the ourios-parquet writer — the directory the writer’s data/ and audit/ partition trees grow under, and whose total byte size is bytes(ourios_output) in the §3.4.1 A1 formula. Default: a fresh temp dir under std::env::temp_dir() per invocation, cleaned up on exit unless --keep-parquet is passed.

CLI (crates/ourios-bench/src/main.rs):

ourios-bench [--corpus <path>]
             [--results-dir <path>]
             [--bucket-dir <path>]
             [--keep-parquet]
             [--hardware-kind <tag>]
             [--allow-unknown-hardware]
             [--update-benchmarks-md]
             [--gates a1,c1,c2]

Flags:

  • --corpus <path> (default testdata/corpus/): directory of corpus files the loader walks recursively. Files are dispatched on extension: *.txt (plain-text per §3.3) and *.jsonl / *.json (OTLP/JSON Lines per §3.1 — one LogsData per line, the OTel File Exporter format). Both formats may coexist in the same directory; any other extension is silently skipped.
  • --results-dir <path> (default benchmarks/results/): where the §3.6 JSON file lands.
  • --bucket-dir <path> (default: fresh temp dir): the Parquet writer’s bucket_root. Cleaned up on exit unless --keep-parquet is passed.
  • --keep-parquet (off by default): suppress the temp-dir cleanup so the Parquet partition tree is inspectable after the bench exits. Path is logged to stderr.
  • --hardware-kind <tag> (required unless --allow-unknown-hardware): the §3.5 annotation.
  • --update-benchmarks-md (off by default): append / rewrite the §9 sub-heading. CI runs without this flag; maintainers invoke with it to commit numbers.
  • --gates a1,c1,c2 (default all): comma-separated subset of gates to compute. Useful when iterating on a single measurement.

Adds a just thesis-bench recipe wrapping cargo run -p ourios-bench --release --. The recipe is not named just bench — the existing bench recipe in justfile already runs cargo bench (criterion micro-benchmarks; the suite is empty today, but the recipe is reserved for the follow-up that lands crates/ourios-bench/benches/). thesis-bench makes the gate-vs-microbench distinction greppable at the recipe level. The --release is normative — A1 on a debug-mode writer would understate compression because debug builds disable some arrow / parquet optimisations the release writer relies on.

CI cadence: not on every PR — too slow for the per-PR loop and hardware-dependent in ways that would generate noise. The bench runs on demand (PR comment /bench, future workflow) and on the nightly schedule that docs/rfcs/0005-parquet- storage.md §7’s open-question on slow-test CI cadence will formalise. RFC 0006 does not commit to a CI cadence — that’s the open question’s domain.

4. Alternatives considered

4.1 criterion instead of a custom harness

criterion is the standard Rust micro-benchmarking framework and CLAUDE.md §6.2 names it for the project’s hot-path benchmarks. Rejected for the thesis-gate harness: criterion is statistically tuned for sub-microsecond function-level measurements (per-iteration noise estimation, warmup loops, bootstrapped confidence intervals), which is the wrong tool for “ingest a 1 M-line corpus, write a Parquet partition, then divide two file-tree sizes.” The bench also runs criterion benchmarks under crates/ourios-bench/benches/ for the per-line miner cost and the per-batch writer cost — but that’s a follow-up PR after the thesis-gate harness lands, not the v1 shape.

4.2 Bench inside ourios-parquet as an [[example]]

A Cargo [[example]] under crates/ourios-parquet/examples/ could drive the writer + reader without a new crate. Rejected: the bench needs the miner and the writer plus a custom result-file writer; living under ourios-parquet would either add a ourios-miner dependency to the storage crate (architecturally wrong — storage has no business knowing about template mining) or grow into a binary that’s not really an “example” anymore. The dedicated crate matches the docs/roadmap.md §4 Phase 3 layout.

4.3 Quote A1 against the LogPAI corpora only

The Drain paper measures on LogPAI’s HDFS / BGL / Spark / Apache / OpenSSH / Windows corpora; we could pin A1 to the same corpora exclusively and call any other corpus a “tuning” measurement. Rejected: docs/benchmarks.md §1 already commits to “every corpus in §1”, including the self-collected archetypes. Restricting v1 to LogPAI would leave the self-collected work unmeasured and reintroduce the “we never ran the bench on the data that matters” gap §1 is designed to close. v1 measures on whatever corpora are committed; the seed corpus is the floor, and additions are additive.

4.4 ZSTD level 3 for the reference

ZSTD-3 is the codec the writer itself uses per RFC 0005 §3.5. Using ZSTD-3 also as the A1 reference would make ourios_ratio / zstd_ratio an apples-to-apples codec-vs-codec comparison instead of a structure-vs-codec one (both sides use the same compressor; Ourios’s win is purely the template-mining pillar). Rejected because:

  • The Drain paper compares against the strongest competent byte codec, and that’s ZSTD-19 / level-max. Using ZSTD-3 understates the codec’s reachable ratio and inflates Ourios’s A1 win.
  • CLAUDE.md §1’s central claim is “Parquet + template mining + DataFusion collapses [the layers]”; that claim is about the whole stack, not just the template-mining pillar. The reference should be the strongest alternative, not the same codec Ourios uses internally.

The downside — losing the codec-vs-codec isolation — is captured as an open question (§7). A future RFC may add A1' (prime, “codec-isolated”) as an additional tuning-goal measurement alongside the thesis-gate A1.

4.5 Defer the bench to after the corpus migration

The roadmap names “OTLP LogsData corpus” as the Phase 3 goal and one could argue the bench should not land until the corpus is in its target shape. Rejected: A1 / C1 / C2 are well-defined on plain-text input today (the seed corpus is plain text and the unit-scale H7.1 test already runs against it). Waiting on the OTLP migration to produce A1 / C1 / C2 numbers couples a mechanical loader change to a measurement deliverable for no real reason. The bench’s corpus.rs exposes the loader as an abstraction so the OTLP migration drops in without touching the harness or the formulas.

5. Acceptance criteria

Scenario RFC0006.1 — A1 formula is well-defined on the seed corpus

  • Given the bench is invoked with --corpus testdata/ corpus/, the writer ships with the §3.5 / §3.6 RFC 0005 encoding policy, and the zstd_safe Rust crate is linked (per the §7 resolution of the ZSTD-integration question)
  • When the bench runs the A1 measurement
  • Then bytes(raw_corpus) equals sum(std::fs::metadata(f).len()) over the consumed corpus files (*.txt, *.jsonl, *.json) in the corpus directory
  • And bytes(ourios_output) equals the sum of all *.parquet (not *.parquet.tmp) file sizes under the bench’s output bucket, including the audit/... partition
  • And bytes(zstd_corpus) equals the sum of std::fs::metadata(f).len() over the *.zst files produced by zstd -19 --no-progress on each consumed input (same extension set as bytes(raw_corpus))
  • And the reported delta equals ourios_ratio / zstd_ratio, rounded down to three significant figures

Scenario RFC0006.2 — C1 = 100% on the seed corpus, mismatch is a hard failure

  • Given the bench is invoked with the seed corpus committed under testdata/corpus/
  • When the bench runs the C1 measurement
  • Then non_lossy_reconstruct_ok / non_lossy_total = 1.000000 (six-decimal precision)
  • And the results JSON records c1.pass = true
  • And if any non-lossy row has reconstruct(record) != ingested_bytes, the bench writes the failing row’s template_id, template_version, expected bytes, and actual reconstruction to stderr and exits with non-zero, and the results JSON records c1.pass = false
  • And the bench writes the results JSON irrespective of --update-benchmarks-md — the JSON file always lands; only the docs/benchmarks.md §9 mutation is gated by the flag, so a failure run still leaves a machine-readable record on disk

Scenario RFC0006.3 — C2 gate (“within 2× of SS by 1 M lines”) on a stable corpus

  • Given a synthetic stable corpus of ≥ 1_000_000 lines whose template alphabet is bounded (constructed by the bench’s integration test; not committed to testdata/corpus/)
  • When the bench runs the C2 measurement
  • Then c2.corpus_at_least_1m = true
  • And template_count_at_1m_lines is the integer template count at the sample whose line index is closest to 999_999 (zero-indexed; per §3.4.3)
  • And template_count_at_end is the integer template count at the final sample (the §3.4.3 SS definition)
  • And convergence_ratio = template_count_at_1m_lines / template_count_at_end ≥ 0.5 — the “within 2× of SS” gate, made non-tautological by defining SS as the end-of-corpus value rather than the running max
  • And c2.pass = true
  • And the convergence curve in the results JSON has exactly ceil(total_lines / sample_cadence) samples (the sampling rule pinned in §3.4.3: indices N-1, 2N-1, 3N-1, … plus a guaranteed final sample at total_lines - 1)
  • And on a corpus of < 1_000_000 lines, c2.corpus_at_least_1m = false, c2.pass = null, and c2.template_count_at_1m_lines = null — the gate abstains rather than passing or failing

Scenario RFC0006.4 — Result file shape is stable and the §9 update is reversible

  • Given the bench has run and written its results JSON to benchmarks/results/<...>.json
  • When a downstream consumer (or a future RFC’s bench) reads the file
  • Then the JSON parses against report::ResultsFile with rfc_version = "v1"
  • And the file contains the §3.6 schema’s required keys (rfc, rfc_version, timestamp, git_sha, hardware_kind, corpus, ourios, zstd, a1, c1, c2)
  • And when --update-benchmarks-md is passed and the §9 section already contains a sub-heading for the same (git_sha, hardware_kind) pair, the bench rewrites that sub-heading in place — running the bench twice on the same commit / hardware does not duplicate §9 rows

Scenario RFC0006.5 — Hardware-kind annotation is required

  • Given the bench is invoked without a --hardware-kind flag and without --allow-unknown-hardware
  • When the bench parses CLI arguments
  • Then the bench exits with a usage error before any measurement runs
  • And if --allow-unknown-hardware is passed, the resulting JSON carries hardware_kind = "unknown" and stderr emits a warning naming the §1 baseline tag for reference

Scenario RFC0006.6 — --gates flag scopes the measurement

  • Given the bench is invoked with --gates c1
  • When the bench runs
  • Then only the C1 measurement executes; A1 and C2 are skipped
  • And the results JSON contains c1 populated and a1, c2 set to null
  • And the §9 update path (when --update-benchmarks-md is passed) leaves the existing A1 / C2 numbers for the (git_sha, hardware_kind) pair untouched

Scenario RFC0006.7 — Bench is reproducible across runs

  • Given the bench is invoked twice on the same git checkout and the same corpus, with no code or data changes in between
  • When the two runs complete
  • Then every measurement field of the results JSON is bit-identical across the two runs — specifically corpus.raw_bytes, corpus.total_lines, corpus.total_files, ourios.data_parquet_bytes, ourios.audit_parquet_bytes, ourios.total_parquet_bytes, zstd.compressed_bytes, a1.delta, c1.rate, c1.non_lossy_total, c1.non_lossy_reconstruct_ok, c2.template_count_at_end, and (when the corpus is ≥ 1 M lines) c2.template_count_at_1m_lines / c2.convergence_ratio
  • And the only fields that legitimately differ are timestamp (wall-clock) and the output JSON file’s path (derived from timestamp). The temp-dir bucket the writer used is not in the JSON per §3.6, so it cannot contribute to a spurious diff

6. Testing strategy

Per CLAUDE.md §6.2 / docs/verification.md §2:

  • RFC0006.1 — integration test in crates/ourios-bench/tests/a1.rs. Calls ourios_bench::run against a fixture corpus committed under crates/ourios-bench/tests/fixtures/, captures the resulting JSON, and asserts each formula leg (raw_bytes from fs::metadata, total_parquet_bytes from inspecting the output bucket, zstd_bytes from the zstd_safe crate per the §7 ZSTD-integration resolution).
  • RFC0006.2 — integration test in crates/ourios-bench/tests/c1.rs. Drives the bench against the seed corpus; asserts c1.rate == 1.0. A second sub-test injects a synthetic record whose reconstruct() disagrees with the input (built by hand, not by the miner) and asserts the bench exits with a non-zero code and emits the mismatch diagnostics to stderr.
  • RFC0006.3 — integration test in crates/ourios-bench/tests/c2.rs. Builds a synthetic corpus in memory (no committed testdata/) of 1.5 M lines with a known small template alphabet; asserts convergence_ratio ≥ 0.5 and the convergence curve has exactly total_lines / sample_cadence entries (rounded). A second sub-test feeds a non-plateauing corpus (every line introduces a new template structure) and asserts c2.pass = false.
  • RFC0006.4 — colocated unit test in crates/ourios-bench/src/report.rs. Serialises a hand-built ResultsFile, parses the JSON back, asserts field-by-field equality. A second sub-test exercises the in-place §9 update via a temp markdown file.
  • RFC0006.5 — colocated unit test in crates/ourios-bench/src/main.rs (#[cfg(test)] mod tests) for the CLI parser. Asserts the missing --hardware-kind flag without --allow-unknown-hardware produces a usage error before Harness::run is invoked.
  • RFC0006.6 — same test file as RFC0006.5; covers the --gates filtering.
  • RFC0006.7crates/ourios-bench/tests/ reproducibility.rs. Runs the bench twice against a fixed fixture corpus and asserts the relevant fields bit-equal.

A criterion bench under crates/ourios-bench/benches/ is deferred to a follow-up PR. The thesis-gate harness this RFC specifies is correctness-first; per-line miner microbenchmarks are a separate measurement category.

7. Open questions

  • zstd integration. Resolved 2026-05-25: the bench links the zstd_safe Rust crate. Already in the dep tree via parquet’s zstd feature, so the marginal build cost is zero. The decision turns on cross-platform reproducibility: shell-out requires zstd on PATH at runtime (not default on macOS or Windows, version varies across Linux distros), and version drift across hosts would mean the same Ourios commit produces different A1 numbers on different machines. With the crate, the compressor version is pinned by Cargo.lock and the bundled C library builds on every Tier 1 Rust platform — A1 is reproducible across Linux / macOS / Windows / CI runners without a host-side install step. The Drain-paper apples-to-apples concern is small in practice: zstd_safe wraps the same C library at the same compression level, so the resulting bytes are identical to what the CLI binary produces. (RFC0006.1 asserts the byte-count formula directly; if a future observer wants to spot-check against a CLI binary, the JSON results file records zstd.level = 19 so a reproduction pipeline is unambiguous.)
  • Convergence curve plotting. The results JSON carries the full sample series. Should the §9 sub-heading also render a tiny SVG / ASCII plot of the C2 curve, or is the curve only for downstream analysis? Defer until at least one real run exists.
  • CI cadence. When (or whether) the bench runs on a schedule: trigger is the RFC 0005 §7 open question on slow-test CI cadence. This RFC inherits the question; resolution is the workflow PR that lands the cadence.
  • Result-file retention policy. benchmarks/ results/*.json will be gitignored by default (§3.6); specific runs are committed when the maintainer cites them in §9. Open: should there be a benchmarks/results/baseline/ sub-directory whose contents are always committed, so regression detection has a stable reference even when the §9 markdown is hand-pruned?
  • Out-of-tree corpora. A --corpus <external-path> invocation against, say, a downloaded LogPAI corpus runs but the results JSON points to a path the repo doesn’t carry. Should the JSON record a content hash of the corpus directory (sha256 of the concatenated files) so future readers can verify they’re comparing against the same input? Probably yes; defer the mechanics until at least one out-of-tree corpus is actually being measured.

8. References

  • CLAUDE.md §1 (project charter), §2 (pillars), §3.3 (bit-identical reconstruction), §6.2 (testing discipline), §10 (docs/hazards.md reading rule).
  • docs/benchmarks.md §1 (corpora + methodology), §2 (A1), §4 (C1, C2), §7 (thesis-gate summary), §9 (Status).
  • docs/roadmap.md §4 Phase 3 (bench + querier scope), §5 (deferred capabilities).
  • docs/rfcs/README.md (RFC process and maturity model).
  • docs/rfcs/0001-template-miner.md §6.6 (reconstruct), §6.4 (audit-event contract that C2’s plateau exercises).
  • docs/rfcs/0005-parquet-storage.md §3.5 (row-group sizing the A1 measurement implicitly depends on), §3.6 (encoding policy that affects compressed bytes), §7 (open question on slow-test CI cadence inherited here).
  • docs/verification.md §2 (scenario-id greppability convention), §3 (maturity-stage gates).

RFC 0007 — Querier


rfc: 0007 title: Querier — DataFusion execution frontend for the logs DSL status: validated author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-06-01 supersedes: — superseded-by: —

RFC 0007 — Querier: DataFusion execution frontend for the logs DSL

Status note. validated (2026-06-12, per the maintainer’s authorization of the same date). The docs/verification.md §3 ladder requires for validated that “every thesis-gate in benchmarks.md §7 that the RFC’s pillars touch passes on representative corpora.” This RFC’s pillar is the query engine (pillar #3 — DataFusion); the gates it touches are B1 and B2, and both now pass authoritatively on the §1 hardware baseline (baseline-8vcpu-32gib), measured over ~1 GB+ corpora including a second corpus family — LogHub HDFS_v1, 11.2 M rows (docs/benchmarks.md §9.4): B1 at 34.2× / 25.4× against the ≥ 10× gate with exact row-count agreement vs the reference pipeline; B2’s windowed template-exact scan flat at 1 row group / 4.2–5.9 ms from 735 k to 11.2 M rows while the full-span variant grows with the corpus. A1’s authoritative FAIL does not gate this RFC: the ladder scopes validation to the gates the RFC’s pillars touch, and A1 belongs to the template-mining / compression pillar (measured under RFC 0006), where its escalation is handled. The prior validated-pending checklist resolves as: (1) authoritative baseline-8vcpu-32gib rerun — ✓ done (§9.4); (2) denser error band — still open, a non-blocking quality improvement (the §9.4 B1 bands remain 11 / 28 rows); (3) second corpus family for B2 — ✓ done (HDFS_v1 via the query-bench arm). Earlier history: the §5 acceptance criteria RFC0007.1–.5 went green via crates/ourios-querier/tests/{execution,boundary,forward_compat}.rs and the crates/ourios-querier/src/lib.rs no-leakage unit test (tests/acceptance.rs is a pointer to them); the first indicative ci-runner B1/B2 readings are §9.3. accepted follows on maintainer sign-off per the docs/rfcs/README.md ladder.

1. Summary

Introduces the ourios-querier crate (pillar #3 — DataFusion as the query engine). It takes a parsed logs-DSL query (RFC 0002), lowers it to a DataFusion LogicalPlan over the RFC 0005 Parquet data + audit files on object storage, executes it with aggressive predicate pushdown (row-group skipping via min/max statistics, bloom filters, page indexes), and returns results without ever exposing DataFusion or SQL to the caller (hazard CLAUDE.md §4.6). It is the home of the B1 (predicate-pushdown) and B2 (template-exact query latency) thesis gates that RFC 0006 §1 deferred. The crate is the read path; it depends on neither the WAL (RFC 0008) nor the receiver (RFC 0003) — it reads what the writer already produced.

2. Motivation

2.1 The thesis’s load-bearing half is unmeasured

CLAUDE.md §1 stakes Ourios on collapsing the inverted index, the compression layer, the storage tier, and the query engine into “one stack of off-the-shelf parts plus thin glue.” The compression and storage claims (A1/C1/C2) are now measured against a real OTLP corpus (RFC 0006, the corpus/otel-demo-v* series). The query claim — that template structure + Parquet statistics let us answer queries by skipping data rather than scanning it — has no code and no measurement. B1/B2 are blank. Until they aren’t, “viable log backend” is unproven on its central premise.

2.2 Why at this layer, and why now

docs/roadmap.md Phase 3 names ourios-querier alongside ourios-bench (shipped). RFC 0006 §1 explicitly routes B1/B2 here. The dependency it needs — ourios-parquet’s reader contract (RFC 0005 §3.9 reader contract) — already exists, so the querier can be built and benchmarked in parallel with the WAL/receiver ingest path. It is the highest-information work available: it converts the project’s biggest open question into a measurement.

2.3 Why an RFC and not just a crate

A new crate is an architectural commitment (CLAUDE.md §7), it realises pillar #3 (§5.1), and it owns hazard §4.6 (no DataFusion leakage to users). The DSL→plan→execution boundary and the B1/B2 acceptance criteria need pinning before code so the bench gates are testable contracts rather than retrofitted numbers.

3. Background — what the querier is and is not

3.1 Is

A library crate exposing a Querier that accepts an RFC 0002 query AST, compiles it to a DataFusion LogicalPlan, registers the RFC 0005 Parquet files as a partitioned ListingTable (or a custom TableProvider when partition pruning needs it), executes via DataFusion’s physical planner, and streams typed result rows back.

3.2 Is not

  • Not the DSL parser/surface — that is RFC 0002. The querier consumes the AST RFC 0002 produces.
  • Not a SQL endpoint. DataFusion’s SQL frontend, LogicalPlan types, and arrow/datafusion errors never cross the public API (hazard §4.6). The public surface speaks logs-DSL and Ourios result/error types.
  • Not the storage format. It reads the RFC 0005 contract; it does not define it.

4. Proposed design

4.1 Crate shape

crates/ourios-querier/, #![deny(unsafe_code)], workspace lints. Public surface (sketch — names provisional):

#![allow(unused)]
fn main() {
pub struct Querier { /* object-store handle, session ctx, config */ }
pub struct QueryRequest { tenant: TenantId, query: ParsedQuery, /* time bounds, limit */ }
pub struct QueryResult { /* typed rows + stats: rows, row_groups_scanned, row_groups_pruned, bytes_read */ }
pub enum QueryError { /* no datafusion/arrow types leaked */ }
impl Querier {
    pub async fn run(&self, req: QueryRequest) -> Result<QueryResult, QueryError>;
}
}

4.2 DSL → LogicalPlan lowering

RFC 0002 §5.5 fixes the compilation target as a DataFusion LogicalPlan for both syntax branches. The querier owns that lowering: predicates → Expr filters; template references → template_id equality/IN; time bounds + tenant → partition-key filters (Hive partitioning per RFC 0005). The lowering is the only place DataFusion types appear; they are an implementation detail behind run.

4.3 Predicate pushdown (the thesis mechanism)

Pushdown is scoped to exactly the columns RFC 0005 indexes. Its §3.3 query-consumer-absence rule fixes the Phase 3 B1/B2 pushdown keys as template_id, tenant_id, and time_unix_nano, and §3.6 deliberately gives params list values no page index and no bloom filter (per-row entropy too high). The querier therefore relies on:

  • Partition pruning: tenant_id and time partition keys filter whole directories before any file is opened.
  • Row-group skipping: min/max statistics on template_id, time_unix_nano, and severity let DataFusion drop row groups whose stats can’t satisfy the predicate.
  • Bloom filter / page index on template_id (RFC 0005 §3.6 writer policy) for high-selectivity template-exact equality (B2).
  • Param predicates are not row-group-prunable under the current RFC 0005 format — they apply as post-scan DataFusion filters over the rows the above pruning leaves. They benefit from template/time pruning narrowing the scan, but a param value alone skips no row groups; param-level pruning would need a future RFC 0005 §3.6 storage amendment (§8).
  • The querier configures the DataFusion session so the above are enabled, and surfaces row_groups_pruned / bytes_read in QueryResult stats so B1 can assert pruning actually happened.

4.4 No-leakage boundary (hazard §4.6)

A boundary test asserts the public API’s types are Ourios-owned: no datafusion::* / arrow::* / SQL strings in signatures or error Display. DataFusion is a pub(crate) dependency.

5. Acceptance criteria

Given/When/Then, ids greppable from tests. These realise the RFC 0006 B1/B2 gates as querier-level contracts.

  • RFC0007.1 — B1 predicate pushdown prunes row groups [thesis]

    • Given a corpus partitioned across many row groups where a target template_id lives in a known minority of them
    • When a template-exact query runs
    • Then the pruned fraction row_groups_pruned / (row_groups_scanned + row_groups_pruned) (both QueryResult stats fields) exceeds a floor (e.g. ≥ 80% on the bench corpus)
    • And bytes_read is sub-linear in corpus size for fixed result size.
  • RFC0007.2 — B2 template-exact latency scales with result, not corpus [thesis]

    • Given the same query against corpora of increasing size with the result-set size held ~constant
    • When each is executed
    • Then median latency is bounded by result size, not corpus size (the inverted-index-collapse claim, docs/benchmarks.md B2) — measured by criterion across the corpus/otel-demo-v* series.
  • RFC0007.3 — no DataFusion/SQL leakage [§4.6]

    • Given the public API
    • When a query errors or returns
    • Then no datafusion/arrow/SQL type appears in any public signature or error message (compile-/string-level boundary test).
  • RFC0007.4 — forward-compatible reads [§3.5]

    • Given Parquet files with unknown columns (future schema) or missing optional columns (old schema)
    • When queried
    • Then results honour RFC 0005 §3.9 reader-contract defaults without error.
  • RFC0007.5 — tenant isolation [§3.7]

    • Given multi-tenant data
    • When a query for tenant T runs
    • Then no row from another tenant can appear, enforced at the partition-prune layer (a query without a tenant is a usage error, not a cross-tenant scan).

6. Testing strategy

Mapped to CLAUDE.md §6.2:

  • Unit — DSL→LogicalPlan lowering (RFC0007.1/.4/.5 plan shape), colocated.
  • Boundary test — RFC0007.3 no-leakage (trybuild/string assertion).
  • Integration — run queries over fixture Parquet from the ourios-parquet writer; assert row_groups_pruned/bytes_read (RFC0007.1) and tenant isolation (RFC0007.5).
  • Bench (criterion) — RFC0007.2 latency-vs-corpus-size across corpus/otel-demo-v*; wired into ourios-bench as the B1/B2 gates, closing the RFC 0006 §1 deferral.
  • Property (proptest) — lowering total over the RFC 0002 AST (no panic; tenant + time bounds always present in the plan).

7. Alternatives considered

  • Expose DataFusion SQL directly (no logs DSL). Cheapest to build — register the tables, hand users SQL. Rejected: it violates hazard §4.6 (no DataFusion/SQL leakage), couples the user-facing query contract to an implementation dependency, and forfeits the logs-shaped ergonomics RFC 0002 exists to provide.
  • Write a bespoke vectorised execution engine. Maximum control over pushdown. Rejected: it contradicts pillar #3 (CLAUDE.md §2 — “we do not write a vectorised execution engine”) and the “off-the-shelf parts plus thin glue” thesis (§1). DataFusion already does row-group skipping from Parquet stats.
  • Lucene/Tantivy-style inverted index alongside Parquet. A second index structure for term lookups. Rejected for v1: the thesis is that template structure + Parquet statistics collapse the inverted index into the columnar store (§1) — adding a separate index pre-judges that the collapse fails, which is what B1/B2 are meant to test. Revisit only if B1/B2 fail.
  • Defer the crate until RFC 0002’s DSL branch is decided. Rejected: the execution layer (lowering target, pushdown, B1/B2 measurement) is branch-independent (RFC 0002 §5.5), and B1/B2 are the project’s largest unmeasured risk — building the branch-independent half now buys the thesis signal soonest. The parser integration landed once RFC 0002 §3 resolved (Branch B); see §8.

8. Open questions

  • RFC 0002 §3 resolved (Branch B, #143) and the parser integration landed (#145–#154; RFC 0002 is green). The execution layer here was branch-independent throughout, as planned.
  • ListingTable vs a custom TableProvider — does partition pruning over object storage need the custom provider, or does the listing table’s pruning suffice?
  • Param-predicate pushdown is out of scope under the current format (RFC 0005 §3.6 gives params no index/bloom). If param predicates ever need row-group pruning, that’s a future RFC 0005 §3.6 storage-format amendment (add index/ bloom to selected param columns — selectivity vs file-size cost), not a querier-side policy decision.
  • Streaming vs materialised results in QueryResult (large result sets); pagination surface.
  • Object-store caching / footer-cache policy for repeated queries — affects B2 measurement methodology.
  • Async runtime + concurrency model for the querier role of the server binary (RFC 0003 sibling).

9. References

  • CLAUDE.md §1 (thesis), §2 pillar #3 (DataFusion), §4.6 (DSL/no leakage hazard), §3.5 (schema evolution), §3.7 (multi-tenancy), §7 (new crate).
  • RFC 0002 — query DSL (the syntax this executes; §5.5 plan target).
  • RFC 0005 — Parquet storage (the reader contract this queries).
  • RFC 0006 — bench harness (defers B1/B2 here; the corpus series).
  • docs/benchmarks.md B1/B2 (the thesis-gate definitions).
  • docs/roadmap.md Phase 3.

RFC 0008 — Write-ahead log


rfc: 0008 title: Write-ahead log — durable buffer between OTLP receiver and Parquet writer status: accepted author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-05-29 supersedes: — superseded-by: —

RFC 0008 — Write-ahead log

Status note. accepted (2026-06-14, maintainer sign-off — the terminal ladder status per docs/rfcs/README.md). Reached green 2026-06-13 (criteria below); validated is vacuous for the WAL (its pillar touches no thesis gate — see the closing paragraph), so the maintainer advances it directly from green to accepted. The docs/verification.md §3 / docs/rfcs/README.md ladder defines green as all §5 acceptance criteria pass. Every RFC0008 §5 arm (.1–.10) now has a live, passing test — no #[ignore]/unimplemented!() acceptance stubs remain under crates/ourios-wal/tests/ (the encode_audit_event free fn in lib.rs is still unimplemented!(), but that is the §9 AuditEvent serde-format deferral, not a §5 acceptance criterion): .1 wal-before-ack, .2 crash-recovery completeness (the real-SIGKILL CI gate), .3 recovery non-amplification, .4 torn-write heal, .5 corruption (all five reasons), .6 segment rotation, .7 checkpoint + durable sidecar, .8 batched-fsync group commit, .9 bounded wal_unflushed_bytes, .10 the startup recovery driver. Landed across #123/#126 (recovery), #185–#187 (snapshot restore), #188 (rotation + §6.9 cadence), #189 (this spec’s audit-deferral amendment), #190 (the .1/.3/.4/.5/.9 arms), and #191 (.8).

One deferral, not a gap. RFC0008.5’s corruption audit event is deferred to a system-scoped-audit follow-up (§9, 2026-06-13 amendment) — the audit stream is tenant-partitioned and WAL corruption has no tenant. The arm’s load-bearing halves (structured RecoveryError + halt-all-segments) are green and corruption stays loud (wal_corrupt_frames_total); only the durable queryable record is postponed.

validated is vacuous here; accepted is the maintainer’s call. The ladder’s validated stage gates on thesis-gates in benchmarks.md §7 (compression / query-latency / reconstruction). The WAL is a durability buffer — its pillar touches no thesis gate — so the validated condition (“every thesis-gate the RFC’s pillars touch passes”) is vacuously satisfied now that §5 is green. The WAL never self-promoted through the vacuous validated stage; the terminal accepted flip was the maintainer’s call per docs/rfcs/README.md, granted 2026-06-14.

How to read this document. Sections §§1–4 are the design contract — the what and the why. §5 lists the normative Given / When / Then scenarios — the contract. §6 is the precise specification the ourios-wal crate is implemented against. §7 records the alternatives we evaluated and rejected. §8 maps each §5 scenario to a test technique and a test file. §9 holds the open questions still up for debate.

1. Summary

Ourios introduces an ourios-wal crate that owns the on-disk write-ahead log between the OTLP receiver and the rest of the ingest pipeline. Every accepted OTLP batch lands as one length-prefixed, CRC-validated frame in an append-only segment file on local disk; the receiver acknowledges only after the batch is durably fsync’d, satisfying CLAUDE.md §3.4 WAL-before-ack. Segments rotate by size or time (whichever first); a recovery scanner replays surviving frames through the normal ingest pipeline on restart; and a checkpoint mechanism lets the Parquet writer signal which records are durably on object storage so the corresponding WAL segments can be deleted. Replication is explicitly out of scope — when it lands, it is in addition to the WAL, not instead of it (CLAUDE.md §3.4).

2. Motivation

2.1 The §3.4 invariant has no implementation

CLAUDE.md §3.4 pins WAL-before-ack as one of the non-negotiable invariants (“Ingester acknowledges an OTLP batch only after it has been durably written to the WAL. … No in-memory-only acks, ever.”). docs/hazards.md H3 carries the matching hazard. No crate currently implements it. RFC 0003 §6.5 calls the contract out as a hard dependency (“the receiver itself is post-MVP per roadmap.md §5; … cannot be enabled until ourios-wal lands, and there is no MVP code path that acks a network request before durability”), but leaves the WAL itself unspecified. This RFC is that specification.

2.2 The receiver is blocked on this

RFC 0003 (OTLP gRPC + HTTP receiver) is at drafted and will stay there until §5’s acceptance criteria can credibly assert the WAL-before-ack sequence — which requires the WAL to exist. Landing ourios-wal therefore unblocks RFC 0003’s progression to specified, then implementation, then a real “telemetrygen → ourios-receiver → measure” live-services test path. The bench’s PR-K2 file-loader path (RFC 0006 §3.1) remains the MVP route in the meantime; the WAL is what lets ingest happen over the wire.

2.3 Roadmap context

docs/roadmap.md §5 lists the WAL as post-MVP. This RFC does not move it into the MVP; it specifies the post-MVP implementation. The MVP corpus path (file loader → miner → Parquet writer) does not use the WAL — it bypasses the receiver entirely, which is precisely why the bench works today without the WAL.

3. Background — what we are and aren’t building

3.1 What a WAL is in this context

A write-ahead log is the canonical pattern from durable storage systems (PostgreSQL, RocksDB, LMDB, Kafka): every durability-relevant change is appended to a strictly-sequential log on stable storage before it is acknowledged or applied to the live data structures. On crash, the system replays the log to reach a consistent post-crash state. Two properties make WALs suitable for the §3.4 invariant:

  1. Sequential append + batched fsync amortises the disk sync cost across many small writes — orders of magnitude cheaper than per-record fsync, with the durability still bounded by the batch latency.
  2. Strict ordering lets recovery be a forward scan: read frames left-to-right and replay each. No log-side rewrite, no merge.

We are not building Raft / Paxos / Chubby. The WAL is a single-writer single-node component; replication is CLAUDE.md §3.4’s explicit non-goal at this layer.

3.2 What goes into the WAL

The WAL carries two frame kinds, distinguished by a 1-byte discriminator (§6.2.2):

  • FrameKind::OtlpBatch — payload is the OTLP protobuf bytes the wire delivered (ExportLogsServiceRequest), verbatim. Per-batch (not per-record) granularity matches the §3.4 ack boundary; one fsync gates one ack. The payload is the same bytes the receiver decoded, so recovery is “re-run the decode + fan-out pipeline” (§6.6) rather than “rehydrate per-record proto from a custom format.” Tenant fan-out (RFC 0003 §6.3) stays on the receiver’s side of the WAL.
  • FrameKind::AuditEvent — payload is a single ourios_core::audit::AuditEvent (the TemplateWidened / TemplateTypeExpanded / TemplateWideningRejectedDegenerate shape RFC 0001 §6.4 defines). RFC 0001 §6.7 and RFC 0005 §3.7 both pin “audit events route through the same WAL path as data records;” RFC 0005 §3.7 explicitly defers the contract to this RFC (“a contract that lands with the post-MVP ourios-wal crate; until then audit-event durability is in-memory and the corpus bench accepts that”). The frame- kind discriminator is how that contract is honoured. The exact AuditEvent byte encoding is §9 open (“AuditEvent has no serde derives today; the encoder lands alongside them”).

The receiver flow RFC 0003 §6.5 already pins for the OTLP-batch kind: decode batch → WAL append → fsync → ack on the critical path; tenant fan-out + mining + Parquet writes happen post-ack. The audit-event kind is appended during the post-ack mining work — under the §6.4 audit-ordering barrier: audit-event frames for record R must be append-ed and sync-ed before the data Parquet row group containing R becomes durable on object storage. RFC 0001 §6.4 spells this out as a normative requirement on this RFC (“a data record carrying template_version = V must not become durable before every audit event justifying the leaf’s progression to V is durable”); §6.4 below pins the WAL-side discipline that satisfies it.

3.3 What does not go into the WAL

  • Miner state. The Drain tree is reconstructed by replaying the WAL records through the miner; we do not snapshot it. Snapshotting becomes interesting if recovery time on a hot-template corpus exceeds the operator’s patience; that is §9 open question.
  • Parquet writer state. The Parquet writer’s open row groups are not durable; on crash the in-flight row group is lost and rebuilt from the WAL. Atomic-publish (RFC 0005 §3.7 / RFC0005.2) means closed row groups are durable and need no replay.
  • Query state. The querier is read-only against object storage; it has no recovery concern at this layer.

4. Background — existing Rust durability ecosystem

4.1 What we surveyed

Rust’s WAL crate landscape divides into two camps:

  • Heavy embedded databases (sled, redb, fjall, rocksdb via FFI). These give us a WAL for free but also a B-tree, MVCC, transaction model, and a persistent key-value abstraction — none of which the ingest path consumes. Carrying them adds dependency surface area (sled is still pre-1.0 with known durability bugs; rocksdb adds a C++ link and forecloses pure-Rust toolchains) for an API we do not use.
  • Focused WAL crates (okaywal, wal, vlog). Smaller surface, but each makes a different opinionated choice (multi-writer arbitration, async vs sync I/O, segment format) and the format becomes our wire-compat boundary the same way it would for a hand-rolled implementation.

4.2 Why hand-roll

The component we need is small (single writer, append-only, length-prefixed framing, CRC, batched fsync, segment rotation, linear recovery, checkpoint-driven truncation — call it 600 lines of careful Rust). The wire format is what we have to be careful about; the surrounding code is mechanical. A focused crate would impose its own format conventions on us at the same boundary, so the dependency saves implementation time but not design time. We hand-roll, keep the format under our direct control, and §7 records the focused-crate alternatives we considered.

5. Acceptance criteria

Scenario RFC0008.1 — WAL-before-ack [§3.4]

  • Given a fake receiver wired to a real Wal (opened with defaults) and a single OTLP ExportLogsServiceRequest batch ready to acknowledge
  • When the receiver runs its accept path
  • Then the 2xx (gRPC OK) response is emitted only after the Wal::sync call returns Ok(_) — measured by an AtomicBool set after sync returns Ok(_) (not inside sync; the probe inside sync would already be true mid-call, which would let an ack racing the sync trivially pass). The ack-emit path asserts the flag is true before sending the response, and the receiver’s pre-sync points (decode, tenant_derive, append) all assert the flag is false
  • And wal_unflushed_bytes is non-zero between append and sync, and zero after sync returns
  • And a fault injected at append (returns AppendError) suppresses both the sync and the ack (no record of the batch ever reaching disk or the client)
  • And a fault injected at sync (returns SyncError) suppresses the ack and surfaces the error to the receiver per §9’s “what does the receiver do when sync returns error?” open question — the test asserts that the ack does not fire, the specific receiver behaviour beyond that being out of this RFC

Scenario RFC0008.2 — Crash-recovery completeness [§3.4 / H3]

  • Given a cargo test harness that forks a child running a receiver wired to a real Wal, with the parent controlling the request rate and a deterministic record generator
  • When the parent sends SIGKILL between Wal::append and Wal::sync (first arm), and between Wal::sync and the simulated ack (second arm)
  • Then on restart, Wal::replay produces every frame the child had fsync’d before the kill (no fsync’d frame is lost — the H3 invariant)
  • And any frame whose append completed but sync did not falls into one of three buckets, per §6.6: replayed as a normal frame (complete + CRC-valid → the kernel post-mortem flush left it on disk; legitimate but un-acked at the client), surfaced via the §6.6 step 4 newest-segment torn-tail truncate (partial header / partial payload), or surfaced as RFC0008.5 corruption (complete frame whose CRC32-C doesn’t match — even on the newest segment, a CRC mismatch is corruption, not truncation). The test does not assert “exactly the fsync’d frames” — that would be stronger than SIGKILL semantics admit, since process death does not discard dirty page-cache data
  • And FrameKind::AuditEvent frames the miner had appended-and-fsync’d before the kill survive identically (per the RFC 0005 §3.7 / RFC0005.2 audit-durability contract this RFC implements via §6.4)
  • And this scenario’s test runs on every PR; failure blocks merge

Scenario RFC0008.3 — Crash-recovery non-amplification [H3]

  • Given a fixture corpus of N ∈ {1, 4, 16} segments each at the default wal_segment_size_bytes (128 MiB) of representative OtlpBatch payloads, captured by a criterion benchmark
  • When Wal::replay runs over the directory and the benchmark measures wall time
  • Then total wall time scales O(N) in segment count, within a ±20 % tolerance to allow for warm-cache vs cold-cache differences across the runs
  • And wal_syncs_total does not advance during replay (replay is read-only on closed segments; the §6.6 step 4 heal fsync only fires on a torn-tail newest segment, which the benchmark fixture deliberately omits)
  • And no per-record audit event is emitted by the recovery driver itself (the happy path emits none; the single RFC0008.5 corruption-path audit event is deferred per the 2026-06-13 §5 amendment, so today the happy path and the corrupt path alike emit zero)

Scenario RFC0008.4 — Torn last frame on the newest segment [H3]

  • Given a segment directory where the lexicographically- greatest segment file has a partial frame at its tail — either a partial 12 B frame header, or a valid header followed by a short payload (truncated at a random offset inside the payload bytes)
  • When Wal::replay walks that directory in order
  • Then the partial bytes are treated as clean truncation: the scan stops on this segment, no error is returned, no audit event is emitted
  • And §6.6 step 4 heals the segment: ftruncate(2) to the last valid frame boundary recorded during the scan, fdatasync the segment, fsync the parent directory — the truncated bytes are physically gone from disk
  • And the post-recovery Wal::append lands at the frame boundary preceding the torn write
  • And a partial header / payload on any older (non- newest) segment is not treated as truncation — it surfaces as RFC0008.5 corruption, because older segments are post-rotation and their final fsync completed; a torn tail there is file-system corruption rather than a legit rotate-pending-fsync. This newest-vs-older fork is the scenario’s central pin

Scenario RFC0008.5 — Corrupt frame [H3]

  • Given a segment with one of: a CRC32-C mismatch on a complete frame, an unknown kind byte (> 0x02), a non-zero _pad, an oversize len (> MAX_FRAME_BYTES), or a torn header/payload on a closed (non-newest) segment
  • When Wal::replay walks the segment containing the corruption
  • Then the scan emits a structured RecoveryError carrying the segment UUIDv7 + byte offset of the corrupt frame
  • And recovery stops scanning all segments — the high-water-mark logic depends on contiguous ordering and a corrupt frame invalidates everything past it (an operator must intervene before the receiver opens its listeners)
  • And the test exercises all five corruption sub-cases in separate arms (crates/ourios-wal/tests/corruption.rs)

Amendment 2026-06-13 (corruption audit event deferred). The original criterion also required a WalRecoveryCorruption { segment, offset, reason } audit event appended to the audit-event Parquet writer’s queue. That half is deferred to a follow-up (§9): the RFC 0005 audit stream is tenant-partitioned (CLAUDE.md §3.7) and WAL corruption is a system event with no tenant, so the durable forensic record needs a system-scoped-audit design that does not yet exist. Deferring it costs no safety — corruption is already loud: replay returns the structured RecoveryError and recovery halts, so the receiver refuses to open its listeners and an operator must intervene. Only the queryable record is postponed, not the failure response. RFC0008.5 is satisfied by the structured-error + halt-all-segments halves; wal_corrupt_frames_total (§6.8) already counts occurrences for the operator dashboard.

Scenario RFC0008.6 — Segment rotation

  • Given an open Wal at default wal_segment_size_bytes (128 MiB) and wal_segment_age_secs (600 s)
  • When an append would push the current segment past the size cap (size-cap arm), OR wal_segment_age_secs elapses since the current segment’s header was written (time-cap arm), whichever fires first per §6.5
  • Then the current segment is closed cleanly: the final fdatasync on the segment + fsync on the parent directory complete before any frame is appended to the new segment
  • And a fresh segment is opened with a new UUIDv7 filename, the 24 B segment header is written, and the subsequent append lands in the new segment — not the old one
  • And no frame is dropped or duplicated across the rotation boundary (asserted by counting frames before / after rotation in the test)
  • And a rotation whose final fsync returns an error surfaces as a hard AppendError: subsequent append calls return the same error, the receiver refuses to accept new batches, and the operator must intervene

Scenario RFC0008.7 — Checkpoint-driven truncation + durable sidecar

  • Given a Wal that has accumulated K segments and a simulated Parquet writer that has durably committed records up to WalOffset X
  • When Wal::checkpoint(X) runs followed by a housekeeping pass
  • Then the <wal_root>/CHECKPOINT sidecar is atomically written (CHECKPOINT.tmpfsyncrename → parent- dir fsync), containing the 32 B record {magic = "OWCK", version = 1, flags = 0, segment_uuid (16 B), byte (8 B LE)}
  • And every segment whose highest frame offset is ≤ X is unlink’d; segments straddling X are kept
  • And wal_disk_bytes drops by the sum of the deleted segments’ sizes

Crash-between-checkpoint-and-housekeeping arm:

  • Given the same setup
  • When SIGKILL fires between Wal::checkpoint(X) returning and the housekeeping pass starting
  • Then the CHECKPOINT sidecar survives the crash (the atomic-write + fsync above is what guarantees this)
  • And on restart, Wal::last_checkpoint() returns Some(X), and the recovery driver suppresses every frame at append-offset ≤ X on its Parquet path — records already published are not re-fed and not duplicated on the data side (replay is at-least-once; dedup is explicitly out of scope, so this suppression is the only mechanism that prevents the dup). replay itself still delivers those frames — the miner may need them when its snapshot lags (2026-06-12 amendment; suppression is per consumer, see §6.6)

Surviving-segments / no-global-counter arm:

  • Given a checkpoint has advanced past several older segments and housekeeping has unlinked them
  • When a fresh Wal::open is followed by a new Wal::checkpoint(Y) where Y > X
  • Then the operation proceeds against the surviving UUID-named files without reconstructing a global offset counter — the (segment_uuid: UUIDv7, byte) WalOffset representation makes this trivially well-defined

Retain-floor arm (2026-06-12 amendment):

  • Given a checkpoint at X and a retain floor S < X (a miner snapshot lagging the Parquet writer)
  • When Wal::housekeeping(Some(S)) runs
  • Then only segments whose highest frame offset is ≤ both X and S are unlinked — segments holding frames in (S, X] survive, because the miner snapshot has not captured them yet and truncating them would leave a hole in the restored tree (template drift, hazard #5)
  • And a later pass with an advanced floor S' ≥ X reclaims them — the floor delays truncation, never cancels it

Scenario RFC0008.8 — Batched-fsync knob

  • Given the group-commit CommitCoordinator over a Wal, with wal_batch_window_ms set in turn to {10, 100, 1000}
  • When a batch of commits is fired together under a paused virtual clock — so the only time that elapses is the coordinator’s own window timer; the real fsync runs but does not advance the virtual clock
  • Then each commit’s ack latency equals the configured window exactly (deterministic, no scheduler/instrumentation jitter) — the window is the dominant contributor, not per-record fsync cost (which would ack at ≈ 0 independent of the window). This virtual-clock formulation supersedes the original wall-clock-P99-within-±30 % one, which was non-deterministic on shared and instrumented CI runners.
  • And wal_syncs_total advances at a rate ≈ (steady-state arrival-rate / per-window batch size) rather than per-record (so appends_per_sync is well above 1 in every setting)
  • And the §3.4 invariant holds across all three: no ack precedes the Wal::sync whose returned offset covers the corresponding frame

Scenario RFC0008.9 — wal_unflushed_bytes is bounded [H3 detection]

  • Given a Wal under a randomised arrival pattern (proptest-driven mix of small frames + max-sized 16 MiB frames + small frames, varying interleavings)
  • When the test samples wal_unflushed_bytes at every append and sync boundary across the run
  • Then the metric never exceeds 2 × wal_segment_size_bytes at any sample, regardless of arrival rate
  • And the §6.9 tunables-table lower bound on wal_segment_size_bytes (≥ MAX_FRAME_BYTES + segment_header + frame_header, validated as ≥ 17 MiB) is what makes the bound achievable: a max-sized frame always fits inside a single segment, so the in-flight batch can never straddle three segments at once
  • And a configuration with wal_segment_size_bytes below the lower bound is rejected at Wal::open time (OpenError::InvalidConfig) — the validation runs on every §6.9 tunable, not just this one

Scenario RFC0008.10 — Startup recovery driver: per-consumer horizons (2026-06-12 amendment)

  • Given a WAL whose frames span a CHECKPOINT at X and a durable miner snapshot whose recorded high-water mark is S ≥ X (the steady-state ordering: snapshots are taken at segment rotation, the Parquet checkpoint lags)
  • When the ingester starts
  • Then recovery runs to completion before the network listeners open (no live append interleaves with replay)
  • And suppression is per consumer, by each delivered frame’s offset: the Parquet path consumes only frames > X (frames ≤ X are already on object storage), the miner only frames > S (the restored snapshot already covers (X, S], so re-feeding them would double-apply)
  • And the post-recovery miner tree state is equal to a control tree built by ingesting the same records from scratch (the RFC 0001 §3.5.3 equivalence, observed through this driver)

Lagging-snapshot catch-up arm (S < X):

  • Given the same WAL but a snapshot whose mark S is below the checkpoint X, with the (S, X] frames retained on disk by the §6.7 floor
  • When the ingester starts
  • Then the miner consumes the retained (S, X] frames (closing its state gap — the floor’s payoff) while the Parquet path suppresses them (already published), and both consume frames > X
  • And the post-recovery tree again equals the from-scratch control

Snapshot-cadence arm:

  • Given live ingest crossing a segment-rotation boundary
  • When the rotation completes
  • Then a per-tenant snapshot write is triggered, recording the rotation-point high-water mark (RFC 0001 §6.9 cadence), and the housekeeping retain floor advances to the new snapshot’s mark once the write is durable

6. Proposed design

6.1 Overall shape

Amendment 2026-06-12 (snapshot-restore support). Four changes land together with RFC 0001 §6.9’s v2 restore (the same-day amendment there is the other half of this design): FrameSink::consume now receives the frame’s WalOffset, and replay delivers every well-formed surviving frame — suppression moves out of replay and into the recovery driver as per-consumer replay horizons (the Parquet path consumes frames above the checkpoint, the miner frames above its snapshot’s high-water mark — §6.6; an in-replay skip would make a lagging snapshot’s retained frames undeliverable); the checkpoint offset is exposed to the driver as last_checkpoint; the housekeeping pass becomes an explicit API taking an optional retain floor so truncation never outruns the miner snapshot (§6.7); and replay takes &mut self, matching the landed implementation (§6.6 step 4 heals the newest segment in place).

ourios-wal is a single Rust crate exposing one struct Wal whose public API is:

impl Wal {
    pub fn open(config: WalConfig) -> Result<Self, OpenError>;
    pub fn append(&mut self, kind: FrameKind, payload: &[u8])
        -> Result<WalOffset, AppendError>;
    pub fn sync(&mut self) -> Result<WalOffset, SyncError>;
    pub fn checkpoint(&mut self, durable_to: WalOffset)
        -> Result<(), CheckpointError>;
    pub fn housekeeping(&mut self, retain_floor: Option<WalOffset>)
        -> Result<(), HousekeepingError>;
    pub fn last_checkpoint(&self) -> Option<WalOffset>;
    pub fn replay(&mut self, sink: &mut impl FrameSink)
        -> Result<(), RecoveryError>;
    pub fn metrics(&self) -> WalMetrics;
}

pub enum FrameKind {
    OtlpBatch  = 0x01,
    AuditEvent = 0x02,
}

/// Opaque, totally-ordered position of a frame in the
/// WAL. Internally `(segment_uuid: Uuid /* UUIDv7 */,
/// byte_offset_in_segment: u64)`; ordering is
/// lexicographic on the pair, which means **UUIDv7's
/// chronological sort gives global monotonicity** even
/// after housekeeping deletes older segments. A pure
/// `u64` representation would be ambiguous after deletion
/// (no global offset survives reconstruction from the
/// UUID-named files), so the pair is the durable form.
pub struct WalOffset { segment: Uuid, byte: u64 }

pub trait FrameSink {
    fn consume(&mut self, offset: WalOffset, kind: FrameKind,
        payload: &[u8]) -> Result<(), RecoveryError>;
}

Semantics:

  • append writes a frame to the current segment and returns the post-append offset. The frame is not yet durable; the caller (the receiver) accumulates appends in a micro-batch and calls sync at the §3.4 batch boundary.
  • sync fsyncs the current segment and returns the highest offset that is now durable. The receiver gates its acks on this returning successfully.
  • checkpoint records “records ≤ durable_to are on object storage; segments wholly below this offset may be reclaimed.” Called by the Parquet writer’s atomic-publish callback. Reclaim happens on the housekeeping pass, not in-line.
  • housekeeping reclaims disk: unlinks every segment whose highest frame offset is ≤ the checkpoint and, when retain_floor is Some(floor), ≤ floor (§6.7). The caller (the ingester) runs it periodically — every wal_housekeeping_secs — passing the latest durable miner snapshot’s high-water mark as the floor; None means no snapshot consumer exists and the checkpoint alone governs.
  • last_checkpoint exposes the CHECKPOINT sidecar’s offset (None pre-first-checkpoint). The recovery driver reads it once at startup as the Parquet-side suppression horizon (§6.6).
  • replay is recovery: walk every surviving segment in chronological order, hand each well-formed frame — including frames at or below the checkpoint that a straddling or floor-retained segment holds — to sink along with its WalOffset. The offset lets the recovery driver suppress per consumer (Parquet above the checkpoint, miner above its snapshot mark — §6.6); replay itself filters nothing, because an in-replay skip would make a lagging snapshot’s retained frames undeliverable. Used by the ingester at startup before opening network listeners. Returns when the scan completes; the caller then begins serving live traffic.

The crate ships no executable. The receiver and the recovery driver both live in ourios-ingester (RFC 0003).

6.2 Segment layout

Segments live under <wal_root>/<UUIDv7>.wal, where wal_root is the local-disk path configured by the operator. UUIDv7 is the same sortable-by-creation identifier RFC 0005 §3.4 already uses for Parquet files; listing the directory in sorted order yields chronological order, which the recovery scan relies on.

A segment is append-only: the writer holds it open until rotation; readers (recovery) open snapshots read-only — except the §6.6 step 4 heal path, which reopens the newest segment writable to ftruncate(2) a torn tail back to the last valid frame boundary, then closes and reopens read-only before any further reads. The writable window is narrow (one ftruncate + fdatasync + parent-dir fsync) and only ever the newest segment. The segment file format is a header followed by zero or more frames:

| segment-header (24 B)            |
| frame-0 | frame-1 | … | frame-N  |

6.2.1 Segment header

| magic: 4 B = b"OWAL"             |
| version: u16 = 1                 |
| flags: u16 = 0 (reserved)        |
| segment-uuid: 16 B (UUIDv7)      |  → 24 B total

The magic + version pair lets the recovery scanner reject foreign files (e.g. a sibling *.lock) early and pins the format version for future migrations. segment-uuid is the same UUID that appears in the filename; carrying it inside the file too means a mv that mangles the name doesn’t make the file unreadable.

6.2.2 Frame format

| len:   u32_le   (payload length, excluding header + CRC)              |
| kind:  u8       (0x01 = OtlpBatch, 0x02 = AuditEvent; reserved >0x02) |
| _pad:  [u8; 3]  (reserved, MUST be zero, validated on read)           |
| crc32: u32_le   (CRC32-C over kind || pad || payload, Castagnoli)     |
| payload: [u8; len]                                                    |

Per-frame header = 12 B (4 + 1 + 3 + 4). len MUST be ≤ a configured maximum (default MAX_FRAME_BYTES = 16 MiB); larger appends are rejected at Wal::append time before any bytes are written, so a malformed call can’t grow the segment past the cap. Unknown kind values surface as a structured corruption error per RFC0008.5 — the reserved range is how the format admits future frame kinds without a version bump.

CRC choice is CRC32-C (Castagnoli, polynomial 0x1EDC6F41) — the same polynomial the Parquet writer already uses on row groups, so we share one implementation and one SIMD-acceleration path on modern x86 / aarch64. The CRC covers kind || _pad || payload (not the len header, which is implicitly validated by the read returning the right number of bytes; not its own bytes). This is the same shape Kafka uses for record-batch CRCs.

6.2.3 Payload encoding

Payload encoding is keyed on kind:

  • FrameKind::OtlpBatch: payload is the OTLP ExportLogsServiceRequest protobuf bytes the receiver decoded — verbatim, no re-encoding. Replay is “re-receive”: the recovery scanner hands the bytes back through the same decoder + tenant fan-out the live request takes. No special replay code path; less surface for the two paths to drift. The WAL’s own format does not embed Ourios’s TenantId; replay rederives it from Resource.attributes per RFC 0003 §6.3.
  • FrameKind::AuditEvent: payload is one serialised ourios_core::audit::AuditEvent. The exact serde format is a §9 open question — AuditEvent has no serde derives today (Debug, Clone, PartialEq, Eq only), and the encoder lands alongside them. Strong candidates are bincode (compact, fast, Rust-native) and serde_json (human-debuggable, already in the dep tree). The choice doesn’t affect this RFC’s frame layout; it lives entirely inside the kind = 0x02 payload bytes.

A future per-tenant WAL split would be additive (a new segment-selection layer above the same frame format), as would future frame kinds (the reserved kind range admits them without a version bump).

6.3 fsync policy

Wal::sync calls fdatasync(2) on the current segment file descriptor (or platform equivalent — FlushFileBuffers on Windows; fcntl(F_FULLFSYNC) on macOS when the operator opts into “full” durability). On a sync that follows a segment rotation (a new segment was opened since the last sync, or an older segment was unlinked by housekeeping), it also calls fsync(2) on the parent directory file descriptor — fdatasync is undefined behaviour on directories under POSIX, and fdatasync on the segment file alone does not flush the directory metadata that makes the new entry (or the unlink) durable. The two calls are distinct: fdatasync for the file’s payload + size, fsync for the directory’s entry. The implementation does not call fsync per append; the receiver is responsible for batching appends across the configured window and calling sync once per batch.

Two knobs are exposed at this layer (per CLAUDE.md §3.4 / H3); both are classified in §6.9’s WAL-tunables table:

  • wal_batch_window_ms (default 100): the receiver-side upper bound on time from first append to corresponding sync. The receiver implements this; the WAL itself is policy-free at this layer.
  • wal_segment_size_bytes (default 128 MiB): segment rotation cap (§6.5). The receiver’s sync MUST also fire whenever this cap is reached on the current segment, even if wal_batch_window_ms hasn’t elapsed — the “or segment fills, whichever first” clause.

6.4 Audit-event ordering barrier

RFC 0001 §6.4 carries the normative requirement (“WAL durability ordering of audit events”) this RFC has to satisfy: a data record carrying template_version = V MUST NOT become durable before every audit event justifying the leaf’s progression to V is durable. Crash recovery may observe [event_1, …, event_k, data_record] or any prefix thereof, but never a data record without the events that caused its version stamp. Without this, replay bumps template_version fewer times than the in-memory leaf did and surviving data records reference a version the audit stream cannot substantiate.

The WAL itself does not enforce the barrier — it provides the primitives (append, sync, the durable checkpoint of §6.7) that the consumer composes into the discipline. The consumer (the miner-side writer in ourios-ingester) is required to follow this sequence for every data record R that emits zero or more audit events E₁, …, Eₖ:

  1. Append all audit-event frames for R first: wal.append(AuditEvent, encode(E₁)) … wal.append(AuditEvent, encode(Eₖ)).
  2. Track the WAL offset returned by the last audit-event append as R’s required_audit_offset — the audit-WAL position that must be durable before R can be published. If R emits zero audit events (k=0), it has no required_audit_offset and does not contribute to the row group’s max_required_audit_offset in step 3 (max over the empty set is MIN, so the gate in step 4 is trivially satisfied for an all-zero-audit row group — common steady-state).
  3. The row group accumulating R’s MinedRecord carries a running max_required_audit_offset across its contained records (the maximum of every record’s required_audit_offset).
  4. The Parquet writer’s atomic-publish gate compares the row group’s max_required_audit_offset against the WAL’s last_synced_offset (the largest offset for which Wal::sync has returned). The publish proceeds only when max_required_audit_offset ≤ last_synced_offset; otherwise the row group is held until the next Wal::sync advances last_synced_offset past it.

The comparison is WAL offset vs WAL offset — same units. An earlier draft compared template_version (a small per-leaf integer) against an audit_durable_to position; that was a unit mismatch an implementer could honour incorrectly. The barrier is “is the durable WAL position at-or-past what this row group needs,” not “is the version label high enough.”

This composes with the OtlpBatch frames the receiver appends pre-ack: data records reach the miner via post-ack mining of an already-fsync’d OtlpBatch frame, so the data record’s ingest is already durable; the §6.4 barrier governs the second-stage publish of its post-mining representation to data Parquet. The §3.4 invariant (no ack without WAL fsync) and the §6.4 invariant (no data publish without audit-event WAL fsync) operate on different boundaries and don’t conflict.

Because audit events are emitted in the miner’s hot path, the per-record cost of “step 1 + step 3” is one append call (cheap) plus a shared fsync amortised across many records via the §6.3 batched window. The barrier therefore does not add a per-record fsync.

6.5 Segment rotation

A rotation closes the current segment, fsyncs it (the last fsync that segment ever receives), opens a new segment with a fresh UUIDv7, writes the new segment’s header, and from that point all subsequent appends land in the new segment. The critical-path cost of a rotation is one extra fsync of the parent directory so the new segment’s directory entry is durable before any frame lands in it.

Two triggers:

  • Size cap: the current segment’s file size (header + appended frames + the frame about to be written) exceeds wal_segment_size_bytes. Computed before the write so the rotation happens before the next frame’s bytes land.
  • Time cap: the current segment’s age (since its header was written) exceeds wal_segment_age_secs (default 600 = 10 min). Bounds the recovery window — a torn-write worst case touches at most one segment-age window of data.

Rotations are silent (no audit event in the steady state). A rotation that fails fsync is a hard error: the receiver must refuse further appends until an operator intervenes, because continuing would risk a frame landing in a segment whose directory entry is not durable.

6.6 Crash recovery

Wal::replay is invoked at startup, before the receiver opens its network listeners:

  1. Read <wal_root>/CHECKPOINT (per §6.7) into cp: Option<WalOffset>. A present sidecar yields Some(parsed); an absent sidecar yields None (first-run / pre-checkpoint). A sidecar that is present but invalid — wrong magic, unknown version, non-zero flags, or a size other than 32 B — is a structured corruption error that aborts recovery (the same posture as a corrupt closed segment): silently treating it as None would drop the Parquet suppression horizon and re-feed every already-published record to the data side. The operator restores or removes the sidecar knowingly; removal is an explicit acceptance of at-least-once re-publish. cp = 0 would be a synthetic offset undefined for the (segment_uuid, byte) pair, so absence is modelled as an option rather than a zero value. cp is exposed to the recovery driver as Wal::last_checkpoint() (§6.1) — it is the driver’s Parquet-side suppression horizon, not a delivery filter inside replay (2026-06-12 amendment; see step 3).
  2. List every *.wal file under wal_root. Sort lexicographically (= chronologically, per UUIDv7). The last segment in this order is the newest (the one that was open for appends at crash time); every other segment is older / closed (its rotation fsync completed before the next segment began).
  3. For each segment in order:
    1. Open read-only, verify the header (magic + version).
    2. Walk frames left-to-right. For each frame:
      • Read the 12 B frame header (len + kind + _pad
        • crc32). If EOF here:
        • Newest segment: clean-truncated tail; stop scanning this segment (RFC0008.4).
        • Older segment: structured corruption error — a closed segment cannot legitimately have a torn tail (rotation fsync’d it before the next segment started), so EOF mid-header is corruption. Emit audit event naming segment + offset; stop scanning all segments (no records past a corrupt point in the log are safe to replay, because the high-water-mark logic depends on contiguous ordering).
      • If len > MAX_FRAME_BYTES, kind is unknown (>0x02), or _pad is non-zero: structured corruption error → same all-segments-stop path.
      • Read len payload bytes. Short read here is the same newest-vs-older fork: a partial payload on the newest segment is RFC0008.4 clean truncation (rotate-pending-fsync at crash time); on any older segment it’s RFC0008.5 corruption (a closed segment with a partial payload means the segment’s final fsync was lost — file-system corruption).
      • Recompute CRC32-C over kind || _pad || payload. Mismatch → corruption (all-segments-stop).
      • Hand (offset, kind, payload) to sink.consume(offset, kind, payload)every well-formed surviving frame is delivered, including frames at or below cp that a straddling segment retains (2026-06-12 amendment; the pre-amendment design skipped them inside replay, which made the §6.7 retain floor useless — a lagging snapshot’s (S, cp] frames were kept on disk but never deliverable). Suppression is per consumer, in the driver: the Parquet path consumes only frames above cp (frames ≤ cp are already durably published — re-feeding them would duplicate on the data side, since replay is at-least-once and dedup is out of scope), and the miner consumes only frames above its restored snapshot’s high-water mark S (frames ≤ S are already folded into the snapshot — re-feeding them would double-apply, RFC 0001 §6.9 v2). The two horizons are independent and either ordering of cp and S is handled by the same rule: with S ≥ cp the miner consumes a suffix of what Parquet consumes; with S < cp (lagging snapshot) the miner additionally consumes the retained (S, cp] frames that Parquet suppresses. The sink is the recovery driver in ourios-ingester; for OtlpBatch it decodes the bytes as ExportLogsServiceRequest and runs the same tenant-fan-out + miner-ingest pipeline the live receiver does (gated per consumer as above); for AuditEvent it deserialises and reinjects into the audit-event Parquet writer’s queue, gated on the Parquet horizon.
  4. Heal the newest segment. If the newest segment’s scan stopped on a torn tail (RFC0008.4 clean truncation), ftruncate(2) the segment file to the last valid frame boundary recorded during the scan, then fdatasync the segment file and fsync the parent directory. Without this step the torn bytes persist and a second crash after a new segment opens would see them on a now-older segment, where RFC0008.5 corruption handling would reject them — contradicting RFC0008.4’s “next append starts at the frame boundary preceding the torn write.” Truncation runs only on the newest segment and only on the torn-tail path; a clean-tail (EOF aligned on a frame boundary) needs no work.
  5. After the last segment’s last frame, append-mode resumes on a new segment.

Recovery is single-threaded and synchronous. The operator-visible cost is “ingester is unavailable for the duration of recovery.” RFC0008.3 constrains recovery to O(N) wall time on N segments; the per-frame work is dominated by the miner’s tokenize cost, which is already corpus-bench- governed.

Replay is at-least-once: a batch that was WAL-fsync’d but not yet acked at crash time will be replayed on restart and re-sent through the pipeline. The client may also retry on its end. Dedup is intentionally not in scope here — RFC 0003 §9 carries it as an open question for a future amendment (likely an idempotency key on the batch envelope, persisted in the frame and checked at replay time).

6.7 Checkpoint-driven truncation

The WAL does not truncate itself based on age, count, or total bytes. It truncates only when the Parquet writer explicitly signals that records up to some WAL offset are durably on object storage:

parquet_writer.on_atomic_publish(|durable_to: WalOffset| {
    wal.checkpoint(durable_to);
});

checkpoint persists the offset to a small sidecar file — <wal_root>/CHECKPOINT — atomically (write to CHECKPOINT.tmp, fsync, rename, fsync parent dir). The file format is fixed: 4 B magic b"OWCK", 2 B version = 1, 2 B flags (reserved, zero), 16 B segment UUIDv7, 8 B little-endian byte-in-segment — 32 B total, matching the (segment, byte) WalOffset pair (§6.1). Storing the segment UUIDv7 rather than a synthetic global counter means the checkpoint survives housekeeping deletion of older segments: a deleted segment’s UUID is below any surviving segment’s UUID by definition of the rotation order, so “segments wholly below cp” is well-defined on the remaining files alone. Durability is required, not advisory: if the process crashes after checkpoint(X) but before the housekeeping pass unlinks segments wholly below X, the recovery driver must still know X so its Parquet path suppresses records already published (replay delivers every surviving frame per §6.6; replay is at-least-once and dedup is explicitly out of scope, so the driver’s suppression is the only thing standing between a surviving frame ≤ X and a data-side duplicate). On startup, the CHECKPOINT sidecar is read into Option<WalOffset> per §6.6 step 1 — present sidecar → Some(parsed); absent sidecar → None (first-run / pre-checkpoint) — and exposed to the recovery driver as last_checkpoint. When Some(offset), the driver’s Parquet path suppresses every frame at or below the offset; when None, no Parquet-side suppression applies (replay itself always delivers every surviving frame — §6.6, 2026-06-12 amendment). cp = 0 would be a synthetic offset undefined for the (segment_uuid, byte) pair, so the option semantics is the only well-defined absence representation.

A periodic housekeeping pass (every wal_housekeeping_secs, default 60; the timer lives in the ingester, the pass is the explicit Wal::housekeeping(retain_floor) API of §6.1) walks the segment directory and unlinks any segment whose highest frame offset is ≤ the checkpoint mark and, when a retain floor is supplied, ≤ the floor — i.e. truncation reclaims only segments wholly below min(checkpoint, floor). Segments that straddle either mark are kept until a later pass advances past them (no per-frame deletion; we delete whole segments).

The retain floor (2026-06-12 amendment). The checkpoint guarantees the data side: frames ≤ checkpoint are durably on object storage. It says nothing about the miner state derived from those frames — that lives in the per-tenant snapshot (RFC 0001 §6.9), whose recorded high-water mark S advances on its own cadence (per segment rotation). If a snapshot write fails or lags so that S < checkpoint, truncating up to the checkpoint would destroy the only remaining source of the miner state in (S, checkpoint]: the data is safe in Parquet, but the restored tree would re-mint template_ids for templates first seen in the gap — exactly the hazard #5 template-drift failure. The ingester therefore passes the latest durable snapshot’s high-water mark as retain_floor, and housekeeping never unlinks a frame the snapshot has not captured. None (no snapshot consumer configured) reduces to the checkpoint-only rule. The cost is bounded: the WAL retains at most the segments appended since the last successful snapshot — in the steady state (snapshot per rotation) the floor leads the checkpoint, and the rule is vacuous. The CHECKPOINT sidecar itself always records the true Parquet horizon, never the min — it is the recovery driver’s Parquet-side suppression horizon (read via last_checkpoint, §6.6), and capping it at the floor would re-feed already-published records to Parquet. The floor governs disk reclamation only; the retained (floor, checkpoint] frames stay deliverable through replay precisely so the miner can catch up from them (§6.6).

If the Parquet writer never checkpoints (e.g. a crash before the first row group commits), the WAL grows. The operator- visible signal is wal_disk_bytes rising monotonically; the H3 escalation rule applies. A future RFC may add a fallback “truncate by hard cap” with explicit data loss, but the default is “WAL grows until Parquet catches up” — losing durability silently is worse than running out of disk loudly.

6.8 Metrics

WalMetrics exposes:

  • wal_appends_total: u64 — frames appended since startup.
  • wal_syncs_total: u64fdatasync calls.
  • wal_unflushed_bytes: u64 — bytes appended but not yet fsync’d (the H3 detection metric, bounded by RFC0008.9).
  • wal_disk_bytes: u64 — sum of file sizes under wal_root (operator dashboard).
  • wal_segment_count: u32 — current segment count.
  • wal_sync_seconds: histogram — per-sync latency.
  • wal_checkpoint_segment: String (UUIDv7 of the segment in the last checkpoint arg) + wal_checkpoint_byte: u64 (byte-in-segment of the same arg). Two fields rather than one because WalOffset is now a (segment, byte) pair (§6.1) and a single u64 would lose the segment identity needed to interpret the value once housekeeping deletes older segments. None checkpoint (pre-first-checkpoint startup) is rendered as the empty string + 0; the ingester logs the transition from “no checkpoint” to “have checkpoint” so operators can tell the difference.
  • wal_recovery_seconds: Gauge (set once at startup).
  • wal_corrupt_frames_total: u64 — RFC0008.5 surface.

Per docs/roadmap.md §5’s maintainer note (2026-05-19, updated 2026-06-03: “instrument through the OpenTelemetry metrics API (meters) and export via the OTel SDK’s OTLP metric exporter (push), not the legacy prometheus client crate and not a scrape endpoint; any Prometheus compatibility is a downstream collector concern”), these are OTel metrics exported over OTLP; the CLAUDE.md §6.3 “every subsystem exposes Prometheus metrics” line predates that direction and the note flagged it for a follow-up amendment. RFC 0001 §6.8 (2026-06-03 amendment) is the normative reference for the export architecture.

6.9 WAL-tunables classification

Per RFC 0004 §3.1, every operator-visible knob is exactly one of Tunable or Invariant, with a startup- validated range and the §3 invariant it lives inside. Same schema as RFC 0004 §3.2’s miner table:

KnobClassDefaultValidated rangeInside invariant
wal_batch_window_msTunable100 (CLAUDE.md §3.4)0..=10_000§3.4 — bounds ack-latency vs durability tradeoff; 0 means per-append sync (allowed but discouraged)
wal_segment_size_bytesTunable128 MiB (matches Parquet row-group class, §6.5)MAX_FRAME_BYTES + segment_header (24 B) + frame_header (12 B) ..= 2 GiB (numerically ≥ 16 MiB + 36 B, validated as ≥ 17 MiB for headroom and round-numbering)§3.4 — bounds the segment-fill arm of the “or … whichever first” sync trigger. The lower bound MUST accommodate a single max-sized frame plus headers (a max frame that wouldn’t fit in any segment would force unbounded wal_unflushed_bytes, violating RFC0008.9)
wal_segment_age_secsTunable600 (10 min, §6.5)1..=86_400§3.4 — bounds recovery window
wal_housekeeping_secsTunable60 (§6.7)1..=3_600§3.6 — bounds local-disk pressure on a slow-publishing Parquet writer
wal_macos_full_fsyncTunablefalse (off — opt-in to the slower-but-stronger F_FULLFSYNC; macOS-only knob, ignored on other platforms)bool§3.4 — operator-visible durability choice on macOS dev boxes (the §9 open question pins the default)
MAX_FRAME_BYTESInvariant16 MiBn/a (compile-time)§3.4 / format compat — a tunable MAX_FRAME_BYTES would let a single batch grow past a segment-recoverable size and would make file-format compatibility per-deployment
Frame-header layout (§6.2.2)Invariantper §6.2n/aformat compat — the on-disk shape is the format-version contract
Segment-header layout (§6.2.1)Invariantper §6.2n/aformat compat — same
CRC32-C polynomialInvariant0x1EDC6F41 (Castagnoli)n/aformat compat
CHECKPOINT sidecar formatInvariantper §6.7n/aformat compat

Per RFC 0004 §3.1’s per-tenant override rule, all Tunables above are process-global at v1 — there is no per-tenant override surface for the WAL because the WAL is a single workspace-wide log (§7.4). A future per-tenant WAL split would inherit RFC 0004’s per-tenant override mechanism.

6.10 Out of scope for this RFC

  • Replication. Per CLAUDE.md §3.4. When it lands it joins a separate RFC and operates over the WAL, not instead of it.
  • Multi-writer arbitration. The ingester is a single process per node; no file lock dance here. A future multi-process design would need a lockfile + a coordinator, both deferred.
  • Snapshotting miner state. Replay rebuilds the miner; if recovery time becomes the operator complaint, a snapshot RFC is the response. §9 carries this.
  • Batch dedup on replay. RFC 0003 §9 owns the idempotency-key question; this RFC inherits whatever that RFC pins.
  • Distributed transactions across WAL + object storage. Atomic-publish (RFC 0005 §3.7 / RFC0005.2) is what we have; this RFC does not promise stronger ordering.

7. Alternatives considered

7.1 Use sled / redb / fjall / RocksDB

These give a WAL as a side effect of a B-tree / KV store. The ingest path consumes none of the surrounding API: we don’t iterate keys, we don’t query by prefix, we don’t transact across rows. Adopting one buys us a WAL implementation at the cost of a much larger dependency, a non-trivial migration if the upstream goes through a format break (sled has done this multiple times pre-1.0), and a wire format we don’t control. The hand-rolled crate is ~600 lines we can audit; the alternatives are tens of thousands of lines of code we don’t need.

7.2 Use okaywal / a focused-WAL crate

Closer fit (focused, small, hand-roll-equivalent). The remaining objection is that the format is what we care about most — recovery semantics, frame layout, CRC choice, checkpoint contract — and a third-party crate’s format is the same wire-compat boundary as our own. We do not save the design work, only the implementation work. For ~600 lines of careful Rust the dependency-discipline default (CLAUDE.md §10 “When in doubt, …”) is to own it. Worth revisiting if okaywal (or a peer) stabilises on a format that matches §6.2 closely enough that we can adopt them as a drop-in.

7.3 Per-record framing (not per-batch)

Per-record gives finer recovery granularity (“the last K records before crash were lost” vs “the last batch was lost”) and bypasses one decoder pass at replay (records are already split). Rejected because:

  • Per-record framing forces the receiver to re-encode each record from the decoded OtlpLogRecord back into a durable form, doubling the encode work on the hot path.
  • Batches are the ack boundary already (RFC 0003 §6.5); a per-record WAL would have to track batch-boundary metadata anyway to know which records to ack together.
  • Replay-as-receive is a strong simplicity win: one decoder, one fan-out, one mining pipeline. Per-record framing forks the code.

7.4 Per-tenant segments

A segment per (tenant_id, time-bucket) would let recovery parallelise by tenant and would shrink the truncation granularity (a slow-flushing tenant doesn’t pin the whole WAL). Rejected for v1 because tenant derivation (RFC 0003 §6.3) happens inside the batch — the WAL would need to peek inside ExportLogsServiceRequest to route, which re-introduces decode work on the critical path. The shared log keeps the WAL stateless about tenants; per-tenant segmentation is a future optimisation that the §6.2 format admits additively.

7.5 fsync per append

The simplest possible policy: every append fsyncs. Rejected because the latency cost is operator-hostile on the steady- state path (a single batch with 100 frames → 100 fsyncs, each ~10 ms on commodity SSDs). The batched-window approach preserves the §3.4 invariant (no ack before fsync) while amortising the cost across the configured window.

7.6 Direct I/O (O_DIRECT)

Skips the page cache for a known cost (fsync always flushes) in exchange for a known benefit (no kernel read-modify-write on small appends). Rejected for v1: the implementation surface is non-trivial (aligned buffers, sector-aligned writes), the benefit is operator-perceptible only at multi-thousand-batch-per-second sustained rates, and the H3 mitigation already gives us a tunable knob. Worth revisiting if production deployment shows fsync amplification as the dominant ack-latency contributor.

7.7 OTLP-protobuf vs bincode / flatbuffers

bincode would be slightly faster to encode and would shed the proto3 overhead, but the receiver has the protobuf bytes in hand for free (the wire decoded into them) — using them verbatim is zero work, while re-encoding into bincode would be a second pass. flatbuffers would require schema duplication we don’t currently maintain. The OTLP wire form also keeps the WAL self-describing to anyone with the opentelemetry-proto headers; a custom format would be ours-only.

8. Testing strategy

Per CLAUDE.md §6.2 (docs/verification.md §2), each §5 scenario maps to a named test:

  • RFC0008.1 — integration test in crates/ourios-wal/tests/wal_before_ack.rs. Drives a fake receiver against a real Wal; asserts the sync-returned offset is the gate.

  • RFC0008.2 — CI crash-recovery test (the H3 normative requirement). A test harness forks a child that appends N frames; the parent sends SIGKILL between append and sync and (in a second arm) between sync and the simulated ack. The assertion has two halves:

    1. No fsync’d frame is lost. Every frame the child fsync’d before the kill is recovered on restart.
    2. Any un-fsync’d frame is handled safely. Process death does not discard dirty page-cache data, so a complete-but-unsynced frame may still be on disk after restart (the kernel flushed it post-mortem). Recovery MUST sort it into one of the three §5 / §6.6 buckets: replayed as a normal frame (complete + CRC valid → legitimate, just unacked at the client); surfaced via the newest-segment torn-tail truncate (partial header / partial payload only — §6.6 step 4); or surfaced as RFC0008.5 corruption (complete frame with CRC mismatch, even on the newest segment — CRC mismatch is never truncation). The test does not assert “exactly the fsync’d frames” — that would be stronger than what SIGKILL semantics admit.

    Runs on every PR; failure blocks merge.

  • RFC0008.3criterion benchmark in crates/ourios-wal/benches/recovery.rs. Generates 1 / 4 / 16 segments of representative size, measures recovery wall time, asserts O(N) growth within a tolerance.

  • RFC0008.4 — property test in crates/ourios-wal/tests/torn_writes.rs. Generates a segment, truncates at a random offset inside the last frame, asserts replay succeeds and the recovered frame count equals the count before the torn frame.

  • RFC0008.5 — property test (crates/ourios-wal/tests/corruption.rs). Five arms, one per §5 RFC0008.5 sub-case, matching the §6.6 corruption branches:

    1. Payload bit-flip (CRC mismatch) on a closed segment — flip a random bit in a random frame, assert replay emits the structured corruption error and stops scanning all segments.
    2. Unknown kind — generate a segment containing a frame whose kind byte is anything other than 0x01 or 0x02 (i.e. inside §6.2.2’s reserved 0x03..=0xFF range — bytes “reserved for future kinds” are rejected today, because no future kind has been added); assert structured corruption.
    3. Non-zero _pad — generate a frame whose 3 B reserved _pad carries a non-zero byte; assert structured corruption (the §6.2.2 contract says _pad MUST be zero and is validated on read).
    4. Oversize len — generate a segment whose frame header declares len > MAX_FRAME_BYTES; assert structured corruption (the read must reject the header before attempting to read len bytes that could exceed the segment size).
    5. Torn header / payload on a closed segment — truncate a closed segment mid-header or mid-payload; assert RFC0008.5 corruption, not RFC0008.4 clean- truncation (the newest-vs-older pin §6.6 introduced).

    Each arm asserts (a) the structured error names the segment UUIDv7 + byte offset and (c) recovery stops scanning all segments (no records past the corrupt point are replayed). The original (b) — the WalRecoveryCorruption audit event — is deferred per the 2026-06-13 §5 amendment (system-scoped audit, §9); wal_corrupt_frames_total carries the operator-visible signal in the interim.

  • RFC0008.6 — integration test (crates/ourios-wal/tests/rotation.rs). Drives appends past the size cap and time cap; asserts no frame is dropped or duplicated and the segment-file count grows by one.

  • RFC0008.7 — integration test (crates/ourios-wal/tests/checkpoint.rs). Four arms:

    1. Normal-flow truncationcheckpoint(X) followed by a housekeeping pass unlinks segments wholly below X and keeps segments straddling it.
    2. Crash between checkpoint(X) and housekeeping — fork a child that calls checkpoint(X), SIGKILL the child before housekeeping runs; restart, assert the CHECKPOINT sidecar survives the crash: last_checkpoint() returns Some(X), so the driver’s Parquet-side suppression of records ≤ X holds (they aren’t re-fed and duplicated on the data side), while replay still delivers them with their offsets. Without this arm a passing test could still hide a non-durable checkpoint (the §6.7 sidecar requirement).
    3. Surviving-segments offset reconstructioncheckpoint(X) advances past several older segments, housekeeping deletes them, then a fresh Wal::open plus a new checkpoint(Y > X) proceeds against the surviving UUID-named files without needing a global offset counter to be reconstructed — verifying the §6.1 WalOffset = (segment, byte) representation is enough.
    4. Retain floor — with checkpoint(X) and a floor S < X, housekeeping(Some(S)) keeps every segment holding frames in (S, X]; advancing the floor to S' ≥ X on a later pass reclaims them.
  • RFC0008.8 — integration test that drives the wal_batch_window_ms knob at {10, 100, 1000} ms under a paused virtual clock and asserts ack latency equals the configured window exactly (deterministic — the window dominates, not per-record fsync).

  • RFC0008.9 — property test on the metric: wal_unflushed_bytes is monitored over a randomized arrival pattern and asserted bounded by 2 × wal_segment_size_bytes.

  • RFC0008.10 — integration test in ourios-ingester / ourios-server (the driver lives there per §6.1, like the RFC 0001 criteria hosted in ourios-querier). Builds a WAL

    • snapshot fixture with S ≥ X, starts the server, and asserts: recovery completes before the listeners accept; per-consumer delivery counts (Parquet sees all frames

    X, the miner only frames > S); and tree-state equality against a from-scratch control. The snapshot-cadence arm drives appends across a rotation and asserts a snapshot artefact appears recording the rotation-point high-water mark.

The crash-recovery test (RFC0008.2) is the single most important test in this RFC and is also the H3 CI gate. It runs on every PR regardless of which files changed — H3’s “any failure is critical” applies.

9. Open questions

  • System-scoped audit for WalRecoveryCorruption (deferred from RFC0008.5, 2026-06-13). RFC0008.5’s durable forensic record — a WalRecoveryCorruption { segment, offset, reason } audit event — was deferred because the RFC 0005 audit stream is tenant-partitioned (CLAUDE.md §3.7) and WAL corruption is a system event with no tenant. The follow-up needs a system-scoped audit partition (a reserved tenant id, or a sibling audit/system/ tree) decided in an RFC 0005 amendment; once it exists, the recovery driver appends the event post-scan (recovery is single-threaded, so the queue drains after the halt). Until then the structured RecoveryError halt + wal_corrupt_frames_total are the operator-facing signal. The same system-scoped partition would host other infrastructure events (rotation-fsync failure, checkpoint-write failure) that today only surface as metrics + the quiesce/error response.
  • AuditEvent serde format. AuditEvent has no serde derives today (Debug, Clone, PartialEq, Eq only), so the FrameKind::AuditEvent payload encoding is intentionally deferred to the implementation PR — this RFC at specified pins the frame layout and the ordering contract (§6.4), not the inner encoding. The encoder lands alongside the serde derives in PR-M2; the candidates are bincode (compact, fast, Rust-native — picks up cross-version compatibility concerns later if the struct evolves) and serde_json (human-debuggable, already in the dep tree, larger on disk). Either lives entirely inside the kind = 0x02 payload bytes and doesn’t affect the frame layout this RFC pins. The choice should be consistent with whatever encoding the audit-event Parquet writer (RFC 0005 §3.7) uses on the read path.
  • Idempotency key on the batch envelope. RFC 0003 §9 carries the at-least-once duplicate problem; the WAL frame can embed a key for replay-time dedup. Sequencing: whichever RFC moves first proposes the key shape, the other amends to consume it.
  • macOS F_FULLFSYNC policy. macOS fsync doesn’t flush the on-disk cache without F_FULLFSYNC. Default to the stronger primitive (slower, correct) or the weaker one (faster, dependent on power-loss assumptions)? Most Ourios deployments are Linux, so the default doesn’t bite the common case, but the macOS dev-laptop bench path benefits from the weaker default. Lean toward an explicit wal_macos_full_fsync = true knob with a documented trade-off.
  • Recovery-time snapshot of miner state. If replay on a hot-template multi-tenant corpus exceeds the operator’s restart-window budget, a snapshot of the miner’s Drain trees becomes worth specifying. Currently deferred with no signal that it’s needed. RESOLVED 2026-06-12: specified in RFC 0001 §6.9 (format + v1 landed 2026-06-10; the v2 restore-and-resume amendment is the counterpart of this RFC’s same-day §6.1/§6.7 amendment — offset-carrying sink, retain floor, RFC0008.10 driver).
  • Cross-segment frame straddling. The §6.2 format forbids it (a frame lives in exactly one segment); the rotation rule pre-checks size before appending. Confirm the receiver-side append loop respects this; one test in §8 already covers it but the open question is whether the knob should be tunable (very large batches near the rotation point) or fixed (always rotate ahead of the oversize append).
  • What does the receiver do when sync returns error? Refuse acks for that batch is the obvious answer; less obvious is whether the receiver tears down its network listener (force the orchestrator to restart it) or holds incoming requests until the error clears. RFC 0003 §9 is the natural owner of this once the WAL contract is specified.
  • Multi-WAL on a single node. Could a single ingester run two Wals (e.g. one per fast-tier disk for IO parallelism)? §6 currently pins a single WAL per process; a multi-WAL design would need a coordinator and a cross-WAL ordering rule. Deferred.

10. References

  • CLAUDE.md §3.4 WAL-before-ack — the load-bearing invariant.
  • CLAUDE.md §3.6 Object storage is the source of truth — the WAL is local-disk cache + durability, not the persistent record.
  • CLAUDE.md §10 When in doubt, … — informs the hand-roll vs adopt-a-crate choice in §4.2 / §7.1.
  • docs/hazards.md H3 WAL durability vs. latency — the mitigation, detection, and escalation language this RFC promises to honour.
  • RFC 0003 §6.5 WAL-before-ack sequencing — the receiver contract this RFC is the other side of. RFC 0003 cannot progress past drafted until this RFC reaches specified (because RFC 0003’s §5 scenarios cite the WAL).
  • RFC 0005 §3.4 Partition layout on disk — provides the UUIDv7 convention §6.2 reuses.
  • RFC 0005 §3.7 / RFC0005.2 Atomic publish — the per-row-group publish primitive §6.4 (audit-event ordering barrier) and §6.7 (checkpoint-driven truncation) compose against.
  • RFC 0005 §3.3 — the canonical-JSON encoding for attributes / structured bodies, which the replay pipeline consumes downstream of the receiver.
  • RFC 0001 §6.1 — OtlpLogRecord shape, the in-memory form the recovery sink fans out to.
  • RFC 0001 §6.4 / §6.7 — AuditEvent schema and the audit-stream-through-WAL contract this RFC implements via FrameKind::AuditEvent.
  • RFC 0005 §3.7 — audit-event Parquet schema; explicitly defers the audit-WAL contract to this RFC (“a contract that lands with the post-MVP ourios-wal crate; until then audit-event durability is in-memory and the corpus bench accepts that”).
  • docs/roadmap.md §5 — the maintainer note (2026-05-19, updated 2026-06-03) pinning OTel metrics (via meters) + OTLP export (not direct Prometheus, not a scrape endpoint) as the metrics surface; the §6.8 instrumentation cites it.
  • PostgreSQL WAL design notes — informed the segment-rotation + checkpoint-truncation pattern.
  • LMDB B+tree on a memory-mapped file — informed the “tiny, owned, audited” approach in §4.2.
  • Kafka log segment format — the per-frame length-prefixed CRC-checked layout in §6.2.2 is the conventional one and follows Kafka closely.

RFC 0009 — Compaction


rfc: 0009 title: Background compaction — small-file consolidation status: validated author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-06-02 supersedes: — superseded-by: —

RFC 0009 — Background compaction: small-file consolidation

Status note. validated (2026-06-15) — the RFC0009.7 D2/D3/B2-post benches were measured authoritatively on baseline-8vcpu-32gib (benchmarks.md §9.7, git 4d52288): D3 PASS (a band-scale compaction output lands at 456.7 MiB, IN the 256 MiB–2 GiB H4 band, 0% under 128 MiB); D2 compaction throughput 166.8 MiB/s single-partition (≫ any per-partition seal rate → backlog drains); B2-post query latency 12.78 ms → 2.10 ms (≈6.1×) as 32 files / row groups collapse to 1. The sustained-ingest soak (D2’s literal one-hour window at D1’s rate) and D1 itself remain unrun — the throughput is the RFC0009.7 D2 measure, not that soak. The prior green status (flipped earlier the same day) rested on every RFC0009 §5 acceptance criterion having a live, passing test: .1 small-file count collapses (rfc0009_1_*), .2 row conservation (compaction_conserves_every_row proptest), .3 atomic publish / no torn read (atomic_publish_… + the ourios-querier rfc0009_3_* manifest tests), .4 crash safety (rfc0009_4_*gc_orphans reclaims orphans, reads stay at a clean generation), .5 tenant/partition isolation (rfc0009_5_* — a mis-partitioned input aborts on the §3.9 row-vs-path check), .6 union-schema merge across an amendment (rfc0009_6_*). The atomic-publish protocol (§3.4) is the per-partition manifest + atomic generation swap; the querier resolves live files reader-first (glob-fallback when absent); the runner lives in ourios-ingester (run_sweep/Compactor) with the §3.6 OTel metrics + audit event.

RFC0009.7 — measured. The D2/D3 criterion benches (compaction throughput, small-file size band) + the post-compaction B2 re-run live in ourios-bench’s compaction bench — CI-indicative via compaction-bench.yml, authoritative on baseline-8vcpu-32gib in §9.7. Its structural half (file count falls under compaction, every row conserved) is also pinned deterministically by RFC0009.1 / compaction_conserves_every_row.

Open follow-ups (§7, post-validated): the full D2 sustained-ingest soak (backlog-returns-to-zero in a one-hour window at D1’s rate) + a measured D1; late-arriving data re-flagging an already-compacted partition (the manifest is authoritative, so a new write into such a partition must be picked up by the candidate scan / folded into the manifest — confirm plan_candidates covers it); the S3 atomic-swap primitive + single-writer lease for object storage (local FS uses rename); and the RFC 0004 cadence defaults.

1. Summary

Ourios’s writers land many small Parquet files per tenant per hour (one per writer flush / time-rotated partition; docs/hazards.md H4). This RFC introduces a background, per-tenant, per-partition compaction pass that consolidates the small *.parquet files of a sealed partition into one (or few) files inside the RFC 0005 §3.5 size targets, without changing a single stored row and without any query ever seeing a row twice or missing one. Compaction reuses the existing ourios-parquet Reader/Writer and the atomic-publish convention (write to *.parquet.tmp, commit by rename); the live set of a partition is named by a small per-partition manifest so the commit is a single atomic object swap. It is the mitigation for hazard H4 and the lever the RFC 0007 §6 / PR #92 B2 bench identified: query latency there is dominated by per-file footer reads, not data scanning, so fewer/larger files is the next query-latency win.

2. Motivation

2.1 The small-file problem is now measured, not theoretical

docs/hazards.md H4 predicted it; the B2 latency bench (crates/ourios-bench/benches/b2.rs, RFC 0007 §6, landed in PR #92) measured it. With result size held constant while the corpus grows 1×/10×/50×, query latency grew sub-linearly but not flat (~0.95 ms → ~1.55 ms → ~4.36 ms). The structural B2 test (rfc0007_2_template_exact_work_scales_with_result_not_corpus) proves the scanned row groups and bytes stay flat; the residual wall-clock growth is per-file footer/metadata reads, because file count scales with corpus. Compaction is the direct lever on that residual: collapse N small files’ N footer reads into one.

2.2 RFC 0005 explicitly deferred it here

RFC 0005 §3.5 says the writer’s job is to “land at the bottom of [the file-size] range or below on its own … compaction is deferred,” and §4.5 parks background compaction as “a post-MVP RFC.” Two writer behaviours guarantee small files even at steady state and so require a sweeper: (a) time-rotated partitions — an hour partition that receives a trickle of late or low-volume traffic produces a sub-128 MiB file; (b) end-of-day audit files (RFC 0005 §3.4) are inherently small. H4’s detection threshold (“fewer than 5 % of files below 128 MiB at steady state”) cannot be met by writer sizing alone.

2.3 Why at this layer

Compaction is a write-path / storage concern, not a query-path one: the querier (RFC 0007, hazard §4.6) must stay a pure reader, and the WAL→Parquet flush sizing (RFC 0005/0008) is a separate mechanism (it sizes files as they are first written; this RFC re-consolidates files already published). Doing it as a background pass keeps it off the ack-latency hot path (WAL-before-ack, CLAUDE.md §3.4 is untouched).

3. Proposed design

3.1 Scope

In scope. Background consolidation of the published, committed *.parquet data files of a single sealed partition (data/tenant_id=<enc>/year=YYYY/month=MM/day=DD/hour=HH/, the RFC 0005 §3.4 Hive layout) into one or a few files meeting RFC 0005 §3.5 size targets, preserving every stored row exactly. The same mechanism applies to the audit-event series (audit/…, day-granular).

Out of scope. WAL→Parquet flush sizing (RFC 0005/0008); retention/expiry/TTL (no compaction-driven deletion of data — only of inputs it has just rewritten); cross-partition or cross-tenant merges; re-mining or re-templating (compaction copies rows, it does not touch the miner); query-side caching.

3.2 Where it runs

A background task hosted in the ingester role (it already owns the write path, the bucket credentials, and per-tenant context), with its own bounded concurrency knob so it never starves ingest. The compaction logic itself is a new compaction module in ourios-parquet (it is Parquet-file manipulation — read many via Reader, write one via Writer); no new crate. Driving it from a dedicated compactor role is a deployment-scaling evolution captured in §4, not an MVP requirement.

3.3 What is eligible: sealed partitions

Compaction only ever touches a sealed partition — one no longer receiving writes — so it never races an active writer for the same input set. A data partition (…/hour=HH/) is sealed once wall-clock time passes the end of its hour plus a compaction_grace margin (default 15 min, tunable per RFC 0004) that absorbs late-arriving records. A sealed partition is a candidate when it has more than compaction_min_files files (default 4) or holds files below 128 MiB. This is a partition-local trigger heuristic — distinct from H4’s tenant-level detection metric (the per-tenant file-size histogram / “fewer than 5 % of files below 128 MiB at steady state”, §3.6), which is the cluster signal compaction’s job is to keep satisfied. Late data that arrives after a partition is compacted lands as a new small file and re-flags the partition as a candidate — compaction is idempotent and re-runnable (§3.5).

3.4 The atomic-publish protocol — per-partition manifest

A query (RFC 0007) plans over a partition by enumerating its committed *.parquet files. If compaction publishes the consolidated file before deleting its inputs, a concurrent query double-counts; if it deletes inputs first, a query misses rows. Object storage (the source of truth, CLAUDE.md §3.6) offers no atomic multi-object operation, so a glob-the-directory reader cannot be made correct under compaction.

The commit mechanism is a per-partition manifest. Each partition carries a small manifest.json naming the live set of data files (UUIDv7 names) plus a monotonically increasing generation number. The read path (RFC 0007) resolves a partition’s files through the manifest, not a raw glob; absence of a manifest means “glob all *.parquet” — so pre-compaction partitions and the current querier keep working, and the reader gains manifest support before any compactor writes one (the reader-first sequencing in §7). Compaction:

  1. reads the live set, writes the consolidated *.parquet.tmp;
  2. renames it to its committed *.parquet name (still not referenced by any manifest, so invisible to queries);
  3. writes manifest.json.tmp naming only the new file at generation + 1, and atomically swaps it into place (single- object rename / conditional put) — this is the commit point;
  4. lazily deletes the now-orphaned input files (a crash here leaves harmless orphans that a GC sweep reclaims; correctness already committed at step 3).

A query reads a consistent generation: either the pre-compaction set or the post-compaction set, never a mix (RFC0009.3). This is the Iceberg/Delta “atomic metadata swap” idea reduced to one flat file per partition — deliberately not a full table format; the generation- subdirectory and glob-the-directory-reader alternatives were weighed and rejected in §4.

sequenceDiagram
    participant C as Compactor (ingester)
    participant FS as Object store (partition)
    participant Q as Querier
    Note over FS: manifest@gen=N → {a,b,c}.parquet
    C->>FS: read live set {a,b,c}
    C->>FS: write compacted.parquet.tmp → rename compacted.parquet
    Q-->>FS: plan @gen=N (sees {a,b,c}) ✓ no torn read
    C->>FS: atomic swap manifest@gen=N+1 → {compacted}
    Q-->>FS: plan @gen=N+1 (sees {compacted}) ✓
    C->>FS: GC orphaned {a,b,c} (lazy, post-commit)

This protocol is an interaction with RFC 0007 (the querier must read through the manifest) and a small extension to RFC 0005 (the manifest is a new per-partition artifact — additive, optional, back-compatible). Both are recorded as resolved decisions in §7.

3.5 Correctness, idempotency, crash safety

  • Row conservation. Compaction preserves every row value exactly — including the raw body bytes — but does not promise byte-identical Parquet files: the physical encoding may differ (row groups re-packed to the §3.5 sizes, compression re-applied, rows possibly reordered within the partition). The logical guarantees hold: same RFC 0005 schema, same partition ⇒ row-vs- path validation §3.9 still holds; bit-identical body reconstruction §3.3 is preserved because rows are copied, never re-mined. Total row count and per-template_id counts are invariant across a compaction (RFC0009.2).
  • Idempotency. Re-running compaction on a partition with a single already-large file is a no-op (not a candidate per §3.3).
  • Crash safety. The only commit point is the atomic manifest swap (step 3). A crash before it leaves the prior generation authoritative — no acknowledged data lost (mirrors the WAL crash-recovery discipline, CLAUDE.md §3.4). Temp files and post-commit orphans are reclaimed by an idempotent GC sweep.
  • Heterogeneous input schemas. Inputs spanning a schema amendment (some files with an added OPTIONAL column) merge to the union schema and stay readable per RFC 0005 §3.9 (the same forward-compatible read RFC0007.4 already tests).

3.6 Audit + observability

Audit event

Every committed compaction emits an audit event to the RFC 0005 §3.7 audit stream — the “nothing happens silently to stored data” stance applied to file lifecycle (CLAUDE.md §3.1), the same way a template merge is audited. The event records the partition, the input file set, the consolidated output file, the row count (which must be conserved, RFC0009.2), and the committed manifest generation.

Open question (§7): the existing audit schema (RFC 0005 §3.7) is shaped for template events — event_kind is a bounded ordinal mapping with no compaction member, and the template-specific columns (old_template, positions_widened, …) are non-nullable. A compaction event can reuse the common envelope (tenant_id, timestamp, event_kind / event_type, reason) but (a) needs a new compaction member in the event_kind mapping and (b) has no applicable value for the non-nullable template columns, nor a place for the file set / generation. This is an implementation detail to settle when the compaction audit-emit code lands — not a design blocker, so it does not gate red (tracked in §7). The two routes:

  • structured reason — carry the file set / generation as a structured reason payload. Avoids new columns, but still needs the event_kind member and forces placeholder values into the non-nullable template columns (or making them nullable, which is itself a schema change), so “no schema change” is not quite free.
  • additive OPTIONAL columns — add OPTIONAL compaction columns and relax the template columns to OPTIONAL (an RFC 0005 §3.8 additive, back-compatible amendment); old readers ignore unknown columns per RFC 0005 §3.9.

The non-nullability tilts this toward the additive route; settle it against RFC 0005 §3.7 when that code lands, not here.

Metrics (OpenTelemetry semantic conventions)

Instrumented as OpenTelemetry meters and exported via the OTel SDK’s OTLP metric exporter (push over OTLP to a collector / endpoint) — the OTel SDK pipeline end-to-end. No prometheus client crate and no Prometheus scrape endpoint (maintainer direction, 2026-06-03, superseding the earlier opentelemetry-prometheus exporter note in roadmap §5; any Prometheus compatibility is a downstream collector concern, not Ourios’s). The names below follow the OTel metric-naming guidelines — dotted/namespaced, no _total/unit suffixes, UCUM units (including UCUM curly-brace annotations such as {sweep} / {file} for dimensionless counts, which annotate the unit 1), dimensions as attributes — and are exported verbatim over OTLP (no exporter-side name mangling).

MetricInstrumentUnitAttributesSource
ourios.compaction.sweepsCounter{sweep}ourios.compaction.resultRFC 0009 §3.2
ourios.compaction.partitionsCounter{partition}partitions consolidated
ourios.compaction.filesCounter{file}input files merged away (H4)
ourios.compaction.rowsCounter{row}rows rewritten (RFC0009.2)
ourios.compaction.ioCounterByourios.io.directionbytes read / written
ourios.compaction.durationHistogramsourios.compaction.resultsweep wall-clock
ourios.compaction.orphan.filesCounter{file}inputs left un-GC’d (gc_failures)
ourios.compaction.backlogUpDownCounter{partition}ourios.tenantsealed-but-uncompacted (lag)
ourios.storage.parquet.file.sizeHistogramByourios.tenantH4 detector — alert when > 5 % of files < 128 MiB

Attributes (namespaced per the conventions):

  • ourios.tenant (string) — tenant id. Cardinality is bounded by the tenant count; on the per-file-size histogram it is the dimension H4 detection needs (“per-tenant file-size histogram”).
  • ourios.io.direction (string, read | write) — mirrors disk.io.direction; one io counter with a direction attribute rather than two _in/_out metrics.
  • ourios.compaction.result (string, committed | noop | error) — sweep / partition outcome (noop = candidate that consolidated nothing; error = a partition skipped per the resilient sweep).

The H4 “file-count grows sub-linearly with bytes” signal is a derived alert over ourios.storage.parquet.file.size (count) and ingested bytes, not a base metric.

Validation gate. This set is the OpenTelemetry semantic- conventions registry at semconv/registry/, validated by weaver registry check in CI (the semconv job, a required check) — so the names/units/attributes stay spec-adherent and can’t drift. Compaction is the first place these conventions are pinned; RFC 0001 §6.8’s Prometheus-style names get the same OTel-source treatment in its own amendment (roadmap §5).

Code generation. Instrumentation does not hand-type these names: weaver registry generate renders the registry into a dependency- free leaf crate ourios-semconv (const &str per metric / attribute, mirroring upstream opentelemetry-semantic-conventions), which every instrumented crate depends on. The generator template lives at templates/registry/rust/; regenerate with the same command CI runs (--future matches weaver registry check --future):

weaver registry generate rust crates/ourios-semconv/src \
    -t templates -r semconv/registry --future
cargo fmt -p ourios-semconv

The same semconv CI job regenerates and fails on any diff (it also catches new untracked files), so the constants cannot drift from the registry. This new leaf crate extends the CLAUDE.md §7 layout; the commitment is blessed here, the same way ourios-telemetry was blessed in RFC 0001 §6.8.

4. Alternatives considered

  • No compaction (rely on writer flush sizing). Rejected: §2.2 — time-rotated low-volume partitions and end-of-day audit files are small by construction, so H4’s <5 % threshold is unmeetable without a sweeper, and PR #92 measured the latency cost.
  • Glob-the-directory reader, delete-after-publish (no manifest). Rejected: object storage has no atomic multi-object op, so there is always a window where a query double-counts (publish-then-delete) or misses rows (delete-then-publish). §3.4.
  • Full table format (Apache Iceberg / Delta Lake). Rejected for now: Pillar 1 commits Ourios to plain Parquet end-to-end (RFC 0005 §4.6 rejects even a second file format); a full manifest-of- manifests, snapshot log, and schema-registry is far more machinery than one flat per-partition manifest needs. The atomic-swap idea is borrowed from them (§3.4); the bookkeeping is not.
  • Compaction in the querier. Rejected: the querier is a pure reader (hazard §4.6); a read path that mutates storage breaks that contract and the multi-reader model.
  • Dedicated compactor role/binary. A viable evolution for isolating compaction CPU/IO from ingest at scale; deferred — the MVP hosts it as a bounded background task in the ingester (§3.2), and the role split is a later, non-breaking change.
  • Generation subdirectories instead of a manifest (…/gen=K/, querier reads the highest). Rejected: it leaks generation into the partition path (a second pruning axis the querier must learn) and complicates partition discovery; the flat manifest (§3.4) keeps the path stable and confines the change to one optional per-partition file. (This was the leading alternative; the manifest won on read-path simplicity.)

5. Acceptance criteria

Given / When / Then / And; ids greppable from tests. These realise hazard H4 and the affected invariants.

  • RFC0009.1 — small-file count falls below the H4 threshold [H4 detection]

    • Given a sealed partition with many sub-128 MiB files
    • When compaction runs to completion
    • Then the partition holds files inside the RFC 0005 §3.5 size range, and at steady state fewer than 5 % of a tenant’s files are below 128 MiB.
  • RFC0009.2 — row conservation [§3.3 / data integrity]

    • Given any set of input files in a partition
    • When they are compacted
    • Then the multiset of stored rows is identical (total row count and per-template_id counts unchanged), and each row still reconstructs bit-identically (RFC 0005 §3.3).
  • RFC0009.3 — query atomicity (no double-count, no miss) [H4 / RFC0007]

    • Given a query planned concurrently with a compaction of the same partition
    • When it executes
    • Then it observes exactly one generation’s file set — every row exactly once — never a torn mix of pre- and post-compaction files.
  • RFC0009.4 — crash safety [§3.4 discipline]

    • Given a compactor killed at any point
    • When the system recovers
    • Then no acknowledged row is lost: the partition reads as either the pre- or post-compaction generation, and orphaned temp/input files are reclaimable.
  • RFC0009.5 — tenant + partition isolation [§3.7]

    • Given multi-tenant data
    • When compaction runs
    • Then it never merges files across tenants or across partition keys; a compacted file’s rows all share the partition’s tenant_id and time bucket (RFC 0005 §3.9 row-vs-path holds).
  • RFC0009.6 — forward-compatible merge [§3.5 / RFC0007.4]

    • Given inputs spanning a schema amendment (some with an added OPTIONAL column)
    • When compacted
    • Then the output carries the union schema and reads without error per RFC 0005 §3.9.
  • RFC0009.7 — file count sub-linear in bytes [H4 / benchmarks D3]

    • Given sustained ingest with compaction running
    • When bytes ingested grow
    • Then file count grows sub-linearly, and template-exact query latency (RFC 0007 §6 B2 bench) does not grow proportionally to the pre-compaction file count.

6. Testing strategy

Mapped to CLAUDE.md §6.2:

  • Property (proptest) — RFC0009.2: over arbitrary input file sets (varied templates, row counts, schemas), compaction preserves the row multiset and per-template counts. The reconstruction property test (RFC 0005 §3.3) runs on compacted output too.
  • Integration — RFC0009.1/.5/.6: build a multi-file partition via the ourios-parquet writer, compact, assert file-size/count and that a Querier returns identical results before and after.
  • Concurrency — RFC0009.3: interleave a query with a compaction commit (drive the manifest swap mid-plan) and assert the row count is exactly correct for one generation.
  • Crash recovery — RFC0009.4: SIGKILL the compactor before and after the manifest swap; assert recovery loses no rows and GC reclaims orphans (the WAL crash-recovery test is the template).
  • Corpus — RFC0009.1: file-size histogram on the otel-demo corpora before/after compaction.
  • Bench (criterion) — RFC0009.7 / benchmarks D2 (compaction throughput) + D3 (file count under load); re-run the RFC 0007 §6 B2 latency bench post-compaction to show the per-file footer-read residual (§2.1) shrinks.

7. Open questions

Resolved at specified (the design forks; recorded here so the history is legible):

  • Manifest vs. generation-subdirectories vs. glob-the-directory reader. Decided: a per-partition manifest.json with an atomic generation swap (§3.4); the generation-subdirectory and glob-the-directory-reader alternatives are rejected in §4.
  • RFC 0007 read-path change. Decided: the querier resolves a partition’s files through the manifest, glob-fallback when absent. Sequenced reader-first — the RFC 0007 amendment + querier PR (reader tolerates a manifest) lands before any compactor writes one, so no flag day.
  • RFC 0005 artifact ownership. Decided: the manifest is specified here in RFC 0009 and is additive, optional, and back-compatible to the RFC 0005 layout (absent ⇒ glob), so it needs no breaking RFC 0005 amendment; RFC 0005 §3.4 is cross- referenced, not rewritten.

Open (implementation details; none block red):

  • Manifest serialization + atomic-swap primitive. Local FS: rename is atomic. S3: needs conditional-put / versioned-put or a single-writer lease. Which object-store abstraction (and does object_store give us the primitive portably)?
  • Single-writer-per-partition. Lease, or rely on the ingester being the sole writer by construction? (Interacts with the eventual horizontally-scaled ingester.)
  • Late-arriving data into a compacted partition. Direction decided: a new small file re-flags the partition as a candidate (§3.3), not re-opening the compacted file; confirm the compaction_grace default.
  • Cadence + concurrency defaults (RFC 0004): scan interval, compaction_min_files, compaction_grace, max concurrent partitions.
  • Audit partition compaction (day-granular) — same protocol, or simpler given lower volume?
  • Retention/expiry interplay — explicitly deferred; note the seam so a later TTL RFC composes with the manifest.
  • Audit-event shape (§3.6). Carry the compaction file set / generation in a structured reason payload vs. OPTIONAL audit columns (RFC 0005 §3.8 additive amendment). Per §3.6 the template columns are non-nullable and event_kind has no compaction member, so the structured-reason route is not schema-free either; leaning the additive OPTIONAL route.
  • Metric semconv validation (§3.6). Run the §3.6 metric names/units/attributes through the OpenTelemetry semantic-conventions check (OTel assistant / weaver / rego policy packages) and fix any divergence before instrumentation lands.

8. References

  • docs/hazards.md H4 (small-file problem) — the hazard this mitigates; CLAUDE.md §4 hazard 4.
  • RFC 0005 §3.4 (partitioning + atomic publish), §3.5 (size targets), §3.9 (reader contract / forward-compat), §4.5 (compaction deferral), §3.7 (audit stream).
  • RFC 0007 §6 + crates/ourios-bench/benches/b2.rs (PR #92) — the B2 latency finding that quantifies the small-file cost; RFC 0007 §4.6 (querier stays a pure reader); RFC0007.4 (forward-compatible reads).
  • RFC 0008 (WAL) — crash-recovery discipline (CLAUDE.md §3.4) the compactor’s commit protocol mirrors.
  • RFC 0004 (configuration policy) — where the cadence/grace/concurrency knobs live.
  • docs/benchmarks.md D2 (WAL→Parquet compaction keeps up), D3 (small-file count under sustained load).
  • Apache Iceberg / Delta Lake atomic metadata-swap commit — design inspiration for §3.4 (the idea, not the machinery).

RFC 0010 — Audit-stream queries & template drift


rfc: 0010 title: Audit-stream queries & template drift status: green author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-06-09 supersedes: — superseded-by: —

RFC 0010 — Audit-stream queries & template drift

Status note. green (2026-06-15) — all eight §5 acceptance scenarios (RFC0010.1–.8) have live, passing tests in crates/ourios-querier/tests/drift.rs: drift returns drifted templates with counts (.1), half-open [from, to) window (.2), event_type scoping excludes non-widenings (.3), tenant isolation (.4), empty-is-empty-not-error (.5), widening_count desc / template_id asc ordering (.6), aggregate version/time bounds (.7), no DataFusion/SQL leakage (.8). The dedicated drift surface (a contained query head, not the general aggregation pipeline) was maintainer-confirmed 2026-06-09; this RFC fills the audit-stream query gap RFC 0002 §6.3 deferred, encapsulating the fixed aggregation RFC 0001 §6.7 wrote out as SQL “for spec clarity”.

RFC0010.1 discharges RFC 0001 H5.3. That hazard test was relocated out of crates/ourios-miner/tests/hazards.rs (now a relocation pointer there) to crates/ourios-querier/tests/drift.rs::h5_3_drift_query_returns_templates_that_gained_a_version, where the drift surface lives — it is no longer #[ignore] / todo!().

This RFC extends RFC 0002 (it does not reopen or renumber it; RFC 0002 stays green) and reads the RFC 0005 audit schema (it does not redefine it). Hazard 6 (CLAUDE.md §4 — no DataFusion/SQL leakage) constrains the surface: drift is exposed through the DSL, never as raw SQL.

Open for accepted (non-gating for green, per §9): the verb-head fork is resolved; the remaining §9 items (range-clause vs stage token, mandatory vs default window, tie-break stability, cross-kind version aggregation) are maintainer confirmations. General audit aggregation stays out of scope (§3.2).

1. Summary

Ourios records every template structural change as a durable audit event (RFC 0001 §6.4, persisted by RFC 0005’s audit/ Parquet series). RFC 0001 §6.7 specifies the operator-facing drift query — “templates that gained a new version in the window [t1, t2)” — but writes it out as SQL “for spec clarity”, explicitly deferring the user-visible form to “the RFC 0002 DSL, not raw SQL”. RFC 0002 in turn deferred the audit-stream query surface as “a future capability” (§6.3). This RFC is that future capability. It specifies a single, contained DSL query head — drift — that scans the per-tenant audit stream over a time window, aggregates the widening/type-expansion events per template, and returns one drift row per affected template. It deliberately does not require RFC 0002’s deferred general count / aggregation pipeline: drift is the one fixed aggregation §6.7 names, so it ships as a closed form rather than as a worked example of a general audit-stream aggregation engine.

2. Motivation

2.1 The gap, precisely

Three existing RFCs (RFC 0001 specified, RFC 0002 green, RFC 0005 drafted) leave a single hole between them:

  • RFC 0001 §6.7 (“Drift detection as a first-class query”) gives the exact semantics as SQL over a template_audit relation, then says: “SQL shown for spec clarity; the user-visible form is the RFC 0002 DSL, not raw SQL — see hazard H6.” The user-visible form was never specified.
  • RFC 0002 §6.3 lists the drift question and resolves the membership half (resolves_to(X) answers “what is template X aliased to”), but explicitly defers the windowed “did this template gain a version” half: “drift is an audit-stream property, not a column in the RFC 0005 data files, so it needs an audit-stream query path — a future capability, not a row predicate in this grammar.”
  • RFC 0005 §3.4 / §3.7 already persists the audit events to a queryable audit/ Parquet series with the columns the §6.7 query reads (event_type, template_id, old_version, new_version, timestamp, …), and ourios-parquet ships ParquetAuditSink / AuditReader / audit_schema(). The data is on disk and readable; nothing turns it into an operator query.

The miner’s RFC 0001 scenario H5.3 is the visible symptom: it is a red-gate #[ignore] / todo!("RFC 0001 §6.7") stub (crates/ourios-miner/tests/hazards.rs) precisely because there is no specified query path to assert against. RFC 0001 §9 records the same as a pending cross-RFC contract (“the DSL surface required to expose drift detection”).

2.2 Why at this layer, and why now

Drift detection is hazard H5 (docs/hazards.md H5, “Template schema evolution across deploys”): a sudden cluster of template_widened events correlated with a deploy is the H5 detection signal, and the §3.5 invariant (“Parquet schema changes require a migration plan”) is the data-side sibling. The audit stream is the only place that signal lives — it is not a column on the data rows. So the query must be an audit-stream query, and it belongs to the querier (RFC 0007, pillar #3) because that is where a compiled query becomes a partition-pruned DataFusion scan.

Now, because the three dependencies are in place: RFC 0001 §6.7 fixed the semantics, RFC 0005 persists the events with predicate-pushable columns, and RFC 0007 is green (the execution layer exists). The only missing piece is the surface and the aggregation that binds them — small enough to ship as a closed form without reopening RFC 0002’s broader deferred work.

3. Scope

3.1 In scope

  • A first-class DSL query head, drift, over the per-tenant RFC 0005 audit/ stream (§6.1, §6.2).
  • The fixed aggregation of RFC 0001 §6.7 (§6.3), its result row shape (§6.4), and its tenancy + window semantics (§6.5).
  • Compilation to a DataFusion plan over the RFC 0005 audit files, executed by RFC 0007 (§6.6).
  • The §5 acceptance criteria, including the H5.3 flip.

3.2 Out of scope (stated explicitly)

  • General audit-stream aggregation. Arbitrary GROUP BY / count / sum over audit events — i.e. RFC 0002’s deferred count / aggregation-stage pipeline applied to a generic audit source — stays deferred. drift is one closed query, not a general engine (§8 alternative A; the dedicated form may later be re-expressed on top of that engine without a surface change).
  • The rejected_degenerate event. drift counts widenings and type-expansions only, exactly as RFC 0001 §6.7’s event_type IN ('template_widened', 'template_type_expanded') filter specifies. template_widening_rejected_degenerate (RFC 0005 ordinal 2) records a non-change and must not count toward widening_count (RFC0010.3). The compaction event (RFC 0005 ordinal 3) is likewise not a template change and is excluded by the same event_type filter.
  • Alias / resolves_to membership. “Is template X aliased to Y” is the cross-alias axis already served by RFC 0002 resolves_to over the RFC 0001 §6.7 alias map. drift is the orthogonal cross-version axis (“did leaf X gain a version in [t1, t2)”); see §8 alternative B.
  • Raw SQL / DataFusion passthrough. Rejected per hazard H6 (docs/hazards.md H6): the DataFusion SQL surface is never exposed. drift is DSL-only (§8 alternative C).
  • The compaction-event query surface. RFC 0005 routes compaction events through the same audit stream; querying those is a separate future need, not folded in here.

4. Background: what is already on disk

This RFC reads, and does not redefine, the RFC 0005 audit schema. The relevant facts, cited so the design below is unambiguous:

  • Partition layout (RFC 0005 §3.4). Audit files live at <bucket>/audit/tenant_id=<tenant_id>/year=YYYY/month=MM/day=DD/<flush_uuid>.parquet — a parallel series to the data/ logs, keyed by tenant_id then a day-granularity time bucket derived from timestamp. tenant_id is a row-level REQUIRED column and the leading Hive partition key, so a per-tenant scan is a partition prune, not a post-filter (§6.5).
  • Columns (RFC 0005 §3.7). event_type (REQUIRED STRING, the predicate-pushdown surface RFC 0005 names “for the RFC 0001 §6.7 drift query”), event_kind (REQUIRED, Arrow UInt8 / INTEGER(8, unsigned) ordinal), template_id (UInt64, OPTIONAL but required-by-convention for the template kinds), old_version / new_version (UInt32, OPTIONAL — relaxed for the compaction kind, required-by-convention for the template kinds), timestamp (TIMESTAMP(NANOS, UTC), REQUIRED), and the template-detail columns (old_template, new_template, positions_widened, slots_expanded, triggering_line_*, reason). Drift reads only tenant_id, event_type, template_id, old_version, new_version, and timestamp.
  • Event-kind mapping (RFC 0005 §3.7). 0 → template_widened, 1 → template_type_expanded, 2 → template_widening_rejected_degenerate, 3 → compaction. Drift’s event_type filter selects ordinals 0 and 1.
  • Reader (ourios-parquet). AuditReader::open_partition is the production query path; audit_schema() is the canonical Arrow schema. This RFC’s compile target (§6.6) consumes that reader.

5. Acceptance criteria

Normative scenarios, in the docs/rfcs/README.md Required-sections acceptance-criteria format (Given / When / Then / And). Each carries a greppable id referenced from the test code. Where a scenario discharges a sibling RFC’s criterion, both ids are listed so the mapping stays greppable from either side.

  • RFC0010.1 — Drift query returns templates that gained a version in the window (discharges RFC 0001 H5.3) [RFC 0001 §6.7], hazard H5

    • Given a tenant’s audit stream containing template_widened and/or template_type_expanded events for template A and for template B, all with timestamp inside [t1, t2)
    • When the drift query drift from <t1> to <t2> runs in that tenant’s context
    • Then the result contains exactly one row for A and one row for B
    • And each row’s widening_count equals the number of that template’s qualifying events in [t1, t2)
    • And this is the criterion that flips the RFC 0001 H5.3 stub (crates/ourios-miner/tests/hazards.rs::h5_3_drift_query_returns_templates_that_gained_a_version), which is owned by RFC 0001 and satisfied here.
  • RFC0010.2 — Window boundary excludes out-of-window events [§6.5]

    • Given a qualifying event whose timestamp is strictly before t1, a second strictly after the window’s upper bound, and a third exactly on each boundary
    • When the drift query over [t1, t2) runs
    • Then the out-of-window events do not contribute to any widening_count
    • And boundary inclusion is half-open [from, to) — the lower bound from is included, the upper bound to is excluded — so a template with only a boundary event is present iff that boundary is the included (lower) one.
  • RFC0010.3 — event_type scoping excludes non-widenings [RFC 0001 §6.7], §3 (out of scope)

    • Given a template C with only template_widening_rejected_degenerate and/or compaction events in [t1, t2) (and no template_widened / template_type_expanded)
    • When the drift query over [t1, t2) runs
    • Then template C does not appear in the result
    • And for a template D with both qualifying and rejected_degenerate events, widening_count counts only the qualifying ones.
  • RFC0010.4 — Tenant isolation [CLAUDE.md §3.7], RFC0007.5

    • Given qualifying audit events for tenant X and qualifying audit events for tenant Y in the same window
    • When the drift query runs in tenant X’s context
    • Then no row attributable to tenant Y’s events appears, enforced at the partition-prune layer (the tenant_id Hive key), and a drift query without a tenant is a usage error, not a cross-tenant scan.
  • RFC0010.5 — Empty result is empty, not an error [§6.4]

    • Given a tenant with no qualifying events in [t1, t2) (no audit files for the window, or only excluded event types)
    • When the drift query over [t1, t2) runs
    • Then it returns an empty result set, not an error.
  • RFC0010.6 — Result ordering is widening_count descending [RFC 0001 §6.7]

    • Given templates whose qualifying-event counts in [t1, t2) differ
    • When the drift query over [t1, t2) runs
    • Then rows are ordered by widening_count descending, matching RFC 0001 §6.7’s ORDER BY widening_count DESC
    • And the tie-break among equal counts is deterministic (ascending template_id) so the result is stable for golden-test pinning.
  • RFC0010.7 — Aggregate version/time bounds per template [RFC 0001 §6.7]

    • Given template A with qualifying events spanning versions v_lo … v_hi and timestamps ts_lo … ts_hi inside [t1, t2)
    • When the drift query over [t1, t2) runs
    • Then A’s row carries min_old_version = v_lo, max_new_version = v_hi, first_seen = ts_lo, last_seen = ts_hi, matching RFC 0001 §6.7’s MIN(old_version), MAX(new_version), MIN(timestamp), MAX(timestamp).
  • RFC0010.8 — No DataFusion/SQL leakage [H6], RFC0007.3

    • Given the public drift surface (string DSL and structured form)
    • When a malformed or SQL-shaped drift query is submitted
    • Then neither the accepted grammar nor any error Display exposes DataFusion or SQL types/identifiers; the drift head is DSL-only, as resolves_to and render are (RFC 0002 §6.5).

6. Proposed design

6.1 A dedicated drift query head, not a general pipeline

RFC 0002’s pipeline is predicate { | stage } over the data/ log table (from logs is implicit; RFC 0002 §6.5). Drift is structurally different in three ways that make it a poor fit for that pipeline as-is:

  1. Different source. It scans audit/, a different Parquet series with a different schema, not data/.
  2. A fixed aggregation. RFC 0001 §6.7 fully specifies the projection, grouping, and ordering. There is exactly one drift query shape.
  3. No log predicate vocabulary. service, severity, body, template_id predicates etc. (RFC 0002 §7 nonsev_field) are log-record fields; they have no meaning over audit rows.

So rather than (a) adding a general audit source plus the deferred aggregation stages and then expressing drift as one instance, this RFC introduces a closed query head:

drift_query = "drift" , "from" , time , "to" , time ;

time is the exact RFC 0002 §7 time productionnow, a signed relative duration (-1h, -7d, …), or an RFC 3339 timestamp — reused verbatim, so the window vocabulary an operator already knows from range(...) carries over. The head is a top-level alternative to RFC 0002’s predicate { | stage } query, not a stage within it; a drift query is its own well-formed query, and it admits no further | stages (the projection, grouping, and ordering are fixed by §6.3, so there is nothing to compose).

Why this surface (drift from <t1> to <t2>) over audit | drift(...). RFC 0002’s pipeline reads as source | transform | …. A bare drift verb head reads as a single declarative question — “drift, from t1 to t2” — which matches how the operator thinks (“show me drift since the deploy”) and keeps the fixed, non-composable nature of the query honest: there is no audit source to further filter or aggregate, because the only audit-stream question this RFC answers is drift. An audit | drift(...) form would imply a general audit source and a composable drift stage, which is precisely the broader engine this RFC declines to build (§8 alternative A); choosing the verb head avoids promising composition the grammar does not deliver. The cost is one more top-level query shape in the grammar; that is paid once and is cheaper than a misleading pipeline.

The structured surface (RFC 0002 §6.4, the MCP/agent contract) carries the same query as a tagged object:

{ "drift": { "from": "-7d", "to": "now" } }

from / to are RFC 0002 §7 lexical time strings (relative duration, "now", or RFC 3339), exactly as the structured surface already carries durations and timestamps. As with the string head, no predicate or stages keys are accepted alongside drift — it is a distinct top-level object, validated by its own published JSON Schema fragment (versioned with the parser, snapshot-tested like the RFC 0002 §7 grammar).

6.2 Example queries

drift from -7d to now

“Which templates gained a version in the last seven days?” — the post-deploy H5 check.

drift from 2026-06-01T00:00:00Z to 2026-06-02T00:00:00Z

Drift confined to a single UTC day (an absolute window straddling one deploy), the form an operator pins in a Perses panel.

6.3 Semantics — RFC 0001 §6.7, verbatim

The drift query is the closed form of RFC 0001 §6.7’s specification. Over the executing tenant’s audit stream:

  1. Filter to event_type IN ('template_widened', 'template_type_expanded') (RFC 0005 ordinals 0 and 1) and timestamp in the window (§6.5).
  2. Group by template_id.
  3. Project per group:
    • widening_count = COUNT(*)
    • min_old_version = MIN(old_version)
    • max_new_version = MAX(new_version)
    • first_seen = MIN(timestamp)
    • last_seen = MAX(timestamp)
  4. Order by widening_count descending, then template_id ascending (the deterministic tie-break of §5 RFC0010.6; RFC 0001 §6.7 leaves ties unspecified, this RFC pins them for stable golden tests).

Equivalent to RFC 0001 §6.7’s SQL, restated here only to anchor the column names this RFC’s result shape uses:

SELECT template_id,
       COUNT(*)          AS widening_count,
       MIN(old_version)  AS min_old_version,
       MAX(new_version)  AS max_new_version,
       MIN(timestamp)    AS first_seen,
       MAX(timestamp)    AS last_seen
FROM   audit                       -- the per-tenant RFC 0005 audit/ stream
WHERE  event_type IN ('template_widened', 'template_type_expanded')
  AND  timestamp >= $t1 AND timestamp < $t2
GROUP  BY template_id
ORDER  BY widening_count DESC, template_id ASC

(SQL is shown for spec clarity only, mirroring RFC 0001 §6.7; the user-visible form is the §6.1 drift head, never raw SQL — hazard H6 / §8 alternative C.)

6.4 Result shape

A drift query returns a typed result set of drift rows, distinct from the log result rows RFC 0007 returns. One row per affected template:

#![allow(unused)]
fn main() {
pub struct DriftRow {
    pub template_id: u64,
    pub widening_count: u64,
    pub min_old_version: u32,
    pub max_new_version: u32,
    pub first_seen: SystemTime,
    pub last_seen: SystemTime,
}
}

The columns map one-to-one onto the §6.3 projection. The carrier follows the RFC 0007 QueryResult shape (typed rows plus scan stats: row_groups_scanned / row_groups_pruned / bytes_read). An empty result is an empty row set (RFC0010.5), never an error. The drift result is its own variant so it cannot be confused with a log-row result; making the two result shapes distinct keeps invalid mixes unrepresentable.

6.5 Tenancy and window semantics

  • Tenant scoping (CLAUDE.md §3.7, RFC0010.4). The tenant is supplied by the executing context, exactly as for RFC 0002/RFC 0007 log queries — never expressed in the query text. It compiles to a tenant_id partition-key filter over the audit/tenant_id=… Hive layout (RFC 0005 §3.4), so isolation is a partition prune, not a post-scan filter (RFC 0007 §6.5). A drift query with no tenant is a usage error, not a cross-tenant scan.
  • Window boundaries (RFC0010.2). drift defines its window as half-open [from, to) — lower bound included, upper bound excluded. (RFC 0002’s range(from, to) stage does not pin its boundary semantics today; RFC 0010 defines half-open for the drift window independently.) from/to reuse the RFC 0002 §7 time grammar (relative durations resolve against query-evaluation now; RFC 3339 timestamps are absolute).
  • Window → partition prune. The window’s resolved [t1, t2) bounds drive year/month/day partition pruning over the audit layout (day-granularity per RFC 0005 §3.4), then an exact timestamp predicate trims the boundary days. This is the RFC 0007 partition-prune model applied to the audit series.

6.6 Compilation and execution

flowchart LR
  Q["drift from t1 to t2<br/>(string DSL / structured)"] --> P[parser / validator]
  P --> IR["drift query IR<br/>{ window: [t1, t2) }"]
  IR --> C["compiler<br/>(no SQL leakage — H6)"]
  C --> LP["DataFusion plan over the<br/>RFC 0005 audit/ series<br/>(Filter → Aggregate → Sort)"]
  LP --> X["RFC 0007 execution<br/>(AuditReader, partition prune)"]
  X --> R["DriftRow result set<br/>+ scan stats"]

The drift head parses (string surface) or validates (structured surface) to a small drift IR carrying only the resolved window; both surfaces lower to the same IR (the RFC 0002 §6.4 “two front-ends, one core” discipline). The compiler lowers the IR to a DataFusion plan over the RFC 0005 audit/ files — registered through the ourios-parquet AuditReader / audit_schema() surface — as Filter (event-type + tenant + window) → Aggregate (group by template_id, the §6.3 aggregates) → Sort (§6.3 ordering). Lowering is the only place DataFusion types appear; they never reach the caller (RFC0010.8 / RFC 0007 §6.5). Execution is RFC 0007’s: partition pruning on tenant_id and the time keys, event_type predicate pushdown (RFC 0005 §3.7 names event_type as the pushdown surface for exactly this query), scan stats surfaced on the result.

The querier today scans only the data/ series and rejects Count / Agg stages (crates/ourios-querier/src/compile.rs). This RFC adds the audit source and the one closed aggregation the drift head needs — it does not unblock the general Count / Agg stages over data/, which remain the RFC 0002 deferred work (§8 alternative A).

7. Testing strategy

Mapping to CLAUDE.md §6.2 and docs/verification.md (red→green two-loop: #[ignore]’d stubs first, implementations second). Every §5 scenario is a test; ids are greppable from the test code.

  • The H5.3 flip (RFC0010.1). The existing crates/ourios-miner/tests/hazards.rs::h5_3_drift_query_returns_templates_that_gained_a_version stub is replaced by a real test driving the drift query over a seeded audit stream and asserting templates A, B and their counts. Because the query path lives in ourios-querier, the integration test seeds an audit partition via the ourios-parquet ParquetAuditSink and runs the compiled drift query; the miner-side hazards.rs test asserts the same end-to-end behaviour through the public surface (so RFC 0001’s H5.3 and this RFC’s RFC0010.1 reference one mechanism).
  • Unit / parse tests. Positive and negative parse tests for the drift_query production and the structured { "drift": … } object, including rejection of trailing | stages and of a predicate/stages sibling key (the closed-form constraint, §6.1).
  • Boundary tests (RFC0010.2). Events placed before, on, and after each window bound; assert the half-open [from, to) inclusion this RFC defines (§6.5) — lower bound included, upper bound excluded.
  • Scoping tests (RFC0010.3). rejected_degenerate and compaction events seeded alongside qualifying ones; assert exclusion and correct widening_count.
  • Tenant-isolation test (RFC0010.4). Two tenants’ audit partitions; assert tenant X’s drift never sees tenant Y, and the no-tenant usage error — mirrors RFC0007.5.
  • Empty-result test (RFC0010.5). No qualifying events / no audit files; assert empty, not error.
  • Ordering / aggregate golden tests (RFC0010.6, RFC0010.7). A seeded multi-template audit set with a pinned expected DriftRow ordering and per-row version/time bounds (golden, like RFC 0002’s compilation goldens and RFC 0007’s end-to-end pins).
  • No-leakage test (RFC0010.8). Compile + error-Display string test that no DataFusion/SQL identifier escapes the drift surface; the same technique as RFC0002.3 / RFC0007.3.

8. Alternatives considered

  • A. General audit-stream aggregation pipeline. Implement RFC 0002’s deferred count / agg / group by stages plus a generic audit source, then express drift as a normal aggregation query (audit | range(...) | count by template_id | sort count desc). More general and reusable — it would answer many audit questions, not just drift — but it is a substantially larger surface, it reopens RFC 0002’s deliberately-deferred aggregation work (and its grammar/versioning contract), and it over-delivers for the one fixed query H5.3 needs. The dedicated head ships the H5 signal now with a closed, testable surface. It is a fair trade only because drift is the single audit question on the table; the dedicated drift head can later be re-expressed on top of the general engine (same DriftRow output, same drift surface) without a user-visible change, so choosing it now does not foreclose the general path — it sequences it after a proven need. Hence A is the rejected-for-now primary alternative, not a dead end.
  • B. resolves_to only. RFC 0002 already ships resolves_to(X), which answers “what template_ids are aliased to X” (cross-alias membership; RFC 0001 §6.7). One might argue drift is already covered. It is not: resolves_to is a membership test on the operator-asserted alias map, answering “are these the same template”, whereas drift is the windowed rate-of-change signal “did leaf X gain a version in [t1, t2)” — the cross-version axis RFC 0001 §6.7 keeps explicitly disjoint from the alias axis. The two are orthogonal; resolves_to cannot express a time window or count events, so it cannot answer H5.
  • C. Raw SQL / DataFusion passthrough. Expose the §6.3 SQL (or a general SQL endpoint) directly. Zero surface-design cost. Rejected per hazard H6 (docs/hazards.md H6, “do not leak DataFusion specifics through to users”) and RFC 0002 §10’s standing rejection of a SQL default: it binds the user surface to DataFusion and reopens the cross-tenant / unbounded-scan risks the DSL exists to contain.
  • D. A template_drift boolean column on the data rows. Materialise a per-row “this template drifted” flag so drift becomes a data-file predicate. Rejected: drift is a property of the audit timeline, not of any single log row; the flag would be window-relative (drift is always “in [t1, t2)”), so it cannot be precomputed at write time, and it would bloat every data row for a low-frequency query. RFC 0002 §6.3 already rules this out (“not a column in the RFC 0005 data files”).

9. Open questions

Must be resolved before accepted; none block specified.

  • Surface fork — verb head confirmed (maintainer, 2026-06-09). §6.1’s drift from <t1> to <t2> top-level verb head (over audit | drift(...), a stage on a general audit source) is the intended surface — it forecloses composing further stages onto a drift query by design, and is NOT the general aggregation pipeline (RFC 0002’s deferred work).
  • Re-use of range vs a head-local window. §6.1 reuses the RFC 0002 range(from, to) bounds via a from … to … clause rather than admitting a literal | range(...) stage on the drift head. Confirm the dedicated clause is preferable to reusing the range stage token.
  • Default window. Log queries get a tenant-default window when range is omitted (RFC 0002 §4 P5 / RFC0002.4). Should drift require an explicit window (current spec: from/to are mandatory), or inherit the same tenant default? Current choice: mandatory, because a default-windowed drift is rarely what an operator means (drift questions are deploy-relative).
  • Tie-break stability. §6.3 pins ties as ascending template_id beyond RFC 0001 §6.7’s ORDER BY widening_count DESC. Confirm this is the desired stable order (vs. e.g. last_seen DESC).
  • old_version / new_version on type-expansion rows. RFC 0005 stores these for both template kinds; min_old_version / max_new_version therefore mix widening and type-expansion version deltas. Confirm that aggregating across both kinds is the intended §6.7 semantics (RFC 0001 §6.7’s SQL groups both, so this RFC follows).

10. References

  • RFC 0001 §6.7 — “Drift detection as a first-class query” (the SQL semantics this RFC closes over) and §6.4 (the audit event model); RFC 0001 scenario H5.3 (the red-gate stub this RFC discharges) and §9 (the pending DSL-surface contract).
  • RFC 0002 — the base DSL this RFC extends (predicate { | stage }, the §6.4 two-surface model, the §7 time production reused here, the §6.5 compilation discipline). RFC 0002 §6.3 explicitly deferred the audit-stream query path; that deferral is resolved by this RFC. RFC 0002 stays green and is not edited here.
  • RFC 0005 §3.4 / §3.7 — the audit/ partition layout and audit-event schema this RFC reads (event_type, template_id, old_version, new_version, timestamp; the event-kind mapping table). This RFC does not redefine the schema.
  • RFC 0007 — the querier execution layer (DataFusion, partition prune, scan stats) that runs the compiled drift query; criteria RFC0007.3 (no-leakage) and RFC0007.5 (tenant isolation) are the siblings of RFC0010.8 and RFC0010.4.
  • CLAUDE.md §3.5 (schema migration), §3.7 (multi-tenancy); docs/hazards.md H5 (schema evolution / drift) + H6 (no DataFusion/SQL leakage).
  • ourios-parquet ParquetAuditSink / AuditReader / audit_schema() (the persisted, readable audit surface this RFC queries).

RFC 0011 — A1 re-scope


rfc: 0011 title: A1 re-scope — template-mining compression is logical (query-pruning), not byte-level status: accepted author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-06-13 supersedes: — superseded-by: —

RFC 0011 — A1 re-scope

Status note. accepted (2026-06-14, maintainer sign-off). A tuning RFC, so it advances directly to the terminal status once its §5 criteria are enacted: RFC0011.1 (A1 is diagnostic, not gating), RFC0011.2 (the miner’s thesis gates are C1 + C2), and RFC0011.3 (the A1 diagnostic is still recorded) are all in force — the docs/benchmarks.md §7 gate table marks A1 diagnostic, RFC 0001’s validated is judged on C1/C2, and §9.5/§9.6 record the A1 readings. Accepting ratifies the re-scope that RFC 0001’s validated/accepted (also 2026-06-14) rests on.

How to read this document. This is a tuning RFC spawned by the docs/benchmarks.md §7 escalation path: a thesis gate (A1) failed and the failure analysis is in, so the gate is reconciled with the evidence rather than left to block indefinitely. §§1–4 are the design contract; §5 is the acceptance criteria (what this RFC must enact); §6 records the measurements. It amends docs/benchmarks.md (the A1 gate’s role) and the thesis-gate set RFC 0001’s validated stage is judged against.

1. Summary

The A1 thesis gate — “Ourios on-disk bytes ≥ 3× smaller than zstd-19 over the raw corpus” — is refuted by measurement on every corpus class tested, including the maximally-templated one, and fails worse the more templated the corpus is. A1 is therefore demoted from a gating thesis criterion to a recorded diagnostic. Template mining’s compression value is realised as query pruning (B1/B2 — row-group skipping, RFC 0007, already validated), reconstruction fidelity (C1), and template-count convergence (C2) — not as on-disk bytes versus a byte codec. RFC 0001’s (template-miner pillar) validated stage is accordingly judged against C1 + C2, both of which pass on a representative ≥ 1 M-line corpus (§6).

2. Motivation

2.1 The measurement

A1 had only ever been measured on the OTel-Demo corpus class (benchmarks.md §9.1/§9.4), where it failed (best 0.829× vs the 3.0× target). The standing analysis attributed this to two structural causes — the demo logs are locally repetitive (so zstd-19 over the concatenated stream captures the redundancy at any size) and columnar Parquet carries a framing premium (per-column/page-index/bloom/row-group overhead) that is the price of queryability. But OTel-Demo is not the corpus where template mining should look best. The decisive test is a maximally-templated corpus: a handful of templates over millions of lines. LogHub HDFS_v1 (11.2 M lines, 1.58 GB) is exactly that.

A1 on HDFS_v1 (§6): ourios 8.300× vs zstd-19 16.000× → delta 0.516× → FAILworse than OTel-Demo, not better.

2.2 Why the best case for template mining is the best case for zstd

The result is not a defect; it is structural and was predictable in hindsight. The more templated (repetitive) a corpus, the more completely a whole-stream byte codec captures its redundancy: zstd-19 over the concatenated HDFS log hits 16×. Template mining collapses the repetitive template text, but the variable bits it extracts — HDFS block IDs, timestamps, IPs — are high-cardinality columns that do not compress to the same degree, and the columnar layout adds framing the single zstd window does not pay. Net: ourios’s 8.3× cannot beat the 16× a byte codec already extracts from the same redundancy. The corpus that most rewards template mining most rewards the byte codec it is measured against, so the ≥ 3× over zstd framing cannot hold on any realistic log corpus.

2.3 What template mining actually buys

The thesis (CLAUDE.md §2 pillar #2) is sound; A1 measured the wrong quantity. Template mining’s “50–200×” is a logical reduction — each line becomes (template_id, params), so a selective query reads a handful of row groups instead of scanning the corpus. That value is captured by B1 (predicate-pushdown latency, ≥ 10×) and B2 (template-exact queries scale with result size, not corpus size) — both pass authoritatively (RFC 0007, validated; benchmarks.md §9.4, incl. HDFS_v1 at 11.2 M rows). The miner’s own correctness is C1 (bit-identical reconstruction or flagged-lossy) and C2 (sub-linear template growth) — both pass on HDFS_v1 (§6). On-disk bytes versus a byte codec is a diagnostic (it tells operators the queryability premium), not a thesis claim.

3. Proposed design

  1. A1 is reclassified diagnostic, not gating. The measurement (ourios ratio, zstd-19 ratio, delta) is still computed and recorded in the benchmarks.md §9 series — it characterises the columnar queryability premium and guards against regression in the codec path — but a delta < 3.0× no longer blocks any RFC’s validated stage. benchmarks.md §7’s gate table marks A1 diagnostic; the §3.4 target text is retained as the diagnostic’s reference line, annotated that it is informational.
  2. The template-miner pillar’s gating thesis criteria are C1 + C2. RFC 0001 (green) reaches validated when C1 and C2 pass on a representative (≥ 1 M-line, benchmarks.md §8) corpus — which they do on HDFS_v1 (§6). The query-pillar gates B1/B2 remain RFC 0007’s, and are already validated.
  3. No change to the codec or the writer. The production ZSTD-3 default stands (the codec gain is small and saturates by level 9, and the residual gap is structural — benchmarks.md §9.1). This RFC changes only what A1 means for the maturity ladder, not any byte on disk.
  4. CLAUDE.md §2 wording is flagged, not changed here. Pillar #2’s “50–200× compression … before any byte-level codec runs” reads as an on-disk-bytes claim; it is precise only as a logical reduction. A one-line clarification is recommended but CLAUDE.md is load-bearing and changes require a meta: RFC + maintainer approval (its own footer), so it is an explicit follow-up (§7), not enacted here.

4. Alternatives considered

  • Keep A1 as a hard ≥ 3× gate. Rejected: it fails on every corpus class including the maximally-favourable one, so it would block RFC 0001’s validated permanently on a criterion the data shows is mis-framed — penalising the project for a measurement that never reflected the thesis.
  • Optimise ourios’s on-disk size to beat zstd-19. Rejected as futile and counter-productive: the ~17 %–2× gap is the columnar framing (page indexes, per-column chunks, bloom filters, row-group metadata) that enables row-group skipping — i.e. it is the price of B1/B2. Shrinking it would trade away the thesis’s actual value to win a metric that doesn’t matter.
  • Drop A1 entirely. Rejected: the ourios-vs-zstd ratio is a useful operator-facing diagnostic (bytes-per-line, the queryability premium) and a regression guard on the codec path. Demote, don’t delete.
  • Redefine A1 to measure the logical reduction (lines → template rows). Considered; deferred. The logical reduction is already what B2 operationalises (result-size-not-corpus-size scaling) and what C2 tracks (template plateau); a third metric restating it adds little. If a standalone “logical compression ratio” proves useful to operators it can be added later as another diagnostic.

5. Acceptance criteria

Scenario RFC0011.1 — A1 is diagnostic, not gating.

  • Given the benchmarks.md §7 thesis-gate table and the §3.4 A1 definition
  • When this RFC is enacted
  • Then A1 is labelled diagnostic (not gating) in the §7 table with a pointer to this RFC, and the §3.4 target is annotated informational
  • And a delta < 3.0× no longer appears in any RFC’s validated blocking set

Scenario RFC0011.2 — the miner pillar’s thesis gates are C1 + C2, and they pass on a representative corpus.

  • Given RFC 0001 (green) and a representative ≥ 1 M-line corpus (benchmarks.md §8)
  • When C1 (reconstruction) and C2 (convergence) are measured on it
  • Then both pass — C1 = 1.000000 bit-identical on non-lossy rows, C2 sub-linear with the formal gate applying (not abstaining) at ≥ 1 M lines — recorded in the §9 series
  • And RFC 0001’s validated stage is judged against C1 + C2 (with B1/B2 the query pillar’s, RFC 0007); A1 does not gate it

Scenario RFC0011.3 — the diagnostic is still recorded.

  • Given a bench run with the A1 gate selected
  • When the harness finalises
  • Then the ourios ratio, zstd-19 ratio, and delta are still computed and written to the §9 results, flagged diagnostic — so the queryability premium stays visible and codec regressions surface

6. Measurements (2026-06-13, local — hardware_kind = "unknown")

Run via ourios-bench --gates … --parquet-zstd-level 19 --allow-unknown-hardware on LogHub HDFS_v1 (Zenodo record 8196385, md5 76a24b4d…; 11,175,629 lines, 1,577,982,906 raw bytes; fetched at bench time, never redistributed — query-bench.yml). Local hardware, so these are diagnostic, not the authoritative baseline-8vcpu-32gib numbers; A1’s verdict is corpus-structural and hardware-independent (compressed bytes are deterministic), and C1/C2 are ratios, so the finding stands regardless of the runner. The authoritative representative-corpus rerun for the actual RFC 0001 validated flip is a maintainer-gated GH Actions / baseline step.

gateresultverdict
A1ourios 8.300× vs zstd-19 16.000× → delta 0.516× (raw 1.578 GB → ourios 189.98 MB, zstd-19 98.21 MB)FAIL (now diagnostic)
C11.000000 reconstruction — 11,175,578 / 11,175,578 non-lossy rows bit-identical; lossy ratio 4.6e-06 (51 rows)PASS
C2end template count 40 at 11.2 M lines (33 at 1 M); ratio 0.825 — sub-linear, formal gate applies (≥ 1 M)PASS

For comparison, A1 on the OTel-Demo class (benchmarks.md §9.1/§9.4) was 0.829× best — so the maximally-templated corpus fails A1 harder, confirming §2.2.

7. Open questions

  • CLAUDE.md §2 pillar #2 wording. “50–200× compression … before any byte-level codec runs” should be clarified to “a 50–200× logical reduction (lines → (template_id, params)), realised as query pruning — not an on-disk-bytes win over a byte codec.” Requires a meta: RFC per CLAUDE.md’s footer; recommended follow-up.
  • Authoritative representative rerun. C1/C2 here are on local hardware. The validated flip for RFC 0001 should cite a baseline-8vcpu-32gib (or equivalent) representative run; the verdicts are not expected to change (deterministic ratios), but the record should be authoritative.

8. References

  • docs/benchmarks.md §3.4 (A1 definition), §7 (gate table + escalation), §9.1/§9.4 (prior A1), §8 (representative-corpus minimum).
  • RFC 0001 §5 (C1/C2 among the miner’s acceptance criteria), CLAUDE.md §2 pillar #2, §3.3 (reconstruction).
  • RFC 0007 (validated) — B1/B2, the query pillar.

RFC 0012 — meta: CLAUDE.md §2 pillar-#2 wording


rfc: 0012 title: “meta: CLAUDE.md §2 pillar-#2 wording — template mining’s 50–200× is a logical reduction, not on-disk bytes” status: accepted author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-06-14 supersedes: — superseded-by: —

RFC 0012 — meta: CLAUDE.md §2 pillar-#2 wording

Status note. accepted (2026-06-14, maintainer-approved + enacted.) The CLAUDE.md §2 pillar-#2 reword (§3.1) and all three coupled reconciliations (§3.2 — benchmarks.md §2, README.md, RFC 0001 §1) were applied in the enacting PR; RFC 0001’s accepted prose took the recommended factual reword (with the RFC 0011 pointer). The §7 footer changelog line + Last updated bump landed in the same diff. This meta-RFC required majority maintainer approval per CLAUDE.md’s footer; that gate is satisfied.

This is a meta: RFC. It proposes a change to CLAUDE.md, which its own footer declares load-bearing: “This document is load-bearing; further changes require a meta: RFC and majority maintainer approval.” Per CLAUDE.md §8.5 (cache discipline) the edit is not made in the drafting session — this RFC specifies the exact change; a maintainer enacts it after approval. Precedent: the §6.2 “tests are specifications” bullet, added via an informal meta: RFC waiver (commit b50067d, 2026-05-13). This RFC follows the same path, written out in full rather than as an informal waiver.

1. Summary

CLAUDE.md §2 pillar #2 currently reads: “Log lines collapse to (template_id, params) at ingest time. This is where the 50–200× compression comes from — before any byte-level codec runs.” That phrasing reads as an on-disk-bytes claim: that template mining alone yields 50–200× smaller files than the raw corpus, ahead of (and independent of) a byte codec. RFC 0011 (accepted) established by measurement that this is false — a whole-stream byte codec (zstd) captures the same redundancy, so on disk Ourios does not beat zstd (the A1 gate is refuted and demoted to a diagnostic). Template mining’s 50–200× is a logical reduction (each line becomes one row keyed by a small, stable template_id), and its value is realised as query pruning — the benchmark gates B1/B2 — not as fewer on-disk bytes than a codec. This RFC amends pillar #2 to say so, so the project’s canonical thesis statement matches its measured reality, and reconciles the coupled echoes of the same framing elsewhere (benchmarks.md §2, README.md, and RFC 0001’s summary).

2. Motivation

2.1 The pillar statement is now contradicted by an accepted RFC

CLAUDE.md §2 is the project’s load-bearing thesis: changing a pillar “is an RFC-level decision.” Pillar #2’s “this is where the 50–200× compression comes from — before any byte-level codec runs” asserts that the byte-savings come from template mining, ahead of the codec. RFC 0011 (accepted 2026-06-14) measured the opposite on every corpus class, including the maximally-templated LogHub HDFS_v1 (ourios 8.3× vs zstd-19 16× → A1 delta 0.516×, benchmarks.md §9.5/§9.6). The headline number in the most load-bearing document in the repo is therefore inaccurate as written. benchmarks.md opens by calling itself “an honesty contract with ourselves”; the same standard applies to the pillar it tests against.

2.2 The number is not wrong — its referent is

The 50–200× figure is real and worth keeping: it is the logical collapse of N near-identical log lines to a handful of (template_id, params) rows. That reduction is exactly what lets a selective query read a few row groups instead of scanning the corpus (pillar #1’s footer-skip), which the thesis gates B1 (predicate-pushdown latency, PASS — 34.2× / 25.4×, benchmarks.md §9.4) and B2 (result-size-not-corpus-size scaling, PASS) measure and confirm. RFC 0011 §2.3 spells this out. So the fix is a referent correction — “logical reduction → query pruning,” not “on-disk bytes → before the codec” — not a retraction of the claim.

2.3 Why fix the wording at all

An inaccurate load-bearing claim quietly licenses bad decisions: someone could “optimise” Ourios’s on-disk size to chase the 50–200×-vs-codec framing, trading away the columnar framing (page indexes, bloom filters, row-group metadata) that is the value (it enables the row-group skipping B1/B2 measure) — exactly the alternative RFC 0011 §4 rejected as counter-productive. Pinning the pillar to the logical-reduction framing forecloses that.

3. Proposed design

3.1 The CLAUDE.md §2 pillar-#2 change

Replace the current pillar #2 (CLAUDE.md §2, the “Drain-derived online template mining” item):

  1. Drain-derived online template mining. Log lines collapse to (template_id, params) at ingest time. This is where the 50–200× compression comes from — before any byte-level codec runs. Correctness of this layer is the single biggest engineering risk in the project.

with:

  1. Drain-derived online template mining. Log lines collapse to (template_id, params) at ingest time — a logical 50–200× reduction (many near-identical lines become rows keyed by one small, stable template_id). That reduction is what lets a selective query read a handful of row groups instead of scanning the corpus, so the payoff is query pruning (pillar #1’s footer-skip; benchmark gates B1/B2), not fewer on-disk bytes than a byte codec — RFC 0011 showed a whole-stream codec captures the same redundancy, so the on-disk-compression-vs-zstd ratio (A1) is a recorded diagnostic, not a gate. Correctness of this layer is the single biggest engineering risk in the project.

The final sentence (the “single biggest engineering risk” line) is preserved verbatim — it is load-bearing in its own right and unaffected.

3.2 The coupled documentation reconciliations

The same on-disk/byte-level framing echoes in three other docs; all are reconciled in the same enactment so the docs stay consistent (none is load-bearing in the CLAUDE.md sense, so they ride normal doc PRs). The authoritative list is whatever the RFC0012.2 framing-grep (§5) surfaces — as of drafting, the phrase “before any byte-level codec” / “over a competent byte codec” appears in exactly these (plus RFC 0011 and this RFC, which quote it to describe the change):

  1. benchmarks.md §2 — the A1 “Why this bar” bullet paraphrases the pillar as the project’s headline claim (§2, CLAUDE.md) is “50–200× over raw, ≥ 5× over a competent byte codec.” That paraphrase (a) attaches a “≥ 5× over a competent byte codec” multiplier the pillar never literally stated and (b) is the byte-vs-codec framing RFC 0011 demoted. Reword to the logical-reduction / diagnostic framing.
  2. README.md — the “Drain-derived online template miner” bullet says lines collapse to (template_id, params) “before any byte-level codec runs.” Same fix: it is the logical reduction, before the codec in the pipeline but not a bytes-vs-codec claim.
  3. docs/rfcs/0001-template-miner.md §1 — its summary states “The compression target is 50–200× over raw bytes before any byte-level codec runs.” Same framing. RFC 0001 is accepted, but this is a factual thesis-statement correction (not a change to its design or §5 acceptance criteria), so reconcile it to the logical-reduction framing with a one-line note pointing at RFC 0011. (If the maintainer prefers to leave an accepted RFC’s prose untouched, the alternative is a dated editorial note rather than a reword — maintainer’s call at enactment.)

Only the framing is reconciled; bare mentions of the 50–200× figure as a logical reduction (e.g. docs/roadmap.md, other RFCs) are correct and are left alone.

3.3 What does not change

  • No code, schema, or on-disk format. This is a documentation-wording RFC.
  • The production codec default (ZSTD-3) and the A1 diagnostic itself (RFC 0011) are untouched.
  • CLAUDE.md §1’s thesis sentence (“collapses the inverted index, the compression layer, the storage tier, and the query engine into one stack”) is left as-is — it describes the stack collapsing layers, not template mining as the byte-compressor; see §7 for the open question on whether it also wants a touch.

4. Alternatives considered

  • Leave the wording. Rejected: an accepted RFC (0011) contradicts a load-bearing pillar; leaving it is the silent-inaccuracy failure mode the project’s honesty contract exists to prevent.
  • Delete the 50–200× number. Rejected: the logical reduction is real, is the thesis’s actual mechanism, and is worth stating — only its referent (logical, not on-disk-bytes) needs fixing.
  • Reword more aggressively (drop the figure, restate the whole pillar around query pruning). Rejected as over-reach for a wording fix: the minimal precise change keeps the pillar recognisable and the diff reviewable.
  • Fold this into RFC 0011. Rejected: RFC 0011 is accepted and explicitly deferred the CLAUDE.md edit to a meta: RFC (its §3 item 4 / §7), because CLAUDE.md changes need the footer’s majority-approval gate that a thesis-gate tuning RFC does not.

5. Acceptance criteria

Scenario RFC0012.1 — pillar #2 states the logical-reduction framing.

  • Given CLAUDE.md §2 pillar #2
  • When this RFC is enacted (post-approval)
  • Then pillar #2 reads per §3.1: the 50–200× is described as a logical reduction whose payoff is query pruning (B1/B2), and the on-disk-vs-zstd ratio is named a diagnostic (A1, RFC 0011), not a gate
  • And the “single biggest engineering risk” sentence is preserved verbatim

Scenario RFC0012.2 — no on-disk-bytes framing of the 50–200× remains.

  • Given the repo docs (CLAUDE.md, README.md, docs/benchmarks.md, docs/rfcs/0001-template-miner.md)
  • When this RFC is enacted
  • Then no passage frames template mining’s 50–200× as on-disk bytes beaten “before any byte-level codec runs” or as “≥ N× over a byte codec” — all coupled echoes (§3.2: benchmarks.md §2, README.md, RFC 0001 §1) are reconciled
  • And a repo-wide grep for the framing phrasesbefore any byte-level codec and over a competent byte codec — returns only RFC 0011 / this RFC (which quote the old wording to describe the change). The check is on the framing, not on the 50–200× figure itself: mentions of that figure as a logical reduction (e.g. docs/roadmap.md, docs/rfcs/0005-parquet-storage.md) are correct and expected to remain.

Scenario RFC0012.3 — consistency with the accepted A1 re-scope.

  • Given RFC 0011 (accepted), benchmarks.md §7’s gate table (A1 = diagnostic), and the amended pillar #2
  • When a reader cross-checks the thesis statement against the benchmark gates
  • Then the three agree: template mining’s value is logical / query-pruning (B1/B2 gate it), A1 is a diagnostic, and C1/C2 are the miner pillar’s gates (RFC 0001 accepted, RFC 0011)

6. Testing strategy

There is no code test: this RFC changes prose in two living documents. The acceptance criteria (§5) are doc-state assertions, verified by review + the grep in Scenario RFC0012.2, exactly as RFC 0011’s RFC0011.1–.3 were. Two notes:

  • Unlike new OTel names (semconv weaver registry generate no-diff CI) or RFC acceptance scenarios (greppable test ids), CLAUDE.md carries no automated consistency gate — the gate is the footer’s majority maintainer approval on the enacting PR. That human gate is this RFC’s “test.”
  • The enacting PR’s diff is the artefact: reviewers confirm the §3.1 text landed verbatim and §3.2’s benchmarks.md reconciliation rode along.

7. Open questions

  • Maintainer approval (majority). CLAUDE.md’s footer requires it for any change; this RFC cannot be enacted without it.
  • Does CLAUDE.md §1’s thesis sentence want a parallel touch? Resolved 2026-06-14 — yes (maintainer). Both the §1 thesis sentence and README.md’s parallel one now carry a one-clause clarification that the “compression” collapsed is Parquet’s byte codec plus the miner’s logical reduction (query pruning), not bytes that beat a codec. The load-bearing sentence itself is kept; only the clarifying clause was added.
  • Footer changelog line. CLAUDE.md’s footer records each meta change with its commit range and rationale; the enacting PR should add the 2026-06-14 line (and bump “Last updated”) in the same diff.

8. References

  • RFC 0011 — A1 re-scope (accepted): the measurement and the diagnostic-not-gating decision this RFC propagates to the pillar wording. Its §3 item 4 / §7 explicitly deferred this CLAUDE.md edit to a meta: RFC.
  • docs/benchmarks.md §2 (A1 + “Why this bar”), §7 (gate table: A1 diagnostic), §9.4/§9.5/§9.6 (the A1/B1/B2/C1/C2 readings).
  • CLAUDE.md §2 (the pillars), §8.5 (cache discipline — why the edit is not made in-session), and the footer (the meta: RFC + majority- approval rule; precedent b50067d).
  • RFC 0001 (accepted) and RFC 0007 (validated) — the miner and querier pillars whose gates (C1/C2 and B1/B2) carry the value the amended wording points at.

RFC 0013 — Object storage (S3-compatible)


rfc: 0013 title: Object-storage backend (S3-compatible) for the Parquet store status: green author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-06-15 supersedes: — superseded-by: —

RFC 0013 — Object-storage backend (S3-compatible) for the Parquet store

Status note. green (2026-06-17; red 2026-06-15). The first shipping-milestone spine: the writer/reader/compactor/audit-sink addressed a single local filesystem bucket_root: &Path, but CLAUDE.md §3.6 declares object storage the source of truth. This RFC abstracts the storage seam behind the Apache object_store crate (already in our tree via DataFusion) so the RFC 0005 data + audit Parquet and the RFC 0009 manifest live on an S3-compatible bucket in production and on local disk in dev/test — without changing the on-disk layout or a single stored row.

All eight §5 scenarios pass. The S3-backed scenarios (RFC0013.1/.3/.4/.7) run in the s3-integration CI job against LocalStack (testcontainers); the local-backend and tenant scenarios (.2/.5) and the reader forward-compat scenario (.8, via the colocated RFC 0005 reader tests) run in the default cargo test; and RFC0013.6 (WAL stays local) is greened end to end through the served binary in ourios-server (tests/rfc0013_6_wal_stays_local.rs), which wires the Store into the RFC 0014 data write path and asserts only Parquet/manifest objects reach the store while the WAL *.wal segments stay on local disk. The crate-shape open question resolved to a module, not a new crate (§3.7).

Landed across green: the S3 backend (object_store aws feature) + conditional-PUT atomic publish (Manifest::publish_cas, RFC0013.3/.4); the writer/reader/compaction/audit consumers migrated from bucket_root: &Path onto Store; and the §7 questions (conditional-PUT portability, credentials via the object_store chain, endpoint override) decided. Deferred to their own follow-ups (not RFC0013 acceptance): a single-writer lease, the multipart-upload threshold, and a read cache.

1. Summary

Ourios’s storage layer addresses a single local-filesystem bucket_root: &Path, threaded through ourios-parquet (writer, reader, compaction, manifest, audit sink) and ourios-server. CLAUDE.md §3.6 makes object storage — “Parquet on S3” — the source of truth, with local disk only a cache and the WAL horizon. This RFC introduces an object-storage backend behind that seam by adopting the Apache Arrow object_store crate (one trait over LocalFileSystem and AmazonS3/S3-compatible stores), so the same code path targets local disk for dev/test/CI and an S3-compatible bucket in production. It pins how the RFC 0009 atomic-publish (manifest generation swap) maps onto object stores that lack POSIX rename (discharging RFC 0009 §7’s deferred S3 atomic-swap + single-writer lease). It changes where bytes live, never the RFC 0005 schema or the Parquet bytes themselves.

2. Motivation

2.1 §3.6 is currently unmet — and it gates deployment

CLAUDE.md §3.6: “Local disk is cache and WAL. Parquet on S3 is the truth. Never design a feature that requires local disk to be durable beyond the WAL horizon.” Today the store is local-filesystem only — no first-party object_store/S3 usage in our Rust source (it is present only transitively, via DataFusion; §2.2); every consumer takes a &Path bucket root. That is fine for the thesis-proving MVP (which ran on single hosts), but it makes Ourios undeployable to a cluster: pods are ephemeral, and acknowledged data must outlive any one node. Durable shared object storage is the spine of the first shipping milestone; nothing else (container image, Helm chart) matters if the data evaporates with the pod.

2.2 Why at this layer, and why object_store

The seam is narrow and already uniform: a bucket_root: &Path (plus the per-partition Hive key layout from RFC 0005 §3.4) threaded through the writer, reader, compact_partition, the manifest, and the audit sink. Abstracting it once behind a backend handle leaves every consumer’s logic unchanged. The natural abstraction is the Apache Arrow object_store crate — and it is already in our dependency tree (v0.13.2) transitively via DataFusion, our query engine (pillar #3). DataFusion’s own table providers read through object_store, so adopting it also aligns the read path: the querier can register the same ObjectStore with DataFusion instead of handing it local file paths. One abstraction, used end to end, that we already ship.

2.3 Why now

The thesis is proven (B1/B2/C1/C2 pass on baseline; benchmarks.md §9.4/§9.6) and the RFC ladder is green-or-beyond. The next milestone is deployability, and this is its load-bearing, architectural-pillar-level prerequisite — hence an RFC (CLAUDE.md §5.1) rather than a PR.

3. Proposed design

3.1 Scope

In scope: the read and write of the RFC 0005 data + audit Parquet series and the RFC 0009 manifest.json through an object-storage backend, with two concrete backends — LocalFileSystem (dev/test/CI; preserves today’s behaviour) and AmazonS3 (production; covers S3-compatible stores — MinIO, Cloudflare R2, etc. — via an endpoint override). Out of scope: the WAL (stays local — it is the §3.4 durability horizon, §3.5 below); any change to the RFC 0005 on-disk schema or Parquet encoding; a table format (Iceberg/Delta — rejected in RFC 0005 §4.1); a local read cache (a future perf concern, §7).

3.2 The object_store abstraction

Adopt object_store::ObjectStore (async put/get/list/delete over an object_store::path::Path — a UTF-8, /-delimited key). The RFC 0005 Hive layout (data/tenant_id=…/year=…/…/<uuid>.parquet, audit/tenant_id=…/…) maps directly onto object keys under a configured prefix — no layout change. A thin Store handle wraps an Arc<dyn ObjectStore> + a key prefix and is threaded where bucket_root: &Path is today.

flowchart LR
    subgraph consumers [ourios-parquet / ourios-server consumers]
        W[Writer] & R[Reader] & C[compact_partition] & A[ParquetAuditSink]
    end
    consumers --> S[Store handle\nan object_store handle + key prefix]
    S --> L[LocalFileSystem\ndev / test / CI]
    S --> O[AmazonS3 / S3-compatible\nproduction]
    Q[ourios-querier] -. registers same store .-> DF[DataFusion] --> S

3.3 The seam migration

Replace bucket_root: &Path with the Store handle across the writer, reader, compact_partition, manifest, and audit sink. Writes go to a temporary key and become live via the §3.4 publish; reads are list + get by key. The change is mechanical and consumer-logic-preserving — the existing RFC 0005/0009 tests re-run against the LocalFileSystem backend to prove no behavioural regression (RFC0013.2).

3.4 Atomic publish without POSIX rename

The hard part. RFC 0009’s atomic publish and the writer’s .parquet.tmp→final both rely on POSIX rename, which object stores do not provide. Map the manifest generation swap onto object stores via conditional PUT: S3 now supports If-None-Match (create-if-absent) and If-Match (compare-and-swap on ETag), surfaced by object_store as PutMode::Create / PutMode::Update{ETag}. A new manifest generation is written with a precondition on the current generation, giving single-writer-wins semantics — exactly the property compact_partition needs so a query never double-counts or misses a row. Data/audit objects are written to a _tmp/ key and made live solely by the manifest swap (no rename). The RFC 0009 §7 single-writer lease (so two compactors don’t race a partition) is realised by the same conditional-PUT contention or a dedicated lease object (§7 open question).

3.5 What stays local

The WAL stays on local disk: it is the §3.4 WAL-before-ack durability horizon, and §3.6 explicitly permits local disk up to that horizon. Recovery (RFC 0008) replays the local WAL into the object store on startup. No feature introduced here requires local disk to be durable beyond the WAL horizon, so the §3.6 invariant holds.

3.6 Schema / compatibility

No change to the RFC 0005 schema, the Parquet bytes, the partition layout, or the reader’s §3.9 forward-compat contract. This RFC is purely about where the bytes are stored; an operator’s existing data semantics are untouched.

3.7 Crate shape — resolved: a module in ourios-parquet

The backend is a store module in ourios-parquet (not a new crate), exposing a Store type. Resolved at red against the less-committing option (CLAUDE.md §7: a new crate is an architectural commitment): the dependency graph confirms it — ourios-querier, -ingester, and -server already depend on ourios-parquet, so the type is visible to every storage consumer without a new crate. If a future consumer needs the store without the Parquet writer/reader, extracting an ourios-store crate is a mechanical follow-up. Configuration (endpoint, region, bucket, prefix, credentials) flows through RFC 0004.

4. Alternatives considered

  • Hand-rolled aws-sdk-s3 client. Direct control, but reimplements what object_store already gives — multi-backend, retries, multipart, and the local/test backend — and diverges from DataFusion’s own storage layer. Rejected: more code, less reuse, two storage abstractions in one tree.
  • Network filesystem (EFS/NFS) mounted into pods, keep &Path. Avoids the S3 work, but violates the §3.6 “S3 is the truth” pillar, inherits NFS’s dicey rename/close-to-open consistency, and is operationally worse and costlier than object storage at log volumes. Rejected.
  • An object-store-as-filesystem shim (s3fs/goofys). Keeps the &Path code, but inherits non-atomic rename and read-after-write pitfalls — the exact correctness hazards §3.4 must avoid. Rejected.
  • A table format (Iceberg/Delta) on object storage. Already rejected in RFC 0005 §4.1 (the manifest in RFC 0009 is the minimal piece we actually need). Out of scope; not reopened here.

5. Acceptance criteria

Normative scenarios in the docs/rfcs/README.md Given/When/Then/And format; each id is referenced from the test code. Refined at specified once the backend trait shape (§7) is fixed, but the scenarios below are the binding contract.

RFC0013.1 — Round-trip through the S3 backend

  • Given a MinedRecord batch covering every RFC 0005 §3.2 column
  • When it is written and then read back through the AmazonS3 backend (a MinIO / localstack container via the testcontainers crate)
  • Then the recovered rows and Parquet bytes equal those from the LocalFileSystem backend, byte for byte.

RFC0013.2 — Local backend regresses nothing

  • Given the existing RFC 0005 and RFC 0009 acceptance suites
  • When they run against the LocalFileSystem backend after the seam refactor
  • Then every one passes unchanged (the abstraction is behaviour- preserving for the local case).

RFC0013.3 — Atomic publish under contention

  • Given two compact_partition runs racing on one partition’s manifest
  • When both attempt to publish a new generation
  • Then exactly one wins; no query observes a torn, doubled, or missing row; and the loser either retries against the new generation or no-ops.

RFC0013.4 — Manifest swap needs no rename

  • Given an object store with no POSIX rename
  • When a generation is published
  • Then it uses conditional PUT — create-if-absent (If-None-Match) and compare-and-swap (If-Match) — with no rename dependency anywhere on the publish path.

RFC0013.5 — Tenant isolation across the key prefix

  • Given data + audit objects for tenants X and Y under the configured prefix
  • When an operation runs in tenant X’s context
  • Then it addresses only X’s key sub-prefix; no read or write touches Y’s keys (CLAUDE.md §3.7).

RFC0013.6 — WAL stays local

  • Given a server configured with an object-storage backend
  • When it ingests and acknowledges a batch
  • Then only the RFC 0005 data/audit Parquet and the RFC 0009 manifest reach the object store; the WAL remains on local disk (the §3.4 durability horizon is unchanged).

RFC0013.7 — S3-compatible endpoints via override

  • Given an S3-compatible store (e.g. MinIO) configured through RFC 0004 with an endpoint override
  • When the backend reads and writes
  • Then it works against that endpoint exactly as against AWS S3.

RFC0013.8 — Reader forward-compat over the object store

  • Given objects written by an older/newer schema (absent / unknown columns, per RFC 0005 §3.9)
  • When the current reader reads them through the object-storage backend
  • Then the §3.9 contract holds (absent columns default, unknown columns ignored) — no error.

6. Testing strategy

Mapped to CLAUDE.md §6.2. The LocalFileSystem backend keeps the current fast, corpus-free unit/proptest path; the AmazonS3 backend is exercised against a MinIO/localstack container (testcontainers, which supports any OCI runtime — Docker on the CI runner, nerdctl/containerd or Podman locally). Per scenario:

  • RFC0013.1 / .7 / .8 (S3 round-trip / S3-compatible endpoint / reader forward-compat over the store) — integration tests against the S3 container, reusing the RFC 0005 round-trip and §3.9 fixtures behind the backend trait.
  • RFC0013.2 (local backend regresses nothing) — the existing RFC 0005 + RFC 0009 suites re-run against LocalFileSystem via a parametrised harness (one suite, two backends).
  • RFC0013.3 (atomic publish under contention) — a proptest / concurrency test driving N racing publishers at the S3 container, asserting exactly-one-wins and no torn / doubled / missing rows.
  • RFC0013.4 (manifest swap, no rename) — integration test asserting the publish path uses conditional PUT (PutMode::Create / PutMode::Update{ETag}) and never a rename.
  • RFC0013.5 (tenant isolation) — integration test interleaving two tenants’ objects under the prefix; asserts no cross-prefix access.
  • RFC0013.6 (WAL stays local) — after ingest + ack, assert WAL frames are on local disk and only data/audit/manifest objects reached the store.

The S3 integration lane is #[ignore] / feature-gated, so the default cargo test stays container-free; CI runs it explicitly.

7. Open questions

  • Crate shape — resolved at red: a store module in ourios-parquet (no new crate; dep-graph-confirmed, §3.7).
  • Single-writer lease — is conditional-PUT contention on the manifest sufficient, or is a separate lease object needed (RFC 0009 §7)?
  • Conditional-PUT portability — do If-None-Match/If-Match cover the compare-and-swap on every targeted store (S3, R2, MinIO, GCS via object_store)? What is the fallback where a store lacks it?
  • Multipart threshold — RFC 0009 outputs are 256 MiB–2 GiB; pick the multipart-upload threshold.
  • Credentials — IAM role (IRSA on k8s) vs static keys via RFC 0004 / k8s Secrets.
  • Local read cache for hot Parquet — defer (perf, not correctness)?
  • Migration — is a local-FS-store → object-store copy tool needed, or is it N/A pre-release (no production data yet)?

8. References

  • CLAUDE.md §3.6 (object storage is the source of truth), §3.4 (WAL-before-ack / durability horizon), §3.7 (multi-tenancy partitioning), §5.1 (RFC-required for a pillar), §7 (new-crate commitment).
  • RFC 0005 — the on-disk Parquet contract being relocated (unchanged).
  • RFC 0009 — the atomic-publish manifest; §7 deferred the S3 atomic-swap + single-writer lease, discharged here.
  • RFC 0004 — configuration policy (endpoint, region, bucket, prefix, creds).
  • object_store — the Apache Arrow object-storage abstraction, already a transitive dependency via DataFusion.
  • S3 conditional writes — If-None-Match / If-Match precondition PUTs.

RFC 0014 — Ingest write path (record sink & flush)


rfc: 0014 title: Ingest write path — record sink and flush policy status: green author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-06-17 supersedes: — superseded-by: —

RFC 0014 — Ingest write path: record sink and flush policy

Status note. green (2026-06-17; red/specified same day). The conspicuous gap in the ingest stack is closed: the miner (RFC 0001) emits each mined MinedRecord into a RecordSink, and production formerly wired NoOpRecordSink — the records were dropped. Every other layer was built and tested (OTLP → WAL → miner; Parquet writer/reader; compaction; the RFC 0013 object-storage seam with a buffer-and-put Writer), but nothing carries a mined record to a Parquet object on the store. This RFC specifies the missing piece: a buffering RecordSink and the flush policy that governs when buffered records become a Parquet object — a CLAUDE.md §4 (small-file) / §3.4 (WAL-durability) / §3.7 (multi-tenancy) decision that no existing RFC covers.

Scope is deliberately narrow: the flush policy + the sink. Wiring the server to construct/inject a Store (RFC 0004 config, local vs S3) and migrating compaction’s manifest publish to Manifest::publish_cas on S3 (RFC0013.3/.4) are follow-on work, tracked as open questions, not part of this RFC’s acceptance.

specified finalizes the §5 acceptance criteria (RFC0014.1–.6, greppable + testable) and §6 testing strategy, and settles the two criteria-shaping design questions: rotation force-flushes every partition (§3.2, RFC0014.3), and the memory ceiling is hardemit blocks rather than exceed it (§3.4, RFC0014.4). The remaining §7 questions (defaults, early-flush victim, rotation-hook surface, size estimation) are tuning / implementation detail, decided across the red/green PRs.

red landed the six #[ignore]d acceptance stubs (RFC0014.1–.6) in crates/ourios-ingester/tests/rfc0014_ingest_write_path.rs. green built the buffering ParquetRecordSink (the hybrid size/age/rotation flush policy + the hard ceiling), then wired it into the miner in place of NoOpRecordSink via a SharedParquetSink the server constructs and the pipeline drives (flush_all on rotation, flush_aged on a batch-window age sweep, a drain on graceful shutdown). All six §5 scenarios pass: RFC0014.1–.4 and .6 drive the sink directly against a LocalFileSystem-backed Store; RFC0014.5 (no acknowledged-data loss) is a real-process SIGKILL crash test (tests/rfc0014_5_crash_no_loss.rs) that extends the RFC 0008 harness — after a crash with a non-empty buffer, WAL replay re-mines every un-flushed acknowledged record into a fresh sink, which flushes them to the store.

No-loss rests on a single ordering rule the server applies at every miner-snapshot cadence point (post-recovery, rotation, shutdown): flush the sink before writing the snapshot, so the miner’s snapshot horizon never outruns the sink’s flushed horizon and recovery’s miner-gated replay covers every un-flushed record. Semantics are at-least-once (a pre-crash flush may re-flush on recovery; nothing is lost). The §7 follow-ons (S3 Store selection via RFC 0004; compaction’s publish_cas adoption) and the exactly-once dedup of cross-crash duplicates remain open, outside this RFC’s acceptance.

1. Summary

A buffering RecordSink implementation — the production data write path — accumulates mined MinedRecords per partition and flushes each partition to a Parquet object on the RFC 0013 Store seam. The flush policy is hybrid: a partition flushes when its buffered bytes reach a size target (toward RFC 0005 §3.5’s file-size band) or its oldest buffered record reaches a max age, and every partition force-flushes when the WAL segment rotates (RFC 0008). Total buffered bytes are bounded by a hard ceiling: exceeding it forces an early flush (and, at the hard limit, applies backpressure to ingest). The sink reuses RFC 0008’s batch-window / rotation machinery rather than inventing a parallel cadence. Records reach the sink only after the WAL is durable (CLAUDE.md §3.4), so an un-flushed buffer is always recoverable by WAL replay.

2. Motivation

Why this change now. The first-shipping-milestone thesis is “OTLP in, queryable Parquet out.” The query path reads Parquet that the ingest path must produce — but the ingest path stops at the miner: RecordSink exists with only NoOpRecordSink (drop), InMemoryRecordSink (test), and SharedRecordSink (test) impls. RFC0013.6 (“WAL stays local; only Parquet/manifest reach the store”) cannot be greened because nothing writes data to the store during ingest. Closing this gap completes the ingest half of the thesis.

Why at this layer. The flush policy sits between the miner (RFC 0001, which emits records one at a time and must not own I/O policy) and the Parquet store (RFC 0005, which specifies the file format and row-group sizing but explicitly not when records are flushed to a file — confirmed a genuine gap). It is the natural home for three hazards that no other RFC binds together:

  • CLAUDE.md §4 small-file problem. Flush too eagerly and the store fills with tiny Parquet objects that defeat predicate pushdown and lean entirely on compaction (RFC 0009) to recover. The flush policy is the first line of defence; compaction is the second.
  • CLAUDE.md §3.4 WAL-before-ack durability. The sink buffers acknowledged data in memory. The buffer must never be the durability of record — that is the WAL’s job. A crash mid-buffer must lose nothing acknowledged.
  • CLAUDE.md §3.7 multi-tenancy. Buffers are keyed by PartitionKey, which carries tenant_id; flushing one partition must never touch another tenant’s data.

Why not defer to compaction. Compaction fixes small files after the fact; it does not remove the cost of creating them (every tiny object is a store PUT, a manifest churn, and a footer read until compacted). Right-sizing at write time is cheaper than over-producing and consolidating.

3. Proposed design

3.1 The sink

A ParquetRecordSink implements RecordSink::emit(&mut self, record: MinedRecord). It owns:

  • Per-partition buffers. A map PartitionKey → PartitionBuffer, where a PartitionBuffer accumulates MinedRecords plus a running estimate of its encoded size and the wall-clock time of its oldest record. The PartitionKey (RFC 0005 §3.4) carries tenant_id, so buffers are tenant-scoped by construction (CLAUDE.md §3.7).
  • A handle to the Store (RFC 0013) — the flush target.
  • Flush configuration (RFC 0004): the size target, the max buffer age, and the global buffered-bytes ceiling.

emit derives the record’s PartitionKey, appends it to that partition’s buffer, updates the size estimate, and evaluates the flush triggers (§3.2).

3.2 Flush triggers (the hybrid policy)

A partition flushes when any of:

  1. Size — its buffered (estimated) bytes reach the size target. The target sits inside RFC 0005 §3.5’s 256 MiB–2 GiB file band so a single buffer becomes one right-sized object.
  2. Age — its oldest buffered record’s age reaches max_buffer_age (inclusive: flush when age ≥ the configured max). This bounds the staleness of low-volume tenants/partitions whose size trigger would otherwise never fire.
  3. WAL segment rotation — when the WAL segment seals (RFC 0008’s rotation hook), every partition force-flushes, including sub-threshold low-volume partitions (no size gate). This aligns the published-Parquet horizon with a WAL boundary: once a segment is sealed and its mined records flushed, recovery never needs that segment for data (only the still-open tail’s records are buffered-but-un-flushed), and the acknowledged-but-unpublished data is capped at roughly one segment. The cost — small files from tiny partitions — is deliberately accepted and left to compaction (RFC 0009) to consolidate; the clean recovery invariant is worth more than avoiding a few small objects.

A flush encodes the partition’s buffered records to a Parquet object (encode_records_to_parquet + Store.put, the RFC 0013 buffer-and-put path, UUIDv7-named per RFC 0005 §3.4) and clears the buffer.

3.3 Reusing the WAL machinery (not a parallel cadence)

The age and rotation triggers reuse RFC 0008’s existing batch-window / segment-rotation mechanism rather than standing up a second timer/coordinator. The ingest pipeline already has a rotation hook (RFC 0009 §6.9 wires snapshot writes to it); the sink subscribes to the same hook for trigger 3, and the age sweep piggybacks on the batch-window tick. One cadence, one source of truth for “time has passed / a segment sealed.”

3.4 Memory ceiling and backpressure

The sink tracks total buffered bytes across all partitions against a hard ceiling:

  • Soft pressure (early flush). As the total approaches the ceiling, the sink force-flushes the largest (or oldest) partition(s) ahead of their size trigger, reclaiming memory without blocking ingest.
  • Hard limit (backpressure). If early flush cannot keep the total under the ceiling (e.g. a flush is slow or the store is unavailable), emit blocks until an in-flight flush frees enough memory — so the buffer can never exceed the ceiling (a hard, not soft, bound). Because the OTLP ack already happened (post-WAL), this blocks only mining/flushing throughput, not durability — no acknowledged data is at risk. The client-facing ack is already sent, so the cost under sustained overload is increased WAL→Parquet publish lag (internal backlog), not client-facing ingest latency.

This makes the in-memory buffer a bounded, best-effort accelerator on top of the WAL, never an unbounded liability (cf. §3.2’s hazard list).

3.5 Durability and crash recovery (CLAUDE.md §3.4)

Records reach the sink only after the WAL has durably committed them (ourios-ingester pipeline: append + fsync → ingest gate → miner → sink — the ordering is already in place). Therefore:

  • A crash with a non-empty buffer loses no acknowledged data: every buffered record came from a WAL frame that is on disk. Recovery re-mines the WAL tail (the un-flushed records) and re-buffers them.
  • The flush itself is not crash-durable beyond the store’s own semantics (object PUT atomicity, no fsync) — identical to the RFC 0005 writer / RFC 0013 store contract. The WAL remains the crash-survival horizon.

3.6 What this RFC does not change

  • Not the on-disk Parquet format or partition layout (RFC 0005) — the sink produces ordinary <uuid>.parquet objects.
  • Not the WAL (RFC 0008) — the sink consumes its rotation/tick signals; it does not alter WAL durability or batching.
  • Not the manifest/compaction (RFC 0009) — flushed files are live immediately via the *.parquet glob; compaction consolidates them later as today.
flowchart LR
  OTLP[OTLP batch] --> WAL[WAL append + fsync]
  WAL -->|durable, post-ack| Miner[miner.ingest]
  Miner -->|emit MinedRecord| Sink[ParquetRecordSink]
  Sink -->|append| Buf[(per-partition buffer)]
  Buf -->|size >= target| Flush[encode + Store.put]
  Buf -->|age >= max| Flush
  Rot[WAL segment rotation] -->|force-flush all| Flush
  Ceil[buffered bytes >= ceiling] -->|early flush / backpressure| Flush
  Flush --> Obj[(Parquet object on Store)]

4. Alternatives considered

Pure size+time window (no rotation trigger). Option 1+2 without 3. Gives right-sized files but decouples the published-Parquet horizon from the WAL, so crash-recovery reasoning must independently bound “how far behind can the buffer be.” The rotation trigger is cheap insurance that makes the horizon argument trivial; we keep it.

WAL-segment-rotation only. Flush exactly when a segment seals. Simplest recovery story (Parquet boundary ≡ WAL boundary) and bounded buffering, but file size is hostage to the WAL rotation cadence — tuned for durability latency, not for the CLAUDE.md §4 256 MiB–2 GiB target. Rejected as the sole trigger; kept as the force-flush bound in the hybrid.

Stream per batch (the A1-bench pattern). Open a Writer per partition, append each OTLP batch, close on rotation. Minimal sink logic, but produces many small files between compactions — it leans the entire CLAUDE.md §4 mitigation onto compaction and pays the small-file cost (PUTs, manifest churn, footer reads) in the interim. Rejected for production; it remains the bench’s expedient.

No sink-side ceiling (trust the size+time triggers). Simpler, but a slow store or a burst across many partitions could grow the buffer without bound between triggers. The hard ceiling + backpressure is the difference between a bounded accelerator and an OOM risk; we keep it.

5. Acceptance criteria

Normative scenarios; ids RFC0014.<m> are referenced from the test code (docs/verification.md §2). One scenario per hazard/invariant this RFC touches (CLAUDE.md §4 small-file, §3.4 WAL-durability, §3.7 multi-tenancy).

Scenario RFC0014.1 — Size trigger

  • Given a partition whose buffered bytes are just below the size target
  • When a record is emitted that brings the buffer to or over the target
  • Then emit flushes the partition to exactly one Parquet object sized within the RFC 0005 §3.5 band
  • And the buffer is cleared

Scenario RFC0014.2 — Age trigger

  • Given a low-volume partition below the size target
  • When its oldest record’s age reaches max_buffer_age
  • Then it flushes on the next batch-window tick

Scenario RFC0014.3 — Rotation force-flush (CLAUDE.md §4)

  • Given buffered records across several partitions, including low-volume sub-threshold ones
  • When the WAL segment rotates
  • Then every partition flushes
  • And no buffered record predates the sealed segment

Scenario RFC0014.4 — Bounded memory (CLAUDE.md §4)

  • Given buffered bytes approaching the ceiling
  • When more records arrive
  • Then the sink early-flushes to stay under it
  • And at the hard limit emit blocks until a flush frees memory, so total buffered bytes never exceed the ceiling

Scenario RFC0014.5 — No acknowledged-data loss (CLAUDE.md §3.4)

  • Given a non-empty buffer
  • When the process crashes
  • Then WAL replay re-mines every un-flushed acknowledged record
  • And no acknowledged record is lost

Scenario RFC0014.6 — Tenant isolation (CLAUDE.md §3.7)

  • Given buffered records for tenants X and Y
  • When one partition flushes
  • Then the produced object holds only that partition’s (single tenant’s) rows
  • And no buffer or flush crosses tenants

6. Testing strategy

Mapped to CLAUDE.md §6.2.

  • Unit tests for each flush trigger (RFC0014.1–.3) and the ceiling (RFC0014.4), driving the sink with synthetic MinedRecord streams and a LocalFileSystem-backed Store.
  • Property test (proptest) for RFC0014.5/.6: for any interleaving of emitted records across tenants and any sequence of triggers, every emitted record lands in exactly one flushed object under its own tenant’s partition, and the multiset of flushed rows equals the multiset emitted (modulo the still-buffered tail).
  • Crash-recovery test (RFC0014.5) in ourios-ingester: kill mid-buffer, recover, assert WAL replay reproduces the un-flushed records — extends the existing RFC 0008 crash-recovery harness.
  • The end-to-end “only Parquet/manifest reach the store; WAL stays local” assertion (RFC0013.6) is greened by the follow-on server-wiring work, not this RFC’s acceptance.

7. Open questions

Tuning + implementation detail, decided across red/green:

  • Default values: go-live values set in ourios-server (size target 256 MiB, max_buffer_age 300 s, ceiling 1 GiB, age sweep every 30 s). Promoting them to RFC 0004 config knobs and tuning against representative corpora remains open.
  • Early-flush victim selection at the ceiling: largest partition (flush_largest) — reclaims the most memory per flush. A soft pressure threshold below the hard ceiling was not needed and is not implemented.
  • Integration surface with RFC 0008’s rotation hook and batch-window tick: the pipeline/server drives the sink (it does not subscribe) — flush_all from the rotation hook, flush_aged from a server-owned age sweep — keeping the sink ignorant of the WAL.
  • Size estimation: a cheap running estimate (estimate_bytes over the large variable-length fields), not encoding to measure — bounds memory and roughly right-sizes files without hot-path cost.
  • Follow-on (out of this RFC’s acceptance): the server constructs a local Store today; S3 selection (RFC 0004) is still open. Compaction’s manifest publish adopting Manifest::publish_cas on S3 (RFC0013.3/.4) also remains. RFC0013.6 is already greened (server-wiring landed). The exactly-once dedup of cross-crash at-least-once duplicates is open too.

8. References

  • RFC 0001 — template miner; RecordSink and the emit contract.
  • RFC 0003 — OTLP receiver; WAL-before-ack ordering, response semantics.
  • RFC 0004 — configuration policy; the flush-config knobs.
  • RFC 0005 — Parquet storage; row-group (§3.5) and file-size targets, partition layout (§3.4), the buffer-and-put Writer.
  • RFC 0008 — WAL; batch-window, segment rotation, crash-recovery harness.
  • RFC 0009 — compaction; the small-file second line of defence.
  • RFC 0013 — object-storage Store seam; encode_records_to_parquet, Store.put, Manifest::publish_cas.
  • CLAUDE.md §2 (pillars), §3.4 (WAL-before-ack), §3.7 (multi-tenancy), §4 (small-file problem, hazards).

RFC 0015 — Fuzzing harness


rfc: 0015 title: Fuzzing harness — cargo-fuzz targets & ClusterFuzzLite CI status: green author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-06-19 supersedes: — superseded-by: —

RFC 0015 — Fuzzing harness: cargo-fuzz targets & ClusterFuzzLite CI

1. Summary

Add a coverage-guided fuzzing harness: a fuzz/ cargo-fuzz workspace member with libFuzzer targets on the project’s highest-risk surfaces — the template miner and the untrusted-input parsers (OTLP protobuf, OTLP/JSON, WAL frame). The miner target does not merely check for panics: it asserts the §3.3 bit-identical-reconstruction invariant, so the fuzzer actively hunts inputs that round-trip wrong. CI is phased — Phase 1 (this RFC) lands the targets plus a bounded smoke-fuzz job that gates on crashes; Phase 2 (a follow-up) layers ClusterFuzzLite for continuous fuzzing, corpus persistence, and OpenSSF Scorecard detection of the Fuzzing check. The new fuzz/ member is the architectural commitment this RFC exists to authorise (CLAUDE.md §7).

2. Motivation

The template miner is named in CLAUDE.md §2 as “the single biggest engineering risk in the project,” and §3.1 / §3.3 make its merge correctness and bit-identical reconstruction load-bearing invariants. The OTLP decoders (RFC 0003) and the WAL frame reader (RFC 0008) parse adversarial bytes off the wire and off disk — exactly the boundary fuzzing is built for.

proptest already guards these invariants (e.g. crates/ourios-miner/tests/invariants.rs), but property tests explore only the input space a hand-written Strategy describes. Coverage-guided fuzzing instruments the binary and mutates toward unexplored branches, reaching malformed-but-structurally-valid inputs — truncated protobuf, non-UTF-8 bodies, CRC-valid-but-semantically-broken frames — that a generator rarely synthesises. The two techniques are complementary: proptest pins the invariants we can describe; the fuzzer finds the ones we did not think to.

Why now: the ingest and query stack is built and tested behind RFC gates, so the parsing and mining surfaces are stable enough that fuzz findings reflect real bugs rather than churn. Fuzzing was previously parked in the “deferred to the shipping milestone” set alongside Signed-Releases; the maintainer has opted to pull it forward (it finds bugs cheaply, before they calcify into the on-disk contract). Closing Scorecard’s Fuzzing check (currently 0) is a secondary benefit of Phase 2, not the primary driver.

3. Proposed design

3.1 The fuzz/ workspace member

A single new workspace member at the repo root, fuzz/, following the cargo-fuzz convention (cargo fuzz init). It is:

  • not published (publish = false) and carries no library API — it exists only to host fuzz targets;
  • built with nightly Rust. libFuzzer requires sanitizer/-Z support absent from stable. rust-toolchain.toml stays stable (the source of truth for every shipping crate per CLAUDE.md §6.1); the nightly toolchain is requested only by the fuzz CI job and by developers running fuzz locally. This is a contained, documented deviation from the §6.1 stable pin — it never touches the binaries we ship;
  • opts out of the workspace unsafe_code = "deny" lint (root Cargo.toml [workspace.lints.rust]; every shipping crate inherits it via [lints] workspace = true), because the libfuzzer_sys::fuzz_target! macro (the libfuzzer-sys crate) expands to unsafe glue. CLAUDE.md §6.1 permits a per-crate waiver where an RFC justifies one (it cites a possible ourios-parquet zero-copy need as the example; no crate carries such a waiver today — every crate root, ourios-parquet included, is #![deny(unsafe_code)]). This RFC is that justification, scoped to fuzz/ alone — the member simply does not inherit the workspace lint; our harness bodies stay safe.

Adding this member is a CLAUDE.md §7 new-crate decision; this RFC is that decision’s record.

3.2 The targets

Four targets, ranked by risk. Each is a fuzz_target!(|data: &[u8]|) reaching a stable entry point with minimal glue.

TargetEntry pointCrateOracle
miner_roundtripingest (with an observable RecordSink) → drain the MinedRecordtemplates_forreconstruct::render, on a string-body recordourios-minerinvariant: the rendered bytes equal the original string body whether render reports Reconstruction::Faithful (rebuilt) or Reconstruction::RetainedVerbatim (retained) — §3.3
otlp_jsondecode_json(&[u8])ourios-ingesterno panic; Ok/Err both fine
otlp_protobufdecode_protobuf(&[u8])ourios-ingesterno panic; Ok/Err both fine
wal_frameframe::read_frame(&mut Cursor::new(data)) — today pub(crate), exposed to the target via the fuzzing feature (§3.2, §7)ourios-walno panic; malformed input yields a typed FrameError, never UB

miner_roundtrip is the centerpiece. Rather than feed the miner a fixed string, the target uses the arbitrary crate to build an OtlpLogRecord whose body is a String (the Drain template path — the fuzz bytes become the log line; attributes are derived alongside). MinerCluster::ingest returns only a template_id, so the harness follows the miner’s real read-back path (the one crates/ourios-miner/tests/invariants.rs uses): the cluster is built with an observable RecordSink (SharedRecordSink), ingest is called, the emitted MinedRecord is drained from the sink, the leaf’s template tokens are looked up via MinerCluster::templates_for(tenant) matching the record’s (template_id, template_version), and reconstruct::render is called with that record and those tokens. It then asserts the §3.3 contract: the rendered bytes equal the original string body in both outcomes — whether render reports Reconstruction::Faithful (rebuilt from the template) or Reconstruction::RetainedVerbatim (the original body surfaced verbatim, not rebuilt). §3.3 guarantees a string line is either reconstructed exactly or has its original body retained, so either a faithful-rebuild mismatch or a retention failure is a violation — and makes the target panic, which libFuzzer reports as a crash. That turns the fuzzer into a search for reconstruction bugs, not just for unwraps.

The target is deliberately scoped to string bodies: that is the template-mining + line-reconstruction path the §3.3 invariant governs. Structured (kvlist/array) bodies take the §6.1 canonical-encoding path (lossy_flag = false, no template walk), whose round-trip is a distinct property — a candidate for a separate target (§7), not folded into this oracle.

The three parser targets are panic-oracles on untrusted-input boundaries: a decoder must reject garbage with a typed error, never panic, abort, or exhibit UB.

frame::read_frame is currently pub(crate). Rather than widen the WAL public API, expose it to the fuzz target through a #[doc(hidden)] shim (or a fuzzing cargo feature) — resolved in §7.

3.3 Seed corpora

Committed seeds live under fuzz/seeds/<target>/ (a tracked directory, distinct from the gitignored working corpus fuzz/corpus/<target>/). The CI job copies the seeds into the working corpus before each run, so the committed inputs bootstrap coverage without the evolving corpus churning the repo:

  • miner_roundtrip seeds from a few real-shaped log lines;
  • otlp_json seeds from a minimal ExportLogsServiceRequest (an empty {"resourceLogs":[]});
  • otlp_protobuf and wal_frame start from libFuzzer’s generated inputs in Phase 1; binary seeds (valid protobuf encodings / valid frames) can be added later.

Committed seeds are kept minimal (enough to bootstrap coverage); the grown corpus is persisted by ClusterFuzzLite in Phase 2, not committed.

3.4 CI — phased

Phase 1 (this RFC’s green): .github/workflows/fuzz.yml. A bounded smoke-fuzz job on a pinned nightly toolchain, run as a matrix over all four targets — the parser targets are cheap, so there is no reason to gate on the miner alone. Each matrix job runs its target for the budget of the triggering event, e.g.:

# Daily schedule: ~300 s per target. Manual dispatch: ~60 s. --target
# forces the gnu host triple (cargo-fuzz otherwise picks musl, whose
# static libc is incompatible with the ASan sanitizer).
cargo +nightly-2026-06-01 fuzz run <target> --target "$host" -- -max_total_time=300

It runs on a daily schedule and on workflow_dispatch — deliberately not on pull_request: the sanitizer build is too heavy for per-change CI, and continuous per-change fuzzing is Phase 2’s job (ClusterFuzzLite). fuzz run builds before it runs, so a target that stops compiling fails its job; because every target is always in the matrix (fail-fast: false), all four are built and run on every invocation. A crash fails that target’s job and uploads the reproducer as an artifact. Top-level contents: read (the workflow-token least-privilege pattern the other workflows follow).

Phase 2: ClusterFuzzLite. .clusterfuzzlite/ (Dockerfile on the OSS-Fuzz base-builder-rust image + build.sh that cargo fuzz builds the same targets and stages them with their seed corpora) plus cflite_batch.yml (scheduled continuous fuzzing that grows and persists the corpus) and cflite_coverage.yml (weekly corpus line-coverage). Both run on schedule + workflow_dispatch only — no PR-fuzzing workflow, consistent with the per-PR rule above. The corpus persists in the GitHub Actions cache (no external storage backend), resolving the §7 open question. ClusterFuzzLite is what Scorecard’s Fuzzing check detects (via .clusterfuzzlite/Dockerfile; it cannot see a bare cargo-fuzz directory), so Phase 2 is what moves that check 0 → positive (RFC0015.7). The cflite container build is verified by dispatching cflite_batch after merge — it cannot run on the introducing PR with no PR trigger.

3.5 Regression discipline

When the fuzzer finds a crash, the workflow per CLAUDE.md §6.2 is: minimise the reproducer (cargo fuzz tmin), commit it as a permanent seed under the tracked fuzz/seeds/<target>/ (the working fuzz/corpus/ is gitignored, so a reproducer parked there would not persist — §3.3), then fix the bug. The seed stays forever, re-checked on every run — a found bug becomes a standing specification, never silently dropped.

4. Alternatives considered

afl.rs (AFL++) instead of cargo-fuzz/libFuzzer. AFL++ is a capable fuzzer, but cargo-fuzz/libFuzzer is the de-facto Rust default, has the smoothest cargo integration, and is the engine ClusterFuzzLite and OSS-Fuzz drive for Rust. Choosing it keeps Phase 1 and Phase 2 on one engine.

Just extend proptest, no coverage-guided fuzzing. The obvious cheaper move is to widen the existing proptest suites rather than add a fuzz toolchain. We keep and value proptest, but it cannot replace fuzzing here: its inputs come from hand-authored Strategy generators that sample a distribution we describe, with no feedback from the code under test. A coverage-guided fuzzer instruments the binary and mutates toward unexecuted branches, reaching the malformed-but-structurally-valid inputs (truncated protobuf, CRC-valid-but-broken frames, non-UTF-8 body bytes) that a generator only hits by luck. proptest pins the invariants we can describe; the fuzzer finds the ones we did not think to write a strategy for. They are complementary layers, not substitutes — which is also why the miner_roundtrip oracle deliberately reuses the same §3.3 assertion the proptest suite already encodes.

OSS-Fuzz from day one instead of ClusterFuzzLite. OSS-Fuzz is the richer option — Google-hosted compute, long-running campaigns, automatic bug filing — and remains the goal once Ourios ships. But acceptance requires a project to be widely used or critical to the ecosystem, which a pre-release backend is not, and onboarding adds an external dependency and review loop we do not control. ClusterFuzzLite is the same engine (libFuzzer) running in our own CI with our own corpus, available today and detected by Scorecard; it is the pragmatic Phase 2, with OSS-Fuzz held as a post-ship upgrade.

A fuzzing feature inside each crate instead of a separate fuzz/ member. Folding targets into the shipping crates would drag the nightly/sanitizer toolchain and the unsafe macro expansion into code we ship. The cargo-fuzz convention isolates all of that in fuzz/.

Keep fuzzing deferred to the shipping milestone. Rejected by the maintainer: the surfaces are stable now, fuzzing is cheap, and bugs found pre-release never reach the on-disk contract. Deferral only delays the find.

5. Acceptance criteria

Scenario RFC0015.1 — miner round-trip target enforces the §3.3 invariant

  • Given the miner_roundtrip target and a MinerCluster built from MinerConfig::default() with an observable RecordSink attached
  • When the target builds an OtlpLogRecord with a String body from the arbitrary input, ingests it, drains the emitted MinedRecord from the sink, looks up the leaf tokens via templates_for for the record’s (template_id, template_version), and calls render
  • Then the rendered bytes equal the original string body in both outcomes — whether render reports Reconstruction::Faithful (rebuilt from the template) or Reconstruction::RetainedVerbatim (the original body returned verbatim) — since §3.3 guarantees a string line is either reconstructed exactly or has its original body retained
  • And the Reconstruction marker is asserted to be one of those two variants, recording which path produced the bytes
  • And any input whose rendered bytes differ from the original string body makes the target panic (a libFuzzer crash) — a faithful-rebuild mismatch and a retention failure are both §3.3 violations
  • And the assertion references the §3.3 invariant id so the mapping back to CLAUDE.md is greppable

Scenario RFC0015.2 — OTLP/JSON decode never panics

  • Given the otlp_json target
  • When it is run on arbitrary bytes
  • Then decode_json returns Ok(_) or Err(DecodeError)
  • And the target never panics, aborts, or triggers a sanitizer error on any input in a bounded run

Scenario RFC0015.3 — OTLP/protobuf decode never panics

  • Given the otlp_protobuf target
  • When it is run on arbitrary bytes
  • Then decode_protobuf returns Ok(_) or Err(DecodeError)
  • And the target never panics, aborts, or triggers a sanitizer error on any input in a bounded run

Scenario RFC0015.4 — WAL frame decode yields a typed error, never UB

  • Given the wal_frame target wrapping the input in a Cursor
  • When read_frame is run on arbitrary bytes
  • Then it returns Ok((kind, payload)) or a FrameError (bad CRC, length over MAX_FRAME_BYTES, unknown kind, or non-zero pad)
  • And the target never panics or exhibits undefined behaviour, including on truncated headers and length fields that overrun the buffer

Scenario RFC0015.5 — CI smoke-fuzz is bounded and gates on crashes

  • Given .github/workflows/fuzz.yml on the nightly toolchain
  • When a PR touches ourios-miner, ourios-ingester, or ourios-wal, or the daily schedule fires
  • Then each target is built (cargo fuzz build) and run for its configured bounded budget
  • And a crash fails the job and uploads the crashing input as an artifact
  • And the job uses top-level contents: read (least privilege, matching the other workflows)

Scenario RFC0015.6 — a found crash becomes a permanent regression seed

  • Given the fuzzer has found and the team has fixed a crash
  • When the fix lands
  • Then the minimised reproducer is committed under fuzz/corpus/<target>/ (or its regressions/ subdir) and is re-exercised on every subsequent run
  • And the seed is never removed to make a run pass (CLAUDE.md §6.2)

Scenario RFC0015.7 — ClusterFuzzLite is detected by Scorecard (Phase 2)

  • Given the Phase 2 follow-up has landed .clusterfuzzlite/ and the cflite_* workflows
  • When the OpenSSF Scorecard workflow runs
  • Then the Fuzzing check detects ClusterFuzzLite and scores greater than 0
  • Note: this scenario is out of scope for this RFC’s green and gates the Phase 2 PR; it is recorded here so the phasing is explicit.

6. Testing strategy

Per CLAUDE.md §6.2, the fuzz targets are the tests — coverage-guided libFuzzer runs rather than fixed-input unit tests.

  • RFC0015.1 — the miner target’s oracle is the same §3.3 invariant asserted by the existing property tests in crates/ourios-miner/tests/invariants.rs and the round-trip unit tests in crates/ourios-miner/src/reconstruct.rs; the fuzz target reuses that assertion under coverage guidance. Cross-referenced so the two layers stay in sync.
  • RFC0015.2 / .3 / .4 — panic-oracle targets. Verified by a bounded fuzz run (no crash) in CI; cargo fuzz build proves they compile even on runs where they are not executed.
  • RFC0015.5 — the fuzz.yml workflow itself; smoke budgets kept small enough to be non-flaky. The real coverage accrues from the Phase 2 continuous runs, not the per-PR smoke job.
  • RFC0015.6 — exercised the first time a crash is found; the committed reproducer is a standing corpus entry thereafter.

Each scenario id (RFC0015.N) is referenced from the corresponding target source or workflow comment so the spec-to-test mapping is greppable (docs/verification.md §2).

7. Open questions

Maintainer review (2026-06-19) gave direction on the following; recorded here as the planned approach for the implementation PRs (to be confirmed as the RFC advances toward green):

  • Nightly pinpin a dated nightly-YYYY-MM-DD in the fuzz job (not a floating nightly), for reproducibility; Renovate bumps it like the other pinned toolchains.
  • Smoke-fuzz budget~60 s per target on PRs, ~300 s on the daily schedule (see §3.4). Revisit if CI minutes or signal warrant.
  • read_frame exposure → a fuzzing cargo feature on ourios-wal gating the pub export, rather than a #[doc(hidden)] shim — slightly cleaner and reusable for future non-fuzz tests.
  • OtlpLogRecord construction → expect a hand-written Arbitrary impl (or a thin newtype) for the string-body path, rather than relying on derive across the body variants, if a derive proves messy.

Still open, deferred to the implementation PRs:

  • A second miner target driving sequences of records, to fuzz template merge behaviour (§3.1), not just single-line round-trip? Possible Phase 1.5.
  • A structured-body round-trip target exercising the §6.1 canonical encoding (AnyValue ↔ stored bytes determinism), separate from miner_roundtrip’s string-body scope? Possible Phase 1.5.
  • Phase 2 corpus-persistence backendGitHub Actions cache (ephemeral, in-repo, no external storage or secrets), chosen over a storage branch/bucket. Implemented in cflite_batch.yml.
  • unsafe waiver for fuzz/: confirm that having the fuzz member opt out of the workspace unsafe_code = "deny" lint (the first such waiver in the repo) is acceptable, given the fuzz_target! macro requires it.

8. References

RFC 0016 — Query-serving endpoint


rfc: 0016 title: Query-serving endpoint — the HTTP query API over the logs DSL status: green author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-06-19 supersedes: — superseded-by: —

RFC 0016 — Query-serving endpoint: the HTTP query API over the logs DSL

Status note. green (2026-06-22; red 2026-06-19). All seven §5 scenarios pass. The querier role is wired into ourios-server as an env-gated HTTP endpoint (POST /v1/query) over the RFC 0007 engine, mirroring the receiver role’s serve/Handle topology: .1.4 (the request/dispatch/error handler driven in-process) landed in #283; .5/.7 (role gating + graceful shutdown + receiver/querier compose) and the §3.6 query metrics (.6) followed. Per the OpenTelemetry usage/state convention, the pruning signal is emitted as raw scanned/pruned row-group counts (ourios.query.row_groups, state = scanned | pruned) plus a ourios.query.duration histogram — the B1 pruned fraction is derived in the backend, not pre-computed. gRPC and authn/z beyond tenant-scoping remain deferred (§7).

1. Summary

Wire the validated query engine (RFC 0007) into ourios-server as a network-reachable querier role: an HTTP endpoint that accepts a logs DSL query (RFC 0002), executes it through Querier::run_query / run_drift, and returns the matching log rows plus pruning statistics as JSON. It mirrors the receiver role’s serve(config) -> Handle topology (RFC 0003) — env-gated, graceful-shutdown, its own listen address. The DSL is the public contract; DataFusion never surfaces (H6). This closes the core product loop — ingest → store → query — and is the keystone the deferred Perses datasource plugin waits on. Returning actual log rows depends on the typed-row payload + read-time render registry delivered by RFC 0017, the engine-layer prerequisite that lands before this transport (§3.1).

2. Motivation

The thesis is proven: B1/B2 (predicate pushdown + the template_id index) pass authoritatively on real corpora (benchmarks.md §9.4), the miner and storage are accepted/green, and the full ingest path is live in the server binary. But the running binary cannot answer a query over the network. ourios-querier (RFC 0007 validated, RFC 0002 DSL green) is a working library that ourios-server does not even depend on; main.rs records the querier role as a “follow-up” and RFC 0007 §8 explicitly defers “the querier role of the server binary (RFC 0003 sibling)” to a sibling RFC. This is that RFC.

Everything Ourios proves is query-side — the value of Parquet pruning and the template index is only realised when an operator can run a query. A backend you can ingest into but cannot query is not a shippable product; packaging it (container image, Helm chart, signed release) should wrap a complete loop, not a write-only collector. The maintainer’s “prove-the-thesis-before-the-DSL-contract” sequencing (the engine drove B1/B2 through a deliberately minimal QueryRequest) is now discharged — the thesis holds, so the DSL can become the real, public query contract.

3. Proposed design

3.1 The pivotal dependency — typed-row payload

Querier::run_query today returns QueryResult { rows: u64, stats: QueryStats }, where rows is a count and stats reports row_groups_{scanned,pruned} + bytes_read. RFC 0007 §4.1 (“Crate shape”) specifies QueryResult as “typed rows + stats”, but the engine currently returns only the count — the typed-row payload is unimplemented (RFC 0007 §8 flags streaming-vs-materialised as the open question). A serving endpoint that returns only counts + pruning stats — never the actual log lines — has little operator value.

This RFC therefore takes returning rendered log rows as a requirement, which makes the typed-row payload a prerequisite. That payload — plus the read-time template registry needed to render each line — is delivered by RFC 0017 (read-time template registry & query-row rendering), landing as the engine-layer slice before this transport. §5 below is written assuming QueryResult.records (RFC 0017) is available.

3.2 Transport — HTTP/JSON, one querier role

A single querier role, mirroring the receiver:

  • ourios_server::querier::serve(QuerierConfig) -> Result<QuerierHandle, String>, returning a handle that exposes the bound address and a shutdown() future, on the same watch::channel(()) graceful-shutdown topology as receiver::serve (RFC 0003).
  • HTTP only for v1 (axum, the receiver’s HTTP stack). gRPC is deferred (§4): operators and the future Perses plugin query over HTTP; the OTLP gRPC path is an ingest concern, not a query one.
  • Env-gated exactly like the receiver: OURIOS_QUERIER_ENABLED (1/true/yes), OURIOS_QUERIER_HTTP_ADDR (default 0.0.0.0:4319), reusing OURIOS_BUCKET_ROOT for the store. Background compaction always runs; the receiver and querier are the env-gated roles, so a binary may run receiver-only, querier-only, or both (with compaction in every case).

3.3 Request

POST /v1/query, body the DSL query. Both DSL front-ends already exist (dsl::parse_statement for the text grammar, parse_structured_statement for the JSON form), so the endpoint accepts either by Content-Type:

  • text/plain → the raw DSL statement, parsed by parse_statement;
  • application/json → either a { "query": "<dsl text>" } wrapper (the text grammar, unwrapped then parse_statement) or RFC 0002’s structured-IR JSON (the top-level IR object, parsed by parse_structured_statement) — these are distinct shapes; the endpoint distinguishes them by whether the body is the {"query": …} wrapper.

The parsed Statement dispatches: Logs(Query)run_query, Drift(DriftQuery)run_drift (RFC 0010). The server supplies now (wall clock) and the configured default time window to the executor, as the DSL compiler expects.

Tenancy. Tenant is required. The querier role takes it from a required X-Ourios-Tenant header (kept out of the query body so the DSL grammar stays tenant-agnostic) and the server rejects a missing/empty header with 400 before invoking the engineQuerier::run_query/ run_drift take a TenantId parameter, so a tenant is always supplied to the engine (the engine’s defined QueryError::TenantRequired variant is thus a guard that the server’s header check makes unreachable in practice). The engine then enforces isolation structurally via the partition-rooted scan (RFC0007.5). Authn/z beyond tenant-scoping is out of scope for v1 (§7).

3.4 Response

200 with application/json: the matching rows (the LogRow shape from RFC 0017) plus the pruning stats (row_groups_scanned, row_groups_pruned, bytes_read) so callers see the pillar-1 win directly. Result-encoding details (a JSON array vs NDJSON streaming for large results, the default limit and its hard cap) are §7 open questions. Drift queries return the RFC 0010 DriftResult shape.

3.5 Error model (H6)

All errors are Ourios-owned; no DataFusion type, SQL string, or plan ever appears in a response. Mapping:

  • DSL parse/validation (DslError, QueryError::InvalidQuery) → 400 with a structured { "error": { "kind": ..., "message": ... } }.
  • Missing/empty X-Ourios-Tenant header → 400, returned by the server’s header check before the engine is invoked (§3.3).
  • Execution failure (QueryError::Storage) → 500, message scrubbed of engine internals (its Display already withholds DataFusion text per RFC0007.3 / H6).

3.6 Observability

The querier role emits metrics through the OTel meter surface (RFC 0001 §6.8 model — per the established “OTel meters, not the Prometheus client” direction): query count, latency histogram, and the pruning ratio (row_groups_pruned / (row_groups_scanned + row_groups_pruned) — the fraction of total row groups skipped, matching QueryStats) so the thesis win is observable in production. New metric/attribute names go through semconv/registry/ + weaver (no hand-written flat names).

4. Alternatives considered

SQL passthrough. Expose DataFusion SQL directly. Rejected by H6 and RFC 0007’s “Not a SQL endpoint” line — leaking the engine’s SQL surface couples the public API to an implementation detail and forfeits the DSL’s template-aware primitives (resolves_to, lossy, drift).

gRPC (instead of / in addition to HTTP) for v1. A query gRPC service is plausible, but adds a second transport and a .proto contract for no v1 consumer — operators use HTTP and the Perses plugin will too. Deferred until a concrete gRPC consumer exists.

Counts-and-stats only for v1 (no row payload). Ship the endpoint over the engine exactly as it is today (return rows: u64 + stats), defer log-line retrieval. Rejected as the primary plan: an endpoint that can’t return logs isn’t a usable query API and wouldn’t justify the packaging work that follows. Recorded because it is the minimal fallback if RFC 0017’s row payload slips.

Serve queries from the receiver process / always-on. Folding the query listener into the receiver role couples ingest and read scaling and removes the querier-only deployment topology. A separate env-gated role (matching CLAUDE.md’s two-role binary) keeps them independent.

Skip the role gate (always serve). Rejected — the binary’s role model (receiver / querier, each env-gated) is established by the receiver; a querier-only or receiver-only deployment is a real operational shape.

5. Acceptance criteria

Scenario RFC0016.1 — querier role serves a DSL query end-to-end

  • Given a populated store and ourios-server started with OURIOS_QUERIER_ENABLED=1 and OURIOS_BUCKET_ROOT set
  • When a client POSTs a logs DSL statement to /v1/query with an X-Ourios-Tenant header
  • Then the server parses it via the RFC 0002 front-end, executes it through Querier::run_query, and returns 200 with the matching rows and the pruning stats (row_groups_scanned, row_groups_pruned, bytes_read)

Scenario RFC0016.2 — tenant scoping is enforced at the API

  • Given two tenants with disjoint data in the store
  • When a query is sent with X-Ourios-Tenant: A
  • Then only tenant A’s rows are ever read or returned, and a request with no tenant header is rejected 400 by the server’s header check, without scanning any data

Scenario RFC0016.3 — a drift query routes to the drift path

  • Given an audit stream with template widening events
  • When a drift from <t1> to <t2> statement is posted
  • Then the endpoint dispatches the Drift arm to run_drift and returns the RFC 0010 DriftResult shape

Scenario RFC0016.4 — malformed DSL is a clean 400, no engine leak

  • Given the querier role running
  • When a syntactically invalid or uncompilable DSL statement is posted
  • Then the response is 400 with an Ourios-owned error body, and no DataFusion type, SQL string, or plan text appears in the response (H6)

Scenario RFC0016.5 — role gating and graceful shutdown

  • Given OURIOS_QUERIER_ENABLED unset
  • When the server starts
  • Then no query listener is bound; and when enabled and then sent SIGINT/SIGTERM, the querier listener drains and the process exits cleanly (mirroring the receiver handle)

Scenario RFC0016.6 — pruning is observable

  • Given a selective query (time window or template_id) over a multi-row-group corpus
  • When it runs through the endpoint
  • Then the response’s row_groups_pruned is non-zero and a query-latency + pruning-ratio metric is emitted via the OTel meter surface

Scenario RFC0016.7 — receiver and querier compose in one binary

  • Given both OURIOS_RECEIVER_ENABLED and OURIOS_QUERIER_ENABLED set, with distinct addresses
  • When the server starts
  • Then both listeners bind and serve, sharing the one OURIOS_BUCKET_ROOT, and shutdown drains both

6. Testing strategy

  • RFC0016.1 / .3 — integration tests in ourios-server (or ourios-ingester-style harness): start the role on :0, POST a DSL statement, assert rows + stats / drift shape. Reuses the querier’s existing fixtures.
  • RFC0016.2 — a two-tenant fixture; assert isolation + the no-header-400 path. Mirrors the engine’s RFC0007.5 partition-prune test at the API layer.
  • RFC0016.4 — table of malformed statements → 400; a grep-style assertion that the response body contains no DataFusion / SQL / LogicalPlan substrings (H6 guard).
  • RFC0016.5 / .7 — process-level tests: env permutations (neither / one / both roles), bind assertions, and a SIGINT-drains-cleanly check (the receiver already has this pattern).
  • RFC0016.6 — assert the pruning stat in the response and the OTel metric emission (testcontainers + the established meter test harness).

Each scenario id is referenced from the corresponding test so the spec-to-test mapping is greppable (docs/verification.md §2).

7. Open questions

  • Typed-row payload sequencing (§3.1) → resolved: the payload + render registry land first as RFC 0017 (engine-layer slice), and this RFC is the thin transport over it.
  • Result encoding for large results — a single JSON array, or NDJSON streaming once row counts are large? And the default limit + its hard cap.
  • Authn/z beyond tenant-scoping — is v1 trusted-network only (tenant header, no auth), or is a token/mTLS story in scope? (Leaning trusted-network for v1; auth as a follow-up RFC.)
  • gRPC query service — revisit when a concrete consumer needs it.
  • Default time window → resolved: a query with no range(...) stage looks back over a server-supplied default window, defaulting to one hour and configurable via OURIOS_QUERIER_DEFAULT_WINDOW_SECS (a non-zero integer of seconds). The server passes it to the compiler as default_window_nanos; it is never unbounded (RFC 0002 §4 P5).
  • Endpoint surface — single POST /v1/query that dispatches Logs/Drift by statement type (proposed), or distinct paths?

8. References

  • RFC 0002 (query DSL — the public query grammar), RFC 0007 (querier engine — §4.1 specifies QueryResult as typed rows + stats, §8 flags the serving role + result materialisation), RFC 0017 (the typed-row payload + read-time render registry this transport returns), RFC 0003 (OTLP receiver — the serve/Handle + env-gating pattern this mirrors), RFC 0010 (drift queries), RFC 0001 §6.8 (OTel metric surface).
  • CLAUDE.md §1 (not a managed service), §3.7 (multi-tenancy on every data path), §6.3 (observability), H6 (query DSL vs DataFusion SQL surface — do not leak engine specifics).
  • docs/roadmap.md §5 (Perses datasource plugin parked behind a stable query API); crates/ourios-querier/src/lib.rs (Querier::run_query, run_drift, QueryResult); crates/ourios-server/src/receiver.rs (serve / ReceiverHandle).

RFC 0017 — Template registry & query rendering


rfc: 0017 title: Read-time template registry & query-row rendering status: green author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-06-20 supersedes: — superseded-by: —

RFC 0017 — Read-time template registry & query-row rendering

1. Summary

Make the querier return rendered log lines, not just a count: add records: Vec<LogRow> to QueryResult (keeping the rows count). A LogRow is a faithful OTLP LogRecord — every OTLP field ingest persisted, plus the body (rendered for string bodies, returned as structure for AnyValue bodies). Rendering needs each leaf’s versioned tokens at read time, so this RFC builds a read-time template registry ((template_id, template_version) → tokens) by folding the tenant’s audit stream — and, because a template’s initial creation is unaudited today, amends the audit contract to emit a template_created event on leaf creation. This delivers the typed-row payload RFC 0007 §4.1 specifies but the engine never built, and is the prerequisite for RFC 0016’s endpoint to return actual logs.

This amends RFC 0001: scenario RFC0001.1 (“fresh-leaf creation does not emit an audit event”) is superseded — leaf creation now emits a template_created event (§3.1). It remains a non-merge (merges_total unchanged), so RFC 0001’s merge-counting contract is untouched.

2. Motivation

A query returns QueryResult { rows: u64, stats } today — a count, no rows. RFC 0007 §4.1 specifies QueryResult as “typed rows + stats”, but the engine implemented only the count; the typed-row payload was never built (RFC 0007 §8 left result materialisation open). RFC 0016’s query-serving endpoint is hollow without real rows, and the point of an operator query is to see the logs, which means reconstructing each line from (template_id, template_version, params, separators)template_version selects the correct token set for that leaf over time (§3.5) — per the CLAUDE.md §3.3 bit-identical contract — or returning the retained body for lossy/parse-failure rows.

Reconstruction needs the leaf’s tokens at read time. RFC 0005 §3.7.1 already commits to the audit-stream-derivation model for read-time maps (the alias map is derived this way; the cached artifact is “deferred, not designed away” — the manifest fork #94/#147). So the registry should be derived from the audit stream, consistent with the alias map. The blocker: derivation is only correct if the audit stream records every template version’s tokens. It records widening (new_template) and type-expansion, but not a template’s initial (version 1) creation — so v1 rows have no derivable tokens. Closing that gap (a template_created audit event) makes the registry complete and the rendering correct.

3. Proposed design

3.1 The audit gap → a template_created event

When the miner allocates a new leaf it assigns a template_id / template_version = 1 but emits no audit event; the first event for that leaf is its first widening. So v1 tokens live only in the miner’s in-memory tree, never durably in the audit stream — unrecoverable for a read-time derivation once the originating rows age out.

Add a TemplateChange::Created variant (RFC 0001 §6.4) and a new audit event_kind ordinal 6 — the next free value after the existing 05 (template_widened=0, template_type_expanded=1, template_widening_rejected_degenerate=2, compaction=3, alias_asserted=4, alias_retracted=5 in crates/ourios-core/src/audit.rs) — paired with the event_type string template_created (an append-only addition per RFC 0005 §3.7 — new ordinal, no renumber, so old readers are unaffected and §3.5 migration holds). It reuses the existing audit columns: new_template = the initial tokens, new_version = 1, and old_template/old_version left NULL — the OPTIONAL “not applicable to this event kind” sentinel per RFC 0005 §3.7 (no prior template), not a zero/empty value. The in-memory TemplateChange::Created variant carries only new_template: a leaf is always born at version 1, so rather than carry-and-validate a new_version field the invariant is made unrepresentable (there is no way to construct a creation at another version). The writer supplies the canonical new_version = 1 for the on-disk column (TEMPLATE_INITIAL_VERSION); the reader does not read it back into the variant. The miner emits it at leaf creation, on the same WAL-before-ack path as the existing template events, so by the time a v1 row reaches Parquet its template_created event is durable.

3.2 derive_template_registry — fold the audit stream

A querier function mirroring alias_store::derive_alias_map (crates/ourios-querier/src/alias_store.rs:40): scan the tenant’s audit/tenant_id=… Parquet files, read the template events (template_created, template_widened, template_type_expanded), and fold them — in the pinned deterministic order (timestamp, file path lexicographic, within-file row index) (RFC 0005 §3.7.1) — into

TemplateRegistry = HashMap<(template_id: u64, version: u32), Vec<OwnedToken>>

keyed by (template_id, new_version), value = the new_template tokens parsed by ourios_miner::tree::parse_template from the canonical space-joined lit … <*> encoding (the inverse of tree::format_template, the exact form the miner writes to the audit new_template column — literals verbatim, <*> per wildcard, joined by single spaces). It is derived once per query (like the alias map), only when the query actually returns rows.

3.3 Query-time rendering

Querier::execute (the lib.rs count bottleneck) gains a row-returning path: instead of only the COUNT(*) aggregate, it collects the matching RecordBatches (bounded by the DSL limit), decodes each into the fields reconstruct::render needs, looks up registry[(template_id, template_version)], and renders — honouring the three-zone model (RFC 0001 §6.3 / §6.6):

  • clean (Reconstruction::Faithful) → the line rebuilt from the versioned tokens + params + separators (bit-identical, CLAUDE.md §3.3);
  • lossy / parse-failure (RetainedVerbatim) → the retained body verbatim;
  • structured (body_kind = Structured) → the structured AnyValue, decoded from the body column’s canonical JSON (RFC 0005 §3.3) and returned as structure — not flattened to a byte line, which would discard the map/array shape the OTLP Body is required to preserve (see §3.4).

A row whose (template_id, version) isn’t in the registry (should not happen once §3.1 lands; a corrupt/foreign row) renders RetainedVerbatim from body (or empty) — never a panic, never a wrong line.

3.4 LogRow + QueryResult (B1/B2-compatible)

QueryResult keeps rows: u64 (the count — B1/B2 and existing tests are untouched) and adds records: Vec<LogRow> (the returned rows, ≤ limit). LogRow is Ourios-owned (H6 — no arrow/DataFusion type crosses the boundary). The endpoint (RFC 0016) serialises records.

Priority: OTLP fidelity outranks downstream API stability. Ourios is pre-release and OTLP-native; where faithful OTLP shape requires changing or breaking a public type, that is acceptable — we do not compromise the LogRecord shape to preserve a Rust API. QueryResult is not #[non_exhaustive] today (crates/ourios-querier/src/lib.rs:117 — only QueryError is), so both adding a public field and marking the struct #[non_exhaustive] are one-time Rust semver breaks for downstream struct literals / patterns. Both are accepted — we don’t compromise the shape to preserve the API — and the #[non_exhaustive] mark buys that subsequent field additions (the execution slice will add more) are non-breaking. The change is in any case behaviour-compatible — B1/B2 and existing tests read rows/stats, which are unchanged — so “B1/B2-compatible” is the precise claim, not “non-breaking at the type level”.

OTLP fidelity is a first-class requirement of this RFC, not a v1 best-effort. Ourios is an OTLP-native log backend, so a returned row MUST carry every OTLP LogRecord field that ingest persisted — a read that drops fields the wire carried and the schema stored is a fidelity bug. The storage path (RFC 0005 §3.2 schema; ourios-core record.rs / otlp.rs) already persists the full record, so LogRow mirrors it field-for-field as Ourios-owned typed fields:

  • time_unix_nano (required) and observed_time_unix_nano (optional);
  • severity_number + severity_text;
  • trace context — trace_id (16 B), span_id (8 B), flags;
  • event_name;
  • attributes and resource_attributes, decoded from the stored canonical JSON (RFC 0005 §3.3) into structured key/values — not handed back as an opaque JSON blob;
  • scope_name / scope_version;
  • dropped_attributes_count (carried verbatim, never recomputed);
  • the body (below), with its Reconstruction marker.

Body — the OTLP Body is an AnyValue (string or structured). The storage path already distinguishes the two via the body_kind discriminator (RFC 0005 §3.2) and stores structured bodies as canonical JSON (RFC 0005 §3.3). LogRow models the body as a sum type so invalid states are unrepresentable rather than a flat line + side flags:

#![allow(unused)]
fn main() {
enum LogBody {
    /// body_kind = String — the §3.3 three-zone result.
    Rendered { line: Vec<u8>, reconstruction: Reconstruction },
    /// body_kind = Structured — the AnyValue decoded from canonical JSON,
    /// returned as structure (map/array), never flattened to a line.
    Structured(AnyValue),
}
}

A string body yields Rendered (clean → Faithful; lossy/parse-failure → RetainedVerbatim, §3.3). A structured body (body_kind = Structured) yields Structured, preserving the map/array shape the OTLP spec mandates Body retain — this is the render-contract Faithful case (the canonical JSON in body round-trips, no template walk). Its one edge: a structured row whose body is absent (a corrupt row — there is no structure to return) falls back to Rendered { line: empty, RetainedVerbatim }, never Structured over nothing, matching ourios_miner::reconstruct::render’s BodyKind::Structured → (empty, RetainedVerbatim) arm. So the Reconstruction marker lives on Rendered; a Structured value is faithful by construction.

The three OTLP fields ingest does not persist today — InstrumentationScope.attributes, and the per-resource / per-scope schema_url (dropped at the receiver, RFC 0003 §6.8 / §9) — are consequently not returnable. Closing those is an ingest-side fix (RFC 0003), out of scope here; this RFC’s contract is that LogRow returns everything the schema holds. Flagged in §7 as the residual fidelity gap.

3.5 Version correctness

A row carrying template_version = N renders against the N-version tokens (the event whose new_version = N), not the latest — so a line ingested before a widening reconstructs as it was then. The registry is keyed by (template_id, version) precisely for this.

3.6 Performance

Deriving the registry folds the audit stream per query — O(audit events), the same cost profile as the alias map, acceptable for v1. The materialised cache (the RFC 0005 §3.7.1 / manifest-fork artifact) is the deferred latency/recovery optimisation, not required for correctness. Rendering is bounded to the returned (limit-capped) rows.

4. Alternatives considered

Derive ≥v2, reconstruct v1 from a surviving row. Skip the template_created event; if a v1 token set is missing, recover it from any still-present v1 row’s shape. Rejected — fragile and lossy: once every v1 row of a template is compacted/retention-expired, its tokens are unrecoverable, so a later query over an older file that does reference v1 renders wrong (or can’t render). Auditing creation is the only complete fix.

Cached-map artifact first (the manifest fork #94/#147). Persist the registry as a published per-tenant file. Rejected as the first step: it’s a latency/recovery optimisation over the derivation (RFC 0005 §3.7.1 says exactly this), bigger, and entangled with the deferred atomic-publish manifest decision. Derivation is correct and sufficient once creation is audited; the cache can layer on later without changing the contract.

Store the rendered line in Parquet at ingest. Write the reconstructed line as a column so the querier needn’t render. Rejected — it duplicates the bytes the template/params reduction exists to avoid (pillar #2), and re-introduces the storage cost the design removes.

Push tokens / render client-side. Return (template_id, params, tokens) and let the client reconstruct. Rejected — leaks internal representation through the public surface (H6) and pushes the three-zone reconstruction logic onto every consumer.

Don’t render — structured rows only. Return the columns, no line. Rejected per the maintainer’s decision: a query that can’t show the log line isn’t a usable query API.

5. Acceptance criteria

Scenario RFC0017.1 — initial template creation is audited

  • Given a miner ingesting a line that creates a new leaf
  • When the leaf (and its template_id) is allocated
  • Then a template_created audit event is emitted carrying (template_id, new_version = 1, new_template = the initial tokens) on the WAL-before-ack path
  • And the new event_kind ordinal / event_type string is an append-only addition (no existing ordinal renumbered), per RFC 0005 §3.7

Scenario RFC0017.2 — the registry derives completely from the audit stream

  • Given a tenant audit stream with template_created, template_widened, and template_type_expanded events
  • When derive_template_registry folds it (deterministic (timestamp, path, row) order)
  • Then the registry contains the tokens for every (template_id, version) the stream describes, including version 1, with later versions not clobbering earlier ones

Scenario RFC0017.3 — a clean row renders bit-identically (CLAUDE.md §3.3)

  • Given a stored clean-path row (Faithful-eligible) and the derived registry
  • When the querier renders it via the registry tokens
  • Then the rendered line equals the originally-ingested line byte-for-byte (the CLAUDE.md §3.3 invariant), and the row’s Reconstruction marker is Faithful

Scenario RFC0017.4 — lossy / parse-failure rows return the retained body

  • Given a row flagged lossy or with no template (parse failure), whose body was retained
  • When the querier renders it
  • Then the returned line is the retained body verbatim and the marker is RetainedVerbatim — no template walk, never a wrong reconstruction

Scenario RFC0017.5 — rows render against their own template version

  • Given a template that has widened (versions 1 and 2 both present in the audit stream) and rows at each version
  • When the querier renders a version = 1 row
  • Then it renders against the version-1 tokens, not the widened version-2 tokens

Scenario RFC0017.6 — typed-row payload is returned, B1/B2-compatible

  • Given a query with a limit
  • When it runs
  • Then QueryResult.records holds up to limit LogRows (rendered/structured body + marker + the OTLP fields per §3.4), and QueryResult.rows (the count) and stats are unchanged so B1/B2 and existing tests still pass
  • And QueryResult is marked #[non_exhaustive] (which, with the field addition, is an accepted one-time semver break per §3.4) so that subsequent field additions are non-breaking

Scenario RFC0017.7 — no engine internals leak (H6)

  • Given the public LogRow / QueryResult surface
  • When inspected
  • Then no arrow/DataFusion/SQL type or text appears in it; all fields are Ourios-owned

Scenario RFC0017.8 — every persisted OTLP field round-trips on read

  • Given a stored row whose ingest carried the full OTLP LogRecord field set (timestamps, severity number + text, trace context, scope name/version, attributes, resource attributes, dropped count, event name)
  • When the querier returns it as a LogRow
  • Then each of those fields equals what the schema stored (RFC 0005 §3.2), attributes / resource_attributes are decoded to structured key/values (not an opaque JSON blob), and no stored OTLP field is dropped on the read path

Scenario RFC0017.9 — a structured (AnyValue) body is returned as structure

  • Given a stored row with body_kind = Structured (the OTLP Body was a map/array, canonical JSON in body, RFC 0005 §3.3)
  • When the querier returns it
  • Then the body is LogBody::Structured(AnyValue) preserving the original map/array shape — not flattened into a byte line — and round-trips the ingested AnyValue

6. Testing strategy

  • RFC0017.1 — a miner unit/integration test asserting a template_created event on first leaf allocation (with tokens), plus an audit-schema test that the new event_kind/event_type is appended (existing ordinals unchanged).
  • RFC0017.2 / .5derive_template_registry unit tests over a synthetic audit stream (creation + widening), asserting completeness and per-version keying; deterministic-order test mirroring the alias-map tests.
  • RFC0017.3 — a property test reusing the CLAUDE.md §3.3 invariant: for a corpus of mined rows, registry-rendered line == original (or flagged lossy). Cross-references ourios-miner’s reconstruction property test.
  • RFC0017.4 — fixtures for lossy + parse-failure + structured rows → expected verbatim/canonical body + marker.
  • RFC0017.6 — querier test asserting records length ≤ limit, the rendered content, and that rows/stats are unchanged (a B1/B2-style count assertion still holds).
  • RFC0017.7 — a grep-style guard that the public crate surface has no arrow/datafusion types (mirrors the RFC0007.3 / H6 guard).
  • RFC0017.8 — a querier test that ingests a record populating every OTLP field, stores it, queries it back, and asserts each LogRow field equals the ingested value (a field-completeness assertion over the RFC 0005 §3.2 column set), with attributes / resource_attributes decoded to structured key/values. The assertion enumerates the field set so a newly-added stored column that the read path forgets fails the test.
  • RFC0017.9 — a property/round-trip test: for structured-body inputs (AnyValue maps/arrays), LogRow.body == LogBody::Structured(v) where v equals the ingested AnyValue (decoded canonical JSON), never a flattened line. Cross-references the ourios-core canonical encode/decode property tests.

Each scenario id (RFC0017.N) is referenced from its test so the mapping is greppable (docs/verification.md §2).

7. Open questions

  • Cached-map artifact — when to materialise the registry (the RFC 0005 §3.7.1 / manifest-fork optimisation) vs. always deriving. Deferred; derivation is the v1 contract.
  • Registry memory bound — for tenants with very large template counts, is the per-query in-memory registry acceptable, or does it need a cap / lazy per-(id,version) lookup?
  • template_created payload — does it also carry slot_types (like TypeExpanded), or just tokens? (Leaning tokens-only for v1; slot types are derivable / not needed for render.)
  • Structured-body renderingresolved (§3.3 / §3.4): the OTLP Body is an AnyValue, and the storage path already preserves the structured case (body_kind = Structured, canonical JSON in body, RFC 0005 §3.2/§3.3). LogBody::Structured(AnyValue) returns it as structure; only string bodies walk the template. No flattening.
  • Residual ingest-side fidelity gapLogRow returns every OTLP field the schema stores, but three are dropped at the receiver today and so cannot be returned: InstrumentationScope.attributes, and the per-resource / per-scope schema_url (RFC 0003 §6.8 “out of scope” / §9). For a backend whose thesis is OTLP-native fidelity these are worth closing — but at ingest (an RFC 0003 schema addition + RFC 0005 columns), not in this read-path RFC. Track as an RFC 0003 follow-up; this RFC is faithful to the stored record by construction.
  • Backfill — existing audit streams predate template_created; templates created before this lands won’t have a creation event, so their v1 rows aren’t in the registry and hit the §3.3 not-in-registry fallback. Caveat: that fallback renders RetainedVerbatim from body, but a clean-path body_kind = String row has no body (absent by design, RFC 0005 §3.2) — so the fallback yields an empty line, not the original, unless tokens are recovered. Options: accept empty-line for pre-template_created clean rows (pre-release, leaning this), a one-time audit backfill, or recover v1 tokens from a surviving v1 row’s shape (the §4 “reconstruct v1 from a surviving row” alternative, rejected there as fragile). Pre-release lean: acceptable + documented.

8. References

  • RFC 0001 §6.4 (template audit events), §6.6 (render contract), §6.7 (audit stream); RFC 0005 §3.7 (audit schema; the append-only event-type rule, the canonical token encoding), §3.7.1 (derive-from- audit model; the deferred cached artifact / manifest fork #94/#147); RFC 0007 §4.1 (specifies QueryResult as typed rows + stats — the payload this RFC implements), §8 (result-materialisation open question); RFC 0002 (render stage); RFC 0010 (drift, the other audit-derived query); RFC 0016 (the query-serving endpoint that consumes records).
  • CLAUDE.md §3.1 (audit events on template change), §3.3 (bit-identical reconstruction), §3.5 (schema migration — append-only audit types), hazard H6 (no DataFusion surface leak), §3.7 (multi-tenancy — the registry is per-tenant).
  • crates/ourios-querier/src/alias_store.rs (derive_alias_map, the pattern); ourios_miner::reconstruct::render; crates/ourios-core/src/audit.rs (TemplateChange); ourios_miner::tree::OwnedToken.

RFC 0018 — OTLP log-spec compliance amendments


rfc: 0018 title: OTLP log-spec compliance amendments status: green author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-06-20 supersedes: — superseded-by: —

RFC 0018 — OTLP log-spec compliance amendments

1. Summary

Close the OpenTelemetry OTLP log-spec gaps surfaced by the 2026-06-20 compliance audit, as one push. Ourios is an OTLP-native log backend, so spec fidelity outranks downstream API stability — these amendments break and extend public types where the spec requires it. Six fixes spanning three green RFCs (0002, 0003, 0005): (1) persist the dropped InstrumentationScope.attributes and the per-resource / per-scope schema_url (a flat OTLP MUSTAnyValue and the scope tuple must be preserved); (2) map transient ingest failures to retryable gRPC/HTTP codes instead of non-retryable INTERNAL/500 (clients currently drop data they should retry); (3) make event_name a first-class DSL filter; (4) round-trip non-finite doubles in canonical AnyValue JSON; (5) preserve out-of-range SeverityNumber + flag it instead of the current silent clamp-to-0 (the backend is a faithful witness, not a corrector — §3.0); (6) correct the body column documentation. This amends RFC 0002 (DSL), RFC 0003 (receiver), and RFC 0005 (schema).

2. Motivation

A three-area audit (receiver, schema, DSL/querier), graded against the OTLP/OTel spec’s own MUST/SHOULD levels, found that the ingest and query paths under-serve the spec in ways a fidelity-first backend must not. The gaps were verified against the OpenTelemetry knowledge base; one audit claim (that structured AnyValue bodies are “type-erased”) was refuted — the canonical JSON Ourios stores is the OTLP protobuf→JSON mapping and preserves the AnyValue discriminator, so it is not in scope here.

The spec is unambiguous on the load-bearing gap: AnyValues expressing empty/zero/empty-string/empty-array “are considered meaningful and MUST be stored and passed on to processors / exporters” (common/#anyvalue), and the instrumentation scope is the (name, version, schema_url, attributes) tuple (common/instrumentation-scope). Ourios decodes only name/version and discards the rest at the receiver boundary, so those fields never reach Parquet and RFC 0017’s LogRow can never return them. The retry-semantics gap is a quieter data-loss bug: mapping a transient WAL/storage failure to gRPC INTERNAL (which the OTLP retry table marks non-retryable) tells the client to drop the batch (otlp/#failures).

“One compliance push” was the maintainer’s chosen sequencing: clear the whole list before more read-path work, so the query read path — RFC 0016’s serving endpoint returning RFC 0017’s LogRow — lands on a complete, spec-faithful schema.

3. Proposed design

3.0 Governing principle — faithful witness, not corrector

Producing spec-valid telemetry is the upstream’s contract — the SDK, the instrumenting library, and any intermediary collectors/processors (OTel ships the tooling for it: severity parsers, the transform processor). When an upstream emits non-compliant data (e.g. SeverityNumber = 25), it broke the contract. Ourios is the storage/query backend, not the normalizer, so its job is to be a faithful witness:

  1. Preserve what arrived, byte-for-byte, up to the point where a storage invariant physically forbids it.
  2. Surface any spec violation as an observable anomaly (a metric, and where practical a marker on read) — so an operator can find the misbehaving upstream.
  3. Never silently correct (clamping/normalizing destroys the evidence and masks the upstream bug) nor silently reject (dropping punishes the operator for an upstream they may not control, and loses logs).

This is Postel’s law, and it matches what OTLP already asks of receivers elsewhere — tolerate unknown fields, preserve unknown (open-)enum values. The spec gives backends latitude in representation (“Backend and UI may represent…”), never a mandate to correct; “normalized to values described” is a producer-side mapping rule, not a backend one. Normalization on ingest, if ever wanted, is a future opt-in config (gated on a concrete consumer), never the silent default. This principle governs the gaps below — most visibly §3.5.

3.1 Persist InstrumentationScope.attributes + schema_url (RFC 0003 + RFC 0005) — the MUST

The receiver (crates/ourios-ingester/src/receiver/materialize.rs) decodes scope.name and scope.version but drops scope.attributes, ResourceLogs.schema_url, and ScopeLogs.schema_url. Add to the decode and to OtlpLogRecord / MinedRecord (crates/ourios-core/src/otlp.rs, record.rs):

  • scope_attributes — the scope’s KeyValue list, encoded as canonical JSON exactly like attributes / resource_attributes (RFC 0005 §3.3), empty → [];
  • resource_schema_url — the ResourceLogs.schema_url string;
  • scope_schema_url — the ScopeLogs.schema_url string.

Add three OPTIONAL columns to the RFC 0005 §3.2 schema (crates/ourios-parquet/src/lib.rs):

columntyperequirednote
scope_attributesSTRING (canonical JSON)OPTIONALper RFC 0005 §3.3 encoding; [] when empty, NULL only in pre-amendment files
resource_schema_urlSTRINGOPTIONALOTLP ResourceLogs.schema_url
scope_schema_urlSTRINGOPTIONALOTLP ScopeLogs.schema_url

All three are OPTIONAL for the RFC 0005 §3.5 migration rule alone (additive columns; readers MUST tolerate their absence in historical files) — not as a value encoding. The two schema_url columns distinguish present-but-empty from absent: a wire schema_url = "" is stored as "" (a present empty value), and NULL is reserved for the historical “column missing” case; scope_attributes follows the attributes convention ([] when empty, NULL only pre-amendment). scope_attributes rides the §3.3 canonical encoder/decoder unchanged, so it inherits its round-trip property tests. This is the only gap the spec makes a flat MUST; it is also the prerequisite for RFC 0017’s LogRow to carry the complete scope and for RFC 0010 drift to see scope-level schema_url changes.

3.2 Retryable error mapping for transient failures (RFC 0003)

crates/ourios-ingester/src/receiver/grpc.rs maps all non-tenant-resolution failures (including WAL append / fsync failures) to Status::internal, and http.rs maps them to 500. Per the OTLP retry table (otlp/#failures), INTERNAL and 500 are non-retryable — so a client that hits a transient WAL/storage failure drops the batch instead of retrying, violating the spirit of WAL-before-ack durability.

Amend the RFC 0003 error-mapping contract to distinguish transient from permanent:

  • Transient (WAL append I/O failure, post-rotation quiesce, fsync failure, storage unavailable, ingest saturation) → gRPC UNAVAILABLE (optionally RESOURCE_EXHAUSTED with a RetryInfo detail for saturation, per otlp/#otlpgrpc-throttling); HTTP 503 (optionally 429 for saturation) with an optional Retry-After header.
  • Permanent failures stay non-retryable, but are not a single HTTP code: malformed payload and tenant-resolution failure → HTTP 400 (gRPC INVALID_ARGUMENT), while an oversize payload (AppendError::TooLarge, a batch over the 16 MiB WAL frame ceiling) → HTTP 413 (gRPC INVALID_ARGUMENT). An oversize batch is a client sizing error, not a WAL outage: retrying it byte-identical can never succeed, so it MUST stay non-retryable even though it surfaces as a WalAppend error.

The 429/503 throttling surface itself remains a SHOULD and may stay minimal (no rate-limiter yet, RFC 0003 §6.7); the binding change here is that a transient failure MUST NOT be reported with a non-retryable code.

3.3 event_name as a first-class DSL filter (RFC 0002)

event_name is stored (RFC 0005 §3.2) and will be returned by RFC 0017, but the DSL cannot filter on it. Add an EventName variant to the DSL Field enum (crates/ourios-querier/src/dsl/ir.rs), a grammar token event_name, and a compile case projecting to the event_name column — mirroring the existing scope bare field exactly (RFC 0002 §6.1). String operators only (=, contains, …), consistent with other string fields. Also add scope_version as a bare field by the same pattern (currently only scope name is filterable); scope_attributes becomes filterable via the existing scope.<key> attribute-path mechanism once §3.1 stores it.

3.4 Round-trip non-finite doubles in canonical AnyValue JSON (RFC 0005)

The canonical encoder (crates/ourios-core/src/otlp.rs) serialises a non-finite double_value (NaN, ±Infinity) to JSON null, which does not decode back to the original — a lossy round-trip pinned by an existing test. Ourios’s canonical encoding is the OTLP protobuf→JSON mapping (proto3 JSON; the same encoding body/attributes already use, RFC 0005 §3.3), and proto3 JSON represents non-finite floats as the quoted string forms "NaN", "Infinity", "-Infinity". Adopt those string forms (not the bare NaN/Infinity tokens — they are invalid JSON and belong to OTel’s separate lossy non-OTLP-protocol string encoding, not the protobuf-JSON mapping), and replace the “encodes to null” test with a round-trip assertion.

3.5 Preserve out-of-range SeverityNumber, don’t clamp it (RFC 0003)

The receiver already clamps: severity_to_u8 (crates/ourios-ingester/src/receiver/materialize.rs:105) maps any value outside 0..=24 to 0 (UNSPECIFIED). Per §3.0 this is the wrong default — it is a silent correction that both destroys the evidence (an operator can no longer see the upstream emitted a bad value) and inverts meaning: SeverityNumber is monotonic (logs/data-model/#severity-fields), so 25 is “more severe than FATAL4 (24)”, and clamping it to 0 turns the most severe record into the least-informative one. It is also doubly damaging because severity_number is a template-key component ((severity_number, scope_name), crates/ourios-miner/src/cluster.rs:1680): every out-of-range value collapses into the single UNSPECIFIED bucket, co-mingling distinct severities in mining.

Change to preserve verbatim:

  • 0..=24 (defined) and 25..=255 (out of the named ranges but storable and monotone-meaningful) → stored as the wire value;
  • a record with severity_number outside 0..=24 is recorded on the existing ourios.ingest.records counter with the standard error.type attribute set to severity_out_of_range — the OTel “recording errors on metrics” convention (one counter for success + anomaly, reason on a low-cardinality error.type; success records carry no error.type), not a bespoke counter. severity_text is retained, so the violation is observable, not masked;
  • the values a u8 physically cannot hold (negative, > 255) become 0 — here the storage invariant wins (§3.0 point 1’s limit). Because they narrow to 0, they are indistinguishable post-narrowing from a genuine UNSPECIFIED and so are not separately attributed on the counter (an accepted limitation: such values are degenerate corruption, not a meaningful severity); the 25..=255 case — the one an operator actually sees — is fully attributed.

Severity comparisons (RFC 0002, which correctly compares on SeverityNumber) stay monotone and correct: severity >= ERROR still matches a 25. The u8 column is retained: 0..=255 covers the entire defined range with 10× headroom for any conceivable future OTLP expansion, and the only values it cannot represent (negative / > 255) are definitionally garbage with nothing to preserve. Widening the column to i32 for absolute wire-fidelity is a one-line alternative (§7).

3.6 Correct the body column documentation (RFC 0005)

RFC 0005 §3.2 describes the body column as “raw bytes … not text,” but for body_kind = Structured rows it holds UTF-8 canonical JSON (§3.3). Clarify the column note: raw original bytes for retained String rows; UTF-8 canonical-JSON AnyValue for Structured rows; absent on clean String rows. Documentation-only; no schema change.

4. Alternatives considered

Defer everything except the MUST (§3.1). Tempting — §3.1 is the only flat MUST. Rejected per the maintainer’s “one compliance push”: §3.2 is a real data-loss bug and the rest are cheap, so clearing them together avoids a second disruptive amendment to the same files.

Add scope_attributes as typed columns rather than canonical JSON. Rejected — it would diverge from how attributes / resource_attributes are already stored (canonical JSON, RFC 0005 §3.3) for no benefit; the typed-attribute representation is a separate, deferred RFC 0005 question.

Keep INTERNAL and rely on clients retrying anyway. Rejected — the OTLP retry table is normative; compliant clients treat INTERNAL as non-retryable and drop the batch. Relying on non-compliant client behaviour is not fidelity.

Make event_name queryable only via the generic attribute path. Rejected — event_name is a top-level LogRecord field, not an attribute; it deserves a bare field like severity / scope, and forcing attr.event_name would misrepresent the data model.

One amendment RFC per touched RFC (three RFCs). Rejected per the chosen sequencing; a single RFC keeps the cross-cutting fidelity story coherent and the acceptance scenarios in one place. Each touched RFC gets a back-reference.

5. Acceptance criteria

Scenario RFC0018.1 — scope attributes + schema URLs survive ingest→storage

  • Given an OTLP batch whose InstrumentationScope carries attributes, whose ScopeLogs carries a schema_url, and whose ResourceLogs carries a schema_url
  • When the receiver materialises the records and they are written to Parquet
  • Then scope_attributes (canonical JSON), scope_schema_url, and resource_schema_url are persisted with the wire values, and a round-trip read returns them unchanged

Scenario RFC0018.2 — the new columns are OPTIONAL / back-compatible

  • Given a historical Parquet file written before this amendment (no scope_attributes / *_schema_url columns)
  • When the reader opens it
  • Then it reads successfully, the three fields read as absent/NULL, and no error is raised (RFC 0005 §3.5 migration rule)

Scenario RFC0018.3 — transient ingest failure is reported retryable

  • Given a WAL append/fsync failure during an Export call
  • When the receiver responds
  • Then the gRPC status is a retryable code (UNAVAILABLE, or RESOURCE_EXHAUSTED + RetryInfo) and the HTTP status is 503 (or 429) — never INTERNAL / 500
  • And a permanent failure (malformed payload, tenant resolution) still maps to INVALID_ARGUMENT / 400

Scenario RFC0018.4 — event_name is filterable in the DSL

  • Given stored rows with differing event_name values
  • When a DSL query filters on event_name
  • Then the predicate compiles to the event_name column and returns exactly the matching rows, with no DataFusion/SQL surface leaking to the user (H6)

Scenario RFC0018.5 — non-finite doubles round-trip through canonical JSON

  • Given an AnyValue (body or attribute) containing NaN, Infinity, and -Infinity
  • When it is canonical-encoded and decoded
  • Then the decoded value equals the original (no null collapse)

Scenario RFC0018.6 — out-of-range SeverityNumber is preserved, not clamped (§3.0)

  • Given OTLP records with severity_number = 25 and = 200 (out of the named ranges but u8-storable)
  • When the receiver materialises them
  • Then the stored severity_number is 25 / 200 verbatim (never silently clamped to 0), the ourios.ingest.records counter records them with error.type = severity_out_of_range, and a severity >= ERROR query still matches them (monotonicity preserved)
  • And a value a u8 cannot hold (negative, > 255) maps to 0 (the storage invariant, not a correction); narrowed to 0, it is not separately attributed (the §3.5 accepted limitation)

6. Testing strategy

  • RFC0018.1 / .2 — an ingester→parquet integration test asserting the three new fields round-trip (incl. a non-empty scope_attributes decoded to structured kv); a reader test over a fixture file lacking the columns (back-compat). scope_attributes reuses the ourios-core canonical encode/decode property tests.
  • RFC0018.3 — receiver unit tests injecting a transient WAL failure (gRPC → retryable code; HTTP → 503/429) and a permanent failure (INVALID_ARGUMENT / 400), mirroring the existing RFC0003.4 mapping tests.
  • RFC0018.4 — a DSL parse+compile test for event_name filters plus an end-to-end querier test asserting matched rows; the H6 no-leak guard (RFC0007.3 style) extended to the new field.
  • RFC0018.5 — a property test over AnyValue including non-finite doubles, replacing the current “encodes to null” assertion with a round-trip one.
  • RFC0018.6 — a receiver test feeding severity_number 25 and 200 and asserting they are preserved (not clamped), that the ourios.ingest.records counter records them with error.type = severity_out_of_range (in-memory MeterProvider, mirroring the compaction-metric test), and that a severity >= ERROR query still matches them (monotonicity); plus a negative / >255 case asserting 0 (the storage-invariant limit). Replaces the prior clamp-to-0 assertion in severity_to_u8’s tests (a contract change — the old test asserted the behaviour this RFC overturns; CLAUDE.md §6.2).

Each scenario id (RFC0018.N) is referenced from its test so the mapping is greppable (docs/verification.md §2).

7. Open questions

  • Saturation backpressure depth — §3.2 makes transient failures retryable, but a real rate-limiter / queue-depth signal (429 with a computed Retry-After) is still deferred (RFC 0003 §6.7). Land the code mapping now; size the limiter later?
  • scope_attributes as a template-key input?resolved: stay out of the key. The key today is (severity_number, scope_name) (cluster.rs:1680); scope_version is already retained-but-not-keyed, and scope_attributes follow that precedent. The keying principle: the key carries low-cardinality fields that identify the log statement’s semantic class (severity_number, scope_name); higher-cardinality emitter metadata (scope_version, scope_attributes) is retained + queryable (scope.<key>) but not keyed — keying on it would explode template_count (the template-cardinality hazard; CLAUDE.md §3.1 / docs/hazards.md #1) for no fidelity gain (attributes are retained per-row; reconstruction §3.3 never depended on scope). Per-attribute partitioning, if ever needed, is a future opt-in config (gated on a concrete consumer).
  • Pre-amendment backfill — historical files lack the new columns; acceptable as NULL (best-effort) for pre-release, or backfill? (Leaning acceptable, consistent with the effective_time_unix_nano amendment.)
  • SeverityNumber reject vs clampresolved: preserve + flag, neither reject nor clamp (§3.0 / §3.5). The faithful-witness principle settles it: clamping is a silent correction, rejecting is silent data loss; both are the backend overstepping a role that belongs upstream.
  • Severity column u8 vs i32resolved: u8. 0..=255 covers the defined 1..=24 with 10× headroom for any conceivable future OTLP expansion; the only values it cannot hold (negative, > 255) are definitionally garbage with nothing meaningful to preserve, so they take the §3.5 storage-invariant path (0 + anomaly count).
  • Anomaly visibility on read — §3.5 surfaces out-of-range severity via a metric; should the read path (LogRow, RFC 0017) also mark a record as carrying out-of-spec severity, so it’s visible per-record and not only in aggregate? (Leaning a metric for now; per-record marker if operators ask.)

8. References

  • OTLP/OTel spec: logs data model (field set, severity fields), common/#anyvalue (empty/zero MUST be stored), common/instrumentation-scope (the (name,version,schema_url,attributes) tuple), otlp/#json-protobuf-encoding (proto3 JSON mapping — non-finite doubles as "NaN"/"Infinity"/"-Infinity" strings), otlp/#failures (retryable vs non-retryable codes), otlp/#otlpgrpc-throttling.
  • RFCs amended: RFC 0002 (DSL — §6.1 bare fields), RFC 0003 (receiver — §6.1/§6.2 error mapping, §6.6 materialisation, §6.8/§9 the previously-deferred schema_url + scope attributes), RFC 0005 (schema — §3.2 columns, §3.3 canonical encoding, §3.5 migration). Consumed by RFC 0017 (LogRow gains the complete scope) and RFC 0010 (drift over scope schema_url).
  • CLAUDE.md §3.5 (schema migration — additive OPTIONAL columns), §3.7 (multi-tenancy — new columns per-tenant), hazard H6 (no DataFusion leak), §3.3/§3.4 (the durability the retry-mapping fix protects).
  • Code: crates/ourios-ingester/src/receiver/materialize.rs (scope/schema drop), grpc.rs / http.rs (error mapping), crates/ourios-core/src/otlp.rs (canonical encoder; severity decode), crates/ourios-parquet/src/lib.rs (schema), crates/ourios-querier/src/dsl/ir.rs (the Field enum).

RFC 0019 — Storage-backend selection


rfc: 0019 title: Storage-backend selection — wiring the server to choose local vs S3 status: accepted author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-06-22 supersedes: — superseded-by: —

RFC 0019 — Storage-backend selection: wiring the server to choose local vs S3

1. Summary

ourios-server always constructs Store::local(OURIOS_BUCKET_ROOT) today, even though ourios-parquet already exposes Store::s3(S3Config) (RFC 0013, green). This RFC wires backend selection through the server: an operator picks local or s3 via config, and the chosen Store is threaded into all three roles. To make S3 actually usable, the querier and the compactor — which still address the bucket through raw std::fs — are migrated onto the Store / object_store abstraction the receiver already uses. The write-ahead log stays local always (CLAUDE.md §3.6). This is the follow-on RFC 0014 §7 and RFC 0013 §7 named; it is the prerequisite for an object-storage-native deployment (and the CLAUDE.md §3.6-correct Helm chart).

2. Motivation

CLAUDE.md §3.6 makes object storage the source of truth: “Local disk is cache and WAL. Parquet on S3 is the truth.” RFC 0013 built the storage seam (Store, S3Config, conditional-PUT atomics) and proved it on localstack, but deferred the selection at the server config layer. The consequence today is concrete: a deployment cannot put data on S3, so the first Helm chart had to back the data store with a local ReadWriteOnce volume and a single replica — a stopgap that contradicts CLAUDE.md §3.6 and blocks horizontal querier scaling. Doing selection at this layer, now, unblocks the architecturally-correct shipping shape and exercises the RFC 0013 S3 path end-to-end through the real server.

The work is at this layer (the server + the querier/compactor read paths) because that is the only place the bucket is still addressed as a local path; the receiver write path (RFC 0014) already goes through Store.

3. Proposed design

3.1 Configuration (extends RFC 0004)

A new startup configuration surface — the storage backend and its addressing — is added under RFC 0004’s governance (its validation + secret-hygiene rules). It is not an RFC 0004 tunable in the strict sense: a tunable is global-with-per-tenant-override, whereas backend selection is necessarily process-wide (one store per process). Credentials are not Ourios configuration at all: they are operator secrets resolved by the standard AWS credential chain, or supplied explicitly as S3-named secret keys (OURIOS_S3_ACCESS_KEY_ID / OURIOS_S3_SECRET_ACCESS_KEY / OURIOS_S3_SESSION_TOKEN), distinct from the non-secret addressing keys above and never logged (see §3.4; added by the 2026-06-28 amendment, §9).

Env varBackendMeaningDefault
OURIOS_STORAGE_BACKENDbothlocal or s3local
OURIOS_BUCKET_ROOTlocaldata + audit store root (existing)— (required for local)
OURIOS_S3_BUCKETs3bucket name— (required for s3)
OURIOS_S3_ENDPOINTs3S3-compatible endpoint (MinIO, R2)unset (AWS)
OURIOS_S3_REGIONs3regionunset
OURIOS_S3_PREFIXs3key prefix within the bucketunset (bucket root)
OURIOS_S3_ACCESS_KEY_IDs3static access key (secret, §3.4)unset (→ credential chain)
OURIOS_S3_SECRET_ACCESS_KEYs3static secret key (secret, §3.4)unset (→ credential chain)
OURIOS_S3_SESSION_TOKENs3session token for temporary credentials (secret)unset (valid only with the static key pair)

OURIOS_WAL_ROOT is unchanged and remains a local path under every backend (CLAUDE.md §3.6 — the WAL is never an object-store key). “Local” here means fsync-durable local-filesystem semantics, not ephemeral storage: the WAL is the recovery mechanism (WAL-before-ack, CLAUDE.md §3.4), so the path MUST be backed by storage that survives a process/pod crash — i.e. a persistent volume, never a scratch/emptyDir-style mount. S3 is deliberately not used for the WAL: it offers no atomic append or fsync and would put S3 PUT latency on the ack path, defeating CLAUDE.md §3.4’s batched-fsync latency/durability knob; S3 is the truth for the flushed Parquet, which is all CLAUDE.md §3.6 requires. The WAL’s durability obligation is bounded by the flush horizon (CLAUDE.md §3.6 — local disk need not be durable beyond it). Surviving the loss of the volume itself (node/AZ failure) is a separate, out-of-scope tier — WAL replication / archiving, which CLAUDE.md §3.4 reserves as an addition to the WAL, not a replacement, and which a future RFC may add. The prior art is the PostgreSQL model (CloudNativePG’s Barman Cloud, barman-cloud-wal-archive): a hot fsync’d WAL on a local persistent volume, plus asynchronous archiving of completed segments to object storage for off-node recovery (§8).

3.2 The StoreConfig seam

ourios-server replaces the bucket_root: PathBuf it threads to each role with a resolved, validated descriptor:

#![allow(unused)]
fn main() {
enum StoreConfig {
    Local(PathBuf),   // OURIOS_BUCKET_ROOT
    S3(S3Config),     // OURIOS_S3_* (S3Config is the RFC 0013 type)
}
}

config_from_env parses OURIOS_STORAGE_BACKEND and fails fast on a missing required field (OURIOS_S3_BUCKET when s3; OURIOS_BUCKET_ROOT when local) or an unknown backend. StoreConfig::open() -> Result<Store, …> dispatches to Store::local / Store::s3. The receiver, compactor, and querier each take a StoreConfig (or a constructed Store) instead of a PathBuf.

flowchart LR
  env[OURIOS_STORAGE_BACKEND + addressing] --> cfg{StoreConfig}
  cfg -->|Local| sl[Store::local]
  cfg -->|S3| ss["Store::s3 / AmazonS3Builder::from_env()"]
  sl --> store[(Store)]
  ss --> store
  store --> rcv[receiver write path]
  store --> cmp[compactor sweep]
  store --> qry[querier read path]
  wal[OURIOS_WAL_ROOT] -->|always local| rcv

3.3 Migrating the querier and compactor onto Store

  • Querier. The bulk Parquet scan moves to DataFusion’s native object-store support: register the Store’s object_store on the SessionContext and address tables by object-store URL rather than a local ListingTableUrl path. The audit-stream helpers that read with std::fs (audit_scan, alias_store::derive_alias_map, template_registry::derive_template_registry) move to Store listing + get_blocking. Querier::new takes a Store (or StoreConfig).
  • Compactor. The filesystem walks (tenants, plan_candidates, compact_partition, gc_orphans) move to Store listing + the ourios-parquet Store-based read/write/delete. The manifest swap adopts Manifest::publish_cas (conditional PUT, RFC0013.3/.4) so concurrent or retried sweeps cannot clobber a generation. Compactor::new takes a Store.

Store exposes object/key I/O (get_blocking/put_blocking/…) but not yet a listing method (listing lives on the inner object_store::ObjectStore). This RFC’s implementation adds a thin Store listing wrapper over ObjectStore::list (prefix → keys, bridged off-runtime like the existing blocking helpers) so the querier and compactor never reach past the Store seam; the alternative — calling ObjectStore::list directly via Store::object_store() — is equivalent but leaks the abstraction.

Both migrations preserve the on-disk layout and the partition key scheme (RFC 0005 §3.4) byte-for-byte — only the addressing changes (a local path vs. an object-store key under the prefix), so historical local stores and the existing reader/writer remain valid (RFC 0013 §3.2).

3.4 Credentials and secret hygiene

S3 credentials resolve explicit-over-chain:

  1. Explicit Ourios config. OURIOS_S3_ACCESS_KEY_ID / OURIOS_S3_SECRET_ACCESS_KEY (and optionally OURIOS_S3_SESSION_TOKEN), when set, are read by Ourios and applied to the AmazonS3Builder (with_access_key_id / with_secret_access_key / with_token). These are S3-API names, not AWS-the-cloud names — they authenticate AWS S3 and every S3-compatible store (MinIO, R2, Hetzner, Ceph, …) identically. The static access key and secret are a pair: setting one without the other, or a session token without that pair, fails fast (the error names only the offending key, never a value).
  2. The standard credential chain (fallback). When the explicit keys are all unset, AmazonS3Builder::from_env() resolves the usual way: static AWS_* keys, a shared profile, IRSA, or instance metadata. Retained because AWS IRSA injects its own AWS_ROLE_ARN / AWS_WEB_IDENTITY_TOKEN_FILE (the EKS pod-identity webhook, outside Ourios’s control), for which there is no Ourios-named equivalent.

Secret hygiene. Credential and secret values MUST never appear in logs, error messages, metric attributes, or a Debug rendering. Ourios reads the explicit OURIOS_S3_* credential keys, so it owns their redaction — S3Config’s Debug shows only credential presence, StoreError withholds backend internals, and a missing-required-config error names only the key (OURIOS_S3_BUCKET), never a credential. Non-secret config values (an addressing knob, an interval) MAY be echoed in a resolution error for diagnosability — e.g. the OURIOS_COMPACTION_INTERVAL_SECS parser reporting the offending value — since those carry no secret; the prohibition is specifically on credential/secret material. (Introduced by the 2026-06-28 amendment, §9.)

4. Alternatives considered

  • Overload OURIOS_BUCKET_ROOT with an s3://bucket/prefix URL. One var, no new knobs — but it conflates path, addressing, endpoint, and region into a single string, hides the MinIO/R2 endpoint override, and couples config parsing to object_store’s URL grammar. Rejected for a flat, explicit knob set that RFC 0004 can govern.
  • Only the receiver writes S3; querier/compactor stay local. Incoherent — the data store is a single backend; a querier reading a local path would find nothing the S3 receiver wrote. Rejected.
  • Project S3 as a filesystem (CSI / s3fs mount). Lets the existing std::fs code run unchanged, but defeats the conditional-PUT atomicity RFC 0009/0013 rely on for the manifest swap, and adds an opaque failure surface. Rejected.
  • Defer (keep local-only). Leaves the shipping chart on a single-replica RWO stopgap that contradicts CLAUDE.md §3.6 and blocks querier scaling. Rejected — this RFC is the unblock.

5. Acceptance criteria

Scenario RFC0019.1 — backend selection from config

  • Given OURIOS_STORAGE_BACKEND unset and OURIOS_BUCKET_ROOT set
  • When the server resolves its config
  • Then it selects the local backend from OURIOS_BUCKET_ROOT; and with OURIOS_STORAGE_BACKEND=s3 + OURIOS_S3_BUCKET it selects S3; and s3 without OURIOS_S3_BUCKET, or an unknown backend value, is a clear fail-fast startup error.

Scenario RFC0019.2 — the WAL stays local under every backend (CLAUDE.md §3.6)

  • Given OURIOS_STORAGE_BACKEND=s3
  • When the receiver role runs
  • Then the WAL is written under the local OURIOS_WAL_ROOT and never as an object-store key; the data + audit Parquet go to S3 (extends RFC0013.6).

Scenario RFC0019.3 — end-to-end ingest→query on S3

  • Given the server configured for an S3-compatible backend (localstack)
  • When a batch is ingested and a DSL query runs
  • Then the Parquet lands under the S3 prefix and the query returns the rows with non-zero pruning stats — the same result the local backend produces.

Scenario RFC0019.4 — compaction operates on S3

  • Given several small files for a partition on the S3 backend
  • When a compaction sweep runs
  • Then they are consolidated via Store I/O and the manifest is swapped with a conditional PUT (publish_cas); a losing concurrent sweep does not clobber the winning generation (RFC0013.3/.4).

Scenario RFC0019.5 — tenant isolation on S3 (CLAUDE.md §3.7)

  • Given two tenants’ data on the S3 backend
  • When one tenant queries
  • Then only that tenant’s prefix is read; another tenant’s objects are never returned.

Scenario RFC0019.6 — config is governed by RFC 0004; no secret leakage

  • Given S3 credentials supplied via the AWS chain
  • When the server starts, logs, errors, or exports metrics
  • Then no credential value appears in any log line, error message, or metric attribute; a missing-S3-config error names only the missing key, never a credential (non-secret knobs may be echoed for diagnosability) (CLAUDE.md §6.3, RFC 0004).

Scenario RFC0019.7 — local backend regression

  • Given no OURIOS_STORAGE_BACKEND set and OURIOS_BUCKET_ROOT set (the default local path)
  • When the full existing suite runs
  • Then behaviour is byte-for-byte unchanged from the local path today: receiver, querier, and compactor produce identical results, and every pre-existing local test passes.

Scenario RFC0019.8 — explicit S3 credentials, S3-named and never leaked

  • Given OURIOS_S3_ACCESS_KEY_ID / OURIOS_S3_SECRET_ACCESS_KEY set and no AWS_* static keys in the environment
  • When the server resolves its config and runs an ingest→query against an S3-compatible backend (localstack)
  • Then the explicit keys authenticate the store (the round-trip succeeds), confirming Ourios applies them to the builder; and when the explicit keys are all unset the standard credential chain (AmazonS3Builder::from_env(), including IRSA) is used unchanged; and a partial set (one of the static pair, or a token alone) fails fast naming only the offending key; and no credential value ever appears in a config error, log line, StoreError, Debug output, or metric attribute — extending RFC0019.6’s redaction to the S3 credential keys.

6. Testing strategy

All eight scenarios have passing tests; the RFC is accepted (§9).

  • RFC0019.1 / .6 / .7 — unit tests on build_store_config / build_config (the main.rs pattern), including the missing-key / secret-scrub assertion for hygiene and the local-default regression. They live in crates/ourios-server/src/main.rs (rfc0019_1_* / rfc0019_6_* / rfc0019_7_*) and run in the default cargo test job.
  • RFC0019.2 / .3 / .4 / .5 — server-level testcontainers + localstack integration tests in crates/ourios-server/tests/rfc0019_storage_backend.rs, reusing the rfc0013_object_store.rs harness (Store::s3 against a localstack endpoint) and spawning the ourios-server binary configured for the S3 backend, driven over HTTP. .2 asserts the WAL stays local while the data backend is S3 (the rfc0013_6_wal_stays_local pattern); .3 ingests then queries end to end on S3; .4 runs the background compactor against S3 and asserts the conditional-PUT manifest swap; .5 proves cross-tenant isolation. They are #[ignore]d for the default cargo test run and gated to the CI s3 integration (localstack) job (Docker-API runtime + the AWS_* env), invoked by name via --ignored --exact.
  • RFC0019.7 (regression) — in addition to the unit test above, the existing local receiver/querier/compactor suites run unchanged over the default config path; they are the byte-for-byte regression guard.
  • RFC0019.8 — two halves. The redaction + validation half is unit tests: the rfc0019_6_* no-leak assertion covers the OURIOS_S3_* secret keys, a with_s3_credentials test (main.rs) that the explicit keys land in S3Config (blank reads as unset, local carries none), and ourios-parquet store tests that Store::s3 accepts a full pair, fails fast on a partial set without echoing the value, and that S3Config’s Debug redacts credentials. The authentication half is the localstack rfc0019_8_explicit_s3_credentials_authenticate integration test (the server configured with the S3 credential keys only, AWS_* removed), gated to the s3 integration (localstack) CI job.

7. Open questions

  • Single-writer lease vs. conditional-PUT contention (carried from RFC 0013 §7) — is publish_cas retry sufficient for the compactor under multi-writer races, or is a dedicated lease object warranted? This RFC adopts publish_cas; a lease is a follow-up if contention shows up.
  • Local read cache for hot S3 objects (RFC 0013 §7) — deferred.
  • Migration tool to copy an existing local store to S3 — deferred; new deployments start on the chosen backend.
  • Multipart upload threshold for the 256 MiB–2 GiB RFC 0009 outputs (RFC 0013 §7) — confirm object_store defaults suffice or expose a knob.

8. References

  • RFC 0013 (object-storage backend — Store, S3Config, conditional-PUT; §7 open questions this resolves), RFC 0014 §7 (names this follow-on), RFC 0004 (configuration policy — the tunable/invariant line this extends), RFC 0005 §3.4 (partition layout, preserved), RFC 0009 (compaction — manifest swap), RFC 0007/0016 (the querier read path being migrated).
  • CLAUDE.md §3.6 (object storage is the source of truth; local disk is cache and WAL), §3.7 (multi-tenancy on every data path), §6.3 (observability / self-telemetry — no secret leakage).
  • crates/ourios-parquet/src/store.rs (Store, S3Config, StoreError), crates/ourios-parquet/tests/rfc0013_object_store.rs (the localstack harness), crates/ourios-server/src/main.rs, crates/ourios-server/src/receiver.rs, crates/ourios-server/src/querier.rs, crates/ourios-ingester/src/compactor.rs.
  • Prior art for the deferred WAL-replication/archive tier (§3.1): PostgreSQL WAL archiving (archive_command / archive_library) and CloudNativePG’s Barman Cloud (barman-cloud-wal-archive) — the same layering, a hot fsync’d WAL on a local persistent volume plus asynchronous shipping of completed segments to object storage for off-node recovery / PITR.

9. Amendment history

  • 2026-06-28 — explicit S3-named credentials. §3.4 as originally accepted introduced “no Ourios-specific credential config” and resolved S3 credentials solely through AmazonS3Builder::from_env() (the AWS-SDK-named chain). Ourios is S3-compatible, not AWS-specific (MinIO, Cloudflare R2, Hetzner, Ceph/RADOS, GCS S3-interop, …), so its credential surface should read as S3. This amendment added the S3-named credential keys (OURIOS_S3_ACCESS_KEY_ID / OURIOS_S3_SECRET_ACCESS_KEY / OURIOS_S3_SESSION_TOKEN, §3.1 table + §3.4) layered explicit-over-chain — the chain retained as the fallback AWS IRSA requires — with the partial-set fail-fast and the widened redaction, and added acceptance scenario RFC0019.8 (§5). Specified, then implemented in the same change set; the RFC stays green (all eight §5 criteria pass).
  • 2026-07-10 — accepted (maintainer sign-off). Promoted green → accepted (terminal). All eight §5 criteria have passing tests (green since #301, amended #306/#307): unit coverage of backend selection + credential scrub, and the localstack S3 integration covering WAL-stays-local, the ingest→query round-trip on S3, the compactor’s conditional-PUT manifest swap, and cross-tenant isolation. No validated stage applies — backend selection is server wiring, not a thesis-gate benchmark — so acceptance follows green directly (the RFC 0001 / 0008 precedent).

RFC 0020 — Configuration file


rfc: 0020 title: Server configuration file — YAML with environment-variable substitution status: green author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-06-30 supersedes: — superseded-by: —

RFC 0020 — Server configuration file: YAML with environment-variable substitution

1. Summary

ourios-server gains a YAML configuration file, selected with --config <path>, as the primary way to configure a deployment. The file maps onto the same resolved ServerConfig the environment-variable path produces today, and supports the OpenTelemetry Configuration Working Group’s environment-variable substitution model (${env:NAME}, ${NAME}, ${env:NAME:-default}, $$ escape; scalar-only, non-recursive). The file is authoritative: when --config is given, configuration comes from the file, and the environment participates only through ${env:NAME} / ${NAME} references inside it. When --config is absent, the existing pure-OURIOS_*-env path is used unchanged, so this is non-breaking.

2. Motivation

2.1 The env-only surface does not scale to a real deployment

Configuration today is ~15 OURIOS_* environment variables read in config_from_env(). That is fine for a single container but awkward at deployment scale: the Helm chart already wires a dozen env vars across three workloads, there is no single artefact an operator can read, diff, or version to see “how is this cluster configured”, and adding a tunable means threading another env var through every layer. A declarative file is the artefact operators expect.

2.2 Match the ecosystem operators already know

Ourios is an OTLP-native backend; its operators run the OpenTelemetry Collector, which is configured by a YAML file with ${env:…} substitution. Adopting the same file-plus-substitution data model (rather than inventing one) means an operator’s Collector instincts transfer directly, and it keeps Ourios honest about dogfooding OTel conventions. The Configuration WG has specified this substitution grammar precisely, including the security-relevant edge cases (no YAML-structure injection, no recursive expansion), so “mirror the spec” is a concrete, testable target rather than a design space.

2.3 Why at this layer, and why now

This is the server’s startup/config layer only — it changes how a ServerConfig is produced, not what is configurable (that boundary is RFC 0004) nor any data-path behaviour. It is self-contained: it has no dependency on the storage, query, or miner subsystems and can land while larger workstreams (e.g. the DataFusion/Arrow upgrade) are blocked. It also unblocks a cleaner Helm chart (a ConfigMap-mounted file plus a Secret-backed ${env:…} for credentials) — the k8s-idiomatic shape.

3. Proposed design

3.1 Relationship to RFC 0004 and ServerConfig

RFC 0004 fixes what may be configured (the tunables-vs-invariants boundary). This RFC fixes how that configuration is delivered. It adds no new tunables and relaxes no invariant; it introduces a second front-end that produces the same resolved ServerConfig (crates/ourios-server/src/main.rs) the env path produces. There is one config type and one set of validation rules downstream of resolution.

3.2 Selection and precedence

  • A new CLI flag --config <path> names a YAML file.
  • --config present → the file is the sole source of Ourios’s configuration. Environment variables are consulted only where the file references them via ${env:NAME} / ${NAME} substitution (§3.3). A bare OURIOS_* env var does not override a value set in the file. (The standard OTEL_* SDK environment is a separate concern entirely — it configures Ourios’s own telemetry SDK, never the data-plane config; see §3.8.)
  • --config absent → the current config_from_env() path runs unchanged (reads OURIOS_* directly). This preserves today’s behaviour exactly and keeps the change non-breaking.

The two modes are mutually exclusive by construction (the presence of the flag selects the front-end); there is no per-key merge between a file and direct env vars. This mirrors the Collector (the file is the configuration; env is an injection mechanism, not an override layer) and avoids a two-sources-of-truth precedence matrix.

3.3 Environment-variable substitution (mirrors the OTel Config WG)

Substitution follows the OpenTelemetry Configuration WG data model and operates on the parsed YAML scalar values, not the raw text: the file is parsed into a node tree first, then each scalar value has its text substituted. Mapping keys are never candidates, and a substituted value is never re-parsed into YAML structure (a mapping or sequence) — so substitution can neither rewrite keys nor inject structure (rules 4–5 below are properties of this approach, not extra post-checks on a text pass; the scalar’s own type tag is still resolved, per rule 7). The grammar for the subset this RFC supports (optional env: prefix + optional :- default; self-contained, non-normative — the full ABNF is the WG spec):

REF      = "${" [ "env:" ] ENV-NAME [ ":-" DEFAULT ] "}"
ENV-NAME = [A-Za-z_][A-Za-z0-9_]*   ; the environment variable to resolve
DEFAULT  = any characters except "}", possibly empty ; used when ENV-NAME is unset or empty

Rules (each is an acceptance scenario in §5):

  1. ${env:NAME} and the prefix-less ${NAME} are equivalent and both resolve NAME from the process environment.
  2. ${env:NAME:-default} / ${NAME:-default} substitute default when NAME is unset or empty.
  3. An undefined reference with no default resolves to the empty string. What that scalar then is follows rule 7: an unquoted empty scalar is read as YAML null, while a double-quoted one ("${MISSING}") yields an empty string.
  4. Scalar-only: substitution applies to scalar values only. A reference appearing in a mapping key position is left verbatim.
  5. Non-recursive: a substituted value is used as-is and is not re-scanned — it can neither inject YAML structure (newlines/keys) nor trigger a second substitution. This is a security boundary, not a convenience limit.
  6. $$ is an escape for a literal $: $${NAME} yields the literal text ${NAME} with no substitution.
  7. Type after substitution: once a scalar’s text is substituted, its type is resolved — a bare (unquoted) substituted scalar is re-interpreted by YAML’s type rules and then deserialized into the target ServerConfig field, so default_window_secs: ${env:W} with W=3600 yields the integer 3600; a double-quoted scalar is forced to a string. Type interpretation therefore happens on the already-parsed scalar, after its value is substituted — never on a pre-parse text pass.
  8. A ${…} reference that does not conform to REF (e.g. ${1BAD}, ${A$B}), encountered in a scalar value during substitution, is a whole-file parse error — no partial resolution, no silent passthrough. Mapping keys are never substituted (rule 4), so a ${…} in a key position is left verbatim whether or not it would conform.

The WG specification’s worked input→output table (data-model § Environment variable substitution) is adopted verbatim as the conformance vector set (§6).

3.4 File schema

The YAML schema maps onto the resolved ServerConfig. Its top-level grouping (storage / receiver / querier / compaction) deliberately echoes the Helm chart’s values.yaml for familiarity, though field names follow the file’s own snake_case convention rather than the chart’s camelCase:

storage:
  backend: s3                       # local | s3
  s3:
    bucket: ${env:OURIOS_S3_BUCKET}
    endpoint: ${env:OURIOS_S3_ENDPOINT:-}   # empty → AWS regional endpoint
    region: us-east-1
    prefix: ""
    # Credentials are NEVER inline literals — only env references (§3.5).
    access_key_id: ${env:OURIOS_S3_ACCESS_KEY_ID:-}
    secret_access_key: ${env:OURIOS_S3_SECRET_ACCESS_KEY:-}
    session_token: ${env:OURIOS_S3_SESSION_TOKEN:-}
  local:
    bucket_root: /var/lib/ourios/data        # backend: local only

receiver:
  enabled: true
  grpc_addr: 0.0.0.0:4317
  http_addr: 0.0.0.0:4318
  wal_root: /var/lib/ourios/wal              # always local (RFC 0019 §3.1)

querier:
  enabled: true
  http_addr: 0.0.0.0:4319
  default_window_secs: 3600

compaction:
  enabled: true
  interval_secs: 300

Parsing is strict: unknown keys are a startup error (deny unknown fields), matching RFC 0004’s “small, deliberately bounded surface”. The same required/optional rules and value validation that build_store_config / build_*_config enforce today apply unchanged to the file-sourced values — there is exactly one validation path after resolution (§3.1).

3.5 Secrets and hygiene (extends RFC 0019 §3.4)

Object-store credentials MUST NOT appear as inline literals in the file. They are expressed only as env references (${env:OURIOS_S3_SECRET_ACCESS_KEY}), which a deployment injects from a Secret. This is enforced: each credential field (storage.s3.access_key_id / secret_access_key / session_token) must be a single ${env:NAME} / ${NAME} reference spanning the whole value, optionally with an empty default (${env:NAME:-}, meaning “unset → fall back to the AWS credential chain”). A literal, a partial reference (prefix-${env:NAME}), or a non-empty default (${env:NAME:-literal}, which would itself embed a secret) is a startup error naming the offending key, never the value. The check runs on the raw value, before substitution — afterwards a reference is indistinguishable from a literal. An absent or empty field is not a literal and is allowed (it reads as unset).

The existing invariant — resolved credentials are never logged, and a config error names the offending key/path, never a value (RFC 0019 §3.4, RFC0019.6) — extends to the file path: substitution errors, schema errors, and the credential-literal error report the YAML key or env-var name, never the resolved secret text. The credential fields are also redacted in the config’s Debug rendering (mirroring ourios_parquet::S3Config).

3.6 Crate placement

A new config module in ourios-server (no new crate; ServerConfig already lives there). The substitution resolver is a pure text→Result<String, _> submodule (config/env_subst.rs) with no dependence on the schema, so it can be property-tested in isolation against the WG vectors.

3.7 Helm chart follow-on (out of scope here)

Migrating the chart from a dozen env vars to a mounted ConfigMap + --config + Secret-backed ${env:…} is a follow-on tracked separately; this RFC only adds the server capability. The chart change is non-breaking-compatible because the env path remains.

3.8 Out of scope: the OTel SDK environment (OTEL_*)

The Ourios config file governs Ourios’s data-plane tunables only. The configuration of Ourios’s own self-telemetry (its OpenTelemetry SDK — RFC 0001 §6.8) is not modeled here: it is driven by the standard OTEL_* environment variables, which the OTel SDK reads directly from the process environment per the OpenTelemetry Environment Variable Specification. There is no otel: section and no bespoke telemetry knob — re-modeling those would duplicate (and drift from) a stable, language- agnostic spec the SDK already implements. The relevant variables are, at least:

  • General: OTEL_SDK_DISABLED, OTEL_SERVICE_NAME, OTEL_RESOURCE_ATTRIBUTES, OTEL_LOG_LEVEL, OTEL_PROPAGATORS.
  • Exporter selection: OTEL_LOGS_EXPORTER / OTEL_METRICS_EXPORTER / OTEL_TRACES_EXPORTER.
  • OTLP exporter: OTEL_EXPORTER_OTLP_ENDPOINT (and per-signal variants), …_PROTOCOL, …_HEADERS, …_TIMEOUT, …_COMPRESSION, …_CERTIFICATE / …_CLIENT_KEY.

So OTEL_* is the one environment namespace that is deliberately not absorbed into the file — it sits beside the file, consumed by the SDK. (Consequence: the chart’s current otel.exporterEndpoint value should become a plain OTEL_EXPORTER_OTLP_ENDPOINT env passthrough — folded into the §3.7 chart follow-on, not this RFC.)

4. Alternatives considered

4.1 Layered: env overrides file

A file as the base with direct OURIOS_* env vars overriding per key (12-factor). Rejected: two ways to set every value and a precedence matrix operators must keep in their heads; diverges from the Collector, which our operators already know. The file-authoritative model with ${env:…} injection covers the same use cases (inject per-environment values, keep secrets out of the file) without the ambiguity.

4.2 A bespoke substitution syntax (or none)

Inventing our own {{VAR}} templating, or only supporting whole-value $VAR. Rejected: the OTel Config WG already specified this grammar including the security edge cases (no structure injection, no recursion); reusing it is less code, less surprise, and directly testable against a published vector table. A bespoke syntax would re-litigate solved problems and surprise Collector users.

4.3 TOML / JSON instead of YAML

Rejected: the Collector, the Helm values.yaml, and Kubernetes manifests are all YAML; an operator configuring Ourios is already in YAML. JSON has no comments; TOML is a third syntax in the stack.

4.4 A full Collector-style provider/URI scheme (--config file:…|env:…|yaml:…, multi-config merge)

The Collector accepts multiple --config URIs across providers and merges them. Rejected as over-scoped for a single binary with a small bounded surface: one --config <path> covers the need. The provider/merge model can be revisited if a real multi-source requirement appears.

5. Acceptance criteria

Scenario ids RFC0020.<m>, referenced from the test code.

Scenario RFC0020.1 — a complete file resolves to the expected ServerConfig Given a YAML file setting storage.backend: s3 with a bucket, an enabled receiver with a wal_root, an enabled querier, and a compaction interval, When the server resolves configuration with --config <that file>, Then the resulting ServerConfig equals the one the equivalent OURIOS_* environment would produce, field for field.

Scenario RFC0020.2 — environment substitution follows the OTel Config WG model Given a file whose scalar values use ${env:NAME}, ${NAME}, ${env:NAME:-default}, a $$-escaped $, and a reference in a mapping key position, When the file is resolved with a known environment, Then ${env:NAME}/${NAME} are replaced by the variable’s value; the default is used when the variable is unset or empty; an undefined reference with no default becomes empty; $$ yields a literal $; the key-position reference is left verbatim; and a substituted value is not re-scanned (no recursive expansion, no injected YAML structure). And the WG specification’s published input→output vectors all hold.

Scenario RFC0020.3 — file is authoritative; bare env does not override Given a file that sets querier.default_window_secs: 1800, When the server is started with --config <that file> and an environment that also sets OURIOS_QUERIER_DEFAULT_WINDOW_SECS=3600, Then the resolved value is 1800 (the file), and the bare env var has no effect.

Scenario RFC0020.4 — no --config preserves the env-only path Given no --config flag, When the server resolves configuration from OURIOS_* variables, Then the resolved ServerConfig is identical to today’s behaviour (the existing config_from_env scenarios continue to pass unchanged).

Scenario RFC0020.5 — invalid configuration fails fast Given a file containing any of: a malformed substitution reference (${1BAD}), an unknown top-level key, or a value the existing validation rejects (e.g. storage.backend: s3 with no bucket), When the server resolves it, Then startup fails with an error identifying the offending key or reference, and no partially-applied configuration is used.

Scenario RFC0020.6 — secret hygiene across the file path Given a file referencing secret_access_key: ${env:OURIOS_S3_SECRET_ACCESS_KEY} with that variable set, When the configuration resolves and when a deliberately invalid sibling value triggers a config error, Then the resolved secret is never emitted to logs, and the error text names the YAML key / env-var name only — never the secret value (extends RFC 0019 §3.4 / RFC0019.6).

6. Testing strategy

Per CLAUDE.md §6.2.

  • Property tests (proptest) for the substitution resolver (config/env_subst.rs, RFC0020.2): generate scalar text with arbitrary interleavings of literals, ${…} refs, defaults, and $$ escapes; assert the invariants (escape round-trips, non-recursion, scalar-only, undefined→empty). The OTel WG worked-example table is encoded as a fixed table test alongside the generators (the normative conformance vectors).
  • Unit tests for schema mapping and validation (RFC0020.1/.3/.5): table of YAML inputs → expected ServerConfig or expected error; the file path and the env path are asserted to converge (RFC0020.1) and to diverge only as specified (RFC0020.3). Reuse the existing build_store_config / build_*_config validation tests as the shared oracle.
  • Regression (RFC0020.4): the existing config_from_env unit tests run unchanged under “no --config”.
  • Secret-hygiene test (RFC0020.6): extends the RFC0019.6 redaction test to the file front-end (assert no secret substring in error/log output; the error names the key).
  • No criterion benchmark — config resolution is a one-shot startup cost, not a hot path.

7. Open questions

  • --config vs OURIOS_CONFIG: also accept an env var naming the config path (convenient for the chart), or flag-only? (Leaning flag-only to keep one selection mechanism; the chart passes the flag.)
  • Empty-vs-unset default semantics: the WG model treats unset and empty identically for :-default. Confirm that matches our “trim, empty → unset” normalisation already used for OURIOS_* (it appears to; verify against build_store_config).
  • Strict unknown-key errors vs warn: this RFC specifies error (deny unknown). Confirm no forward-compat need for tolerated-unknown keys (none expected pre-1.0).
  • Per-tenant overrides (RFC 0004 §3.4): out of scope here; the file configures the server globally. Note for a future RFC whether per-tenant tunables ever want a file representation.

8. References

RFC 0021 — DataFusion / Arrow upgrade


rfc: 0021 title: Coordinated DataFusion / Arrow upgrade — phased behind upstream status: green author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-07-03 supersedes: — superseded-by: —

RFC 0021 — Coordinated DataFusion / Arrow upgrade, phased behind upstream

1. Summary

Upgrade the storage/query dependency stack (epic #314) in two phases, each following what upstream has actually shipped:

  • Phase 1 (now): DataFusion 53.1 → 54.0, one arrow. DataFusion 54 pins arrow/parquet ^58.3 — the same arrow the querier already pulls — so ourios-parquet moves from arrow/parquet 55.2 to 58.3 and the whole workspace unifies on a single arrow. That removes the RFC 0017 row-path workaround (#276): the dual decoder and the schema_force_view_types = false override exist only because two arrow major versions coexist. MSRV moves 1.85 → 1.88 (DataFusion 54’s floor).
  • Phase 2 (when upstream ships it; expected around DataFusion 55): object_store ≥ 0.14 and parquet 59. parquet 59 drops the thrift dependency entirely (clears the GHSA-2f9f-gq7v-9h6m advisory, #295); a DataFusion release that carries object_store 0.14 unblocks #310 and lifts the renovate hold (#313). The quick-xml deny.toml ignores (RUSTSEC-2026-0194/0195) are removed in this phase iff the object_store release pins quick-xml ≥ 0.41 — that may trail phase 2.

The phase boundary is not a preference; it is where upstream currently is: no released DataFusion accepts object_store 0.14 or parquet 59 (DataFusion 54.0.0 pins object_store ^0.13.2, parquet ^58.3.0).

2. Motivation

2.1 The security cluster

thrift 0.17 (GHSA-2f9f-gq7v-9h6m, DoS) enters via parquet 55.2 and is still pinned by parquet 58.3; it is gone only in parquet 59. The advisory is GHSA-only today, so cargo deny does not fail yet — but it will the day RustSec mints an id. The quick-xml DoS advisories (RUSTSEC-2026-0194/0195) are accepted in deny.toml with an explicit removal condition that also sits behind this upgrade chain. Waiting for a single coordinated bump keeps both windows open longer than needed; phase 1 shrinks the eventual security-driven change to a small step.

2.2 The dual-decoder debt (#276)

The RFC 0017 row read path decodes DataFusion’s arrow-58 RecordBatches separately from ourios-parquet’s arrow-55 reader, and pins schema_force_view_types = false to keep the two schemas compatible. Every read-path feature pays this tax twice. Unifying on one arrow removes the second decoder and restores the upstream view-types default.

2.3 Pillar drift

Parquet-on-disk and DataFusion-as-engine are §2 pillars; the longer the stack sits behind upstream, the larger (and riskier) the eventual jump on exactly the code we can least afford to destabilise. Phasing keeps each jump small.

2.4 Why the phases follow upstream

The version locks, as of this writing:

LockFact
DataFusion 54.0.0 → arrow/parquetpins ^58.3.0
DataFusion 54.0.0 → object_storepins ^0.13.2
parquet 58.3 → thriftpins ^0.17 (vulnerable); dropped in parquet 59
object_store 0.14.0 → quick-xmlpins ^0.40.1 (< patched 0.41)
ourios-querier ↔ ourios-parquetmust share one object_store (the querier registers Store::object_store() with DataFusion’s SessionContext, RFC 0013 §2.2)
DataFusion 54.0.0 → rustcMSRV 1.88.0 (workspace documented 1.85 pre-phase-1; now 1.88)

A “single coordinated bump” resolving the whole epic is therefore not constructible from released crates today. What is constructible now — arrow unification — happens to be the riskiest part (it touches the on-disk format pillar), and doing it in isolation means the property/corpus/reconstruction suites validate exactly one change.

3. Proposed design

3.1 Phase 1 — DataFusion 54, arrow 58 everywhere, MSRV 1.88

One coordinated workspace bump: datafusion = 54, and ourios-parquet moves arrow/parquet 55.2 → 58.3 so the lockfile carries a single arrow major. Expected churn:

  • ourios-parquet: writer, reader, schema declaration, encode_records_to_parquet — arrow 55 → 58 API changes. This is the load-bearing on-disk format (§2 pillar #1); the §3.3 and §3.5 invariants below bound the change.
  • ourios-querier: DataFusion 53 → 54 API changes (logical plans, ListingTable / SessionContext, pruning statistics); removal of the RFC 0017 dual decoder and the schema_force_view_types = false override (#276).
  • ourios-bench: compile-level churn only.
  • rust-toolchain.toml note + workspace rust-version 1.85 → 1.88 (documented per CLAUDE.md §6.1; CI already runs a newer stable).

What must not change (the §3 invariants this RFC touches):

  • On-disk bytes are the contract (§3.5). The upgrade introduces no schema change: field names, types, repetition, and the RFC 0005 §3.2 column set stay identical. Files written before the upgrade MUST read identically after it (RFC0021.2). Any arrow-58 behaviour change that would alter written bytes (encodings, statistics defaults) must be pinned back to the current behaviour or explicitly RFC’d as a §3.5 schema migration — not absorbed silently.
  • Bit-identical reconstruction (§3.3). The reconstruction property and corpus tests run unchanged and must stay green.
  • The compactor’s conditional-PUT CAS (RFC 0013 §3.3/§3.4) is untouched — object_store does not move in this phase.

3.2 Phase 2 — object_store ≥ 0.14 + parquet 59 (upstream-gated)

Opens when a released DataFusion carries them (watch DataFusion 55). Scope, known today:

  • object_store 0.13 → 0.14+ API churn concentrated in crates/ourios-parquet/src/store.rs (AmazonS3Builder, PutMode/PutOptions, S3ConditionalPut, list/ list_with_delimiter, UpdateVersion). The compactor’s publish-CAS (RFC0013.3/.4) must be preserved and is re-proven by the existing localstack suite.
  • parquet 59: thrift leaves the lockfile → close #295.
  • Supply chain: object_store 0.14 pulls new transitives (aws-lc-rs / aws-lc-sys family among them) — deny.toml licenses/advisories re-cleared, osv-scanner.toml updated if needed.
  • Renovate: lift the <0.14.0 hold (#313); close #310.
  • quick-xml: drop the RUSTSEC-2026-0194/0195 ignores iff the object_store release pins quick-xml ≥ 0.41; otherwise the ignores stay with their documented removal condition.

3.3 Non-goals

No Parquet schema change, no logs-DSL surface change, no Store trait change, no query-semantics change. This RFC is a dependency migration with pinned invariants, not a feature vehicle.

4. Alternatives considered

4.1 Wait for DataFusion 55 and do one coordinated bump

Rejected: it couples the riskiest migration (arrow 55 → 58 on the on-disk pillar) with the object_store API churn in the same change, leaves #276’s dual decoder and the security windows open for longer, and gambles on DataFusion 55’s actual contents. Phase 1 is exactly the de-risking slice: upstream’s own arrow unification with nothing else moving.

4.2 Fork/patch object_store 0.13 onto quick-xml 0.41

Rejected: a patched fork of a supply-chain-sensitive crate trades a documented, low-exposure DoS ignore for permanent maintenance burden and a worse provenance story.

4.3 Bump only ourios-parquet to parquet 59 (thrift fix first)

Rejected: parquet 59 means arrow 59 in ourios-parquet while DataFusion 54 carries arrow 58 — reintroducing the dual-arrow split (#276) one version higher, on the read and write path this time.

5. Acceptance criteria

Scenario ids RFC0021.<m>. Phase 1 = .1.6; phase 2 = .7.9 (upstream-gated: their stubs land red only when phase 2 opens).

Status note (2026-07-03): phase 1 is complete — .1.6 are discharged (#339 dependency bump, #340 decoder unification; indicative B1/B2 ci-runner run on #340). green here covers phase 1; opening phase 2 lands .7.9 as red stubs and moves the status back to red until they pass.

Scenario RFC0021.1 — one arrow. Given the phase-1 bump, When the workspace lockfile is inspected, Then exactly one arrow major (58.x) and datafusion 54.x are present, and the workspace builds with MSRV 1.88.

Scenario RFC0021.2 — old files read identically (§3.5). Given Parquet files written by the pre-upgrade writer (committed fixture + freshly generated), When the post-upgrade reader reads them, Then every row and column decodes identically to the pre-upgrade reader’s output, with no schema-mismatch errors.

Scenario RFC0021.3 — reconstruction stays bit-identical (§3.3). Given the existing reconstruction property and corpus suites, When they run on the upgraded stack, Then they pass unchanged (no test weakened or deleted).

Scenario RFC0021.4 — the dual decoder is gone (#276). Given the RFC 0017 row read path, When a query renders rows end-to-end, Then decoding goes through the single unified arrow path, schema_force_view_types is no longer overridden, and the RFC 0017 suites pass.

Scenario RFC0021.5 — the pruning thesis holds (B1/B2). Given the benchmarks.md B1/B2 gates, When the query benchmarks run on the upgraded stack (indicative ci-runner pass; authoritative baseline rerun on maintainer opt-in), Then selective-query row-group pruning shows no regression beyond run-to-run noise.

Scenario RFC0021.6 — the full gate is green. Given the phase-1 change, When CI runs, Then the complete suite passes — including s3 integration (localstack) (the CAS paths, untouched) and live-check (weaver).

Scenario RFC0021.7 (phase 2) — CAS survives object_store 0.14. Given the object_store bump, When the RFC0013.3/.4 conditional-PUT localstack suites run, Then concurrent-sweep publish semantics are preserved.

Scenario RFC0021.8 (phase 2) — thrift is gone. Given the parquet 59 bump, When the lockfile is inspected, Then no thrift crate is present (#295 closed).

Scenario RFC0021.9 (phase 2) — supply chain re-cleared. Given the new transitive set, When cargo deny check runs, Then it passes with the renovate hold lifted (#313) and the quick-xml ignores removed iff object_store pins quick-xml ≥ 0.41.

6. Testing strategy

Per CLAUDE.md §6.2. The existing suites are the oracle — this RFC adds one artefact and changes no test semantics:

  • Fixture for RFC0021.2: before the bump, a small Parquet file (representative rows: structured + templated bodies, attributes, non-finite doubles) is generated by the current writer and committed under testdata/; a new test reads it and asserts decoded equality against its committed expected rows. This makes “old files still read” a permanent regression test, not a one-off migration check.
  • Property/corpus/reconstruction suites (§3.3), the RFC 0005 §3.9 absent-column tests, and the RFC 0017 suites run unchanged.
  • RFC0013.3/.4 localstack CAS tests re-prove the store seam (phase 1: unchanged; phase 2: the actual subject).
  • Benchmarks: B1/B2 indicative on ci-runner first, per the standing bench policy; the paid baseline rerun only on explicit opt-in.

7. Open questions

  • DataFusion 55 contents and timing — does it pick up object_store 0.14 and parquet 59 together? (Determines whether phase 2 is one step or two.)
  • aws-lc-rs / aws-lc-sys license family under deny.toml’s allow-list when object_store 0.14 lands (ISC + Apache-2.0 variants; needs review, possibly an exceptions entry).
  • Is an authoritative baseline B1/B2 rerun wanted after phase 1, or indicative-only until phase 2 completes the epic?
  • MSRV cadence: 1.85 → 1.88 is forced here; do we want a documented policy (e.g. “MSRV may follow DataFusion’s floor”) instead of per-RFC decisions?

8. References

  • Epic #314 (this RFC), #310 (object_store 0.14, blocked), #295 (thrift GHSA-2f9f-gq7v-9h6m), #276 (RFC 0017 dual decoder), #313 (renovate hold).
  • RFC 0011 (A1 demotion — context for the bench gates), RFC 0013 (Store / object_store seam, CAS), RFC 0017 (row read path).
  • CLAUDE.md §2 (pillars #1, #3), §3.3 (bit-identical reconstruction), §3.5 (schema migration), §6.1 (MSRV), §6.2 (tests are specifications).
  • deny.toml RUSTSEC-2026-0194/0195 ignore block (removal condition).

RFC 0022 — Queryable attribute columns


rfc: 0022 title: Queryable attribute columns (RFC 0005 amendment) status: green author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-07-03 supersedes: — superseded-by: —

RFC 0022 — Queryable attribute columns (RFC 0005 amendment)

1. Summary

Discharge the typed-attribute amendment that RFC 0005 §3.3 reserved (“the gate is a concrete consumer”) — the consumer exists: the RFC 0002 DSL exposes service, resource.<key>, and attr.<key> as first-class fields, and today they compile to a substring LIKE over the canonical-JSON attribute columns (#146, tracked by #147). That stopgap is correct for string equality and nothing else: no row-group pruning, and ordering / regex comparisons are rejected.

This RFC adds a promoted attribute column set to the RFC 0005 data schema:

  • Each promoted key is projected at write time into its own OPTIONAL Utf8 column (dictionary + page index + bloom filter), named literally after the DSL path (resource.service.name, attr.http.request.method).
  • The promoted set always contains the resource key service.name (the Required, Stable identity attribute of the OTel service resource entity per the semconv registry, the DSL’s bare service field); operators extend it via a new storage.promoted_attributes key that this RFC adds to the RFC 0020 config schema (§3.2).
  • DSL predicates on promoted keys compile to the typed column with the full cmp_op set (ordering + regex) and row-group pruning; a hybrid fallback arm keeps results correct on pre-amendment files and on non-string values. Non-promoted keys keep the RFC 0002 LIKE behaviour unchanged.
  • The JSON columns (attributes, resource_attributes) remain the source of truth. Promoted columns are query-only projections: the read path (RFC 0017 LogRow) never consumes them, so OTLP fidelity and reconstruction are untouched.

Sibling (out of scope here): RFC 0007 §8’s reserved param-predicate pushdown amendment.

2. Motivation

service == "api" and severity >= error | count by template_id is the canonical Ourios query shape (RFC 0002 §1). Today the service half is a LIKE '%{"key":"service.name",…}%' scan over resource_attributes in every row group the other predicates fail to prune. Three concrete costs:

  1. No pruning. The JSON columns carry no useful min/max statistics and no bloom filters (RFC 0005 §3.6 table); an attribute-only query reads the full corpus. That is exactly the failure mode the pillar-2 thesis exists to avoid (CLAUDE.md §2, benchmark gates B1/B2).
  2. Operator gap. Substring-on-JSON can only do exact key+string-value matching, so the DSL rejects ordering and regex on attributes (InvalidQuery) — a visible feature cliff between severity_text =~ "..." and attr.http.route =~ "...".
  3. The reservation is due. RFC 0005 §3.3 deliberately deferred the typed-attribute column set until “we have a concrete consumer”; the DSL surface and #146’s stopgap are that consumer.

3. Proposed design

3.1 Promoted columns in the data schema

For each promoted key, the writer appends one column to the RFC 0005 §3.2 data schema:

PropertyValue
NameThe DSL path, literally: resource.<key> or attr.<key> (so resource.service.name, attr.http.request.method)
Arrow / Parquet typeArrow Utf8 / Parquet STRING logical type over BYTE_ARRAY (matching the RFC 0005 §3.2 string columns), OPTIONAL
ValueThe attribute’s string value, exactly as stored in the JSON column — no truncation, no normalisation
NULL whenThe key is absent on the record, or its value is not a string AnyValue
EncodingsDictionary yes, page index yes, bloom filter yes (extends the §3.6 table)

Rules:

  • service.name is always promoted. The effective promoted set is {resource: ["service.name"] ∪ configured, log: configured}.
  • String values only. A promoted key whose value is an int, bool, double, bytes, array, or kvlist projects NULL. ==/!= predicates on such cells fall through to the JSON arm (§3.3) — precisely the stopgap’s semantics for values it cannot match; ordering/regex predicates are typed-arm-only (§3.3) and never match them. Typed numeric promotion is a future extension (§7).
  • No truncation. Truncating a projected value would make == silently miss; the projection is byte-faithful or NULL. The cardinality/size exposure this creates is handled by telemetry, not by lying (§3.5).
  • Projection, not truth. attributes / resource_attributes keep their RFC 0005 §3.3 contract unchanged. The RFC 0017 read path (LogRow, rendering, OTLP fidelity) continues to decode from the JSON columns only — a divergence between a promoted cell and the JSON is impossible to observe through the read path, and the §5 round-trip suites stay the oracle for fidelity.

Column-name note: literal dots in column names are valid in Parquet and Arrow. On the DataFusion side the compiler must not reference these columns through datafusion::prelude::col("…") — that parses its argument, so col("resource.service.name") reads as a qualified reference (relation resource, column …). The required mechanism is explicit unqualified construction: Expr::Column(Column::new_unqualified("resource.service.name")) (datafusion::common::Column), which treats the whole string as the literal column name. The querier never routes these names through the SQL identifier parser, so no mangling scheme (and therefore no collision handling) is needed. The resource. / attr. prefixes are reserved column-name namespaces in the data schema from this RFC on.

3.2 Configuration (an RFC 0020 schema extension)

storage.promoted_attributes does not exist in RFC 0020’s schema today — this RFC adds it (RFC 0020’s own evolution path for new knobs):

storage:
  promoted_attributes:
    resource: [k8s.namespace.name]   # service.name is implicit, always on
    log: [http.request.method, http.route]  # string-valued keys
  • Keys are plain attribute-key strings, taken literally (no globbing).
  • The set applies to new files at write time; it is not retroactive. Files written under different sets coexist (§3.4).
  • Defaults: empty beyond the implicit service.name — promotion beyond that is an explicit operator decision because each promoted key costs file bytes on every row (§3.5). The key itself is optional: configs that omit it are unchanged.
  • Rollout ordering: RFC 0020 parses strictly — an unknown key is a startup error — so a config carrying storage.promoted_attributes requires a binary at or above this RFC’s green. Upgrade first, extend the config second; rolling back the binary requires removing the key. (Data written meanwhile stays readable either way — §3.4’s unknown-column rule covers files a rolled-back binary encounters.)
  • Per-tenant sets are deferred (§7); the knob is global, consistent with every other RFC 0020 setting.

3.3 Predicate compilation

Promoted-key predicates compile by operator class (P = promoted column, J = the JSON arm — the existing #146 LIKE fragment machinery, which expresses exactly == and, with its presence guard, != on a key + string value, and nothing else):

== / != — the two-arm form:

match_expr(==, v) :=
      (P = v)                          -- typed arm: prunable
   OR (P IS NULL AND J(==, v))         -- fallback arm: pre-amendment
                                       --   files, non-string values

match_expr(!=, v) :=
      (P IS NOT NULL AND P != v)       -- presence check explicit: don't
                                       --   lean on 3-valued logic
   OR (P IS NULL AND J(!=, v))
Ordering (< <= > >=) and regex (=~ / !~) — the typed arm only. J cannot express these (that inexpressibility is why the stopgap rejects them), so there is no fallback arm: `match_expr(op, v)
= (P op v). The explicit consequence: on **pre-amendment files** the column reads as all-NULL (§3.9) and **rows in those files never match an ordering/regex predicate** — a silent non-match, consistent with the DSL's missing-field rule (NULLnever matches), not an error. Operators querying history older than their promotion cutover with these operators get promoted-era data only; the stopgap's answer to the same query was a hardInvalidQuery`, so no existing query degrades.

Both operator classes keep the missing-field semantics the DSL uses everywhere: NULL never matches, and != requires the key present with a different value (P IS NOT NULL AND P != v, mirrored in the JSON arm’s presence guard).

Why the fallback arm is cheap where it matters:

  • Post-amendment files, key present on every row: the row group’s P null-count is 0, so P IS NULL prunes the entire fallback arm and the typed arm’s dictionary/bloom/min-max stats do the work — this is the steady-state fast path.
  • Pre-amendment files: P is absent; the RFC 0005 §3.9 missing-column carve-out reads it as all-NULL, the typed arm matches nothing, and the JSON arm reproduces today’s exact behaviour. No historical file is rewritten and no query returns different rows than the stopgap (only ordering/regex, which the stopgap rejected outright, are newly answerable — and they are answerable only on promoted keys).
  • Mixed row groups (some rows lack the key / hold non-string values): the fallback arm scans that row group’s JSON — correctness costs a scan exactly where a scan is the only correct answer.

Operator set on promoted keys: the full RFC 0002 cmp_op== != < <= > >= (lexicographic, as for every other string field) plus =~ / !~, with the per-class compile above. The RFC 0002 rejection text moves from “attributes don’t support this” to “non-promoted attributes don’t support this”.

Non-promoted keys: compile exactly as today (#146). No behaviour change.

flowchart LR
    Q["attr.k op v"] --> C{k promoted?}
    C -- no --> J["JSON LIKE arm only<br/>(== / != , unpruned)"]
    C -- yes --> T["typed column arm<br/>full cmp_op, bloom + stats prune"]
    T --> O["OR"]
    J2["== / != only:<br/>P IS NULL AND JSON arm<br/>(old files, non-string values)"] --> O
    C -- yes --> J2

3.4 Schema evolution and migration plan (CLAUDE.md §3.5)

  • All promoted columns are OPTIONAL and additive — the §3.9 missing-column carve-out covers every pre-amendment file, and the unknown-column rule covers post-amendment files read by older binaries. This is the same evolution class as RFC 0018’s columns.
  • No rewrite of historical data. The §3.3 fallback arm is the migration plan: old files answer correctly (identically to today) without touching them. Compaction (RFC 0009) naturally re-projects rows it rewrites using the current promoted set, so history converges toward pruneability as a side effect, but nothing depends on that.
  • Changing the configured promoted set between deploys is safe by the same rules (the implicit service.name cannot be removed — §3.1): a key removed from the set stops being projected in new files (old files keep the column; the compiler still emits the two-arm expression whenever the scanned union schema carries the column), a key added starts NULL-backed in history. Scan-time schema union across files with different promoted sets is the ordinary §3.9 case.

3.5 Hazards (CLAUDE.md §4)

  • Cardinality / file bloat (hazard #2). A promoted key with unbounded values (request IDs, URLs with query strings) bloats the dictionary and the bloom filter of its column. Mitigations: the set is opt-in per key (the failure is contained to an explicit operator decision), and the writer emits per-promoted-column byte telemetry (via the weaver registry, §3.6) so the tradeoff is observable. No truncation (§3.1) and no automatic demotion — predictability over cleverness; revisit if telemetry shows real-world foot-guns.
  • Small-file / wide-schema pressure (hazard #4). Each promoted key adds one column chunk per row group. The config default (empty beyond service.name) keeps the floor where RFC 0005 left it.
  • Query DSL leakage (hazard #6). The DSL surface is unchanged — the same field paths gain operators and speed; nothing about column names or promotion leaks into query syntax.

3.6 Telemetry

Per the weaver-registry discipline: an ourios.storage.parquet.promoted.size instrument (attribute: promoted column name) recording per-flush projected bytes, mirroring ourios.storage.parquet.file.size (histogram, UCUM unit By) in both namespace and shape. The unit lives in instrument metadata, not the name, per the OTel metric semantic conventions (“metrics that have their units included in OpenTelemetry metadata SHOULD NOT include the units in the metric name”). Exact instrument fields are settled in the semconv registry entry at implementation time, as always. Query-side pruning is already observable through the RFC 0016 scanned/pruned row-group counters — RFC0022.5 uses them as its oracle.

4. Alternatives considered

  • MAP<STRING,STRING> column (the sketch in RFC 0005 §3.3). One column regardless of set size, but Parquet statistics and bloom filters on a map’s value leaf are not key-scoped, and DataFusion has no map-key predicate pushdown — it prunes nothing. Pruning is the entire point (#147’s ❌ list); rejected.
  • Full flattening (a column per key ever seen). Schema explosion under attribute-key churn, unbounded wide-schema pressure, and every file carries every key’s column chunk. The explicit promoted set is the deliberate, operator-owned subset of this.
  • Name mangling (attr__http_method). Avoids dots in column names but needs an escaping scheme plus collision handling (http.method vs http_method), and the mangled names leak into every diagnostic. Literal names cost only unqualified-column construction on the DataFusion side; chosen.
  • JSON path expressions at query time (DataFusion UDF over the JSON column). Fixes the operator gap but not pruning; strictly worse than the two-arm compile for the same implementation weight.
  • Rewrite history at cutover. A compaction-style backfill would make pruning retroactive but couples the amendment to a corpus-wide rewrite (cost, object-store churn, §3.6 truth-of-storage risk during the swap). The fallback arm delivers correctness without it; convergence via ordinary compaction is free.

5. Acceptance criteria

Scenario ids RFC0022.<m>.

Scenario RFC0022.1 — service.name is always projected. Given records whose resource attributes carry service.name as a string (plus records where it is absent or non-string), When the writer flushes them, Then the file carries an OPTIONAL Utf8 resource.service.name column whose cells equal the JSON values byte-for-byte where the value is a string and are NULL otherwise, and the resource_attributes JSON column is byte-identical to a pre-amendment writer’s output.

Scenario RFC0022.2 — configured keys project the same way. Given storage.promoted_attributes naming a resource key and a log key, When records carrying those keys (string and non-string) are flushed, Then resource.<key> / attr.<key> columns exist with the §3.1 projection semantics, and a key not in the set produces no column.

Scenario RFC0022.3 — old files answer identically (§3.9 / §3.4). Given a scan spanning a pre-amendment file (no promoted columns) and a post-amendment file, When service == X / attr.<k> == X / != queries run, Then the result set equals the pure-LIKE compile’s result set on the same data, row for row.

Scenario RFC0022.4 — full operator set on promoted keys only. Given a promoted key and a non-promoted key, over a scan spanning a pre-amendment file and a post-amendment file, When ordering (<, >=, …) and regex (=~, !~) predicates are issued against each, Then the promoted key answers them from the typed arm only — rows in the pre-amendment file never match (§3.3’s documented silent non-match) — and the non-promoted key still rejects them with InvalidQuery, ==/!= continuing to work as today.

Scenario RFC0022.5 — promoted predicates prune (pillar 2). Given a multi-row-group corpus where a promoted key’s value is concentrated in a minority of row groups, When a selective equality query on that key runs, Then the RFC 0016 scanned/pruned counters show pruned > 0 (scanned < total), and B1/B2 gates are unchanged (indicative ci-runner; authoritative on maintainer opt-in, per the standing bench policy).

Scenario RFC0022.6 — the read path is projection-blind (§3.1). Given files with promoted columns, including a hand-forged file where a promoted cell disagrees with the JSON, When rows are returned through the RFC 0017 read path, Then every OTLP field round-trips from the JSON columns exactly as before — the forged promoted cell is invisible — and the existing full-fidelity suites pass unchanged.

Scenario RFC0022.7 — promoted-set drift across deploys (§3.4). Given three files written under configured promoted sets {}, {a}, {a,b} for keys a,b (each on top of the implicit, non-removable service.name), When one scan spans all three and predicates on a and b run, Then the scan unions schemas without error and each predicate returns the correct rows from every file (typed arm where the column exists and is non-NULL, JSON arm otherwise).

6. Testing strategy

Per CLAUDE.md §6.2. RFC0022.1/.2 are writer unit + footer-inspection tests in ourios-parquet (encodings asserted from the Parquet metadata, as the RFC 0005 §3.6 suites do). RFC0022.3/.4/.7 are querier acceptance tests over generated old/new file mixes — .3 reuses the pre-amendment fixture discipline RFC 0021 §6 established (a committed file written before the schema change). RFC0022.6 extends the RFC 0017 fidelity suites with a forged-divergence file. RFC0022.5 is a deterministic pruning test in the shape of rfc0007_1_* (counters, not wall-clock), plus the indicative bench dispatch. Property tests: the projection function (AnyValue → cell) round-trips against the canonical-JSON encoder for arbitrary string values (proptest, shared generators with the RFC 0001 §6.1 codec suite).

7. Open questions

  1. Typed numeric promotion. Numeric attributes split into two cases today. A string-encoded number (“500” as a string AnyValue) projects and compares lexicographically — >= "500" works within one magnitude, cross-magnitude comparisons don’t. A true numeric AnyValue (http.status_code as an int, the common OTLP emission) projects NULL (§3.1), so ordering/regex predicates on it silently never match and even == only answers through the JSON arm. A future Int64-typed promotion class (per-key type declaration in config) is what makes numeric attributes first-class; deferred until a consumer demands it.
  2. Per-tenant promoted sets. Global-only in this RFC. Multi-tenant operators with divergent schemas may want scoping; the column mechanism doesn’t change, only config addressing.
  3. Automatic demotion / cardinality guards. Telemetry-first (§3.5); revisit if promoted-column bloat shows up in practice.
  4. Bloom filter sizing. Writer defaults initially; per-key tuning is config surface we can add without schema impact.

8. References

  • #147 (this amendment’s tracking issue), #146 (the LIKE stopgap PR), RFC 0002 (#143 epic) — the DSL field surface.
  • RFC 0005 §3.2 (data schema), §3.3 (AnyValue encoding rule + the reserved amendment this RFC discharges), §3.6 (encodings table this RFC extends), §3.9 (evolution rules the migration plan leans on).
  • RFC 0016 (scanned/pruned counters — the RFC0022.5 oracle).
  • RFC 0017 (the projection-blind read path in RFC0022.6).
  • RFC 0020 (the config schema this RFC extends with storage.promoted_attributes; strict parsing → §3.2 rollout ordering).
  • RFC 0007 §8 (the sibling param-pushdown reservation, untouched).
  • CLAUDE.md §2 pillar 2, §3.5 schema-migration invariant, §4 hazards #2/#4/#6.

RFC 0023 — Bounded template memory


rfc: 0023 title: Bounded template memory (RFC 0001 amendment) status: green author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-07-04 supersedes: — superseded-by: —

RFC 0023 — Bounded template memory (RFC 0001 amendment)

1. Summary

The miner’s per-tenant template store grows without bound. The first 10–100 GiB scale run (2026-07-04, LogHub HDFS_v2 — 16 GiB / 71 M lines of Hadoop daemon logs, on baseline-8vcpu-32gib) was OOM-killed at 31.5 GiB RSS during the B2 store build: the miner had minted ≥ 56,000 templates by the 1.8 GiB mark (the busiest covering only 0.67 % of rows), with memory growing roughly linearly at ~2× corpus bytes. The bench-side suspects were eliminated first — the corpus loader streams (#350) and the harness’s quadratic snapshot capture was fixed (#351) — leaving the miner’s tree itself as the proven cause.

This is not bench-only: the production ingester runs the same MinerCluster, so a single tenant shipping shape-diverse logs (stack traces, multi-format daemon output) can OOM an ingester pod. That is a direct hit on hazards #1 and #2. Upstream Drain3 carries max_children and a cluster cap for exactly this input class; MinerConfig today has neither.

This RFC adds three configurable bounds — a per-node fan-out cap, a per-tenant template ceiling, and a per-line token cap — with one overflow rule everywhere: fail honestly (parse-failure path, body retained, counted and observable), never force-merge. The §3.1 no-silent-merge invariant is load-bearing throughout.

2. Motivation

  • Hazard #2 (cardinality blowup), tree edition. RFC 0001 §6 bounds parameter bytes (param_byte_limit) but nothing bounds the number of leaves or the token width of a stored template. A corpus whose lines are structurally diverse (HDFS_v2’s node logs interleave block events, GC lines, and multi-hundred-token stack traces) mints a new leaf every few lines forever.
  • Measured, not hypothetical. The scale-run evidence chain: streaming loader held 1.3 GiB flat for hours (loader exonerated); gdb stack samples during the slow phase landed in bench-harness snapshot capture (CPU pathology fixed in #351, miner CPU exonerated); the rerun then OOM-killed at 31.5 GiB anon RSS (dmesg), while 1.1 GiB and 1.8 GiB subsets completed — with the 1.8 GiB subset showing template ids ≥ 56,199. Linear growth at ~2× corpus bytes extrapolates exactly to the observed kill.
  • The fragmentation itself is a correctness smell. 56 k templates with the busiest at 0.67 % of rows means pillar #2’s logical reduction (50–200×) has failed on this corpus shape: pruning value collapses along with memory. A bounded miner turns that failure mode from “process dies” into “observable degradation with bodies retained”.

3. Design

3.1 Three bounds, one overflow rule

All three are MinerConfig fields, enforced per tenant (the tree is per-tenant, CLAUDE.md §3.7). Overflow never attaches a line to a template it did not match (§3.1 no-silent-merge); it takes the RFC 0001 §6.3 parse-failure path: template_id = NO_TEMPLATE, body retained verbatim, counted.

  1. max_node_children (default 100, Drain3’s default) — cap on an internal prefix node’s distinct-token children. When a node is full, unseen tokens route through a <*> wildcard child (minted on first overflow) instead of a new branch. This bounds tree width. Routing is not merging: leaf attach below the wildcard child stays simSeq-gated exactly as everywhere else — a line that matches no leaf at or above the floor still mints its own leaf (subject to bound 2) or fails parse.
  2. max_templates (default 20,000) — per-tenant ceiling on Drain-tree leaves. At the ceiling, both minting paths (the §6.3 lossy-zone new leaf and the no-candidate new leaf) divert to parse-failure. The first ceiling hit per tenant logs a structured warning; every diverted line increments the parse-failure counter with a reason attribute (§3.4). Existing leaves keep widening normally — the ceiling stops growth, not matching.
  3. max_line_tokens (default 512) — lines that tokenize past the cap go straight to parse-failure with the body retained. This bounds stored-template token width (a 900-token stack-trace line today mints a 900-token template) and, with bound 2, makes worst- case tree memory a computable product instead of an open-ended sum.
flowchart LR
    L[line] --> T{"tokens ≤ max_line_tokens?"}
    T -- no --> PF["parse-failure:<br/>body retained, counted"]
    T -- yes --> D["descend tree<br/>(full node → wildcard child)"]
    D --> M{"simSeq vs leaves"}
    M -- "≥ threshold" --> A[clean attach / widen]
    M -- "lossy zone /<br/>no candidate" --> C{"leaves < max_templates?"}
    C -- yes --> N[mint new leaf]
    C -- no --> PF
    M -- "< floor" --> PF

3.2 Why fail-honest instead of Drain3’s alternatives

Drain3 under pressure either force-merges into the nearest cluster or LRU-evicts old clusters (max_clusters). Both are wrong here:

  • Force-merge is precisely the §3.1 corruption the project treats as its worst failure: a search for one event returning another’s rows. Rejected outright.
  • LRU eviction invalidates template_ids already written into Parquet: the read-time registry (RFC 0017) renders rows from the audit-derived template history, and eviction either breaks those renders or demands tombstone machinery in the audit stream. That cost isn’t justified before a real tenant needs template churn (as opposed to a cap); deferred to §7.

Parse-failure with body retention is already a first-class, bit-faithful path (RFC 0001 §6.3, C1 excludes it by construction and the body column preserves the line exactly), so overflow degrades to “unmined but fully stored and searchable” — the honest floor.

3.3 What does not change

  • No schema change. Parquet layout, template_id semantics, and every existing file are untouched (CLAUDE.md §3.5 satisfied trivially).
  • Healthy corpora are unaffected. HDFS_v1, the OTel-Demo captures, and the seed corpus mine to well under 5 % of the default ceiling with fan-out far below 100; defaults must be invisible there (RFC0023.5 pins byte-identical template sets).
  • Existing knobs keep their meaning. similarity_threshold, similarity_floor, param_byte_limit, prefix_depth are untouched; the new bounds compose with them.

3.4 Telemetry (weaver registry, per the standing discipline)

  • ourios.miner.parse_failures (existing counter) gains a ourios.miner.parse_failure.reason attribute — values below_floor | line_too_long | template_ceiling — following the OTel “error.type on an existing instrument” convention rather than minting per-cause counters.
  • ourios.miner.template.count (existing gauge) is the ceiling’s observable: count == max_templates plus a non-zero template_ceiling failure rate is the operator’s saturation signal.
  • Exact registry entries are settled in semconv/registry/ at implementation time via weaver registry generate, as always.

3.5 Configuration surface

The bounds land as programmatic MinerConfig fields with the defaults above. Exposure in the RFC 0020 config file (a miner.* section) is a small follow-up schema extension in the RFC 0020 evolution style — the same pattern storage.promoted_attributes used (RFC 0022 §3.2) — and is not required for this RFC to go green: defaults protect every deployment immediately.

4. Alternatives considered

  • Byte-budget accounting (cap tree bytes, not counts). More direct, but the trigger becomes opaque (“why did mining stop at 17:42?”) and the accounting itself is invasive. Count × width caps give the same asymptotic bound with explainable, testable knobs.
  • Force-merge under pressure (Drain3 default-ish). Violates §3.1; rejected — see §3.2.
  • LRU eviction (max_clusters). Breaks written-data guarantees; deferred — see §3.2 / §7.
  • Do nothing, document the limit. Leaves the ingester OOM-able by a single tenant’s log shape — an operational DoS vector (hazard #2) — and leaves the 10–100 GiB thesis gates unmeasurable.

5. Acceptance criteria

Scenario ids RFC0023.<m>.

Scenario RFC0023.1 — the ceiling holds and never merges. Given a MinerConfig with a small max_templates and a corpus that would mint more, When the corpus is ingested, Then the tenant’s template count plateaus at the ceiling, every would-mint line takes the parse-failure path with its body retained, and no overflow line is attached to any existing template (no silent merge: template row sets are identical to an uncapped run truncated at the ceiling).

Scenario RFC0023.2 — overflow lines stay stored and searchable. Given ceiling-overflow lines from RFC0023.1 written to Parquet, When the bodies are read back, Then each round-trips bit-identically through the body column.

Scenario RFC0023.3 — node fan-out caps via wildcard routing. Given a corpus whose lines present more than max_node_children distinct tokens at one prefix level, When ingested, Then the node’s child count never exceeds the cap, later tokens route through the wildcard child, and attach under that child remains threshold-gated (a below-floor line still fails parse rather than merging).

Scenario RFC0023.4 — the long-line guard. Given a line tokenizing past max_line_tokens, When ingested, Then it takes the parse-failure path, its body round-trips bit-identically, and no template of that width exists in the tree.

Scenario RFC0023.5 — defaults are invisible on healthy corpora. Given the default bounds, When the corpus suites (HDFS_v1, seed, OTel-Demo captures) run, Then the mined template sets are identical to an unbounded run (C1/C2 and the reconstruction property suites pass unchanged).

Scenario RFC0023.6 — saturation is observable. Given a ceiling-saturated tenant, When telemetry is scraped, Then ourios.miner.parse_failures carries reason = template_ceiling increments and ourios.miner.template.count reads the ceiling value.

Scenario RFC0023.7 — the scale run completes (the falsifier). Given LogHub HDFS_v2 (16 GiB) on baseline-8vcpu-32gib under default bounds, When the B1/B2 store builds run, Then mining completes with peak RSS under 8 GiB and the query benches produce results (indicative ci-runner first, authoritative on maintainer opt-in, per the standing bench policy). If bounded mining still cannot complete this corpus, the design is wrong — reopen.

6. Testing strategy

Per CLAUDE.md §6.2. RFC0023.1/.3/.4 are miner unit + property tests (proptest over adversarial token streams for the no-silent-merge half: an overflow line’s row must never carry another template’s id). RFC0023.2 rides the existing writer round-trip suites. RFC0023.5 is the existing corpus gate rerun under defaults — the “tests are specifications” tripwire for this whole RFC: no existing suite may be weakened to make the bounds fit. RFC0023.6 uses the in-memory meter harness the other miner-metric tests use. RFC0023.7 reuses the scale runner (scratch/baseline/) with its peak-RSS sampler.

7. Open questions

  1. Eviction / template aging. Long-lived tenants with genuine template churn (deploys renaming log sites) will eventually fill any ceiling with dead templates. An aging mechanism needs audit tombstones + registry support; deferred until a consumer exists.
  2. Per-tenant overrides. Global defaults now, consistent with every RFC 0020 knob; revisit with multi-tenant operations.
  3. Ceiling-hit audit event. A system-scoped audit event (the RFC 0008 §9 deferred family) would give drift queries visibility into when saturation began; metrics-only for now.
  4. miner.* config-file section — §3.5 follow-up.

8. References

  • Scale-run evidence (2026-07-04): attempt logs + subset probes retained by the maintainer; summarized in docs/benchmarks.md §9.10 and §1 above. Bench-side fixes: #350 (streaming corpus loads), #351 (snapshot-capture skip).
  • Drain3 (logpai/Drain3): max_children, max_clusters — the upstream mechanisms this RFC adapts (adopting the first, rejecting the second’s eviction semantics for §3.2’s reasons).
  • RFC 0001 §6.2 (tree walk), §6.3 (three-zone model + parse-failure path this RFC reuses as its overflow floor).
  • CLAUDE.md §2 pillar 2, §3.1 (no silent merges), §3.7 (per-tenant scoping), §4 hazards #1/#2.

RFC 0024 — OTLP-envelope property testing


rfc: 0024 title: OTLP-envelope property testing and corpus-calibrated generation (RFC 0006 amendment) status: green author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-07-05 supersedes: — superseded-by: —

RFC 0024 — OTLP-envelope property testing and corpus-calibrated generation (RFC 0006 amendment)

1. Summary

The verification surface has two layers today, and a gap between them. Frozen corpora (RFC 0006: the seed corpus, the OTel-Demo captures, the LogHub stress family) exercise reality — but only the exact records that happened to be captured. Property suites (RFC 0003’s wire-decode equivalence over the proto value space, the miner’s hazard and RFC 0023 fanout properties) exercise arbitrary inputs — but each at one unit’s boundary, never through the full ingest → store → query pipeline.

The gap: nothing generates realistic-but-arbitrary OTLP and asserts end-to-end invariants over it — and the strongest such invariant, query-result correctness against an independent oracle, does not exist anywhere in the suite today.

This RFC amends RFC 0006 with:

  1. Calibration manifests — small, committed distribution summaries extracted from a real capture (attribute-count and body-length histograms, severity mix, AnyValue shape frequencies), so generators are shaped by measured reality rather than guesses.
  2. OTLP-envelope generatorsproptest strategies over OtlpLogRecord, with a calibrated mode (the realistic centre) and an adversarial mode (the envelope’s legal extremes).
  3. Four end-to-end properties — bit-faithful round-trip, no silent merge, RFC 0023 bounds, and the query oracle: for generated data and generated predicates, the querier’s answer must equal an independent linear-scan evaluator’s.

Scope is OTLP only, per the standing product decision: legacy log formats are Collector concerns; generators target the OTLP envelope space exclusively.

2. Motivation

  • There is no at-scale OTLP corpus to test against. OTLP logging is the least-adopted OTel signal; public corpora at the §8 sizes are legacy text. The demo captures are real OTLP but friendly — a dozen well-behaved services will never emit deeply nested AnyValue bodies, thousand-entry attribute maps, zero timestamps, or adversarial attribute keys. Production feeds are the only truly representative corpus and arrive only after deployment. Generation is the pre-production instrument that covers the space around the captures.
  • The §9.11 lesson generalises. The 16 GiB run surfaced an input-shape-driven failure (unbounded template minting) that no existing corpus had triggered. RFC 0023 bounded it; this RFC makes “an input shape we didn’t anticipate” a generated, repeatable test class instead of a paid-infrastructure discovery.
  • Query correctness has no oracle. C1 pins reconstruction; RFC0022.3 pins old-file parity against the prior compile; but no test asserts that a DSL query returns the right rows against an independent evaluator over data the test didn’t hand-shape. For a query backend, that is the invariant users actually rely on.

3. Design

3.1 Calibration manifests

A calibration.json per corpus release (committed under testdata/calibration/<corpus-tag>.json, single-digit KiB), extracted by a new ourios-bench --calibrate <corpus-dir> pass:

  • attribute-count histogram (per-record resource + log attributes),
  • body length histogram and body_kind mix,
  • severity number/text distribution,
  • AnyValue shape frequencies (string / int / double / bool / bytes / array / kvlist, and nesting depth),
  • distinct-key counts for attribute keys (cardinality signal).

The manifest is a measurement, versioned with the corpus it summarises; regenerating it is deterministic for a given corpus.

3.2 Generators

proptest strategies over [OtlpLogRecord] (the RFC 0003 §6.6 in-memory shape — generation happens past wire decode, which the RFC 0003 equivalence suites already cover):

  • Calibrated mode — field distributions weighted by a calibration manifest. Statistical, not exact: the §5 sanity criterion checks gross moments, not equality.
  • Adversarial mode — uniform-ish over the envelope’s legal extremes, bounded only by documented product limits: AnyValue nesting to the canonical-JSON depth bound, attribute maps to a few thousand entries, empty/absent everything, zero and u64::MAX timestamps, non-ASCII and confusable keys, text-heavy bodies past max_line_tokens (the Collector-fronted-legacy shape).

Both modes will live in crates/ourios-testgen, a dev-only crate the calibration green slice introduces (no production crate grows a proptest dependency; ourios-bench cannot host them because it already depends on ourios-querier, and the querier’s P4 suite consuming generators from it would create a dev-dependency cycle). The crate is test infrastructure; naming it in this RFC satisfies CLAUDE.md §7, which treats any new crate as an architectural commitment requiring an RFC. It will never be published, and nothing in the workspace’s production graph will depend on it.

3.3 The four properties

Over generated batches (both modes), through the real pipeline (MinerCluster → RFC 0005 writer → reader / querier):

  • P1 — round-trip fidelity. Every generated record’s stored form round-trips per the RFC 0017/0018 fidelity contract; string bodies bit-identical, structured bodies canonical-JSON equal.
  • P2 — no silent merge. A generated record’s row carries either a template its line actually attached to under §6.3’s zones, or NO_TEMPLATE with the body retained — never another line’s template. (The §3.1 invariant, now under arbitrary input.)
  • P3 — bounds hold. RFC 0023’s three bounds are never exceeded mid-stream: template count ≤ ceiling, node fan-out ≤ cap, over-long lines always divert. (Generalises the tree-level fanout property to the full pipeline.)
  • P4 — the query oracle. For a generated batch written to a store and a generated predicate from the supported DSL surface (severity / time-window / template-id / promoted- and non-promoted-attribute equality), the querier’s row count equals an independent in-memory evaluator’s over the same MinedRecords. The reference evaluator is deliberately naive (linear scan, no DataFusion) — its correctness must be reviewable by eye.

Case counts: CI runs proptest defaults (fast, deterministic regressions via committed failure persistence); a scheduled deep run may crank PROPTEST_CASES (§7).

3.4 What this does not change

No production code paths, no schema, no telemetry. This is test infrastructure; RFC 0006’s corpus methodology and every recorded §9 number are untouched. The LogHub family keeps its role as the Collector-output stress corpus.

4. Alternatives considered

  • More frozen corpora only. Necessary (the v7 capture is happening) but not sufficient: a corpus can only contain what its emitters emitted; §9.11-class findings live in the combinations.
  • Fuzzing the full pipeline (cargo-fuzz). The existing fuzz targets cover wire decode, where coverage-guided byte mutation shines. Pipeline invariants need structured inputs and cross-checked outputs — property testing’s home ground.
  • Differential testing against another backend (e.g. DuckDB over the same Parquet). Powerful but heavyweight; P4’s naive evaluator buys most of the assurance at a fraction of the machinery, and the Parquet files remain externally checkable by hand when wanted.

5. Acceptance criteria

Scenario ids RFC0024.<m>.

Scenario RFC0024.1 — calibration extraction. Given a corpus release, When --calibrate runs, Then a deterministic manifest is produced (byte-identical on rerun) and committed alongside the corpus tag it summarises.

Scenario RFC0024.2 — calibrated generators are shaped by the manifest. Given a calibration manifest, When N records are generated, Then gross distribution moments (mean attribute count, body-length quartiles, severity mix) fall within a documented tolerance of the manifest’s.

Scenario RFC0024.3 — P1 holds. Round-trip fidelity over generated batches, both modes.

Scenario RFC0024.4 — P2 holds. No silent merge over generated batches, both modes.

Scenario RFC0024.5 — P3 holds. RFC 0023 bounds over generated streams with deliberately tiny configured bounds.

Scenario RFC0024.6 — P4 holds. Query-oracle equality over generated batches and generated predicates, covering every operator class the DSL supports on each field kind — including at least one promoted-attribute predicate (RFC 0022’s two-arm compile) and one non-promoted one.

Scenario RFC0024.7 — adversarial mode finds nothing today. The full property set passes at an elevated case count on the adversarial generators. (This scenario is the regression tripwire: any future failure here is a minimal reproducer by construction.)

6. Testing strategy

The RFC is testing strategy; the §5 scenarios are the suites themselves. Failure persistence files are committed so any generated counterexample becomes a permanent regression case. The properties run in the crates that own the invariant (miner: P2/P3; parquet: P1; querier: P4) so a failure lands at the responsible boundary.

7. Open questions

  1. Deep-run cadence. A scheduled high-case-count run (nightly? weekly?) vs CI-only defaults — decide once the suite’s wall-clock is known.
  2. Trace/metric envelopes. Out of scope (logs backend), noted only because the demo capture contains correlated trace ids that generators should populate realistically.

8. References

  • RFC 0006 (bench corpus methodology — amended), RFC 0003 §6.6 (the generated shape) and its wire-decode property suites, RFC 0017/0018 (fidelity contracts P1 pins), RFC 0022 §3.3 (the two-arm compile P4 must cover), RFC 0023 (the bounds P3 pins; §9.11 for why generated shapes matter).
  • Standing scope decision (2026-07-05): OTLP only; legacy formats are Collector concerns.

RFC 0025 — Absent-body representation


rfc: 0025 title: Absent-body representation and permanent-encode-error quarantine (RFC 0005 amendment) status: green author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-07-05 supersedes: — superseded-by: —

RFC 0025 — Absent-body representation and permanent-encode-error quarantine (RFC 0005 amendment)

1. Summary

A legal OTLP log record with an absent body (LogRecord.body unset) is currently a poison pill: the receiver materializes it faithfully (body: None), the miner emits it faithfully (BodyKind::Absent, RFC 0001 §6.1), and the Parquet encode rejects it permanently (BatchError::UnsupportedAbsentBody — RFC 0005 §3.2’s body_kind column pins ordinals 0 = String, 1 = Structured). The ingest sink retains its buffer on flush error, so one absent-body record halts Parquet persistence for its (tenant, hour) partition forever and pins buffer memory (#362, found by the RFC 0024 adversarial suite on its first run).

This RFC amends RFC 0005 with:

  1. A third body_kind ordinal2 = Absent — with a NULL body cell, making the wire-legal state representable on disk.
  2. A read-path contract — absent-body rows render with no body (the RFC 0017 LogRow carries none), never as an empty string.
  3. A sink quarantine rule — a permanent encode error must never wedge a partition: the sink separates the rejected record(s) from the buffer, persists the rest, and surfaces the rejection through the existing flush-error counter with an error.type attribute. Defense in depth: with (1) in place, UnsupportedAbsentBody disappears, but the wedge mechanism would fire identically for any future permanent BatchError (timestamp overflow is one that exists today).

2. Motivation

  • Absent bodies are spec-legal and real. OTLP permits records with no body — event-shaped records carrying only event_name + attributes are the canonical case. A backend that wedges on them fails the RFC 0003 fidelity posture from the wire side.
  • The failure mode is silent and unbounded. The WAL holds the acknowledged data (§3.4 holds), but the ingest→Parquet path stalls for the partition; buffers grow to the memory ceiling; nothing reaches object storage. Operators see a flush-error counter tick and stalled data — the worst diagnosis surface.
  • Timestamp overflow shares the mechanism. A record whose observed_time_unix_nano exceeds i64::MAX is also a permanent encode rejection today; quarantine fixes both.

3. Design

3.1 Schema (RFC 0005 §3.2 amendment)

body_kind gains ordinal 2 = Absent. For such rows the body column is NULL, params and separators are empty, and lossy_flag = true is retired for this case: absence is not loss — the row reconstructs to “no body” exactly. The miner’s emission changes from lossy_flag = true to false for BodyKind::Absent rows (RFC 0001 §6.1 note: reconstruction is defined and total — it renders nothing).

Migration (§3.5 compliance): additive only. Old files never contain ordinal 2 and remain fully readable. Old readers (any pre-amendment binary) encountering a future file with ordinal 2 must error per the §3.2 shape-validation contract — this is the standard forward-compatibility posture already pinned by RFC0005.14 (unknown-ordinal rejection), and operators upgrade readers before writers as with every schema-affecting release. No historical rewrite.

3.2 Read path (RFC 0017 amendment)

  • Reader accepts ordinal 2 and materializes body_kind = Absent, body = None.
  • Query rendering (LogRow): the body field is absent (None / omitted in JSON), not "" — an empty string body is a different legal record.
  • The RFC 0002 DSL: absent-body rows match non-body predicates normally; body-text predicates never match them.

3.3 Sink quarantine (ourios-ingester)

On flush, when the encode fails with a permanent BatchError (the existing is_transient split already classifies this):

  1. Bisect the buffer to the offending record(s) (binary search on singleton encodes — O(k·log n) for k poison records, and k is almost always 1).
  2. Emit the poisoned record(s) to the audit stream (event kind: record_quarantined, carrying the tenant, the partition key, and the error text; the WAL retains the record itself) and drop them from the buffer.
  3. Flush the remainder normally.
  4. Count via the existing flush-error counter with error.type = the BatchError variant name (per the OTel recording-errors convention — no new metric).

The WAL retains the record (durability unchanged); the quarantine audit event is the operator’s pointer for manual recovery or replay after a fix. The cadence-drain publish path applies the same rule — both routes to the encoder quarantine rather than requeue. No new config: quarantine is not optional behavior — the alternative is the wedge.

4. Alternatives considered

  • Map absent to Body::String("") at the receiver. Destroys fidelity (RFC 0017/0018): empty-string and absent are distinct wire states, and the read path already distinguishes them.
  • Drop absent-body records at the receiver. Data loss for spec-legal input; violates the acknowledged-data contract.
  • Retry-forever with alerting (status quo + alarm). Leaves the partition wedged and the memory pinned; alerting on an unbounded failure is not a fix.
  • Quarantine to a side file instead of the audit stream. A new on-disk artifact class (lifecycle, retention, discovery) for a rare event the audit stream already models.

5. Acceptance criteria

Scenario ids RFC0025.<m>.

Scenario RFC0025.1 — absent bodies round-trip. Given a mined BodyKind::Absent record, When it is written and read back, Then every RFC 0005 §3.2 column round-trips, body is NULL, and the RFC 0024 P1 suite’s pinned-rejection arm for absent bodies is replaced by round-trip assertion.

Scenario RFC0025.2 — old files unaffected. Given a pre-amendment file, When read by the amended reader, Then results are identical to the prior reader (committed-fixture parity, the RFC 0021 §6 discipline).

Scenario RFC0025.3 — rendering distinguishes absent from empty. Given one row with body = "" and one with body_kind = Absent, When both are rendered through the query path, Then the empty-string row carries "" and the absent row carries no body field.

Scenario RFC0025.4 — the sink no longer wedges. Given a buffer containing an absent-body record (pre-amendment encoder simulated) or a timestamp-overflow record, When flush runs, Then the healthy records persist, the poisoned record is quarantined to the audit stream with a record_quarantined event, and subsequent flushes of the partition succeed.

Scenario RFC0025.5 — quarantine telemetry. Given a quarantine, Then the existing flush-error counter increments with error.type set to the BatchError variant, and no new metric name is introduced.

6. Testing strategy

RFC0025.1/.3 as integration tests in ourios-parquet / ourios-querier; RFC0025.2 via the committed pre-amendment fixture; RFC0025.4/.5 in ourios-ingester (the quarantine path is deterministic — no property machinery needed, though the RFC 0024 adversarial umbrella inherits coverage automatically once the P1 arm flips).

7. Open questions

  1. Miner sentinel for absent bodies. Absent rows currently take the NO_TEMPLATE id with lossy_flag = true; with §3.1 they keep NO_TEMPLATE but drop the lossy flag. Should they instead share the structured-sentinel mechanism (per (severity, scope))? Deferred — NO_TEMPLATE is adequate and queryable.
  2. Quarantine replay tooling. The audit event carries the WAL position; an operator replay-quarantined subcommand is deferred until demand exists.

8. References

  • #362 (the finding), RFC 0024 §2 (the suite that found it), RFC 0005 §3.2 (body_kind ordinals), RFC 0001 §6.1 (BodyKind::Absent emission), RFC 0017 (read-path fidelity), RFC 0008 (WAL durability the quarantine leans on), RFC 0015 §9 of RFC 0008 (audit-event precedent for system-scoped events).

RFC 0026 — Authentication & tenant binding


rfc: 0026 title: Authentication and tenant binding (ingest + query) status: accepted author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-07-05 supersedes: — superseded-by: —

RFC 0026 — Authentication and tenant binding (ingest + query)

1. Summary

Ourios’s multi-tenancy is structural but unauthenticated. The ingest side derives tenant_id from resource attributes the sender controls (RFC 0003 §6.3), and the query side takes the x-ourios-tenant header on faith (RFC 0016 shipped deliberately as “trusted-network for v1; authn as a follow-up RFC”). Any client that can reach either listener can write into and read from any tenant. RFC 0003 §9 has carried the open question — “does the authenticated identity feed into the tenant_id derivation?” — since the receiver landed. This RFC is that follow-up:

  1. Ingest authn — static bearer tokens on the OTLP listeners (gRPC metadata / HTTP Authorization), configured through the RFC 0020 config file with ${env:VAR} substitution so secrets never live in the file.
  2. Query authn — the same token mechanism on the RFC 0016 HTTP API (and thereby everything layered on it, e.g. RFC 0027).
  3. Tenant binding (authz) — each token carries an allowed tenant set. Ingest: the RFC 0003 §6.3 attribute-derived tenant must fall inside the token’s set, else the batch is rejected before the WAL ack. Query: the x-ourios-tenant header must fall inside the token’s set. This closes RFC 0003 §9: identity constrains derivation rather than replacing it.

Transport encryption stays delegated (TLS termination at the operator’s proxy, per the existing posture); this RFC is identity and scoping, not channels.

2. Motivation

  • The gap is now user-facing. The tester-recruitment push invites people to run Ourios beyond localhost; the first shared deployment turns “structural tenancy” into “no tenancy” — sender-controlled attributes choose the tenant, so isolation is cooperative, not enforced. §3.7 (“multi-tenancy is not bolted on”) demands the enforcement half before exposure, not after.
  • Two RFCs already point here. RFC 0003 §9 (identity → tenant derivation) and RFC 0016 §1 (authn follow-up) both deferred to an authentication RFC. Leaving the question open now blocks RFC 0027 (an MCP surface productizes remote query access) and the Helm chart’s security story (workstream C).
  • Ack semantics make ingest authz special. Rejection must happen before the WAL ack (§3.4): once acknowledged, data is durable — an unauthorized batch must never reach that point.

3. Design

3.1 Token store (RFC 0020 config amendment)

A new top-level auth section:

auth:
  tokens:
    - name: edge-collector          # audit/metric label, not secret
      token: ${env:OURIOS_TOKEN_EDGE}
      tenants: ["acme", "globex"]   # explicit allow-list
    - name: admin-cli
      token: ${env:OURIOS_TOKEN_ADMIN}
      tenants: ["*"]                # wildcard: all tenants
  • Tokens are opaque strings, compared in constant time; the config holds them only via ${env:...} indirection (the RFC 0020 substitution engine), so files stay committable.
  • tenants is an exact-string allow-list or the single wildcard "*". No patterns — pattern semantics on a security boundary invite grief; revisit only with demand (§7).
  • No auth section ⇒ open mode, preserving today’s behavior for local/dev, with a structured startup warning naming the exposure. An empty auth.tokens list is a startup configuration error (locked-out server is never the intent).

3.2 Ingest enforcement (RFC 0003 amendment)

  • Both OTLP listeners (gRPC + HTTP) require Authorization: Bearer <token> when auth is enabled. Missing or unknown token ⇒ gRPC UNAUTHENTICATED / HTTP 401 before any decode work.
  • Per-batch authz: every ResourceLogs group’s derived tenant (RFC 0003 §6.3, unchanged) is checked against the token’s set. Any out-of-set tenant rejects the whole batch with PERMISSION_DENIED / 403 before the WAL append — partial-batch acceptance would make the OTLP partial-success surface a tenancy oracle, and §3.4 forbids acking anything not durably accepted.
  • The RFC 0003 §9 question resolves as: derivation stays attribute-based (the sender’s resource attributes remain the source of truth for which tenant), and identity bounds the set of tenants a sender may speak for. A token pinned to one tenant is the single-tenant-sender case; no attribute rewriting.

3.3 Query enforcement (RFC 0016 amendment)

  • The HTTP query API requires the same bearer scheme. Status contract: missing/unknown bearer ⇒ 401; missing or empty x-ourios-tenant ⇒ 400 (today’s contract, unchanged — the header stays the tenant selector); a well-formed tenant outside the token’s set ⇒ 403.
  • Enforcement composes with — never replaces — the structural scoping: the querier still roots every scan under the tenant’s partition directory (RFC0007.5). The failure bound is worth stating precisely: a fail-open authz bug would re-open the pre-RFC exposure (any tenant selectable by header for an authenticated caller) — a real regression — but the structural scoping still confines each request to the single tenant it names; no bug in this layer yields cross-tenant reads within one query or unscoped scans.

3.4 Telemetry and audit

  • Rejections count on the existing request counters with error.type (unauthenticated | permission_denied) — no new metric names (OTel recording-errors convention; new attributes go through the weaver registry).
  • Ingest authz rejections additionally emit an audit event carrying the token name (never the token) and the offending tenant — cross-tenant write attempts are exactly what an operator audits.

4. Alternatives considered

  • mTLS as the identity mechanism. Delegating TLS to a fronting proxy is the project’s posture; client-cert identity does not survive typical proxy hops without header-forwarding conventions that are themselves a trust decision. Bearer tokens work through every OTLP exporter and HTTP client today. mTLS remains available at the proxy layer, orthogonal to this RFC.
  • JWT / OIDC. Brings expiry, issuers, key rotation, clock dependence, and a validation dependency tree — for a system whose senders are collectors with static config. Static tokens match the OTel Collector ecosystem’s operational reality (headers: on the OTLP exporter). An IdP integration can layer on later (§7) without changing the tenant-binding model.
  • Identity-derived tenancy (token ⇒ tenant, ignore attributes). Breaks the multi-tenant-collector case (one edge collector forwarding many teams’ telemetry) and silently discards the RFC 0003 §6.3 contract. Constraining beats replacing.
  • Per-tenant listeners / network policy as authz. Pushes tenancy into deployment topology; contradicts the single-binary shape and makes the Helm chart combinatorial.

5. Acceptance criteria

Scenario ids RFC0026.<m>.

Scenario RFC0026.1 — token store configuration. Given a config with an auth.tokens list using ${env:VAR} values, When the server starts, Then tokens resolve through the RFC 0020 substitution engine; an empty auth.tokens list is a startup configuration error; a missing auth section starts in open mode and emits a structured startup warning naming the exposure.

Scenario RFC0026.2 — ingest authentication. Given auth enabled, When an OTLP export arrives with a missing or unknown bearer token (gRPC metadata and HTTP Authorization, both listeners), Then it is rejected (UNAUTHENTICATED / 401) before wire decode, nothing reaches the WAL, and no ack is returned.

Scenario RFC0026.3 — ingest tenant binding. Given a token bound to tenants {a, b}, When a batch whose derived tenants are all within {a, b} arrives, Then it is accepted and acked normally; When a batch containing any ResourceLogs group deriving to a tenant outside the set arrives, Then the whole batch is rejected (PERMISSION_DENIED / 403) with no WAL append and no partial success — nothing of the batch becomes durable.

Scenario RFC0026.4 — query enforcement and status contract. Given auth enabled, Then the query API returns 401 for a missing/unknown bearer, 400 for a missing or empty x-ourios-tenant (today’s contract, unchanged), 403 for a well-formed tenant outside the token’s set, and correct results for an in-set tenant — with the drift endpoint under the same gate.

Scenario RFC0026.5 — wildcard binding. Given a token with tenants: ["*"], When it ingests to and queries arbitrary tenants, Then both paths behave as if every tenant were listed.

Scenario RFC0026.6 — open-mode parity. Given no auth section, When the full existing ingest + query acceptance suites run, Then behavior is byte-for-byte today’s (the amendment is invisible until configured), warning aside.

Scenario RFC0026.7 — rejection telemetry and audit. Given authn/authz rejections on either path, Then the existing request counters increment with error.type (unauthenticated / permission_denied) and an ingest authz rejection emits an audit event carrying the token name and the offending tenant — and never any token value, on any surface (metrics, audit, logs, errors).

5.1 Discharge record (green, 2026-07-06)

  • RFC0026.1 — #390 (token store: config schema, ${env:…}-only secrets, startup error/warning arms) + #395 (store moved to ourios_core::auth for the ingest enforcement point).
  • RFC0026.2/.3 — #398: bearer authn before wire decode on both listeners (gRPC interceptor / HTTP handler), whole-batch tenant binding before the WAL append, served-stack gRPC arm; WAL emptiness asserted on the journal.
  • RFC0026.4/.5/.6 — #408: the 401→400→403 gate order pinned with exact bodies, wildcard binding on both halves, open-mode parity (exactly-once warning + a live listener connection).
  • RFC0026.7 — #409: rejections on the existing counters via error.type (unauthenticated | permission_denied; the query histogram under the new rejected kind member), and the ingest_denied audit event (kind 8, denied_token_name column — §3.7 additive-OPTIONAL, schema pin updated) with a no-token-value sweep across every surface.

5.2 Validation record (validated, 2026-07-07)

Run: scratch/validation/rfc0026-0027-validate.sh — the release binary served over real sockets with a file config whose tokens resolve through ${env:…} (RFC 0020), two tokens (tenant-bound + wildcard), both roles + MCP enabled. 16/16 checks pass:

  • Ingest matrix (OTLP/HTTP): no bearer 401, unknown bearer 401, out-of-set tenant 403, in-set 200, wildcard-to-arbitrary-tenant 200.
  • Query matrix: no bearer 401, missing tenant 400 (valid bearer), out-of-set 403, in-set 200.
  • Denial audit: the ingest_denied event is durable in the store’s audit Parquet (event-type string present in the flushed files) after the cadence/shutdown flush.
  • End-to-end data flow: rows ingested under a valid token survive a graceful restart (the RFC 0014 drain) and serve on both query surfaces.

6. Testing strategy

RFC0026.1 in ourios-server config tests (the RFC 0020 suite’s home); .2/.3 as receiver integration tests against both listeners (the RFC 0003 suite pattern), asserting WAL emptiness on rejection; .4/.5 in the querier-role HTTP tests (RFC 0016 suite pattern); .6 runs the existing suites under a no-auth config — parity is the assertion; .7 through the in-memory OTel reader (the established telemetry-test pattern) plus the audit-sink test fixtures. Token comparison is constant-time by construction (a dedicated comparison helper with a unit test on the API shape, not a timing measurement — timing assertions in CI are noise).

7. Open questions

  1. Token rotation ergonomics. Config reload vs restart; whether two tokens per name (old + new) is worth first-class support.
  2. IdP / OIDC layering. If demanded, a validator that maps a verified claim to the same (name, tenants) shape — the binding model is designed to be the stable layer.
  3. Tenant patterns. Prefix grants (team-*) if explicit lists prove operationally painful; needs careful semantics before any wildcard beyond "*".
  4. Rate limiting per token. Adjacent concern; deliberately out of scope here.

8. References

  • RFC 0003 §6.3 (tenant derivation) and §9 (the open question this closes), RFC 0016 §1/§3 (the query API and its authn deferral), RFC 0020 (config file + ${env} substitution the token store rides), CLAUDE.md §3.4 (ack-before-WAL interplay) and §3.7 (multi-tenancy invariant), RFC 0027 (the MCP surface gated on this RFC).

RFC 0027 — MCP query surface


rfc: 0027 title: MCP query surface (agent-facing read tools over the querier) status: accepted author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-07-05 supersedes: — superseded-by: —

RFC 0027 — MCP query surface (agent-facing read tools over the querier)

1. Summary

Expose the querier’s read surface as a Model Context Protocol (MCP) server, so LLM agents can query logs, inspect templates, and run drift analysis as typed, discoverable tools instead of hand-rolled HTTP calls. The surface is a thin adapter over what already exists — the RFC 0002 DSL through the RFC 0016 endpoint machinery, the RFC 0017 template registry, the RFC 0010 drift query — hosted on the querier role’s existing HTTP listener (streamable HTTP transport) at /mcp. Read-only by design: no ingest, no administration, no state mutation reachable through it.

Implementation is gated on RFC 0026: an MCP endpoint is exactly the thing agents reach from laptops and CI over shared networks, and it must not ship ahead of query-side authentication.

2. Motivation

  • The product story. Ourios is an OTLP-native backend built in the open with agents; “point your agent at your logs” is the natural demo and the sharpest differentiator available to a pre-1.0 backend courting testers. Template mining is unusually agent-friendly: list_templates gives an agent the shape of a corpus in a few hundred rows — something raw-log backends cannot offer without a scan.
  • Tool typing beats API docs. Agents can already hit the RFC 0016 JSON API, but every consumer must be taught the DSL, the tenant header, and the response shape by prompt. MCP moves that contract into the protocol: schemas are discovered, the DSL grammar ships as a resource, and errors are structured.
  • Cheap by construction. The querier already owns the DSL parse → compile → run path and its HTTP hosting; the adapter adds tool plumbing, not query machinery. Hazard §4.6 (don’t leak DataFusion through user surfaces) is inherited, already-solved behavior, not new work.

3. Design

3.1 Placement and transport

  • A module in ourios-server’s querier role — no new crate (§7 layout untouched; the adapter is small and shares the querier’s types). The MCP SDK dependency (rmcp, the official Rust SDK) lives in ourios-server only.
  • Transport: streamable HTTP on the existing querier listener at /mcp, enabled by a querier.mcp.enabled config flag (RFC 0020 section; default off). No stdio transport in v1 — the querier is a deployed server, not a spawned subprocess; a local stdio bridge can be a later convenience (§7).
  • Authentication: the RFC 0026 bearer scheme, identically to the JSON API. The token’s tenant set bounds every tool call; the tenant is an explicit tool argument validated against that set.

3.2 Tool set (v1)

ToolBacks ontoNotes
query_logsRFC 0002 DSL via the RFC 0016 pathargs: tenant, query (DSL string), optional limit; returns count + up to limit rendered rows + pruning stats
list_templatesRFC 0017 registryargs: tenant; returns (template_id, rendered_template, version) rows — the corpus’s shape at a glance
template_driftRFC 0010 drift surfaceargs: tenant, from, to; the audit-stream drift analysis over the half-open window [from, to) (RFC0010.2’s boundary rule, inherited verbatim)

Plus one resource: the DSL grammar/reference doc, served verbatim so agents learn the query language from the protocol rather than from prompt engineering.

Deliberately absent: any write, any admin (compaction, snapshots), any raw-SQL escape hatch (hazard §4.6), and any cross-tenant enumeration — there is no list_tenants tool; a token knows its tenants out of band.

3.3 Output discipline

  • Tool results are the RFC 0016 JSON shapes re-encoded as MCP content — one serialization boundary, no new response schema to drift.
  • query_logs defaults to a conservative limit (rows are LLM context, not a data export); the full count always accompanies the rows so agents know what they’re not seeing.
  • Returned log bodies are untrusted text. A log line is attacker-influenceable input that will be placed into an LLM context; the server cannot sanitize meaning away, but the tool descriptions MUST carry the standard treat-as-data warning so well-behaved clients render results as content, not instructions. (This is a consumer-side hazard the RFC documents rather than solves; see §7.)

4. Alternatives considered

  • No MCP; agents use the JSON API directly. Works today, loses discovery, typing, and the grammar-as-resource; every integration re-teaches the DSL by prompt. The adapter is small enough that “just use HTTP” saves little.
  • A separate ourios-mcp sidecar binary/crate. Another artifact to version, deploy, and secure, wrapping an API that lives one process away. A module behind a config flag delivers the same surface with none of the operational spread. Revisit only if the MCP dependency tree bloats the server build measurably.
  • stdio-first transport. Natural for laptop-local tools, wrong for a deployed backend: it would couple agent hosts to process lifecycle on the server host. Streamable HTTP is MCP’s remote story and matches the existing listener.
  • Exposing SQL instead of the DSL. Directly violates hazard §4.6 (DataFusion specifics leaking through a user surface) and widens the authz analysis from three tools to a query planner.

5. Acceptance criteria

Scenario ids RFC0027.<m>. Maintainer sign-off: 2026-07-05 (“go on 0027 and 0019”). This RFC treats serving /mcp as gated on RFC 0026 (§1 — a remote query surface must never precede authn); that gate is satisfied as of RFC 0026’s green, 2026-07-06.

Scenario RFC0027.1 — gating and placement. Given querier.mcp.enabled unset or false, When the querier role serves, Then /mcp returns 404 and the existing JSON API endpoints are behaviorally unchanged (same routes, status contracts, and response schemas — the RFC 0016 and RFC 0026 §5 suites still pass verbatim); Given the flag true, Then /mcp speaks MCP streamable HTTP on the same listener, And no new crate exists (the adapter is an ourios-server module).

Scenario RFC0027.2 — the RFC 0026 gate applies verbatim. Given auth enabled, When an MCP request arrives with a missing/unknown bearer, Then it is rejected as unauthenticated before any tool dispatch; When a tool call names a tenant outside the token’s set, Then it fails with the tenant-denied error and touches no data; And open mode (no auth section) serves MCP exactly as it serves the JSON API.

Scenario RFC0027.3 — query_logs. Given a seeded tenant, When query_logs runs a DSL statement, Then the result carries the total count, at most limit rendered rows (the conservative default when unset), and the scanned/pruned stats, matching the JSON API’s answer for the same statement; And a malformed statement returns the DSL error as a tool error, never a transport failure.

Scenario RFC0027.4 — list_templates. Given a tenant with mined templates, When list_templates runs, Then every row is (template_id, rendered_template, version) and matches the RFC 0017 registry surface for that tenant.

Scenario RFC0027.5 — template_drift. Given audit history, When template_drift runs over [from, to), Then the analysis equals the RFC 0010 drift surface’s for the same half-open window (RFC0010.2’s boundary rule inherited verbatim).

Scenario RFC0027.6 — the grammar resource. Given the server is enabled, When the client lists/reads resources, Then the DSL grammar/reference doc is served from the canonical source, docs/rfcs/0002-query-dsl.md, embedded at compile time (include_str!) and trimmed to its §7 grammar section at startup — the served text is byte-identical to that section, so the resource cannot drift from the documentation.

Scenario RFC0027.7 — output discipline. Given any tool result, Then it is the RFC 0016 JSON shape re-encoded as MCP content (one serialization boundary), And every tool description carries the treat-log-bodies-as-data warning, And no tool or resource enumerates tenants or accepts SQL.

5.1 Discharge record (green, 2026-07-07)

  • RFC0027.1 — #413 (transport): rmcp server-side at /mcp behind querier.mcp.enabled (file + env paths), the RFC 0026 bearer layer answering before any MCP dispatch, the loopback Host guard kept in open mode, the body cap on the nested router.
  • RFC0027.2/.3/.4/.5/.7 — #414 (tools): the §3.2 three over the querier engine with per-call tenant binding off the request’s own Authorization (sessions outlive requests); .3/.5 are payload-equality proofs against the JSON API over the same seeded store; the limit argument is a hard cap; all tools record on the shared ourios.query.duration histogram (logs/drift/the new templates kind member).
  • RFC0027.6 — #415 (resource): ourios://dsl-grammar serves the RFC 0002 §7 section byte-identically (include_str!, extracted once at role startup with a loud panic on shape drift), text/markdown, asserted by an independent extraction in the test.

5.2 Validation record (validated, 2026-07-07)

Run: scratch/validation/rfc0026-0027-validate.sh — the release binary with querier.mcp.enabled + RFC 0026 auth, driven by the official MCP inspector CLI (@modelcontextprotocol/inspector, the TypeScript SDK — an independent client implementation, not this repo’s test client). 16/16 checks pass; the RFC 0027 arms:

  • tools/list advertises exactly the §3.2 three.
  • resources/read ourios://dsl-grammar serves the §7 section (heading-checked; byte-identity is the §5.1 CI test’s oracle).
  • query_logs over really-ingested rows returns a payload equal to /v1/query’s for the same statement and tenant.
  • template_drift answers over the audit stream.
  • An unknown bearer is rejected before any MCP dispatch.

6. Testing strategy

.1/.2 at the served-querier level (the RFC 0016 §5 pattern: spawn or in-process router, flag off/on, the RFC 0026 status matrix over /mcp). .3.5 as equivalence tests: drive the tool through an MCP client against a seeded store and assert equality with the corresponding JSON-API/engine answer — the adapter must add nothing but the protocol. .6/.7 by inspection of the served resource/descriptors against the RFC 0002 §7 grammar source named in .6 and a deny-list assertion on the advertised tool/resource set.

7. Open questions

  1. Result pagination. Whether query_logs grows a cursor for result sets past the row limit, or agents are expected to refine predicates instead (the DSL makes refinement cheap).
  2. stdio bridge. A ourios mcp-stdio --endpoint <url> local proxy for clients that only speak stdio — convenience, not architecture; demand-driven.
  3. Prompt-injection posture. Whether to offer an opt-in result-wrapping mode (e.g. explicit content fencing) beyond the tool-description warning, once client conventions settle.
  4. Aggregation tools. count by template style pre-shaped tools vs teaching agents the DSL’s pipe stages; start with the grammar resource and observe.

8. References

  • RFC 0026 (authentication — the implementation gate), RFC 0002 (the DSL surface exposed), RFC 0016 (the querier HTTP role this co-hosts on, incl. the x-ourios-tenant scoping), RFC 0017 (template registry behind list_templates), RFC 0010 (drift), CLAUDE.md §4.6 (DSL vs engine leakage hazard), §3.7 (tenancy), §1 (scope — this stays a query surface, not a new product line); Model Context Protocol spec (streamable HTTP transport).

RFC 0028 — Build-feedback program


rfc: 0028 title: Build-feedback program — test-harness consolidation and workspace decomposition status: green author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-07-06 supersedes: — superseded-by: —

RFC 0028 — Build-feedback program: test-harness consolidation and workspace decomposition

1. Summary

Developer feedback latency is a first-order engineering constraint (“slow feedback is a development and velocity killer” — maintainer, 2026-07-06, with explicit precedence over feature work). This RFC turns the measured build-cost profile (epic #382) into a program:

  1. Test-harness consolidation — collapse the workspace’s 104 integration-test binaries (ingester 31, querier 19, parquet 17, wal 11, server 9, miner 7, …) into ~1–3 harnesses per crate. Every binary links its crate’s full dependency stack (DataFusion, tonic); link count dominates cargo test wall time, measured at 57 s for touch core → querier test binaries before a single test runs. No new crates; test names and assertions are preserved exactly — files move under a harness root, nothing is weakened (CLAUDE.md §6.2).
  2. ourios-core decomposition — split the fat hub along its fault line: pure data types (tenant, records, OTLP, audit, alias, confidence) stay in ourios-core; MinerConfig and its validation move to a new ourios-config crate (name bikesheddable). A core edit currently rechecks 9 crates (38 s); config churn — a frequent edit class — stops invalidating type-only consumers.
  3. Deferred-with-tripwire: ourios-parquet split (reader/writer/compaction/store). Re-measure after (1); a parquet edit’s 27 s / 5-crate fan-out may be acceptable once the link storm is gone. Splitting prematurely costs API churn across the RFC 0005 surface for unproven gain.
  4. cargo-nextest for test execution (local + CI): per-test parallelism over the consolidated binaries, faster reruns, crisper failure output. Additive; cargo test keeps working.

Measured honestly: incremental check feedback is already fine (17–38 s). The program targets the three verified sinks — link count, branch-churn invalidation (worktrees are the practice; documented in CONTRIBUTING), and hub fan-out — in that order.

2. Motivation

  • The numbers (epic #382, 2026-07-06): 9 m 46 s warm-up after branch churn; ~10 min full-workspace cargo test; 57 s to relink querier tests after a core touch; target/debug hit 314 GiB before the #373 debuginfo trim. A single session repeatedly tripped 10-minute task budgets on rebuilds.
  • Every test file is a linker invocation. The RFC-ladder discipline creates one integration-test file per scenario group — correct for clarity, quadratic-feeling for links. 31 binaries in ourios-ingester each link the tonic/tokio receiver stack.
  • sccache does not save the local loop (measured: 37/199 hits, all C/C++ build scripts) — cargo’s incremental dev builds bypass it by design. Its value is CI; local latency must come from structure.
  • The hub tax compounds. Every future crate consuming core types inherits the config-churn invalidation unless the split happens while the workspace is still 11 crates.

3. Design

3.1 Test-harness consolidation (slices 1–2)

Per crate: a single tests/it/main.rs harness (Cargo’s one-binary idiom) with mod declarations per current file — tests/it/rfc0003_1_wal_before_ack.rs etc. keep their content and test names verbatim. Shared fixtures (tests/common, tests/ingest_support) become harness modules, ending the compile-per-binary duplication of helpers.

  • Worst crate first (ourios-ingester, 31 → 2: one general harness plus keeping any test that requires process isolation — e.g. SIGKILL crash-recovery — as its own binary, explicitly annotated).
  • Scenario-name greppability is preserved: cargo test rfc0003_1 still works; CI invocations by --test <name> are updated in the same slice (the rfc0024 deep-run workflow names four).

3.2 ourios-core split (slice 3)

New crate ourios-config holding MinerConfig, MinerConfigError, bound constants and builders. ourios-core keeps pure data types and the canonical codec. Consumers move one use path; no behavior change. The §7 layout table gains one row — this RFC is the architectural commitment §7 requires.

Explicitly out: splitting audit/alias/otlp out of core — no measurement implicates them, and every split multiplies version lockstep costs.

3.3 Parquet split (slice 4, decision gate)

Re-run the #382 probe set after slices 1–2. Proceed with a reader/writer split only if a parquet edit still costs > 30 s of check fan-out or shows up in the top of cargo build --timings critical path; otherwise record the decision and close.

3.4 nextest (slice 5)

cargo nextest run locally and in CI’s test job; cargo test remains supported (property suites’ proptest integration is runner-agnostic). CI keeps the exact same suite inventory.

4. Alternatives considered

  • Only crate splits (the original instinct). The data says the link storm, not check fan-out, is the dominant cost; splits alone would leave 104 binaries linking.
  • One mega test binary per workspace. Cross-crate harnesses can’t exist (integration tests are per-crate), and a single binary per crate that force-includes isolation-sensitive tests (crash recovery) would serialize or destabilize them.
  • CARGO_INCREMENTAL=0 + sccache locally. Trades away incremental compilation (the thing that makes 17–38 s checks possible) to feed sccache; strictly worse for the edit loop.
  • Shared monolithic tests/common crate. A dev-only fixtures crate would rebuild on every core change and re-couple the crates the split decouples; harness-local modules suffice.

5. Acceptance criteria

Scenario ids RFC0028.<m>. Maintainer sign-off: 2026-07-06 (the proposed scenarios accompanied the drafting PR, #383).

Scenario RFC0028.1 — consolidation preserves the test inventory. Given the pre-consolidation cargo test -p <crate> -- --list inventory, When the crate’s harness consolidation lands, Then the post-consolidation inventory lists the same set of tests, differing only by the harness’s module-path prefix (--list prints test names as module paths; a file moving under tests/it/ gains its module segment), And no test body changed in the move.

Scenario RFC0028.2 — isolation-sensitive tests stay isolated. Given the slice-1 inventory of tests requiring process isolation (process-global installers, env-mutating, hardware-gated), Then those tests are not merged into a shared harness — they stay in dedicated integration-test binaries (grouped where they can safely share one), each annotated with the reason it cannot join the harness.

Scenario RFC0028.3 — the probe set improves. Given the epic #382 probe set re-run as the slices land — the edit-loop probe after slices 1–2, the runner-dependent full-suite gate after the runner slice it names — on the same machine and under the same conditions the baseline was captured (warm workspace, same toolchain; environment recorded next to the numbers in the epic) — Then the incremental-edit probe — touch crates/ourios-core/src/lib.rs (an mtime-only update, exactly as the epic’s baseline measured it) followed by cargo test -p ourios-querier --no-run — drops below 30 s, And full-workspace suite wall time — under the test runner CI adopts (plain cargo test, or cargo nextest run once slice 5 lands; clarified at the green flip so the criterion matches the slice-5 design) — drops by at least 30% against the epic’s baseline.

Scenario RFC0028.4 — the core split is behavior-free. Given the ourios-config extraction, When the full workspace suite runs, Then results are identical pre/post split, And a MinerConfig edit no longer rechecks type-only core consumers.

Scenario RFC0028.5 — CI parity. Given the consolidated harnesses (and nextest, if slice 5 adopts it), Then CI runs the identical suite inventory and stays green.

5.1 Discharge record (green, 2026-07-06)

  • RFC0028.1 — per-PR inventory proofs: #399 (ingester, 129/129), #400 (querier, 162/162), #401 (parquet, 162/162), #402 (wal, 64/64), #403 (server, 90/90), #404 (miner, 206/206); every diff a pure module-path-prefix rename.
  • RFC0028.2 — committed exemption lists: crates/ourios-ingester/tests/README.md and crates/ourios-miner/tests/README.md (+ the server harness header); all exemptions are process-global OTel meter-provider installers.
  • RFC0028.3 — both gates pass (measurement tables on epic #382, 2026-07-06): touch core → querier --no-run 57 s → 28.6 s (< 30 s); warm workspace suite ~10 min → 48.2 s under nextest (≥ 30% gate). Steady-state protocol notes (macOS first-exec assessment) recorded with the numbers.
  • RFC0028.4 — proven in #405: a MinerConfig whitespace edit leaves ourios-core and ourios-parquet Fresh; the rebuild set is the semantic one (config → miner → querier).
  • RFC0028.5 — #406: CI runs cargo nextest run --workspace --all-features + cargo test --doc, preserving the exact suite inventory; the workflow invocations that named old binaries were retargeted in the same PRs that moved them (#401, #403, #404).
  • Slice 4 (parquet split) — closed not-triggered per the §3.3 tripwire: RFC0028.3’s < 30 s edit-loop probe passed without it.
  • red note — this RFC’s scenarios are review/measurement mechanisms (§6), not stub-able tests; there was no red rung, as recorded in the slice-1 PR.

6. Testing strategy

Inventory diffs are the mechanism for RFC0028.1/RFC0028.5’s name half, and the PR diff is the mechanism for its no-body-change half: a consolidation PR is restricted to file moves plus the mechanical harness scaffolding (tests/it/main.rs mod lines, import-path adjustments); the reviewer rejects any hunk inside a test function body. For RFC0028.1’s inventory, a cargo test -p <crate> -- --list snapshot (scoped to the crate being consolidated, matching RFC0028.1) is captured in each consolidation PR’s description and diffed against the post-move run — the reviewer checks the diff is a pure path-prefix rename. RFC0028.2 is a committed list (the harness-exempt binaries and their reasons, in the consolidating crate’s tests/ README or module docs). RFC0028.3’s probe numbers are recorded in epic #382 alongside the baseline so the before/after is one table. RFC0028.4 is the full suite run plus a recheck-set spot check: a whitespace-only edit inside the MinerConfig definition (crates/ourios-core/src/config.rs today; its new home after the split), then cargo build -vv on a type-only core consumer, asserting the build reports the consumer Fresh (no Compiling/Dirty line for it).

7. Open questions

  1. Crash-recovery isolation inventory. Which tests genuinely need their own process/binary (SIGKILL, env-mutating, #[ignore]d hardware gates)? Slice 1 produces the list.
  2. Per-branch target dirs. Worktrees already give this implicitly; whether to document CARGO_TARGET_DIR conventions for branch-heavy local work, or leave it to worktree practice.
  3. ourios-config naming and scope — config only, or does the RFC 0020 file-config layer’s schema (currently in ourios-server) eventually belong beside it?

8. References

  • Epic #382 (measurements, 2026-07-06), maintainer precedence instruction (same date), #373 (debuginfo trim), CLAUDE.md §6.2 (tests are specifications — consolidation moves, never weakens), §7 (new crates are RFC-level), §8.2 (worktrees for parallel work), cargo book (integration-test harness layout), cargo-nextest.

RFC 0029 — OIDC bearer layer


rfc: 0029 title: OIDC bearer layer (issuer-agnostic, Dex-validated) status: green author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-07-07 supersedes: — superseded-by: —

RFC 0029 — OIDC bearer layer (issuer-agnostic, Dex-validated)

1. Summary

RFC 0026 (accepted) authenticated both data-plane surfaces with static bearer tokens bound to tenant sets, and deliberately deferred identity-provider integration (§7.2) — designing the (name, tenants) binding as “the stable layer” a verified-claim validator could later map onto. This RFC is that layer:

  1. OIDC JWT verification as a second credential kind on every RFC 0026 gate (OTLP ingest, the query API, the RFC 0027 MCP surface): standard iss/aud/exp/signature validation against the issuer’s published JWKS, with a configured claim → tenant mapping that resolves each verified token to exactly the (name, tenants) shape the existing enforcement consumes. No enforcement point changes; only the resolution in front of it grows a branch.
  2. Issuer-agnostic by construction, Dex-blessed by test. Ourios implements the OIDC standard, not a vendor SDK; any conforming issuer works. Dex (the CNCF identity broker) is the recommended lightweight deployment and the implementation the acceptance suite runs against (a real Dex container via testcontainers — the LocalStack pattern from RFC 0019).
  3. Additive, never replacing. Static tokens (RFC 0026 §3.1) remain fully supported and can coexist with OIDC in one config — static for dev/single-box, OIDC for fleets. Open mode is untouched.

Touches invariant §3.7 (multi-tenancy — the binding derivation gains a second source) and rides the RFC 0026 audit/telemetry surfaces unchanged. Resolves RFC 0026 §7.1 (token rotation) as a side effect: JWTs expire and renew; no long-lived shared secret crosses the wire.

2. Motivation

  • Fleets outgrow static tokens. A handful of collectors with ${env} tokens is fine; dozens of teams rotating shared secrets through config management is the operational failure mode OIDC exists to remove. Expiry, rotation, and revocation become the issuer’s job — solved once, not per backend.
  • The ecosystem path already exists. The OTel Collector’s oauth2client extension performs the client-credentials flow against any OAuth2 token endpoint and attaches the bearer to exporters — collectors can authenticate to Ourios through an IdP today, with zero collector-side custom code. Dex supports the grant (opt-in: DEX_CLIENT_CREDENTIAL_GRANT_ENABLED_BY_DEFAULT) and token exchange as the documented machine-to-machine paths.
  • MCP’s authorization model is OAuth 2.1. RFC 0027 shipped the agent surface under the static-bearer gate; the MCP specification’s own auth story is OAuth. An OIDC layer is the prerequisite for spec-compliant agent authentication rather than a parallel invention.
  • RFC 0026 planned for this. §4 rejected JWT/OIDC as the baseline (“expiry, issuers, key rotation, clock dependence, and a validation dependency tree — for senders that are collectors with static config”) and §7.2 named the layering as the follow-up. The baseline argument stands; this RFC adds the layer without disturbing it.

3. Design

3.1 Configuration (RFC 0020 amendment)

A sibling to auth.tokens:

auth:
  tokens:                          # RFC 0026, unchanged; optional
    - name: dev-cli
      token: ${env:OURIOS_TOKEN_DEV}
      tenants: ["dev"]
  oidc:                            # this RFC; optional
    issuer: https://dex.internal.example
    audience: ourios
    tenant_claim: ourios_tenants   # claim carrying the tenant list
    name_claim: sub                # audit/metric label (default sub)
  • issuer is the OIDC discovery root: Ourios fetches /.well-known/openid-configuration once at startup and the JWKS it names, then re-fetches keys on rotation (cache with the standard kid-miss refresh; a bounded grace covers issuer blips — §7).
  • audience is required — an Ourios deployment must never accept tokens minted for another service.
  • tenant_claim names a claim whose value is a list of tenant ids (or the wildcard "*"), mapped verbatim onto RFC 0026’s TenantSet; name_claim (default sub) feeds the audit/metric label. The mapping is deliberately dumb — group-to-tenant indirection lives in the issuer (Dex connectors already map upstream groups into claims), not in Ourios.
  • At least one of tokens / oidc must be configured in an auth section; both together are valid. The RFC 0026 empty-list rule is unchanged and unconditional: an explicit tokens: [] always fails startup — to run OIDC-only, omit tokens entirely. No auth section remains open mode with the RFC 0026 startup warning.

3.2 Verification and resolution

  • One resolution path in front of the existing gates: a presented bearer is first matched against the static store (constant-time, RFC 0026 §6); an unmatched credential that parses as a JWT is verified OIDC-side — signature against the cached JWKS (asymmetric algorithms only: RS256/ES256 family; alg: none and HMAC are rejected outright), iss equality, aud containment, exp/nbf with a small configured clock skew. A verified token resolves to the RFC 0026 (name, tenants) binding — the values of the configured name_claim / tenant_claim keys — and flows into the unchanged RFC 0026 enforcement: whole-batch tenant binding before the WAL ack, the query/MCP 403 contract, the same rejection telemetry (error.type values unchanged) and ingest_denied audit event carrying the name label.
  • Verification is local (a signature check against cached keys) — no per-request issuer round-trip, so the §3.4-adjacent ingest hot path gains arithmetic, not network. The issuer is contacted only at startup, on JWKS rotation, and on kid misses.
  • Failure stays one undifferentiated 401 on the wire (RFC 0026’s no-oracle rule); the telemetry may distinguish unauthenticated reasons only at the existing low-cardinality error.type level.

3.3 Dex as the blessed deployment

  • Docs and the acceptance suite treat Dex as the reference issuer: single Go binary, CNCF, federates upstream identity (LDAP, GitHub, SAML, OIDC) through connectors, and issues the JWTs Ourios verifies. Machine senders use the client-credentials grant (Collector oauth2client → Dex token endpoint) or token exchange; humans/agents use the standard flows Dex provides.
  • The §5 suite runs against a real Dex container (testcontainers, CI-gated like the LocalStack S3 jobs): mint real tokens, verify against Dex’s real JWKS, exercise expiry and rotation. Nothing in ourios-server links Dex-specific code — conformance is to the OIDC standard.

3.4 What deliberately does not change

  • Static tokens, open mode, the enforcement points, the audit schema, the metric names, and the (name, tenants) model are all untouched. This RFC is a second resolver, not a second model.
  • Transport encryption remains the fronting-proxy posture (RFC 0026 §1); bearer-over-plaintext caveats apply identically to JWTs.

4. Alternatives considered

  • Keycloak (or a cloud IdP) as the blessed issuer. Heavier to run than Dex and no more standard; since Ourios implements the protocol, they all work anyway — the blessing is about docs and CI weight, and Dex’s single-binary, connector-broker shape matches this project’s deployment story. CNCF alignment is a tiebreaker, not the argument.
  • Vendor-SDK integration (issuer-specific). Couples the backend to one IdP’s release train and dependency tree for zero standard coverage gain. Rejected.
  • OpenFGA (Zanzibar-style ReBAC) for the authorization half. Answers a different question — what may this identity touch — and answers it with a separate stateful service plus a check-API round-trip on the pre-ack ingest path, where today’s model is one in-memory set-membership test over a flat tenant list. Adopt-if: tenancy grows hierarchy (orgs → teams), per-stream ACLs, or delegation. The seam is already clean — RFC 0026’s binding check is a single tenants().allows(...) call an FGA-backed resolver could slot behind without reshaping the model. Until that requirement exists, an external authz service is operational surface without a question to answer.
  • mTLS client identity. Re-rejected on RFC 0026 §4’s grounds: it does not survive the fronting-proxy posture without header-forwarding trust decisions.
  • Opaque tokens + issuer introspection (RFC 7662). Puts the issuer on the request path (introspection call per token) — the availability coupling §3.2 exists to avoid. JWTs verify locally.

5. Acceptance criteria

Scenario ids RFC0029.<m>. Scenario .1 is pure config resolution (no issuer); .2–.6 run against a fixture issuer (a local keypair serving discovery + JWKS over a loopback listener — fast, deterministic, no container); .7 is the real-Dex acceptance arm.

Scenario RFC0029.1 — config resolution. Given a config with an auth.oidc section whose values use ${env:VAR}, When the server starts, Then they resolve through the RFC 0020 substitution engine; a missing audience is a startup configuration error; an auth section with neither tokens nor oidc is a startup configuration error; an explicit tokens: [] is a startup configuration error regardless of whether oidc is present; an oidc-only section starts and serves; a missing auth section starts in open mode with the RFC 0026 warning, unchanged.

Scenario RFC0029.2 — verification matrix. Given OIDC configured against the fixture issuer, When a request presents a bearer that is (a) a valid in-audience token, Then it is accepted; and when it presents (b) an expired token, (c) a token before its nbf beyond the configured skew, (d) a wrong-aud token, (e) a wrong-iss token, (f) a token with a corrupted signature, (g) an alg: none token, (h) an HMAC-signed token whose key is the public JWKS material (downgrade), or (i) a non-JWT unknown bearer, Then every one of (b)–(i) is rejected as the same undifferentiated 401 (identical status and body — no oracle), before wire decode on ingest, and nothing reaches the WAL.

Scenario RFC0029.3 — claim binding drives unchanged enforcement. Given a verified token whose tenant_claim value is ["a", "b"], Then the RFC 0026 §5.3/§5.4 contracts hold verbatim with the OIDC-resolved binding substituted for the static one: in-set ingest batches ack; any batch touching a tenant outside {a, b} is whole-batch 403 with no WAL append; the query API and the MCP surface enforce the same 401→400→403 order; and the name_claim value appears as the name label where the token name appears today.

Scenario RFC0029.4 — wildcard claim. Given a verified token whose tenant_claim value is ["*"], Then ingest and query to arbitrary tenants behave as if every tenant were listed (RFC 0026 §5.5 parity).

Scenario RFC0029.5 — coexistence and resolution order. Given one config with both tokens and oidc, Then a static token authenticates via the constant-time store, a JWT from the issuer authenticates via OIDC, each carrying its own tenant binding side by side; a static-only config and an oidc-only config each serve; and with no auth section the full RFC 0026 §5.6 open-mode parity arm passes unchanged.

Scenario RFC0029.6 — JWKS rotation. Given a served instance verifying against the fixture issuer, When the issuer rotates its signing key mid-run, Then a token signed by the new key (unseen kid) triggers a JWKS re-fetch and verifies without restart, and a token signed by the withdrawn key is rejected once the refreshed key set no longer contains it.

Scenario RFC0029.7 — Dex end-to-end with telemetry parity. Given a real Dex container (testcontainers, CI-gated like RFC 0019’s s3 integration (localstack) job) with the client-credentials grant enabled and a static client whose claims carry the tenant list, When a token minted from Dex’s token endpoint drives ingest, query, and MCP against a served instance verifying Dex’s real JWKS, Then all three succeed; a short-TTL token is rejected with the undifferentiated 401 after expiry; rejections increment the existing counters with the unchanged error.type values and an ingest authz denial emits the ingest_denied audit event carrying the name_claim value — and no JWT material (token, header, claims payload) appears on any surface (metrics, audit, logs, error bodies).

6. Testing strategy

Unit level: .1 is pure config resolution (no issuer at all); the §5 fixture issuer (local keypair) covers .2–.6 — fast, deterministic, no container. Acceptance level: the real-Dex testcontainers job (.7), CI-gated alongside RFC 0019’s s3 integration (localstack) job.

Image note (2026-07-07, .7 green slice): the client-credentials grant and staticClients[].clientCredentialsClaims (the static client’s tenant-list claims this scenario relies on) are merged upstream (dexidp/dex#4691) but not yet in a Dex release — v2.45.1 predates both. The CI job therefore runs Dex master pinned by image digest (reproducible; recorded in ci.yml and the test). Bump to the release tag when Dex v2.46 ships.

The RFC 0026 §5 suite re-runs unchanged with an OIDC-resolved binding substituted for the static one — the enforcement-invariance proof behind .3–.5.

7. Open questions

  1. JWKS outage grace. How long verified-key caches may serve after the issuer becomes unreachable (bounded staleness vs. fail-closed on rotation-with-outage).
  2. Human/agent flows for the query and MCP surfaces. Device flow via Dex for CLI/agent login, and whether /mcp should advertise OAuth metadata per the MCP authorization spec once this layer exists.
  3. Claim schema convention. Whether ourios_tenants becomes a documented convention Dex configs ship, or stays fully deployment-chosen.
  4. Revocation latency. Short TTLs are the plan; whether any deployment class needs sub-TTL revocation (and thus introspection after all) is demand-driven.

8. References

  • RFC 0026 (the binding model, §4’s JWT-baseline rejection, §7.1–.2 the rotation/IdP follow-ups this RFC discharges), RFC 0027 (the MCP surface; MCP’s OAuth 2.1 authorization model), RFC 0020 (config schema + ${env}), RFC 0019 §6 (the testcontainers CI-gating pattern), CLAUDE.md §3.7.
  • Dex: https://dexidp.io (CNCF; client-credentials grant opt-in via DEX_CLIENT_CREDENTIAL_GRANT_ENABLED_BY_DEFAULT, token exchange per its machine-auth guide). OTel Collector oauth2client extension (the collector-side client-credentials flow). OpenFGA: https://openfga.dev (the adopt-if ReBAC engine, §4).

RFC 0030 — TLS/mTLS on the listeners


rfc: 0030 title: TLS/mTLS on the data-plane listeners status: green author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-07-08 supersedes: — superseded-by: —

RFC 0030 — TLS/mTLS on the data-plane listeners

1. Summary

Ourios supports authentication on every data-plane surface (RFC 0026 static bearers, RFC 0029 OIDC JWTs; open mode remains for perimeter-trust deployments) but serves all of them over plaintext TCP. Bearer credentials over plaintext are not auth — any on-path observer can replay them. This RFC closes the gap identified as “gates everything below” in the #331 epic:

  1. Server TLS on all three listeners — OTLP gRPC (:4317), OTLP HTTP (:4318), and the querier HTTP surface (:4319, including the RFC 0027 /mcp route) — via rustls (already the workspace TLS stack; no OpenSSL linkage is required — the only openssl-named crate in the tree stays openssl-probe, rustls-native-certs’s pure-Rust trust-store path prober).
  2. Optional mTLS per listener: a configured client CA turns on require-and-verify client-certificate authentication, as transport hardening. Identity stays with the RFC 0026/0029 bearer layer — a client cert proves network admission, not tenant binding (deferred; §7.1).
  3. Certificate reload without restart: cert/key pairs are re-read on a configurable interval so cert-manager-style rotation works with no dropped listener.
  4. Config mirrors the OTel Collector’s configtls server model (cert_file, key_file, client_ca_file, min_version, reload_interval_secs) so operators configure Ourios like the Collector in front of it (names adapted to RFC 0020’s flat *_secs conventions; semantics identical).

TLS remains opt-in per listener: an unconfigured listener serves plaintext, preserving the documented perimeter-trust deployment mode (gateway/mesh terminates TLS) and every existing config. Enabling auth on a plaintext listener logs a prominent startup warning (§3.4).

Touches hazard §4.6 adjacent surfaces (the listener layer in front of the DSL) and the §3.7 tenancy perimeter indirectly (credential confidentiality); no storage or query semantics change.

2. Motivation

  • Bearer tokens require confidentiality. The OTel Collector’s bearertokenauth extension “explicitly requires TLS” for exactly this reason; RFC 0026 §7 acknowledged the same and deferred the transport question to this RFC. Until it lands, the honest guidance for production is “put a TLS-terminating proxy in front” — workable but easy to skip silently.
  • The ecosystem default is native TLS. Every Collector receiver takes a tls: block; operators pointing a Collector exporter at Ourios today must set insecure: true, which reads (correctly) as a warning sign.
  • mTLS is the fleet norm for collector→backend links. Where an IdP is overkill (edge collectors with provisioned certs), a client CA is the established alternative; the Collector’s server side supports client_ca_file for the same reason.
  • Rotation is not optional. Kubernetes cert-manager renews certificates on a cadence; a listener that requires a restart to pick up a renewed cert turns rotation into an outage generator.

3. Design

3.1 Configuration (RFC 0020 amendment)

The amendment is purely additive to RFC 0020’s existing flat listener keys (receiver.grpc_addr, receiver.http_addr, querier.http_addr are untouched): each listener gains an optional sibling *_tls block.

receiver:
  grpc_addr: 0.0.0.0:4317
  grpc_tls:
    cert_file: /etc/ourios/tls/server.crt     # required to enable TLS
    key_file: /etc/ourios/tls/server.key      # required alongside cert_file
    client_ca_file: /etc/ourios/tls/ca.crt    # optional: enables mTLS
    min_version: "1.2"                        # default; "1.3" allowed
    reload_interval_secs: 300                 # optional: never if unset
  http_addr: 0.0.0.0:4318
  http_tls: { ... }                           # same shape
querier:
  http_addr: 0.0.0.0:4319
  http_tls: { ... }                           # same shape, covers /mcp

The field names and semantics inside the block are the Collector’s configtls server settings; the two adaptations to RFC 0020’s house conventions are the flat <listener>_tls placement (no nested listener objects exist to hang a tls: key off) and the duration spelling (below).

Rules:

  • cert_file and key_file come as a pair; one without the other is a config error at startup (named field in the message).
  • client_ca_file without cert_file/key_file is a config error — mTLS presupposes server TLS.
  • min_version accepts "1.2" (default) and "1.3" only. TLS 1.0 and 1.1 are not implemented (rustls does not ship them; the Collector deprecates them).
  • reload_interval_secs is a positive integer number of seconds — RFC 0020’s existing duration convention (default_window_secs, interval_secs), not the Collector’s Go-style duration string. Zero or negative is a config error; unset means never reload.
  • Paths may use ${env:VAR} (RFC 0020 §3.5) like any other config value; the file contents are read at startup and on reload, never embedded in config.
  • Unknown fields under a *_tls block are rejected (RFC 0020 strict-mode parsing, unchanged).

3.2 Implementation shape

One shared ourios-ingester-side (receiver) and ourios-server-side (querier wiring) seam:

  • A TlsSettings -> rustls::ServerConfig builder in one place: certificate chain + key from the configured files, client CA into a RootCertStore + WebPkiClientVerifier when present, ALPN h2/http/1.1 as appropriate per listener (gRPC requires h2).
  • Both HTTP-family listeners (OTLP HTTP, querier axum router) accept through tokio-rustls’s TlsAcceptor in front of the existing hyper serve loop; the gRPC listener uses the same acceptor in front of tonic’s Server::serve_with_incoming (tonic’s own tls feature is not enabled — one rustls wiring for all three listeners instead of two).
  • Reload (reload_interval_secs): the acceptor holds the active Arc<rustls::ServerConfig> behind a read-mostly std::sync::RwLock (each handshake clones the Arc out); a task re-reads the files on the interval and swaps on content change. In-flight connections keep their session; new handshakes see the new material. A reload failure (unreadable/invalid files) logs an error and keeps the last good config — it never takes the listener down.
  • New dependencies: tokio-rustls only (already in the transitive tree; declared directly at the seam’s home), plus rcgen as a dev-dependency to mint test CAs and leaf/client certs. The reload swap uses std::sync::RwLock — no new runtime crate.

3.3 mTLS semantics

client_ca_file set ⇒ RequireAndVerifyClientCert (the Collector’s documented behavior for the same field): a handshake without a valid client cert chain to that CA fails — the request never reaches the auth layer. mTLS composes with, and does not replace, bearer auth: the RFC 0026/0029 resolver still runs on every request that survives the handshake. Client-cert identity extraction (SAN → tenant binding) is deliberately out of scope (§7.1).

3.4 Plaintext + auth = warning

When any credential source (auth.tokens / auth.oidc) is enabled and a listener has no *_tls block, startup logs one prominent warning naming the listener (“bearer credentials over plaintext”). It is not a hard error: TLS may legitimately terminate at a fronting proxy/mesh. Whether a future major flips this to opt-out strictness is an open question (§7.2).

3.5 What deliberately does not change

  • The auth layer (RFC 0026/0029): resolvers, bindings, audit events, telemetry — untouched. TLS sits strictly below it.
  • Open mode: a listener with neither a *_tls block nor credentials behaves exactly as today.
  • Outbound TLS (object storage): already rustls via object_store; not this RFC.
  • The Helm chart gains value plumbing (secret-mounted certs → the grpc_tls/http_tls blocks) in a follow-up chart release; the chart is not part of the acceptance gate here.

4. Alternatives considered

  • tonic’s built-in tls feature for gRPC + separate axum-side wiring. Two TLS stacks to configure and keep consistent; tonic’s feature also pins its own rustls wiring. One TlsAcceptor in front of all three serve loops is smaller and uniform.
  • Terminate TLS only at the gateway, document, and skip native support. The Loki model. Rejected: it leaves bearer tokens plaintext on every non-mesh deployment, contradicts the Collector norm our operators expect, and #331 explicitly scopes native TLS as the base everything else builds on.
  • SIGHUP-triggered reload instead of an interval. Signals are awkward in containers (PID 1 handling) and unavailable on some targets; the Collector’s reload_interval is the established shape. Interval it is.
  • Hard-fail auth-over-plaintext (§3.4 as an error). Would break every current mesh-terminated deployment on upgrade; a warning preserves them while making the risk visible.

5. Acceptance criteria

Each criterion is a Given/When/Then that lands as a red test first (the Red gate, docs/verification.md). Test CAs/certs are minted at test-time with rcgen — no committed key material (house rule since the RFC 0029 fixture-key incident).

Scenario RFC0030.1 — gRPC ingest over TLS. Given a receiver grpc listener with cert_file/key_file from a test CA, When an OTLP gRPC client connects over TLS trusting that CA and exports a batch, Then the export succeeds and the batch is ingested; And When a plaintext gRPC client dials the same port, Then the connection fails at the transport layer and nothing reaches the auth layer or the WAL.

Scenario RFC0030.2 — HTTP ingest over TLS. Given a receiver http listener with cert_file/key_file from a test CA, When an OTLP/HTTP client posts a batch to https://…:4318 trusting that CA, Then the export succeeds and the batch is ingested; And When a plaintext http:// request hits the same port, Then it fails at the transport layer and nothing reaches the auth layer or the WAL.

Scenario RFC0030.3 — querier + MCP over TLS. Given a querier listener with TLS enabled and a static bearer configured, When a query request (valid bearer + X-Ourios-Tenant for a tenant the token binds) and an MCP initialize (valid bearer) arrive over TLS, Then both succeed — transport is the only variable under test; And a plaintext request to the same port fails at the transport layer.

Scenario RFC0030.4 — mTLS require-and-verify. Given a listener with client_ca_file set and a static bearer configured, and a valid bearer presented in every case below (only the client cert varies), When the client presents a cert signed by that CA, Then the request proceeds through bearer auth (RFC 0026) and is ingested; When the client presents no cert, Then the handshake fails; When the client presents a cert from a different CA, Then the handshake fails. In the two failure cases nothing reaches the request handler or the auth layer.

Scenario RFC0030.5 — config validation. Given cert_file without key_file, or client_ca_file without a server pair, or min_version: "1.1", When the server starts, Then startup fails with an error naming the exact offending field; Given an unreadable or non-PEM cert_file, Then startup fails naming the path.

Scenario RFC0030.6 — certificate reload. Given a TLS listener with reload_interval_secs set and an established baseline connection, When the cert/key files are replaced with a new pair (same CA) on disk and the interval elapses, Then new handshakes serve the new certificate (observed via the peer certificate’s serial) without a process restart; And When the files are replaced with garbage, Then new handshakes keep serving the last good certificate and an error is logged.

Scenario RFC0030.7 — plaintext-auth warning. Given auth.tokens configured and a listener without a *_tls block, When the server starts, Then exactly one warning naming that listener is emitted; Given the same listener with its *_tls block configured, Then no such warning.

Scenario RFC0030.8 — served end-to-end (Collector-shaped client). Given the served ourios-server binary running both roles in one process (the deployment-level end-to-end; the test lives in ourios-server, §6), with TLS on both receiver listeners, mTLS on gRPC, and TLS on the querier, When an OTLP exporter that is configured the Collector way (tls.ca_file plus a client cert pair) exports over gRPC, and a second exporter posts the same way over HTTPS, Then both batches land and are queryable over the TLS querier — the full stack, with no plaintext hop.

Scope (clarified 2026-07-10, maintainer-approved). RFC0030.8 asserts transport end-to-end only: every hop — gRPC ingest, HTTP ingest, and query — is TLS, gRPC is mutually authenticated at the transport layer, and no plaintext hop exists in the served stack. It deliberately does not assert any client-cert-identity → tenant binding; that is open question §7.1, deferred. Application-layer authentication is verified by RFC 0026 / 0029; .8 is the transport composition of those layers, not a re-test of them. (“Queryable over the TLS querier” is met by the query surface serving over TLS; the served sink flushes only on graceful drain, so landing is read back from the store after shutdown — the batches are durable and the read transport is exercised.)

Scenario RFC0030.9 — min_version enforcement. Given min_version: "1.3", When a client attempts a TLS 1.2-only handshake, Then the handshake is refused; a TLS 1.3 handshake succeeds.

6. Testing strategy

  • §5 arms live as integration tests in the owning crates (ourios-ingester for the .1/.2/.4/.5/.6/.9 receiver + seam arms, ourios-server for .3/.7/.8 — .7 observes the spawned binary’s startup warning, which only the server crate can do), joining the consolidated harnesses (RFC 0028) — no new test binaries.
  • rcgen mints a CA + server/client leaves per test; nothing key-shaped is committed (RFC 0029 precedent).
  • Reload (.6) drives a temp-dir cert swap and polls handshakes with a short interval — bounded, no wall-clock sleeps beyond the interval.
  • TLS handshake overhead on the ingest hot path is measured indicatively on ci-runner (house bench rule) and recorded on the epic; it is a diagnostic, not a gate — TLS cost is a known, accepted tax.

7. Open questions

  1. Client-cert identity → tenant binding. mTLS here is transport only. Mapping a client-cert SAN to an RFC 0026 (name, tenants) binding (the Envoy-style pattern) would make certs a third credential kind. Deferred until a deployment actually asks for it.
  2. Auth-over-plaintext as a hard error. §3.4 warns. A future major could flip the default (opt-out via an explicit allow_plaintext_credentials: true), matching the Collector’s bearertokenauth stance. Maintainer call, post-1.0 discussion.
  3. cipher_suites / curve_preferences exposure. The Collector exposes both; rustls’s defaults are deliberately safe and narrow. Left out until someone presents a compliance requirement.
  4. HTTP→HTTPS redirect / dual-listen. Some operators expect the plaintext port to keep answering with a redirect during migration. Out of scope; a listener is either TLS or plaintext.

8. References

  • #331 — the authn/transport epic this RFC advances (“TLS/mTLS on both listeners first (everything else depends on it)”).
  • RFC 0026 — authentication + tenant binding (accepted); RFC 0029 — OIDC bearer layer (green). The layers this RFC carries.
  • OTel Collector configtls server settings — the config model mirrored here (cert_file/key_file/client_ca_file/ min_version; the Collector’s reload_interval is spelled reload_interval_secs in RFC 0020 terms; client_ca_file ⇒ RequireAndVerifyClientCert).
  • rustls / tokio-rustls — the TLS stack (already the workspace’s via reqwest/object_store; no OpenSSL).

RFC 0031 — Comparative evaluation vs Loki


rfc: 0031 title: Comparative evaluation against Grafana Loki status: red author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-07-11 supersedes: — superseded-by: —

RFC 0031 — Comparative evaluation against Grafana Loki

1. Summary

Pins the methodology for the one measurement the project has never made: Ourios against the incumbent it defines itself against. CLAUDE.md §1 states the existence test — “Not a Loki/Mimir/ ClickHouse clone. If the answer is ‘just use $X,’ we should not be building this” — and to date every thesis-gate in docs/benchmarks.md is self-referential (Ourios versus its own full scan, versus zstdcat | grep). This RFC adds Grafana Loki as a second reference system and fixes the comparative methodology: the same OTLP stream ingested into both, the same logical queries run against both on the same hardware, and a fixed set of comparative gates (the L-gates) written into docs/benchmarks.md. The headline corpus is a real OpenTelemetry-Demo OTLP capture — Ourios is an OTLP-native backend, so the honest test is real OTLP logs, the workload we claim to do best, not a favourable plain-text corpus. The query taxonomy is anchored to OpenTelemetry’s own stated log correlation/analysis model (§2.3): the four must-win classes exercise the four ways Ourios turns OTLP structure into pruning — template id, resource/attribute columns, high-cardinality trace context, and typed template parameters for frequency aggregation. The load-bearing metric is bytes read from object storage per query — the implementation- independent expression of the pruning thesis — with wall-clock latency reported as practical corroboration. Result-set equivalence (multiset-exact), a committed and competent (non-strawman) Loki configuration, and mandatory publication of losses are acceptance criteria, not afterthoughts. This RFC amends docs/benchmarks.md §1 (reference systems) and §7 (thesis-gate escalation); it does not touch any CLAUDE.md §3 invariant or the Parquet schema.

2. Motivation

2.1 The thesis has only been tested against a strawman

docs/benchmarks.md §1 names exactly one reference system: zstdcat <file.zst> | grep <pattern>. The B1 gate is “≥ 10× faster than zstdcat | grep”; B2 is “scales with result size, not corpus size.” Both are real and both pass (§9.4, §9.8) — but both measure the mechanism, not the choice. Parquet footer statistics do prune row groups; the template count does converge. What no number in the repository shows is that this beats the system a prospective user would otherwise reach for. Loki also beats zstdcat | grep. The question CLAUDE.md §1 raises — is there a reason to run Ourios instead of Loki — is the project’s existential question, and it is unmeasured.

2.2 Why Loki, specifically

Of the three systems CLAUDE.md §1 names, Loki is the sharpest comparison because it shares the premise and differs in the mechanism. Both Ourios and Loki reject the full inverted index of Elasticsearch/Quickwit; both store compressed log blocks on object storage and lean on cheap storage plus selective reads. Where they diverge is exactly the Ourios thesis:

  • Loki indexes a small set of operator-chosen labels and, within the matching label streams, brute-force scans (greps) compressed chunks.
  • Ourios mines a template id per line at ingest and leans on Parquet’s per-row-group min/max statistics, bloom filters, and page indexes to skip chunks the query cannot match — automatically, without the operator choosing labels, and at a granularity finer than a label stream.

The comparison therefore tests the precise claim in CLAUDE.md §2 pillar #1–#2: that automatic template mining + Parquet pruning skips more data than label-index + chunk scan on the selective queries that dominate real log investigation. ClickHouse (general-purpose columnar) and Quickwit (full-text index) are different enough in philosophy that comparing to them answers a different question; they are noted in §4 and deferred.

2.3 OTLP is where the gap is widest, and OTel names the axes

The comparison runs on real OTLP logs (§3.3) because that is the workload Ourios exists for, and because OTLP structure is exactly where the two mechanisms diverge hardest. Critically, the query taxonomy is not invented here: the OpenTelemetry Logs specification’s Log Correlation section names the dimensions along which logs are navigated, filtered, queried and analysed — “these correlations can be the foundation of powerful navigational, filtering, querying and analytical capabilities” — and they are precisely the axes Ourios prunes on:

  • Time of execution — every query is time-bounded; Parquet row-group time statistics prune it.
  • Execution (trace) contexttrace_id / span_id on the LogRecord. The spec calls this out as what “would make logs significantly more valuable in distributed systems”: it directly correlates logs with traces and correlates logs across the components that served one request.
  • Resource contextservice.name, k8s.*, and other resource attributes identifying the telemetry’s origin.

An OTLP log record arrives with severity_number, these resource attributes, log attributes, and the trace context. Ourios promotes this structure into queryable, statistics-bearing columns automatically (template id at ingest per RFC 0001; severity, service, and configured attributes as Parquet columns per RFC 0022), so per-row-group min/max and bloom filters prune on OTLP fields without the operator declaring anything. Loki’s model is the inverse: an operator must hand-pick a small set of low-cardinality labels, and everything else is brute-force chunk scan. Four consequences follow, and they are the four must-win query classes (§3.4):

  • Where template mining fires, Ourios prunes on template id (L1).
  • Where it does not (the OTel-Demo capture is heavily NO_TEMPLATE on some services — RFC 0023), Ourios still prunes on the promoted resource/attribute columns (severity, service.name — L2). The pruning thesis on native OTLP is therefore template mining + attribute promotion, a stronger and more honest framing than a synthetic well-templated corpus would show.
  • trace_id is high-cardinality by construction, so it cannot be a Loki label without exploding Loki’s index. Loki must brute-force scan to answer “show me every log line for this trace”; Ourios promotes trace_id to a bloom-filtered column and prunes to the handful of row groups that contain it (L3).
  • Template mining yields typed parameters, so “how often does template X fire over time, grouped by extracted field Y” is a columnar GROUP BY for Ourios. This is a first-class OTLP operator workflow — the canonical OTLP-log query set opens with a severity-count time series, and an OTel-native vendor doing Drain-style mining demonstrates “a log-frequency alert filtering on the pattern and grouping by the product-id field … without any metrics, without an extra metric, without a regular expression” (OTel Night, Berlin 2025). Loki, holding unstructured chunks and no typed params, must scan and regex-and-count. This is the workload the template + params pillar exists to serve (L4).

2.4 Why measurement now

The engineering is substantially complete (RFCs 0001–0030 green or beyond; both data paths shipped and gated). The marginal green RFC no longer changes whether the project should exist; the comparative number does. docs/benchmarks.md §7 already states the discipline: “The worst failure mode for a greenfield project is shipping something whose central claim quietly fails on real data and then papering over it with more implementation.” An unmeasured existential comparison is that failure mode latent. This RFC converts it into a gate — one that can be lost, and whose loss is a pillar-level signal, not a tuning knob.

2.5 Why bytes-read is the primary metric, not latency

Ourios is a young implementation on top of DataFusion; Loki is a mature engine with years of query-path optimisation. A naive latency-only comparison confounds two very different claims — “Parquet pruning reads less data” (an architectural claim, the thesis) and “our query engine is faster today” (an implementation- maturity claim, not the thesis). We isolate the thesis by making the primary gate bytes read from object storage per query: the direct, engine-independent measure of how much data each architecture must touch to answer a query. Pruning is, definitionally, reading less. Wall-clock latency (p50/p99) is reported alongside as the number an operator actually feels, but a latency loss paired with a decisive bytes-read win is interpreted as “sound architecture, young implementation” — a roadmap signal — whereas a bytes-read loss on a selective query is a thesis failure. This asymmetry is the honesty core of the RFC and is fixed in §5, not left to interpretation after the fact.

3. Proposed design

3.1 Shape

A new comparative bench workstream, layered on the RFC 0006 harness and the RFC 0007 querier, that:

  1. Ingests one fixed corpus into both systems over their native OTLP path (§3.3).
  2. Runs a fixed query taxonomy (§3.4) against both, expressed once in the Ourios DSL and once in LogQL, asserting result-set equivalence (§3.5) before any timing is trusted.
  3. Records the L-gate metrics (§3.6) into docs/benchmarks.md §9 in the same diff-reviewable shape RFC 0006 established.
  4. Ships the exact Loki configuration and orchestration in-repo so the comparison is third-party-reproducible (§3.7).

The Ourios-side numbers come from the existing querier and its OTel query metrics (RFC 0016: scanned / pruned row-group counts, which this RFC extends to bytes — §3.6). The Loki-side numbers come from Loki’s own query-statistics API (Summary.totalBytesProcessed, execTime), which Loki returns per query — no instrumentation of Loki’s internals is required or permitted (that would be a fairness hazard).

3.2 Infrastructure

Both systems run as containers under GitHub Actions (containerd; no local Docker dependency), against the same object-store backend — a single MinIO/localstack S3 endpoint — so the storage substrate is byte-for-byte identical and cannot bias the bytes-read metric. Loki runs in single-binary mode with the tsdb index and S3 chunk storage; Ourios runs its normal ingester + querier against the same bucket. Per the established norm (benchmarks.md §1, and the project’s bench-on-ci-runner-first discipline), the first comparative run is indicative on ci-runner; the authoritative run is on the baseline-8vcpu-32gib tag and is gated on maintainer opt-in. Neither system is co-scheduled with the other during a timed query (they share a bucket, not a CPU): ingest both, then quiesce, then query each in isolation with the other stopped, to remove noisy-neighbour effects from the latency numbers.

3.3 Corpus and ingest parity

The headline corpus is the OTel-Demo v8 capture — the canonical real-OTel corpus per the project’s corpus policy, native OTLP with the full attribute/trace_id structure §2.3 turns on. This is the number the project stands behind. It is worth stating plainly that the OTel-Demo logs are comparatively well-structured (shipped over OTLP as JSON with rich attributes); real-world Kubernetes logs are typically messier raw-string bodies with only basic attributes (OTel Night 2025, ibid.). So OTel-Demo is the honest OTLP headline but not a worst case — the harder real case (mostly NO_TEMPLATE, sparse attributes) is exactly where attribute promotion and the L4 aggregation carry the thesis, and §7 keeps “a messier captured corpus” as a follow-up. LogHub HDFS_v1 (already wired, bench-time-fetched, ~1.47 GiB) is retained as a secondary, well-templated sanity floor — it reproduces the best case for template mining and anchors against the Drain-paper corpora — but it is explicitly not the headline, and it is non-native (plain text replayed as text-body OTLP), so it exercises template pruning without the OTLP-attribute story.

Both corpora are fed to both systems as the same OTLP log stream: a single replay driver emits OTLP/gRPC to Ourios’s receiver and, in parallel, to Loki over OTLP (native OTLP endpoint preferred, or an OTel Collector loki exporter — §7), so neither system gets a preprocessing advantage and both derive their structure from the identical OTLP records. Label selection for Loki is part of the committed config (§3.7) and must be a competent operator’s choice (service.name, severity, a small set of low-cardinality resource attributes), not a single catch-all label that would force a full scan (an unfair strawman in Ourios’s favour), nor a high-cardinality label (trace_id, or one label per template) that smuggles Ourios’s promoted columns into Loki’s index and would blow it up in a real deployment (an unfair strawman in Loki’s favour, and not how anyone operates Loki). The label set is frozen in the config and machine-checked as the §5 RFC0031.10 gate.

3.4 Query taxonomy

Seven query classes, each with a must-win / acknowledged-loss / floor / parity disposition fixed up front so the result cannot be reframed after it is known. The four must-win classes map one-to-one onto OTel’s log analysis axes (§2.3) and the four ways Ourios turns OTLP structure into pruning:

ClassQueryOTel axis / Ourios pruning mechanismDisposition
L1Template-exact lookup: all lines of one rare template over the full corpusbody pattern → template id (RFC 0001)must-win (thesis)
L2Attribute predicate: severity ≥ ERROR AND service.name = X over a bounded windowresource context → promoted columns + Parquet stats (RFC 0022)must-win (thesis)
L3Trace correlation: every log line for one trace_idexecution context → high-cardinality bloom columnmust-win (thesis, OTLP-native)
L4Frequency aggregation: count of a template over time, grouped by an extracted paramtyped template params → columnar GROUP BYmust-win (thesis, OTLP-native)
L5Substring needle: an arbitrary literal not captured by a template or a promoted column (embedded in a param)none (brute scan for both)acknowledged — loss permitted, published
L6Broad scan: all lines in a wide time range, low predicate selectivitylittle prunesfloor — bounded, not must-win
L7Ingest throughput: sustained OTLP lines/s to steady stateparity — within a stated factor

L1–L4 are where the pruning thesis lives and must win on bytes-read (§3.6). L3 and L4 are the two Loki structurally cannot serve efficiently: L3 because trace_id cannot be a label, L4 because Loki holds no typed params and must scan-then-regex-and-count where Ourios does a columnar aggregation. L5 is the honest inclusion: neither template mining nor attribute promotion helps a substring the miner folded into a parameter, and Loki’s brute-force chunk grep may match or beat Ourios there — we publish it. L6 tests the floor (when little can be pruned, Ourios must not be catastrophically worse — bounded, not required to win). L7 checks that thesis-side query wins are not bought with an unacceptable ingest regression.

3.5 Result-set equivalence (the integrity gate)

A latency or bytes comparison between two queries that return different answers is meaningless. For every query in the taxonomy, the harness compares the two systems’ answers exactly before any metric for that query is recorded:

  • For the line-returning classes (L1–L3, L5, L6) it extracts each system’s matching lines keyed by (timestamp_unix_nanos, body_bytes) and compares as a multiset — the count of each key must match, not merely the set, so a system returning three identical duplicate lines where the other returns two is a mismatch, not a silent pass.
  • For the aggregation class (L4) the grouped result itself is the answer: the (bucket, group_key) → count map must be identical between systems.

A mismatch fails the run (non-zero exit, no metric written for that class) — it means the two queries are not asking the same question and the comparison is invalid. This is RFC0031.1 and it gates every other L-scenario.

3.6 Metrics and the bytes-read extension

Per query, per system, the harness records:

  • bytes_read — bytes fetched from object storage to answer the query. Ourios: extended from the RFC 0016 scanned/pruned row-group counts to the bytes of the row groups actually read (footer + read row-group byte length), emitted on the existing OTel query-metrics path. Loki: recorded on two channels (definitions in the 2026-07-13 amendment below): storage-side (compressedBytes + headChunkBytes) and processed (totalBytesProcessed); each frozen gate cites one (§7). Primary gate metric — with the rationale applying to Ourios’s figure and Loki’s storage-side channel; the processed channel measures decompressed engine work, not fetched bytes. Because the storage-side comparison counts bytes fetched from the shared object store, it is by construction insensitive to CPU speed and engine maturity; to keep it insensitive to local page cache as well, each measured query runs against a freshly started server with OS page cache dropped, so a warm local cache cannot mask an architecture that would fetch more from storage.
  • latency_p50 / latency_p99 — wall-clock over N repetitions, reported for both a cold reading (fresh process, dropped cache — the same state the bytes-read gate is measured in) and a warm reading (repeated in-process), stated separately. Corroborating, not sole-gating (§2.5).
  • storage_footprint — total bytes each system persists for the corpus on the shared bucket. Recorded diagnostic (like A1, per RFC 0011 — a byte codec captures redundancy the thesis does not claim to beat); not gating.
  • ingest_throughput — steady-state OTLP lines/s (L7 only).
  • peak_rss — high-water memory of each system’s query path, diagnostic.

Measurement-fidelity amendment (2026-07-12, RFC in red). The Ourios-side bytes_read figure is the total bytes fetched from object storage to answer the query: the count/pruning scan plus the row-materialization scan that fetches the ≤ limit returned records plus the template-registry derivation (the RFC 0017 §3.2 audit-stream read that reconstructs string bodies). The channel previously reported the count scan alone, silently excluding two real IO components and biasing the ratio in Ourios’s favour; Loki’s counterpart figure includes delivering results, so the §3.7 anti-strawman discipline requires ours to as well. The querier’s QueryStats::bytes_read keeps its count-scan-only meaning (the B1/B2 gates and the RFC 0016 metrics depend on it); the two new components are additive QueryResult fields the harness sums.

Template-map acquisition (amendment, 2026-07-13, RFC 0033). Since RFC 0033’s cached template-map artifact, the third component is the template-map acquisition bytes: the total bytes fetched to obtain body-rendering capability, whatever the source — the audit-stream fold on a cache miss (byte-for-byte the registry derivation described above) or the template_map.json artifact GET on a cache hit. QueryResult::registry_bytes_read keeps its name and its additive place in the three-component sum; only the source of the bytes changes. One field, one honest meaning — the harness needs no code change.

Channel definitions (amendment, 2026-07-13). The Loki comparator is recorded on two channels, and each frozen gate names which it uses (§7): the storage-side channel (compressedBytes + headChunkBytes from the query-stats tree — compressed chunk bytes fetched from storage plus memory-served head-chunk bytes, the latter counted so data not yet flushed is not free; the conservative apples-to-apples counterpart of Ourios’s fetched-compressed total) and the processed channel (totalBytesProcessed — decompressed engine work, the measure of the scanning the §1 thesis eliminates). Both are always recorded; gates cite one. Where a §5 scenario’s shorthand reads loki.bytes_read (or names Summary.totalBytesProcessed directly — legacy wording, kept for scenario stability, not a redefinition of that key), interpret it as the channel the frozen gate cites in §7: storage-side for RFC0031.2/.4, processed for RFC0031.3 under the interim rule.

3.7 Reproducibility and anti-strawman commitment

The entire comparison — Loki config (index, chunk, retention, S3, label selection), the OTLP-into-Loki config (native endpoint or an OTel Collector loki exporter — §7), the query pairs (DSL ↔ LogQL), and the orchestration — is committed under bench/comparative/ and runnable by a third party with one command. The Loki configuration must be a good-faith competent deployment: tuned chunk target size, appropriate index period, the label set from §3.3. The config carries a header comment inviting challenge, and the L-gate results in benchmarks.md §9 link the exact config commit. Crucially the label set is machine-checked, not merely eyeballed (RFC0031.10): a test asserts the committed labels are drawn from a declared low-cardinality allowlist and that the disallowed keys (trace_id, span_id, and any per-template id) are absent, so a strawman config cannot slip in unnoticed. A benchmark whose loser’s configuration cannot be inspected and re-run is not evidence; this section is what makes the number defensible rather than a claim.

3.8 benchmarks.md amendments

  • §1 gains Loki as a second reference system, described as above.
  • §7 gains the L-gate escalation: an L1, L2, L3, or L4 bytes-read loss on the headline OTel-Demo corpus is a pillar-level finding (revisit CLAUDE.md §2 before further implementation), exactly as two failing thesis-gates are today. A must-win latency loss with a bytes-read win is a roadmap item, not an escalation. L5 (substring) loss is expected and never escalates. L6 beyond its floor, or an L7 regression past its factor, is a tuning RFC.

4. Alternatives considered

Compare against ClickHouse instead of Loki. ClickHouse is the closest system architecturally (columnar, statistics-based skipping), so a ClickHouse comparison would test “did we build a worse ClickHouse” rather than “should you use Ourios over the log-native incumbent.” It is the more flattering comparison to defer and the more dangerous one to skip; it belongs in a follow-up RFC once the Loki number exists, because losing to ClickHouse-on-logs is a distinct and also-existential finding. Deferred, not dismissed.

Compare against Quickwit / Elasticsearch. These carry a full-text inverted index — the exact structure CLAUDE.md §2 claims to collapse. They will win outright on arbitrary substring search (L5-like queries) and pay for it in storage and ingest. That trade is already understood and is not the question Ourios’s thesis stakes itself on; benchmarking it measures a different product. Out of scope (benchmarks.md §8 already excludes SIEM-style full-text latency).

Keep zstdcat | grep as the only reference. This is the status quo and it is insufficient for the reason in §2.1: it validates the mechanism, not the choice. Retained as a floor, not removed.

Latency as the primary gate. Rejected in §2.5: it confounds the architectural thesis with implementation maturity and would let a young-engine latency loss read as a thesis failure (or, worse, tempt us to chase engine micro-optimisation to rescue a number that the architecture already wins on bytes). Bytes-read is the honest primary.

No result-set equivalence check — just run “the same query” in each DSL. Rejected: LogQL and the Ourios DSL have different matching semantics (label streams vs template ids vs substrings), and “looks equivalent” is exactly how comparative benchmarks lie. §3.5 makes multiset-exact equivalence a hard precondition.

Make it an RFC 0006 amendment rather than a new RFC. RFC 0006 pins the self-referential thesis-gate methodology; this introduces a second system, an equivalence harness, and a fairness contract — enough new surface, and enough new failure modes, to warrant its own decision record. It references RFC 0006’s harness rather than editing it.

5. Acceptance criteria

Scenario RFC0031.1 — Result-set equivalence gates every comparison

  • Given a query from the §3.4 taxonomy expressed as an Ourios-DSL / LogQL pair, and the fixed corpus ingested into both systems
  • When the harness executes both queries
  • Then for a line-returning class it extracts each system’s matching lines keyed by (timestamp_unix_nanos, body_bytes) and asserts the two multisets are identical (per-key counts equal, so duplicates are not silently collapsed); for the L4 aggregation class it asserts the (bucket, group_key) → count maps are identical
  • And if the answers differ, the harness records no L-metric for that class, writes the symmetric-difference (or count-delta) summary and up to N example keys to stderr, and exits non-zero
  • And no benchmarks.md §9 row is written for a class whose equivalence check did not pass

Scenario RFC0031.2 — L1 selective template lookup wins on bytes read

  • Given the headline OTel-Demo corpus ingested into both systems and a template that matches < 0.1% of corpus lines
  • When the harness runs the L1 query against each and reads bytes_read (Ourios: row-group bytes actually read per the RFC 0016 metric extension; Loki: Summary.totalBytesProcessed)
  • Then ourios.bytes_read / loki.bytes_read ≤ 1 / M_L1 where M_L1 is the committed must-win margin (§7)
  • And the class disposition in the results is must-win, so a result above the ratio flips l1.pass = false and is surfaced as a pillar-level finding per benchmarks.md §7 (amended)
  • And latency_p50, latency_p99 (cold and warm) are recorded for both systems as corroborating, non-gating numbers

Scenario RFC0031.3 — L2 attribute predicate wins on bytes read

  • Given the headline corpus ingested into both systems and the L2 predicate (severity ≥ ERROR AND service.name = X over a bounded window) expressed equivalently in both DSLs, equivalence per RFC0031.1 holding
  • When the harness runs L2 against each
  • Then ourios.bytes_read / loki.bytes_read ≤ 1 / M_L2
  • And the same pillar-level escalation as RFC0031.2 applies on failure

Scenario RFC0031.4 — L3 trace correlation wins on bytes read (OTLP-native)

  • Given the headline corpus ingested into both systems and a trace_id present in it, with trace_id not a Loki label (per the §3.3 frozen set — high-cardinality and un-labelable), equivalence per RFC0031.1 holding
  • When the harness runs “every log line for this trace_id” against each (Ourios: bloom-filtered promoted column; Loki: label-stream scan)
  • Then ourios.bytes_read / loki.bytes_read ≤ 1 / M_L3
  • And the class disposition is must-win with the same pillar-level escalation as RFC0031.2 on failure — this is a query Loki’s model cannot answer without a full scan (§2.3), so a loss here is among the strongest possible signals against the thesis

Scenario RFC0031.5 — L4 frequency aggregation wins on bytes read (OTLP-native)

  • Given the headline corpus ingested into both systems and a frequency-aggregation query — count of one template over time, grouped by an extracted param (Ourios: columnar GROUP BY on template_id + a typed param column; Loki: count_over_time with a LogQL pattern/label_format extraction over scanned chunks) — equivalence per RFC0031.1 (the grouped-count maps) holding
  • When the harness runs L4 against each
  • Then ourios.bytes_read / loki.bytes_read ≤ 1 / M_L4
  • And the class disposition is must-win with the same pillar-level escalation as RFC0031.2 on failure — this is the query the template + typed-params pillar exists to serve (§2.3)

Scenario RFC0031.6 — L5 substring needle is measured and published, loss permitted

  • Given an L5 query for a literal not captured by a template or a promoted column (embedded in a param, so nothing prunes it), equivalence per RFC0031.1 holding
  • When the harness runs L5 against each
  • Then both systems’ bytes_read and latency are recorded with class disposition acknowledged
  • And the run passes irrespective of which system wins — an Ourios loss here does not fail the run and does not escalate, but it must appear in the published benchmarks.md §9 table (a suppressed L5 loss is a process violation)

Scenario RFC0031.7 — L6 broad scan stays within the floor

  • Given an L6 low-selectivity wide-time-range query, equivalence holding
  • When the harness runs L6 against each
  • Then ourios.latency_p50 ≤ F_L6 × loki.latency_p50 where F_L6 is the committed floor factor (§7)
  • And exceeding the floor is a tuning-RFC signal, not a pillar-level escalation

Scenario RFC0031.8 — L7 ingest throughput parity within a stated factor

  • Given the OTLP replay driver feeding both systems to steady state on the same hardware
  • When the harness measures sustained lines/s for each
  • Then ourios.ingest_throughput ≥ loki.ingest_throughput / F_L7 where F_L7 is the committed parity factor (§7)
  • And the WAL-before-ack invariant (CLAUDE.md §3.4) is not relaxed to obtain the number — Ourios’s throughput is measured with durable acks, and the config proving it is recorded

Scenario RFC0031.9 — Storage footprint is recorded as a diagnostic, not a gate

  • Given both systems having ingested the full corpus into the shared bucket
  • When the harness sums each system’s persisted bytes
  • Then both storage_footprint values and their ratio are written to benchmarks.md §9 as a diagnostic row
  • And no pass/fail is derived from it (parity with A1’s RFC 0011 demotion — a byte codec captures redundancy the thesis does not claim on disk)

Scenario RFC0031.10 — The Loki configuration is committed, competent, and machine-checked

  • Given the comparative workstream under bench/comparative/
  • When a third party checks out the repo
  • Then the exact Loki config (index, chunk target size, S3 backend, retention, and the frozen label set), the OTLP-into-Loki config, and the DSL↔LogQL query pairs are present and the whole comparison runs with a single documented command
  • And a test asserts the label set is drawn from a declared low-cardinality allowlist and that trace_id, span_id, and any per-template id are absent — so neither a single catch-all label (forcing Loki into a full scan) nor a high-cardinality label (smuggling Ourios’s promoted columns into Loki’s index) can slip in; the config header states this and invites challenge
  • And each L-gate row in benchmarks.md §9 links the config commit used to produce it

Scenario RFC0031.11 — Losses are published and escalation follows benchmarks.md §7

  • Given a completed comparative run
  • When results are written to benchmarks.md §9
  • Then every class in the taxonomy appears — wins and losses — with its disposition, both systems’ numbers, the corpus, and the hardware tag
  • And an L1, L2, L3, or L4 bytes-read loss on the headline OTel-Demo corpus is recorded as a pillar-level finding that pauses further implementation pending a CLAUDE.md §2 revisit (the §7 amendment), whereas a must-win latency-only loss with a bytes-read win is recorded as a roadmap item

6. Testing strategy

Per CLAUDE.md §6.2, mapped to the §5 scenario ids:

  • Equivalence harness (RFC0031.1) — an integration test over a small committed fixture corpus (not the full OTel-Demo/HDFS fetch) that runs a DSL↔LogQL pair against a containerised Loki and the in-process querier and asserts multiset-equality of the keyed line sets (and grouped-count maps for L4); a deliberately mismatched pair, and a duplicate-count mismatch, both assert the non-zero-exit / no-write path.
  • L-gate computation (RFC0031.2–RFC0031.9) — unit tests over recorded/synthetic per-query metric inputs assert the ratio math, the pass/fail dispositions, and the diagnostic-vs-gating distinction (mirroring RFC 0006’s a1/c2 gate-math unit tests). The margins M_L1, M_L2, M_L3, M_L4, F_L6, F_L7 are configuration, so a calibration test pins their wiring, not their values.
  • Bytes-read metric extension (RFC0031.2–.5) — a querier test asserts the new bytes-read figure equals the summed byte length of the row groups the RFC 0016 path reports as scanned (and excludes pruned), so the primary gate metric is verified against the existing pruning counters rather than trusted.
  • Config machine-check (RFC0031.10) — a test parses the committed Loki + OTLP-path configs, asserts the label allowlist / disallowlist property, and asserts the documented one-command entry point exists and references them.
  • Full comparative run (RFC0031.11) — a workflow_dispatch job (indicative on ci-runner first, authoritative on baseline-8vcpu-32gib on opt-in) ingests the OTel-Demo capture (the headline) and HDFS_v1 (the secondary floor), runs the taxonomy end to end, and appends the §9 table. Not a per-PR gate (it fetches large corpora and runs two systems); it is the RFC-validated step, consistent with benchmarks.md’s authoritative-run cadence.

Validation (benchmarks.md §7): RFC 0031 reaches validated when the authoritative comparative run has been recorded in §9 with L1, L2, L3, and L4 passing on the headline OTel-Demo corpus. A must-win failure does not block validated in the “we didn’t finish” sense — it is a result, and per §5 RFC0031.11 a pillar-level one.

7. Open questions

  • Must-win margins — PARTIALLY FROZEN (2026-07-13, informed by the benchmarks.md §9.13 calibration record — whose channel choice was still open at its writing; this amendment resolves it. Maintainer delegated). M_L1 = 10 and M_L3 = 10 are frozen on the storage-side channel (the conservative one, §3.6 channel definitions): both classes clear it with headroom (L1 77.2–77.7×, L3 21.2–21.9×) across 3–4 consecutive equivalence-verified runs, and both wins are structural rather than tuned. M_L2 is deferred with a named condition: the measured storage-side band is 1.05–1.31× — an honest parity, not a 10× claim — and two named levers (the RFC 0033 cached template map, constant 513,862 bytes per query, and write-side sizing) are expected to move it; freeze after RFC 0033 lands. Until then L2 gates on the processed channel at M = 10 (measured 32.5–39.3×), with the storage-side figure recorded as informational. M_L4 is deferred until L4 is first measured (query shape below). Rationale for the split channels is the benchmarks.md §9.13 assessment: the storage channel is the conservative claim where we can make it, and the processed channel measures the work the §1 thesis eliminates.
  • Floor / parity factors — F_L6 FROZEN, F_L7 DEFERRED (2026-07-13). F_L6 = 3 is frozen on the latency channel, as RFC0031.7 is written: run #18 measured all three window pairs inside the floor (ratios 0.34 / 3.43 / 1.32, oriented loki_p50 / ourios_p50 so > 1 means Ourios is faster; the floor passes at ≥ 1/3 — Ourios outright faster on two of three). Harness alignment (asserting the frozen gates instead of reporting them) lands in the companion slice immediately after this amendment. The window pairs’ bytes figures are reclassified from a gated floor to a published diagnostic (informational bar, benchmarks.md taxonomy): the storage-channel loss (0.003–0.018 across the record; 0.007–0.018 on current code, post-#486) is real, structural to time-partitioned chunks vs columnar layout, small in absolute terms (≤ 4.5 MB), and its only lever is the write-side layout fork — publishing it honestly is the commitment; gating on it would gate on a number we do not intend to chase. F_L7 = 2 stays deferred until L7 (ingest parity) is first measured.
  • L4 aggregation query shape. Which template + param + bucket width best represents the real alerting/dashboard workload on the OTel-Demo corpus, and how is the LogQL equivalent (pattern/label_format extraction + count_over_time … by) pinned so RFC0031.1 equivalence is achievable? Confirm against LogQL’s current metric-query surface at implementation time.
  • Headline corpus — DECIDED: OTel-Demo. Ourios is an OTLP-native backend, so the honest headline is real OTLP logs — the workload the project claims to do best — not the favourable well-templated HDFS_v1. HDFS_v1 is retained only as a secondary well-templated sanity floor (§3.3). A messier real-world captured corpus (sparse-attribute k8s text) is a worthwhile follow-up but not required for the first result. (Maintainer decision, 2026-07-11.)
  • Loki index backend. tsdb (current Loki default) vs boltdb-shipper. Pick the one a competent 2026 operator would deploy; likely tsdb. Confirm against Loki’s current guidance at implementation time.
  • OTLP → Loki path. Loki’s native OTLP endpoint vs an OTel Collector with the loki exporter. Native OTLP is the fairer apples-to-apples (both consume OTLP directly); confirm label derivation is equivalent to the frozen set either way.
  • New crate vs ourios-bench extension. Does the comparative driver + equivalence harness live in ourios-bench or a new bench/comparative/ (non-crate) harness plus a small querier-side metric addition? A new crate is a CLAUDE.md §7 commitment; a harness under bench/ is not. Leaning bench/ + a querier metric extension. Maintainer call.
  • Does this touch docs/hazards.md? The comparison itself adds no runtime hazard, but the bytes-read metric extension touches the RFC 0016 query-metrics path; confirm no regression to those counters.

8. References

  • CLAUDE.md §1 (the existence test — “just use $X”), §2 (pillars #1 Parquet pruning, #2 template mining), §3.4 (WAL-before-ack, held in L7), §7 (new-crate commitment, open question).
  • docs/benchmarks.md §1 (reference systems — amended), §7 (thesis-gate escalation — amended), §8 (out-of-scope: full-text latency), §9 (results shape).
  • RFC 0006 — bench harness (the self-referential thesis-gate methodology this extends; A1/C1/C2 gate-math test pattern reused).
  • RFC 0007 — querier (provides the query path measured here).
  • RFC 0010 — audit-stream / drift queries (template-frequency aggregation precedent the L4 gate builds on).
  • RFC 0011 — A1 demotion to diagnostic (precedent for the storage-footprint diagnostic disposition, RFC0031.9).
  • RFC 0016 — query-serving endpoint and OTel query metrics (scanned/pruned counts, extended here to bytes-read).
  • RFC 0022 — promoted attribute columns (the resource-context pruning L2 exercises).
  • RFC 0023 — bounded template memory (the NO_TEMPLATE fraction on heterogeneous corpora that makes the OTel-Demo corpus the honest hard case).
  • OpenTelemetry Logs specification, Log Correlation (time / execution-context / resource-context correlation — the axes the §3.4 must-win taxonomy is anchored to).
  • Canonical OTLP-log query patterns: clickhouseexporter (severity-count time series, service/attribute filters, substring, trace-id skip index) — the query classes a real OTLP log backend serves.
  • OTel Night Berlin 2025, Leveraging AI for OpenTelemetry data (an OTel-native vendor doing Drain-style template mining on OTLP logs; the template-frequency-alert workload the L4 gate models; the “real k8s logs are messier than OTel-Demo” caveat).
  • Grafana Loki — architecture (label index + chunk store) and the query Summary statistics (totalBytesProcessed, execTime) used for the Loki-side numbers.
  • Jieming Zhu et al., Loghub: A Large Collection of System Log Datasets for AI-driven Log Analytics, ISSRE 2023 (HDFS_v1 corpus; license notice in benchmarks.md §1).

RFC 0032 — Query-schema and cost-model resource


rfc: 0032 title: Query-schema and cost-model resource for the MCP surface (RFC 0027 amendment) status: green author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-07-13 supersedes: — superseded-by: —

RFC 0032 — Query-schema and cost-model resource for the MCP surface

1. Summary

Add a second MCP resourceourios://query-schema — beside the RFC 0027 grammar resource, carrying the stored-log field vocabulary and a query-class cost model: the fixed OTLP log columns (including the OTel 1–24 severity scale the DSL’s severity names compile onto), the promoted attribute columns of this deployment (the running PromotedAttributes set, RFC 0022), and a structural classification of predicate kinds into cost tiers (index-backed / pruned / scan). RFC 0027 is accepted (terminal), so this lands as a new RFC amending it, à la RFC 0022/0023/0024: read-only, additive, no new tool — the existing list_resources/read_resource hook gains one resource. The grammar resource already teaches an agent how to write a query; list_templates gives the body vocabulary; this completes the set with the field vocabulary and with which query shapes the backend answers cheaply.

2. Motivation

  • Agents guess field names; the deployment knows them. An agent can learn the DSL from ourios://dsl-grammar, but the grammar’s resource.<key> / attr.<key> productions are open-ended — which keys exist as typed, prunable columns is per-deployment configuration (storage.promoted_attributes) that no client can guess. OTel field practice supports the claim: an OTel-native vendor doing Drain-style mining reports that handing an agent semantic-convention + resource-attribute context makes it “way better at writing correct queries on the first try” (OTel Night Berlin 2025, sig-end-user transcript). Issue #465 is the scoping record.
  • The severity scale is a first-try failure mode. severity >= error only works if the client knows severity is the numeric OTel SeverityNumber and the names are four-wide bands (error → 17..=20). That mapping is Ourios’s documented choice (RFC 0002 §6.1, SeverityName::floor/ceil); it belongs in the protocol, not in each consumer’s prompt.
  • The cost model is structural, and agents can exploit it. The RFC 0031 comparative program (§9.13, epic #498) demonstrated the durable shape of Ourios query cost: exact-id lookups and promoted equality prune to a handful of row groups, time windows prune by statistics, body-substring browses scan. That tiering is true by construction — it follows from which columns the writer bloom-filters and page-indexes — so it can be published as structure without ever publishing benchmark numbers (which rot). A consumer that knows trace_id == … is cheap and contains(body, …) is a scan writes better queries at zero per-query cost to the backend, and is steered onto the backend’s structural strengths (pillar #1/#2, CLAUDE.md §2).
  • Cheap by construction. The list_resources/read_resource hook, the config plumbing (storage.promoted_attributes is already resolved into a PromotedAttributes at startup, ourios-server/src/main.rs), and the tier facts (which columns are bloomed, ourios-parquet/src/writer.rs) all exist. The new work is one JSON document and threading the promoted set into the querier role’s MCP handler.

3. Proposed design

3.1 Placement

  • A second Resource in the RFC 0027 module (crates/ourios-server/src/mcp.rs), URI ourios://query-schema, MIME application/json. list_resources returns both resources; read_resource dispatches on URI.
  • The querier role today does not receive the resolved PromotedAttributes (only the receiver’s write path does). The server threads config.promoted into mcp_routerOuriosMcp, and the resource document is built once at role startup from that set — configuration is startup-static (RFC 0020), so the document is immutable for the process lifetime, like the grammar section.
  • Read-only contract untouched: no new tool, no write, no tenant-scoped data. The document derives exclusively from static configuration and compiled-in schema facts — never from ingested telemetry, so it is the one MCP payload that carries no untrusted-content caveat.

3.2 The document

The resource body is one versioned JSON object (format_version evolution hook per the RFC 0033 precedent: consumers treat an unknown version as “fetch nothing, fall back to the grammar + docs”):

{
  "format_version": 1,
  "fields": [
    { "name": "ts",          "type": "timestamp" },
    { "name": "observed_ts", "type": "timestamp" },
    { "name": "severity",    "type": "integer" },
    { "name": "body",        "type": "string" },
    { "name": "trace_id",    "type": "hex_string" },
    { "name": "span_id",     "type": "hex_string" },
    { "name": "scope",       "type": "string" },
    { "name": "flags",       "type": "integer" },
    { "name": "service",     "type": "string" },
    { "name": "template_id", "type": "integer" },
    { "name": "confidence",  "type": "float" },
    { "name": "lossy",       "type": "boolean" }
  ],
  "severity": {
    "comparison": "numeric, OTel SeverityNumber 1-24",
    "names": [
      { "name": "trace", "floor": 1,  "ceil": 4 },
      { "name": "debug", "floor": 5,  "ceil": 8 },
      { "name": "info",  "floor": 9,  "ceil": 12 },
      { "name": "warn",  "floor": 13, "ceil": 16 },
      { "name": "error", "floor": 17, "ceil": 20 },
      { "name": "fatal", "floor": 21, "ceil": 24 }
    ]
  },
  "promoted_attributes": {
    "resource": ["service.name", "k8s.namespace.name"],
    "log": ["http.route"]
  },
  "cost_model": {
    "tiers": ["index_backed", "pruned", "scan"],
    "classification": [
      { "kind": "exact_equality", "fields": ["trace_id", "span_id", "template_id"],
        "tier": "index_backed", "mechanism": "bloom" },
      { "kind": "ordering_or_equality", "fields": ["severity"],
        "tier": "index_backed", "mechanism": "statistics" },
      { "kind": "promoted_attribute_equality",
        "fields": ["service", "resource.<promoted key>", "attr.<promoted key>"],
        "tier": "index_backed", "mechanism": "bloom" },
      { "kind": "time_window", "fields": ["ts", "observed_ts"],
        "tier": "pruned", "mechanism": "statistics" },
      { "kind": "non_promoted_attribute_predicate",
        "fields": ["resource.<other key>", "attr.<other key>"],
        "tier": "scan" },
      { "kind": "body_substring_or_regex", "fields": ["body"],
        "tier": "scan" },
      { "kind": "unscoped_browse", "fields": [],
        "tier": "scan" }
    ]
  }
}

Normative content rules:

  • fields — exactly the RFC 0002 §7 field production (the DSL surface, not the raw Parquet schema; hazard §4.6 — the resource must not leak storage columns the DSL does not expose). Each entry MAY carry a short description string; the shape above is the minimum.
  • severity — the six names with their floor/ceil bands MUST equal the DSL’s SeverityName::floor/ceil mapping (crates/ourios-querier/src/dsl/ir.rs): ordering comparisons use the floor, equality tests the band. This is the resource’s answer to “how do I write severity >= ERROR”.
  • promoted_attributes — the effective running set from the threaded PromotedAttributes (resource_keys() / log_keys()): service.name always present and first, configured keys after, in the deduplicated config order. This is the per-deployment half an agent cannot guess, and it is what makes the cost_model deployment-specific: promoted_attribute_equality is index-backed for exactly these keys, in this instance; the same predicate on any other key is non_promoted_attribute_predicate (the RFC 0022 §3.3 JSON-LIKE fallback — correct, unpruned).
  • cost_model — structure only, never numbers: no latencies, no byte counts, no ratios. The tier facts are true by construction of the writer:
    • bloom mechanism entries correspond one-to-one to the columns writer.rs actually bloom-filters today: template_id (RFC 0005 §3.6), trace_id/span_id (the RFC 0031 L3 fix), and every promoted attribute column (RFC 0022 §3.1).
    • severity carries no bloom filter — its predicates prune through min/max page statistics (ordinal data, where statistics are the right index); the resource says statistics, not bloom, because claiming index-backing that the writer does not provide is exactly the drift RFC0032.4 gates against.
    • time_window is the range(t1, t2) stage pruning on the time columns’ statistics; unscoped_browse (no range stage beyond the default look-back) and body substring/regex predicates are scans — expensive, still correct.

3.3 Tool-description placement rule

Each of the three RFC 0027 tool descriptions gains one advisory sentence pointing at the resource, e.g. for query_logs: “Read the ourios://query-schema resource first for the queryable fields, the severity scale, and which predicates are index-backed.” The full tiering lives only in the machine-readable resource — tool descriptions are prompt real estate in every client context, and the tiers would otherwise be paraphrased into prose that drifts. One pointer, one source of truth.

3.4 What this RFC does not change

No Parquet schema change, no DSL change, no new tool, no new crate, no change to any RFC 0027 tool’s arguments or output. The RFC 0027 §5 suite must pass after this lands, with only the §3.1 two-resource amendment applied (RFC0032.6 pins the exact contract).

4. Alternatives considered

  • Static-only resource (fixed columns + severity scale, no config plumbing — issue #465’s first fork). Trivial to ship, but it omits exactly the half an agent cannot guess: which resource.<key>/attr.<key> predicates are typed, prunable columns here. Without the promoted set the cost model cannot be stated honestly either (promoted equality and non-promoted fallback land in different tiers). Rejected; the plumbing is one threaded value.
  • Put the schema in the tool descriptions. Descriptions ship into every client’s context on tools/list; a schema + cost table there is paid on every session and invites clients to treat prose as data. A resource is fetched on demand and machine-readable. Rejected — this RFC pins the one-advisory-sentence rule instead (§3.3).
  • Extend the grammar resource instead of adding a second one. The grammar resource’s contract is byte-identity with RFC 0002 §7 (RFC0027.6) — appending deployment-specific JSON would break that invariant and mix a static doc with dynamic config. Rejected.
  • A describe_schema tool. Tools imply arguments and per-call work; this content is constant per process and tenant-independent. MCP resources exist precisely for this. Rejected (also keeps the RFC 0027 deny-list — “exactly the §3.2 three tools” — intact).
  • Serve ourios-semconv names. Wrong vocabulary: that crate holds Ourios’s own emitted-telemetry names (how the backend describes itself), not the stored-log query surface (issue #465 notes this explicitly). Rejected.
  • Include benchmark-derived cost numbers. The RFC 0031 numbers are corpus- and channel-dependent and rot with every writer change; the tier structure is what is durable. Rejected — the cost model is structural by rule (§3.2).

5. Acceptance criteria

Scenario ids RFC0032.<m>, referenced from test code.

Scenario RFC0032.1 — listed and readable. Given querier.mcp.enabled, When a client lists resources, Then exactly two resources are advertised — the RFC 0027 grammar resource and ourios://query-schema (application/json); When the client reads ourios://query-schema, Then the body parses as JSON with format_version: 1 and carries the §3.2 top-level keys (fields, severity, promoted_attributes, cost_model); And tools/list still advertises exactly the RFC 0027 §3.2 three — no new tool.

Scenario RFC0032.2 — content matches the running config. Given storage.promoted_attributes configured with resource and log keys, When the resource is read, Then promoted_attributes equals the effective PromotedAttributes set — service.name first, configured keys deduplicated in order; And with the section omitted, promoted_attributes.resource is ["service.name"] and .log is empty; And two servers with different promoted sets serve different resource bodies (the per-deployment property).

Scenario RFC0032.3 — severity scale correctness. Given the resource body, Then the severity.names entries equal the DSL’s SeverityName mapping — for each of the six names, floor equals SeverityName::floor and ceil equals SeverityName::ceil — the test asserts against the ourios-querier functions, not repeated literals, so the resource cannot drift from the compiler.

Scenario RFC0032.4 — cost-tier classification stability. Given the resource body, Then every cost_model.classification entry with mechanism: "bloom" names only columns the writer actually bloom-filters — the test derives the expected set from the writer’s properties for the configured PromotedAttributes (template_id, trace_id, span_id, and every PromotedAttributes::column_names column) and asserts the resource’s index-backed equality kinds cover exactly the DSL fields backed by that set; And severity’s entry carries mechanism: "statistics", never "bloom"; And no classification entry carries a numeric cost value (structure, never numbers).

Scenario RFC0032.5 — tool-description placement. Given tools/list, Then each of query_logs, list_templates, and template_drift carries exactly one advisory sentence naming ourios://query-schema, And no tool description enumerates tiers, severity bands, or promoted keys (the full tiering lives only in the resource).

Scenario RFC0032.6 — read-only contract preserved. Given the amendment applied, Then the RFC 0027 §5 suite passes with the §3.1 two-resource amendment applied (same tools, same outputs, grammar byte-identity and mime assertions intact — the one relocated assertion is rfc0027_6_grammar_resource’s exactly-one-resource count, which moved to RFC0032.1’s exactly-two; the grammar test now locates the grammar among the advertised resources), And reading ourios://query-schema performs no query, touches no tenant data, and its body contains no ingested-telemetry-derived content; And an unknown resource URI still returns the resource-not-found error.

6. Testing strategy

Mapped to CLAUDE.md §6.2:

  • RFC0032.1/.2/.5/.6 — integration tests in crates/ourios-server/tests/it/rfc0027_mcp.rs’s harness shape (in-process router, MCP JSON-RPC over /mcp): resources/list, resources/read, tools/list against servers built with distinct storage.promoted_attributes configs; .6 additionally re-runs the existing RFC 0027 suite untouched (tests are specifications — none may be weakened).
  • RFC0032.3/.4 — unit tests beside the resource builder in mcp.rs, asserting against SeverityName::floor/ceil and against the writer-properties bloom set derived from the same PromotedAttributes value, so both halves of the document are pinned to the code they describe rather than to literals.
  • At validation, the RFC 0027 §5.2 precedent applies: the official MCP inspector CLI (an independent client) lists and reads the resource against the served release binary, extending scratch/validation/rfc0026-0027-validate.sh.

7. Open questions

  • Template-vocabulary hints. Should the resource carry a pointer at (or a sample of) the template vocabulary, or does list_templates already cover the body-shape half cleanly? Current position: the resource stays tenant-independent and static per process; templates are per-tenant, queryable data and belong to the tool. Confirm before green.
  • Config reload. Configuration is startup-static today, so the document is built once. If a future RFC makes storage.promoted_attributes reloadable, the resource must follow and MCP listChanged/subscription semantics become relevant — out of scope here, but the once-at-startup build is the assumption to revisit.
  • severity_text exposure. The stored schema carries severity_text, but the DSL deliberately compares on the numeric scale (RFC 0002 §6.1). If the DSL ever exposes it, the resource’s fields follows the grammar automatically — noting so the two don’t drift silently.
  • Tier vocabulary stability. index_backed/pruned/scan are this RFC’s names; if RFC 0031’s docs settle on different public terminology for the query classes, align before green (renames after clients consume the resource cost a format_version bump).

8. References

  • Issue #465 — the scoping record, including the 2026-07-13 maintainer comment adding the query-class cost model and the placement rule.
  • RFC 0027 — the MCP query surface this RFC amends (accepted, terminal); §3.2 resource precedent, §5.2 inspector-validation precedent.
  • RFC 0022 — promoted attribute columns: PromotedAttributes, storage.promoted_attributes, the promoted-vs-fallback compile split the cost model encodes (crates/ourios-parquet/src/promoted.rs).
  • RFC 0002 §6.1/§7 — the DSL field surface and the severity name→number choice (crates/ourios-querier/src/dsl/ir.rs, SeverityName).
  • RFC 0005 §3.6 / RFC 0031 (L3, trace-context blooms) — the bloom set the tiers rest on (crates/ourios-parquet/src/writer.rs).
  • RFC 0033 §3.2 — the format_version evolution-hook precedent for small versioned JSON artifacts.
  • OTel Logs Data Model — SeverityNumber 1–24 and the compare-on-number mandate.
  • OTel sig-end-user, OTel Night Berlin 2025 transcript — the schema-context-for-agents motivation.
  • CLAUDE.md §2 (pillars #1/#2 — the pruning structure being published), §4.6 (DSL vs engine leakage — the resource describes the DSL surface only), §3.7 (tenancy — the resource is tenant-independent by design).

RFC 0033 — Cached template-map artifact


rfc: 0033 title: Cached template-map artifact status: red author: Jens Holdgaard Pedersen jens@holdgaard.org drafting-assistance: Claude created: 2026-07-12 supersedes: — superseded-by: —

RFC 0033 — Cached template-map artifact

1. Summary

Discharges the RFC 0005 §3.7.1 deferral: a per-tenant cached fold of the audit stream — one artifact carrying both the RFC 0017 §3.2 template registry and the RFC 0005 §3.7.1 alias map — published to object storage next to the audit files it is derived from. The audit stream remains the source of truth; the artifact is a derived acceleration, valid only when the exact audit-file set it folded equals the tenant’s live audit-file listing, discardable at any time, and bypassed (fresh fold, exactly today’s behaviour) whenever absent, stale, torn, or unreadable. Publication follows the RFC 0009 §3.4 write-tmp-then-atomic-swap precedent; the writer is the querier itself, write-through after a cache-miss derivation. This replaces a per-query read of the tenant’s entire audit history — measured at a constant 513,862 bytes per body-rendering query in RFC 0031 comparative run #8 — with one small object GET.

2. Motivation

2.1 The deferral condition has been met — and measured

RFC 0005 §3.7.1 pinned v1 as “no persisted per-tenant artifact: the audit stream is the alias store”, and deferred the cached map with an explicit escape hatch — “a pure recovery/latency cache over this derivation”, to be designed when it measurably matters. RFC 0017 §3.6 took the same stance for the template registry: “O(audit events), the same cost profile as the alias map, acceptable for v1.”

It now measurably matters. RFC 0031’s honest total-bytes accounting (§3.6, measurement-fidelity amendment 2026-07-12) counts the registry derivation into every comparative query’s bytes_read, and comparative run #8 (2026-07-12, otel-demo-v8 corpus, 4.9 M records) measured it at a constant 513,862 bytes per query: every query that renders bodies calls template_registry::derive_template_registry_measured, which walks audit_scan::read_all_events over the tenant’s entire audit subtree — every audit Parquet file, full-object GETs on the S3 backend — before answering. The alias map (alias_store::derive_alias_map) folds the same full stream the same way at query-compile time whenever the DSL uses resolves_to.

Three properties make this a tax worth an RFC rather than a shrug:

  1. It is per-query. The fold is derived once per executed query (RFC 0017 §3.2), so the 514 KB is paid on every body-rendering query, not amortised.
  2. It grows with tenant age, not query selectivity. The audit stream is append-only; every widening, type expansion, creation, and alias assertion in the tenant’s history adds to it. A selective query over a day of data pays for the tenant’s entire template history. This is the inverse of the pruning thesis (CLAUDE.md §2 pillar #2): the data scan shrinks with selectivity while the registry scan only ever grows.
  3. It is now inside the headline metric. RFC 0031’s L-gates gate on total bytes read from object storage. A constant ~514 KB floor under every Ourios query is a direct, growing drag on the project’s existential comparison.

2.2 Why this layer

The fix belongs at the derivation seam, not in the fold semantics: derive_template_registry / derive_alias_map already sit behind narrow functions whose contract is “the fold of the tenant’s audit history in the §3.7.1 total order”. Caching the result of that contract keyed on the exact inputs changes no query-visible semantics — the same “v1 full-replay now, accelerate later, no format change” shape RFC 0001 §6.9 pinned for the miner snapshot and RFC 0005 §3.7.1 explicitly promised for this artifact.

3. Proposed design

3.1 One artifact, not two

The registry and the alias map are folds of the same append-only audit stream, resolved through the same audit_scan::audit_files walk, with the same total fold order and the same validity domain (the exact set of audit files folded). They ship as one artifact:

  • One freshness check (one LIST comparison) instead of two.
  • One atomic publish, so the two folds can never disagree about which frontier they reflect — a split artifact could serve a registry at frontier F1 and an alias map at F2 in the same query.
  • The dominant cost being replaced is the shared read_all_events byte scan, not the per-fold CPU; splitting buys nothing there.

The alternative (two artifacts, independently refreshed) is recorded in §4.

3.2 The artifact — format and location

A single JSON object per tenant, named template_map.json (legacy v1 encoding — key and transport encoding superseded by the 2026-07-13 amendment at the end of this section; the JSON structure below is unchanged, but v2 carries format_version: 2 and ships zstd-compressed at the v2 key), living at the root of the tenant’s audit subtree:

audit/tenant_id=<percent-encoded>/template_map.json
  • Object storage per CLAUDE.md §3.6 — the artifact lives on the same store as the audit files it folds; local disk holds no copy the store does not.
  • Tenant-scoped path per CLAUDE.md §3.7 — under the same tenant_id= partition key the audit walk is already scoped to.
  • Invisible to every existing reader by construction: the local audit walk collects only *.parquet entries and the S3 listing filters ends_with(".parquet") (audit_scan.rs), so a JSON object in the subtree contributes nothing to any deployed binary’s scan. This is the additive-artifact property §3.6 relies on.

JSON follows the manifest.json precedent (RFC 0009 §3.4): small, human-inspectable, serde-round-tripped, no Parquet machinery for a kilobyte-scale object. Content:

{
  "format_version": 1,
  "tenant_id": "acme",
  "folded_files": ["year=2026/month=07/day=11/….parquet", "…"],
  "registry": [
    { "template_id": 7, "version": 1, "template": "user <*> logged in" },
    { "template_id": 7, "version": 2, "template": "user <*> logged <*>" }
  ],
  "alias_map": [
    { "representative": 3, "members": [3, 9, 12] }
  ]
}
  • folded_files — the frontier: the exact audit *.parquet file set the folds consumed, as store-relative keys under the tenant’s audit root, sorted lexicographically. Audit files are immutable once committed (uncommitted writers use *.parquet.tmp, which the walk already ignores), so set equality is a complete validity condition — no per-file ETags needed.
  • registry — the RFC 0017 §3.2 (template_id, version) → tokens map, template encoded in the canonical space-joined format_template form the audit stream itself stores (the exact input parse_template already consumes), so the artifact adds no second token encoding to the system.
  • alias_map — the folded RFC 0001 §6.7 equivalence classes, one entry per class, representative = min(members) as §6.7 defines. Storing the folded classes rather than the event log keeps the reader a deserialization, not a re-fold.
  • tenant_id — the row-vs-path discipline (RFC 0005 §3.9, CLAUDE.md §3.7) applied to the artifact: a reader MUST verify it matches the tenant whose path it was fetched from and fail loudly on mismatch, exactly as read_all_events does for audit rows.
  • format_version — evolution hook: a reader encountering an unknown version treats the artifact as absent (fresh fold, then republish at its own version), mirroring the RFC 0005 §3.9 unknown-column tolerance. No migration of old artifacts is ever required because the artifact is derived and discardable.

Size bound. The registry is bounded by RFC 0023’s bounded template memory (per-tenant template count is capped) times the per-template version count; templates are token strings, not log data. The alias map is rare operator actions. The artifact is therefore expected to be kilobytes-to-low-megabytes, and on any tenant with meaningful history substantially smaller than the audit stream it folds (which carries the same templates plus envelopes, samples, hashes, and full history) — but this is a measured expectation, not a guarantee: on a very small tenant the frontier list and JSON envelope can exceed the audit bytes. The publisher therefore abstains when the serialized artifact is not smaller than the audit bytes just folded (nothing to win) or exceeds a configured size ceiling; the exact ceiling is an open question (§7). Abstention costs nothing — the no-artifact path is today’s behaviour.

Amendment (2026-07-13, run #20 / §9.14): compressed artifact encoding — format_version 2. Comparative run #20 (docs/benchmarks.md §9.14) showed the v1 encoding losing to its own guard on the headline corpus: on otel-demo-v8 the uncompressed JSON of every (template_id, version) canonical template meets or exceeds the 513,862 B zstd-compressed Parquet fold it must undercut, so the size abstention correctly refused every publish and the corpus never ran warm (RFC0033.6’s corpus arm undischarged, status green → red). The defect is transport encoding, not structure; this amendment changes only how the bytes ship.

  • Encoding. The artifact body is the §3.2 JSON object, zstd-compressed as a single frame. The JSON structure, field meanings, canonical sort orders, and validation rules above are unchanged — only the bytes on the wire are. The compression level is the crate default (3), an implementation constant, not configuration: the object is kilobyte-scale and written once per miss, the template-string JSON is highly redundant (the same strings zstd-compress into the 513,862 B audit Parquet with their full event history alongside), so the needed order-of-magnitude win does not hinge on the level; raise the constant in code if run #21 measures the ratio marginal.
  • Key: template_map.v2.json.zst, same tenant audit root (audit/tenant_id=<enc>/template_map.v2.json.zst) — the version moves into the key. A pre-amendment reader GETs only template_map.json, so for it the v2 artifact is literal absence — genuine fresh fold, correct by §3.3’s design, with honest telemetry. A post-amendment reader GETs only the v2 key. Both keys stay invisible to every audit walk by construction (local walk keeps only extension == "parquet" entries, S3 listing filters ends_with(".parquet")audit_scan.rs; the filter ignores any number of non-Parquet keys, so a second one changes nothing). Future encoding-affecting bumps repeat the pattern: new key, new in-body version, best-effort delete of the predecessor (§3.4 amendment).
  • Rejected: same key, magic-frame sniff. The alternative keeps template_map.json and has readers sniff the zstd frame magic (0xFD2FB528) before JSON parse. It is correct — an old reader GETs the compressed body, fails JSON parse, classifies Torn, folds fresh, self-heals — but it lies twice: §3.7 pins torn as the RFC 0008-style corruption signal, so a mixed-version fleet would page on healthy state for as long as one old binary keeps querying; and §3.3’s UnknownVersion disposition — designed for exactly this evolution — is unreachable there, because the parse fails before the version probe runs. A .json key carrying zstd bytes also misnames the object. The one cost of the new-key route — a bounded second key during the mixed-version window, deleted best-effort — is cheaper than a permanently lying corruption signal.
  • format_version: 2, in the decompressed body. The version names the whole artifact contract including the transport encoding, not just the JSON shape: TEMPLATE_MAP_FORMAT_VERSION becomes 2, and the probe runs on the decompressed bytes as defense-in-depth — a v1 body planted at the v2 key (or a decompressed v2 body at the v1 key) classifies UnknownVersion → treated as absent, harmless, per §3.3’s rule.
  • Dispositions at the v2 key (§3.3 table unchanged in spirit): not a zstd frame, failed decompression, or post-decompression parse/validation failure → Torn; decompressed format_version ≠ 2 → UnknownVersion; tenant_id mismatch → loud failure. Everything else as tabulated.
  • Abstention, restated (unchanged in spirit). Publish iff the compressed artifact byte size is smaller than the audit bytes just folded: the comparison is between the bytes a warm GET would pay and the bytes the fold just paid — the v1 rule applied to the bytes actually shipped.
  • Telemetry (§3.7). The artifact-size histogram records the compressed (published-object) bytes — the GET cost, which is what the instrument always measured (it records the published bytes, and those are now compressed). Lookup and publish outcome values are unchanged.
  • Reading rule. References to template_map.json elsewhere in this RFC (§3.3–§3.5, §5, the §3.4 diagram) read as the versioned key post-amendment; the local tmp is template_map.v2.json.zst.tmp (extension tmp, ignored by the walk as before).
  • Dependency. Zero new dependencies: zstd 0.13 is already compiled into every querier build (parquet 58’s zstd feature via ourios-parquet, and arrow-ipc), and ourios-bench already binds the crate directly as the A1 reference codec (RFC 0006 §3.4.1). Adding zstd = "0.13" to ourios-querier introduces no new transitive crate and passes the existing cargo-deny license gate unchanged.
  • Validation: comparative run #21, before merge. The amendment is validated by a comparative dispatch from the implementation branch before it merges (the measure-before-merge workflow), and the harness MUST print each pair’s publish outcome explicitly — published (with the compressed size), abstained (with the would-be size vs. the folded audit bytes), lost_race, or error — so run #20’s ambiguity (abstention and publish IO failure both leaving the same “no artifact” label) cannot recur.

3.3 Freshness — the frontier check

The audit stream is append-only, so cache validity is exactly:

the artifact’s folded_files set equals the tenant’s live audit-file listing at read time.

The read path becomes:

  1. List the tenant’s audit *.parquet set (the existing audit_files walk / prefix LIST — no GETs).
  2. GET template_map.json. If absent, torn (JSON parse failure), unknown format_version, or tenant_id-mismatched — see dispositions below.
  3. If folded_files == the live set (set equality; both sides are sorted-unique already): cache hit — deserialize, use.
  4. Otherwise (new files appended, or files removed by a future retention/GC): stale — fall back to the fresh fold over the live set, exactly today’s read_all_events path, then write-through (§3.5).

Dispositions, pinned:

ConditionDisposition
Artifact absentFresh fold (today’s behaviour), write-through
Frontier ≠ live setFresh fold, write-through at the new frontier
Torn / unparseable JSONTreat as absent; fresh fold, write-through overwrites; emit telemetry (§3.7)
Unknown format_versionTreat as absent (forward compat)
tenant_id mismatchFail the query loudly — corrupt or foreign object under the tenant’s root, same stance as the audit row-vs-path backstop

The first four never produce a wrong answer — every non-hit path is the v1 fold. The stale-cache fallback is re-derive, never serve stale: a hit reflects exactly the events a fresh fold at the same listing would, so the RFC 0005 §3.7.1 consistency bound (audit-flush visibility) is unchanged by this RFC. The only ordering requirement is LIST-before-GET-is-compared: the frontier comparison uses one listing, taken once, for both the validity check and the fallback fold, so a file appearing mid-query affects a cached and an uncached query identically.

Amendment (2026-07-13, run #20 / §9.14). At the v2 key (§3.2 amendment), “torn / unparseable JSON” includes a missing zstd frame or a failed decompression, and the unknown-format_version probe runs on the decompressed bytes. The table’s dispositions and the LIST-before-GET rule are otherwise unchanged. Note the version-in-key choice means a pre-amendment reader never fetches a v2 artifact at all: for old binaries the encoding bump manifests as literal absence — the cleanest possible realization of the unknown-version-is-absent rule this table was designed around.

3.4 Atomic publish — the RFC 0009 §3.4 precedent

The artifact is published the way the compaction manifest is committed:

  • Local backend: write template_map.json.tmp, rename into place (Manifest::write_atomic shape). A crash mid-write leaves the prior artifact (or its absence) authoritative and a harmless .tmp for the GC sweep; the rename is the only visibility point.
  • S3 backend: single-object conditional put (Manifest::publish_cas shape). Object stores make the whole PUT visible atomically; the conditional (create / ETag-match) precondition prevents interleaved writers from tearing each other.

Unlike the manifest, a lost race is harmless here: every writer publishes a correct fold of some frontier, the reader verifies the frontier independently at every read (§3.3), and a superseded artifact is simply detected stale on the next query and rewritten. So on CAS conflict the loser discards its write and moves on — no retry loop, no error. The manifest needed CAS to prevent lost updates of authoritative state; the cache needs only atomicity of the object itself, and gets CAS cheaply because the primitive already exists.

Amendment (2026-07-13, run #20 / §9.14). The publish targets the v2 key (template_map.v2.json.zst; local tmp template_map.v2.json.zst.tmp, same rename; same CAS ladder on S3, the expectation being the v2 key’s observed ETag or create-if-absent), and on a successful publish best-effort deletes the stale v1 template_map.json key. The delete is unconditional (no CAS needed — any v1 artifact is derived and discardable by definition) and never a query failure; a crash or failure between publish and delete leaves both keys, which is harmless: each reader population GETs only its own key and verifies the frontier at every read, and the next successful v2 publish retries the delete implicitly. During a mixed-version window an old binary’s write-through may republish the v1 key (on tenants where the uncompressed artifact still beats the fold); correctness is unaffected — each version population maintains its own cache — and hygiene converges once old binaries retire.

sequenceDiagram
    participant Q as Querier
    participant FS as Object store (tenant audit subtree)
    Q->>FS: LIST audit/tenant_id=t/*.parquet → live set S
    Q->>FS: GET template_map.v2.json.zst
    alt hit — folded_files == S
        Q->>Q: deserialize registry + alias map (no audit GETs)
    else miss / stale / torn / unknown version
        Q->>FS: GET every audit file in S (today's fold)
        Q->>Q: fold registry + alias map (§3.7.1 order)
        Q-->>FS: publish template_map.v2.json.zst @ frontier S (tmp+rename / CAS, best-effort)
    end
    Q->>Q: answer the query (identical either way)

3.5 Who writes it — querier write-through

Position: the querier publishes, write-through, after every cache-miss derivation. After a fresh fold (miss or stale), the querier serializes the fold it already holds plus the frontier it already listed, and publishes best-effort — a publish failure is telemetry, never a query failure.

Both folds, one scan — never a partial artifact. The two derivation call sites are asymmetric (body rendering derives only the registry; only resolves_to queries derive the alias map), so a naive write-through after a registry-only miss would publish an artifact with an empty alias fold that a later alias query would trust. The miss path therefore folds both maps from the single read_all_events capture it already paid for — the marginal cost is CPU over in-memory events, zero extra IO — and publication of a partially populated artifact is forbidden by construction. RFC0033.1’s property test covers both folds, and RFC0033.6’s integration arm includes a body-rendering query followed by a resolves_to query against the artifact the first one published.

Rationale:

  • Zero extra derivation work. The fold and the frontier are in hand at exactly the moment of publish; no component re-derives anything to warm the cache.
  • No ingest-path coupling. The WAL-before-ack hot path (CLAUDE.md §3.4) gains no IO, no new failure mode, and no knowledge of reader-side fold semantics.
  • Warms exactly where it pays. Tenants that query get a warm cache after the first miss; tenants that never query never pay a publish.
  • Self-healing. Any wrong, torn, or ancient artifact costs one fresh fold and is overwritten on the same query.

The consequence to own honestly: on an actively-mutating tenant (templates still being widened), every mutation staleness-misses the next query, which pays one fresh fold plus one publish. That is today’s cost plus a small PUT — never worse than v1 by more than the publish — and template mutation decays as a tenant’s template set converges (the miner’s convergence thesis, RFC 0001). The ingester-side write-through at mutation time is the recorded alternative (§4, §7).

3.6 Back-compat — additive and advisory (CLAUDE.md §3.5)

This RFC changes no Parquet schema: no columns added, removed, renamed, or retyped. The artifact is a new single JSON object whose name no existing code path matches (§3.2). Concretely:

  • Old binaries, new stores: deployed readers filter *.parquet; they never see the artifact and behave byte-for-byte as today.
  • New binaries, old stores: artifact absent → fresh fold, today’s behaviour, then write-through.
  • Deletion at any time: an operator (or a GC policy) may delete template_map.json unconditionally; the sole cost is one re-derivation. Nothing durable depends on it.
  • The audit stream remains the single source of truth for template and alias history — this RFC makes that normative for the cache: no code path may treat the artifact as authoritative over the stream, and any doubt (parse failure, unknown version, frontier mismatch) resolves by folding the stream.

3.7 Observability (CLAUDE.md §6.3)

Via OTel meters on the existing querier metrics path, names to be minted through the semconv registry (weaver):

  • cache lookups, keyed by outcome (hit / miss / stale / torn / unknown_version) — the torn/unknown outcomes are the RFC 0008-style corruption signal for a derived artifact;
  • publishes, keyed by outcome (published / lost_race / error);
  • the artifact byte size at publish (the number RFC0033.6 gates on).

QueryResult::registry_bytes_read is today documented as bytes fetched from the tenant’s audit stream; a cache hit fetches the artifact instead, and the artifact carries the alias fold and frontier alongside the registry. At green this RFC therefore amends the field’s contract (and RFC 0031 §3.6’s wording) to template-map acquisition bytes: the total bytes fetched to obtain body-rendering capability, whatever the source — the audit-stream fold on a miss, the artifact GET on a hit. One field, one honest meaning, no separate channel; the comparative harness needs no code change, and the alternative (a separate artifact-bytes field with the old field pinned to audit-stream-only) is recorded in §4.

4. Alternatives considered

Two artifacts (registry and alias map separately). Independent refresh would let an alias assertion invalidate only the alias artifact. Rejected: both folds share one byte-dominant input scan and one validity domain; splitting doubles the freshness checks and publish points, and admits frontier divergence between the two folds inside a single query (§3.1). Alias events are also so rare that independent refresh buys nothing measurable.

Ingester write-through at template-mutation time. The component that emits the audit event updates the artifact in the same breath, so queries never miss. Rejected for v1: it puts derived- artifact IO and reader-side fold semantics on the ingest path (against §3.4’s discipline of keeping the hot path minimal), it publishes on every widening for tenants nobody queries, and under ingester/querier role separation the ingester would need the querier’s fold code. Recorded as the natural v2 if miss-rate telemetry (§3.7) shows mutation-driven staleness dominating. §7.

A background refresher (compactor-style loop). A periodic task re-folds and republishes per tenant. Rejected: it adds a scheduling component and a staleness window policy for something the write-through gets for free at the moment of demand, with the freshness check making the window irrelevant to correctness anyway.

Parquet instead of JSON for the artifact. Consistency with the data plane and columnar compression. Rejected: the object is kilobyte-scale, read whole or not at all, never predicate-pushed; manifest.json set the precedent that flat derived metadata is JSON. Parquet here is machinery without a query.

Incremental fold on staleness (fold only the new files onto the cached state). Attractive — staleness usually means a few appended files. Rejected as the pinned behaviour because it is not generally equivalent to a fresh fold: the §3.7.1 total order sorts by event timestamp across files, and an appended file may carry an event timestamped before already-folded events (clock skew, late flush), which an append-only incremental fold would order incorrectly. A guarded fast path (apply only when the new files’ minimum timestamp ≥ the folded maximum, recorded in the artifact) stays open in §7; the unconditional fallback is the fresh fold.

Do nothing (keep the v1 fold). The RFC 0005 §3.7.1 deferral was explicitly conditioned on measurement; run #8 produced the number (§2.1). A constant per-query floor that grows with tenant age and sits inside the RFC 0031 headline metric fails the condition.

5. Acceptance criteria

Scenario RFC0033.1 — Cached fold ≡ fresh fold (property)

  • Given any generated per-tenant audit-event history (template creations/widenings/type-expansions/rejections and alias assertions/retractions, arbitrary timestamps including same-nanosecond ties), flushed to one or more audit Parquet files
  • When the fold is derived fresh and published, and a second read resolves it through the artifact (frontier equal, cache hit)
  • Then the cache-hit registry equals the fresh derive_template_registry result and the cache-hit alias map equals the fresh derive_alias_map result, for every key
  • And the query answer produced through either path is identical.

Scenario RFC0033.2 — Staleness is detected and never served

  • Given a published artifact at frontier S
  • When new audit events are flushed (one or more new audit files appear) and a query runs
  • Then the frontier check fails, the artifact is bypassed, and the answer equals the no-cache fold over the live set — including events in the new files
  • And the querier republishes at the new frontier, and a subsequent unchanged-store query is a cache hit
  • And the same holds when files disappear from the live set (frontier is set equality, not subset).

Scenario RFC0033.3 — Crash/tear safety around the publish

  • Given a publish interrupted mid-write (simulated: a stray template_map.json.tmp, a truncated/corrupt template_map.json, or an S3 CAS loss to a concurrent writer)
  • When the next query runs
  • Then a stray .tmp is ignored, a torn artifact is treated as absent (fresh fold — the query succeeds with the correct answer, no error surfaced), a CAS loss discards the losing write without failing its query
  • And the torn-artifact case emits the §3.7 torn outcome
  • And the fresh fold’s write-through overwrites the torn artifact, so the store self-heals.

Scenario RFC0033.4 — Additive and advisory (back-compat)

  • Given a store with no artifact (old data) and a binary with cache support
  • When a body-rendering query runs
  • Then the result is identical to the pre-RFC binary’s result and the fold reads the audit stream exactly as today
  • And deleting the artifact between two queries changes neither query’s answer
  • And the artifact’s presence changes nothing a *.parquet scan sees: the audit file walk/listing over a store carrying the artifact returns the same file set as without it.

Scenario RFC0033.5 — Tenant isolation

  • Given two tenants with distinct template/alias histories and published artifacts
  • When each tenant queries
  • Then each cache hit serves only that tenant’s registry and alias map (paths tenant-scoped under tenant_id=<enc>)
  • And an artifact whose body tenant_id differs from the tenant of the path it was fetched from fails the query loudly (the row-vs-path stance), never silently serving or ignoring foreign data.

Scenario RFC0033.6 — The measured tax collapses (RFC 0031 channel)

  • Given the RFC 0031 headline-corpus shape (otel-demo-v8, 4.9 M records — run #8 baseline: registry_bytes_read = 513,862 B constant per query) ingested, and a warm published artifact
  • When a body-rendering query runs cache-warm
  • Then QueryResult::registry_bytes_read equals the artifact object’s byte size exactly (the only registry-path GET is the artifact)
  • And the ratio warm.registry_bytes_read / cold.registry_bytes_read ≤ 1/10 on that corpus — the gate is the ratio, not an absolute byte count, so it holds as the corpus and baseline evolve
  • And both numbers are recorded in docs/benchmarks.md alongside the run #8 baseline.

Run #20 note (2026-07-13, §9.14): undischarged on the corpus. The dispatch shows every pair cold with no artifact published — consistent with §3.2’s size abstention: the artifact is uncompressed JSON of every (template_id, version) canonical template, while the 513,862 B it must beat is the zstd-compressed Parquet of the same strings, so on otel-demo-v8 the guard correctly refuses a publish that would make warm acquisition cost more bytes than the fold. The local-shape arm (rfc0033_6_measured_tax_collapses, 55.8×) stands; this corpus arm needs a compressed artifact encoding (format_version 2 — cheap by §3.3’s own rule: unknown versions are treated as absent, no migration) before the gate can be measured. The scenario stays as written; the RFC status returns to red until it passes.

Amendment pointer (2026-07-13): the compressed encoding this note calls for is specified in the §3.2 amendment. The scenario text above needs no change: the “artifact object’s byte size” a warm GET pays is the compressed object’s size, and the ratio gate is encoding-agnostic. Validation is comparative run #21, dispatched from the implementation branch before merge (measure-before-merge), with the harness printing each pair’s publish outcome — published (compressed size) / abstained (would-be size vs. folded audit bytes) / lost_race / error — so run #20’s abstention-vs-failure ambiguity cannot recur.

Scenario RFC0033.7 — Observable outcomes

  • Given a served querier with the OTel metrics pipeline (RFC 0016) active
  • When queries drive a miss, a hit, a staleness, and a torn artifact
  • Then the §3.7 lookup-outcome and publish-outcome instruments record each with the correct outcome attribute, and the publish-size instrument records the artifact size
  • And the instrument names exist in the semconv registry (weaver-generated constants, no hand-written flat names).

6. Testing strategy

Mapped to CLAUDE.md §6.2:

  • RFC0033.1proptest: generated event histories (the RFC 0024 generator discipline), round-tripped through real audit Parquet files on the local backend; equivalence asserted per key. This is the invariant test — the cache must be a pure memoization.
  • RFC0033.2, RFC0033.3, RFC0033.4, RFC0033.5 — integration tests in crates/ourios-querier/tests/ against both backends (local root; S3 via the existing localstack harness, RFC 0019), scenario ids referenced from the test code.
  • RFC0033.6 — the RFC 0031 comparative harness (ourios-bench), cold-vs-warm on the headline corpus; the ratio is the gate, the absolute numbers are recorded.
  • RFC0033.7 — the RFC 0016 metrics-pipeline test shape (in-memory exporter), plus the semconv no-diff CI gate.

Amendment (2026-07-13). §6 is structurally unchanged by the compressed encoding: the same tests exercise the v2 artifact (round-trip and torn-classification now run through the compressed body; RFC0033.6’s local arm asserts warm acquisition bytes equal the artifact’s byte size exactly, which holds unchanged because the GET is the compressed object). The one addition is run #21’s harness printing publish outcomes (§3.2 amendment / the Scenario RFC0033.6 run-#20 note’s pointer).

7. Open questions

  • Guarded incremental fold on staleness: apply new files on top of the cached fold only when their minimum event timestamp ≥ the artifact’s recorded maximum folded timestamp (else fresh fold). Worth it, or is the fresh fold on miss cheap enough forever?
  • Ingester write-through at template-mutation time (the §4 alternative): adopt if §3.7 miss-rate telemetry shows mutation-driven staleness dominating on live tenants? Requires an ingester/querier code-sharing decision.
  • Hard size guard: should a publish above a byte threshold be skipped (cache abstention) rather than published, and what is the threshold? RFC 0023 bounds the registry, but versions accumulate per template over tenant lifetime.
  • Frontier growth: folded_files lists every audit file; a very old tenant’s frontier list could itself grow large. Fold the frontier to a digest (sorted-keys hash) once measured to matter?
  • Retention/GC of audit files: no audit retention exists today; when it lands, deleting folded files shrinks the live set and correctly staleness-misses (RFC0033.2), but the fresh re-fold loses history — that is a property of audit retention itself, to be pinned by the retention RFC, not by this cache.
  • Should the freshness LIST count into RFC 0031 bytes_read? Today neither backend counts listing overhead; the comparative-fairness call belongs to RFC 0031’s harness.
  • Drift queries (RFC 0010) intentionally do not use the artifact (they need raw events, not the fold) — confirm no future consumer is tempted to.
  • Legacy v1 key hygiene (raised by the 2026-07-13 amendment): the v2 publish best-effort-deletes template_map.json; once no pre-amendment binaries remain, keep the delete as permanent hygiene (one cheap idempotent DELETE) or drop it?

8. References

  • RFC 0005 §3.7.1 — the deferral this RFC discharges; §3.7 audit schema; §3.9 row-vs-path backstop.
  • RFC 0017 §3.2 (registry fold), §3.5 (version keying), §3.6 (the performance stance being revised).
  • RFC 0009 §3.4 — the per-partition manifest: the atomic-publish precedent (write_atomic / publish_cas, crates/ourios-parquet/src/manifest.rs) this artifact follows.
  • RFC 0031 §3.6 — the honest total-bytes channel and registry_bytes_read; comparative run #8 (2026-07-12, otel-demo-v8, 4.9 M records): 513,862 B constant per query.
  • RFC 0001 §6.7 (alias semantics), §6.9 (the “full-replay now, accelerate later” precedent).
  • RFC 0019 §3.3 — the hybrid local/S3 audit scan the freshness check reuses.
  • RFC 0023 — bounded template memory (the artifact’s size-bound argument).
  • RFC 0006 §3.4.1 / crates/ourios-bench — the workspace’s existing zstd (0.13) binding, the A1 reference codec; the 2026-07-13 compressed-encoding amendment reuses the same crate, zero new dependencies.
  • docs/benchmarks.md §9.14 — comparative run #20 (2026-07-13): the abstention finding the compressed-encoding amendment answers.
  • CLAUDE.md §3.5 (schema/migration — satisfied additively), §3.6 (object storage is the source of truth), §3.7 (per-tenant scoping), §6.3 (observability).
  • Code: crates/ourios-querier/src/audit_scan.rs, crates/ourios-querier/src/template_registry.rs, crates/ourios-querier/src/alias_store.rs.

Template mining in Ourios


title: “Template mining in Ourios: what Drain says, what it leaves out, and what we commit to” speaker: Jens Holdgaard Pedersen drafting-assistance: Claude target-duration: 45 minutes audience: engineers familiar with log backends but not the Drain paper companion-rfc: docs/rfcs/0001-template-miner.md created: 2026-04-24

Template mining in Ourios

A lecture manuscript. Prose is written for spoken delivery; figures are sized to lift onto slides.


Abstract

Log storage at scale has a compression problem that looks unsolvable when you squint at it. A terabyte of raw log lines is mostly repetition — the same twenty-odd templates interleaved with ever-changing parameters — but commodity byte-level compressors like zstd cannot see that structure. They see bytes. Template mining is the layer that turns the repetition into a first-class citizen before any byte codec runs, and the algorithm we use — Drain, published in 2017 — is so simple it fits on one slide.

But the paper is ten pages long, and a production log backend needs answers to at least six questions the paper does not answer. Those unanswered questions are not implementation details. They are the difference between a search engine that tells the truth and one that quietly conflates a login event with a logout event because the two lines shared enough token structure to merge. This lecture is about those six questions, the commitments Ourios makes in response, and the honesty contract those commitments form with the user.

Thesis

Drain is not a log parser. Drain is a tree. What makes it safe to put into production is everything we build around the tree — the confidence scoring, the merge auditing, the body retention, the reconstruction property — none of which appear in the paper.

Hold on to that sentence. Every figure in this talk exists to defend it.

Learning objectives

By the end of this lecture you should be able to:

  1. Draw the Drain parse tree from memory and walk a log line through it.
  2. Name the six gaps between the published algorithm and a production log backend, and state the Ourios invariant that fills each gap.
  3. Explain why bit-identical body reconstruction is a property test and not a unit test.
  4. Defend the thesis above against a critic who says “just use zstd.”

Outline

§TopicMinutes
1Motivation: where the compression comes from5
2The paper: Drain as published10
3Worked example: a line walks the tree5
4What the paper does not say8
5The Ourios extensions8
6The honesty contract: reconstruction5
7What is still open2
Questions2

1. Motivation: where the compression comes from

I want to start with a number, because the number is what makes this whole project coherent. Operators of large log deployments — people running Loki, Elasticsearch, proprietary SIEMs — consistently report that their raw log volume compresses by somewhere between fifty and two hundred times when it lands in a structured backend. That compression does not come from zstd. If you zstd a day of raw logs you get maybe ten times. The rest — the factor of five to twenty on top of the byte codec — comes from noticing that your logs are not really text at all.

They are a program output. The program has maybe two thousand printf-style call sites. Each call site fires somewhere between a few hundred and a few million times a day, always with the same template and different parameters. A log line that reads

ERROR db connection failed for user 42 after 3 retries

is not a string. It is a tuple. It is template number, say, 847, plus the parameters (42, 3). The template itself appears once per deployment. The parameters appear once per event. If you store the template once and the parameters inline, you have already compressed the log before you have compressed a single byte.

This is not a theoretical claim. It is how every serious log backend built in the last decade actually works under the hood. What differs between backends is how they recover the templates. You can ask developers to annotate them at compile time — SLF4J’s structured logging, OpenTelemetry’s log records — but the reality of a heterogeneous deployment is that you inherit a pile of logs from Python scripts and Go services and JVM apps and legacy C++ daemons, and the only common substrate you have is the emitted text.

So you mine the templates online, from the text, as the logs flow. That is what Drain does.

2. The paper: Drain as published

The Drain paper — He, Zhu, Zheng, and Lyu, ICWS 2017 — introduces a single data structure and one algorithm that walks it. The data structure is a tree with a fixed depth. The algorithm is: preprocess the line, walk the tree from root to leaf, decide at the leaf whether this line matches an existing log group or opens a new one. That is the whole paper. Ten pages.

Let me draw the tree.

Figure 1 — The Drain parse tree

Drain parse tree: a root node branching to three length-group children (len=5, len=7, len=11); each length child branches further to token-prefix children keyed on the first token; each prefix node points to a list of leaf log groups.

Three levels matter here. The root has a child per distinct token count — Drain assumes that two log lines of different length are probably from different call sites, and this is empirically true often enough to use as a cheap first-level filter. Below the length node sits a chain of prefix nodes — one per token, up to a configured depth. At depth two, as drawn, the tree branches on the first token of the line. If the depth were three you would also branch on the second token, and so on. The paper defaults to depth three or four; the deeper you go, the more precise the partition but the more groups you end up with.

At the bottom of each prefix chain is a leaf. A leaf is not a single template. It is a list of templates — what the paper calls log groups — each with its own parameter positions. When a line arrives at a leaf, Drain compares it against each log group in the leaf by token-wise similarity, picks the best match if the similarity exceeds a threshold, and either merges the line into that group or, if no group is similar enough, opens a new group.

The similarity function is where the arithmetic lives. It is simply the fraction of positions where the template and the line have the same token — wildcards count as matches. So if a leaf contains the template ERROR db connection failed for user <*> and a line arrives reading ERROR db connection failed for user 42, every token matches — the wildcard absorbs the 42 — and similarity is 1.0. A different line, ERROR db connection timeout for user 7, matches six of seven tokens — connection matches, but timeout does not equal failed — so similarity is about 0.86. If the threshold st is 0.7, both lines land in the same group; the template widens to ERROR db connection <*> for user <*>. If the threshold is 0.9, only the first line matches; the second opens a new group.

That is Drain. That is the whole thing. I am not hiding complexity. The paper is short because the algorithm is short.

3. Worked example: a line walks the tree

Let us walk one line through concretely so the abstraction has weight.

Figure 2 — Walking ERROR db connection failed for user 42

Line: "ERROR db connection failed for user 42"

Step 1 — preprocess
    tokens: ["ERROR", "db", "connection", "failed",
             "for", "user", "42"]
    length: 7

Step 2 — walk
    root          →  len=7 node
    len=7         →  tok₀="ERROR" branch
    tok₀="ERROR"  →  leaf L₇

Step 3 — compare at leaf L₇
    candidate A: "ERROR db connection failed for user <*>"
                 similarity = 7/7 = 1.00   ← best

    candidate B: "ERROR db pool exhausted for user <*>"
                 similarity = 5/7 = 0.71

Step 4 — decide
    threshold st = 0.7
    similarity(A) ≥ st   →  assign to group A
    param extracted: ["42"]
    template unchanged (already fully general at that slot)

Result
    template_id  = hash("ERROR db connection failed for user <*>")
    params       = ["42"]

Pause on step three. The whole engine is visible here. Every decision Drain makes — whether to match, whether to widen, whether to open a new group — is a function of that similarity score and that one threshold. Lift the threshold and you get more, narrower templates. Lower it and you get fewer, more abstract templates that absorb lines they arguably should not absorb.

That single scalar is the most important knob in the whole system. Remember the thesis: what makes it safe to put into production is everything we build around the tree. We are about to talk about what the paper does not say about the threshold, and about much else.

4. What the paper does not say

I want to go through this carefully, because these are the questions that become bugs in production if you skip them.

4.1 It does not say what the threshold should be for your corpus

The paper reports empirical results on a handful of public corpora with thresholds around 0.4 to 0.7. These are the datasets the authors had access to — HDFS, BGL, Apache, OpenSSH. Your corpus is not one of those. The right threshold for an application that emits heavily templated, well-structured log lines is different from the right threshold for an application that concatenates stack traces and request payloads into each line.

This is not a criticism of the paper. This is a reminder that the paper reports that there exists a sweet spot, not what it is for you. In Ourios we default to a strict threshold — at least 0.7 — and expose it as tenant-configurable, and we gate any reduction below 0.7 behind an RFC. That last part matters. There is always an engineer who, when templates look noisy, wants to lower the threshold to “clean things up.” What they are actually doing is forcing unrelated templates to merge. A strict default plus a gate keeps that pressure from silently drifting the system toward wrong.

4.2 It does not say what to do when similarity is close but not above threshold

Drain is a classifier with two classes: match, and no-match. In practice there is a third case that matters deeply to a log backend. Imagine a line that matches the best candidate at 0.65 when the threshold is 0.7. What do you do? The paper says: open a new group. The paper is right that this is the safe default, but it is wrong that this is a complete answer. In a log backend the user has a specific question: was this line produced by the same code as that template? If you opened a new group because similarity was 0.65, you have told the user “these are different” — but you only know that with 0.65 confidence, not 1.0 confidence. A query that asks “show me all events from template X” will miss this line even though it came from the same call site, probably.

Ourios handles this with a three-zone model.

Figure 3 — The three-zone confidence model

Three-zone confidence model: a horizontal axis from 0 to 1 with dashed verticals marking the floor and the threshold. The axis splits into three labelled zones — parse_failed (retain body, count error), lossy match (retain body and template, set lossy_flag), and clean match (template plus params only; body optional).

Three zones, three behaviours. Above the threshold, the happy path: store the template id and the parameters. Below the threshold but above the floor — what I am calling the lossy zone — store the template id, the parameters, and the original body, and raise a flag on the row so the reader knows not to trust reconstruction against this row. Below the floor, parse failed altogether: store only the body, increment parse_failures_total, and move on.

The floor is the second most important knob in the system. Set it too low and you never see parse failures — everything is technically a match, just a bad one. Set it too high and you throw away useful partial matches. A reasonable default sits around 0.3. The point is that the three-zone model exists at all, because without it the backend is lying to the user in the lossy zone.

4.3 It does not say what to do when parameters are enormous

The paper implicitly assumes parameters are short variable bits — numbers, hostnames, UUIDs. In production a parameter slot may capture an entire stack trace, a request body, a base64 payload. If you put a megabyte of stack trace into a parameter, Parquet’s dictionary encoding collapses. File sizes explode. Query latency degrades. The backend’s whole value proposition evaporates for that column.

The Ourios answer is a per-parameter byte limit — 256 bytes by default — with overflow behaviour that is explicit rather than clever. When a parameter exceeds the limit, the original value spills into the body column of the row, the params slot gets a short truncation marker, and a counter increments. Per-service alerts fire when more than 1% of rows hit overflow. The ceiling on the limit is 1 KiB; above that we would rather open an RFC than silently accept larger values.

This is the kind of rule that looks ugly on a whiteboard and is invisible in a paper but saves the storage format from a class of tail-latency failure that is otherwise impossible to diagnose in production.

4.4 It does not say whether to preserve whitespace

The paper talks about tokens. Tokens are a convenient abstraction and they are also a lossy abstraction. When you tokenise connection failed — two words separated by three spaces — into ["connection", "failed"], you have thrown away the three spaces. Later, when an operator opens the UI and asks “show me what was actually logged,” and you reconstruct from template plus parameters, you produce connection failed — one space. You have lied. Quietly, in a way that the user will only notice if they happen to be debugging a whitespace-sensitive format.

This is the invariant in CLAUDE.md §3.3 — bit-identical body reconstruction — and it is stricter than it sounds. It says: for every line we ingest, either we can reproduce the original byte stream exactly from what we stored, or we have flagged the row as lossy. No in-between. The miner either captures the inter-token whitespace as part of the template, or it gives up honestly and keeps the body.

4.5 It does not say how templates evolve over time

A service ships a new version. The log format changes — a new field appears, an old one goes away, word order shifts. The template tree you built from last month’s logs no longer matches this month’s logs cleanly. The paper has nothing to say about this; it assumes a static tree.

Real deployments are never static. Ourios needs a template versioning story: what changes cause a new template version vs. a new template, what aliases hold between old and new templates, and how a query that says “template X” either resolves across versions or surfaces the drift explicitly to the user. This is hazard 5 in docs/hazards.md and it is genuinely hard — hard enough that the RFC has it as an open question rather than a solved problem.

4.6 It does not say anything about multi-tenancy

The paper describes one tree. A log backend serves many tenants whose logs cannot cross-pollinate: tenant A’s login template must not end up merged with tenant B’s logout template just because they share token structure. This is CLAUDE.md §3.7, and it is the invariant that says the tree is not one tree — it is one tree per tenant — and every code path that touches data carries a tenant id. Retrofitting this after the fact is more expensive than building it in at the start; the RFC makes it foundational.

Figure 4 — Gaps to invariants

What the paper doesn’t sayOurios invariant (CLAUDE.md)
What threshold to pick§3.1 — strict default ≥ 0.7, RFC gate below
What to do in the lossy zone§3.1 — three-zone model, body retained under threshold
What to do with huge parameters§3.2 — 256 B limit, overflow to body, 1% alert
Whether whitespace is preserved§3.3 — bit-identical reconstruction or lossy flag
How templates evolve§3.5 — versioning, aliases, drift detection
How tenants are isolated§3.7 — one tree per tenant, tenant id on every path

This is the table to internalise. Everything else in the design descends from these six lines.

5. The Ourios extensions: the record shape and the merge policy

Let me show you what a mined record looks like in Ourios, because it makes the invariants concrete.

Figure 5 — The Ourios log record

The Ourios log record: a 3×3 grid of fields. Row 1: tenant_id, template_id, template_version. Row 2: params[], body?, confidence. Row 3: lossy_flag, timestamp, service. tenant_id is highlighted as the partition key, confidence and lossy_flag are highlighted as honesty-contract fields.

Every field on that diagram is a commitment:

  • tenant_id is present on every row, not on every file — the partitioning is a separate question. We never trust the file to tell us the tenant; we trust the row.
  • template_id is the identity of a template within a tenant. The same text in two tenants yields two different ids. This is deliberate — it means a query never needs to join across tenants to resolve identity.
  • template_version lets a template’s representation change over time while the logical identity persists.
  • params are length-bounded per 4.3 above.
  • body? is present whenever the lossy-or-fail zone fired, and optionally always, as a tenant-configurable choice. Paying the storage cost of always keeping the body buys perfect reconstructability; most tenants will not want to pay it, and the default should be “only when needed.”
  • confidence is the scalar the three-zone model was defending.
  • lossy_flag is the boolean the reader checks before trusting template-based rendering.

Now the other piece the paper does not address — merging.

Drain as published merges templates implicitly. When a line matches an existing log group but its tokens differ at some positions, the template at those positions becomes a wildcard. The template has widened. This is a merge. The paper does not call it that and does not audit it.

In Ourios, every widening event that crosses a configurable threshold of semantic change fires a merge audit event — a structured record with the old template, the new template, the tenant, the timestamp, and the reason. The audit event is a first-class citizen: it goes to the same storage, it is queryable, and there is a metric merges_total that dashboards the rate.

Why does this matter? Because the horror story for a template miner is a silent merge that crosses a semantic boundary. user logged in <*> and user logged out <*> differ in one token. Depending on your threshold, they can merge into user logged <*> <*>, and now a query for the login event returns logout events too. The user will not know this has happened unless we tell them. The audit event is how we tell them.

Strict defaults plus visible audits plus a merge-rate metric are not paranoia. They are the shape of “we are not going to let this system lie to you silently.”

6. The honesty contract: reconstruction as a property

We have seen confidence scoring, length limits, whitespace capture, versioning, tenancy, merge auditing. There is one more piece that ties them together, and it is less a design and more a claim we make to the user.

Figure 6 — The reconstruction invariant

\[ \begin{aligned} &\forall\, \mathtt{line} \in \mathtt{corpus}: \\ &\quad \mathtt{reconstruct}(\mathtt{mine}(\mathtt{line})) \equiv \mathtt{line} \\ &\quad \lor\;\; \mathtt{mine}(\mathtt{line}).\mathtt{lossy\_flag} = \mathtt{true} \end{aligned} \]

In English: for every log line we ingest, either we can reproduce the exact bytes the customer’s application wrote, or we flag the row so the reader knows not to claim we can.

This is not a design decision. It is a property. It is what we prove on every CI run. The test is:

for every line in testdata/corpus/ :
    record = mine(line)
    if record.lossy_flag == false :
        assert reconstruct(record) == line

If that assertion ever fails, the backend is lying, and that PR does not merge.

The reason this is a property test and not a unit test is that the set of log lines we care about is the power set of our token vocabulary, and we cannot write unit tests against a power set. What we can do is assemble a corpus — real, anonymised log lines from real applications — and run the property against every line in the corpus on every build. proptest lets us go further: it generates synthetic adversarial inputs that stress the whitespace capture, the tokeniser, the length limits, and the merge policy, looking for a counterexample. When it finds one, we have learned something real.

The reconstruction property is the single honesty contract between this system and its operators. Everything else in the design — the confidence model, the body retention, the merge audit — is in service of making this property defensible.

7. What is still open

I am going to close with the things I do not yet know, because if this lecture ended with a polished answer it would be a marketing pitch and not a lecture.

  • Threshold on real corpora. We have said “strict default, at least 0.7.” The paper’s sweet spot is corpus-dependent. Until we run Ourios on meaningful corpora we do not know whether 0.7 is merely safe or also good.
  • Masking placement. Drain3 does regex-based masking — IPs, UUIDs, numbers — before the tree walk. This improves template stability dramatically but it also couples the tree to a set of regex rules that are inherently wrong at some edges. Where exactly that masking happens — pre-tree, post-tree, both, neither — is an open design question.
  • Binary and malformed input. Log lines are not always valid UTF-8. They are not always text. A mature miner has a story for what happens when the input is simply not parseable into tokens. We do not yet have that story written down.
  • Template identity across versions. The versioning story in §4.5 needs an alias mechanism and a drift query surface. Neither is designed yet.

These four items are in docs/rfcs/0001-template-miner.md under Open Questions, and the RFC cannot move to accepted until they are resolved.

Thesis, restated

Drain is not a log parser. Drain is a tree. What makes it safe to put into production is everything we build around the tree — the confidence scoring, the merge auditing, the body retention, the reconstruction property — none of which appear in the paper.

If you take one thing away from this lecture, take that sentence. The tree is a reasonable default partition function over log lines. The system around it is the product.

Questions

Prompts for the Q&A segment. Seed these into the room if the audience is quiet.

  1. Why not use an LLM-based parser instead of Drain?
  2. Why is reconstruction a property test and not a unit test — can you give an example of a bug that a unit test would miss?
  3. How does the merge audit scale when a single deployment produces a high merge rate — does the audit stream itself need to be templated?
  4. If a tenant configures a threshold below 0.7, how is that audited as a policy event?
  5. What happens to the template tree when a service is sunset and its templates go cold?

References

  • He, P., Zhu, J., Zheng, Z., Lyu, M.R. Drain: An Online Log Parsing Approach with Fixed Depth Tree. ICWS 2017.
  • Drain3 (IBM): https://github.com/logpai/Drain3
  • LogPAI benchmark suite: https://github.com/logpai/logparser
  • Ourios: CLAUDE.md §2.2, §3.1–§3.3, §3.5, §3.7, §4, §6.2, §6.3
  • Companion RFC: docs/rfcs/0001-template-miner.md