Applies to v1.3.18

ESRA — Operations

Audit, metrics, tracing, health and diagnostics. ESRA has no pipeline of its own for any of these: it emits into the platform's.


Audit

ESRA emits governance audit records with a dedicated action namespace, so its stages appear in the Call Flow trace and reach external immutable audit targets like every other governance record.

Retrieval:

Action Records
esra.invoke invocation id, tenant, client, exposure, capability, configuration version, outcome, total duration, input/output/total token counts and model-call count (not gated on payload capture — counts, not content)
esra.sources.resolve all four scope levels and every narrowing note
esra.sources.select candidates, mandatory, policy-forced, model-selected, rejected, confidence
esra.plan plans generated, mappings selected, queries per source, applied limits, model reference
esra.plan.reject query id and reason code for every rejected query — and the entity, for a reason about the entity: RECORD_FILTER_UNRESOLVED (withheld, degraded) or STATIC_FILTER_EXCLUDES_ENTITY (skipped: a constant it binds proves no row can match)
esra.provider.query source, provider, mapping, query id, duration, result count, error classification, retries, circuit state, cache hit
esra.aggregate candidate count, deduplicated count, dedup ratio, source distribution
esra.rerank rerank input count, fallback used, token usage
esra.answer answer status, citation validation outcome
esra.document.fetch document ref hash, source, offset, returned size

Administrative actions. Creating, changing, testing, publishing, rolling back, enabling and disabling sources, capabilities and exposures have no ESRA action of their own. Like every Portal administration request, each is recorded as a portal-access / admin.access record naming the user, the tenant, the endpoint called and the status code it returned, but not what changed. Three kinds of ESRA administration write records of their own:

  • esra.preview, from Try & trace (see Diagnostics below), records that a query was previewed;
  • esra.source.governance-binding-changed is written for each confirmed change to what a source's record filter compares (see Security and governance);
  • tool-access-policy.create, .update and .delete, in the esra-exposure-admin category, record changes to an exposure's tool access policies.

Capability invocation: a capability tool branches out of the mapping pipeline before the request.transform / response.transform audits that would otherwise carry its MCP payloads, so the Runtime writes its own capability.invoke record — the caller's tool arguments and the response they received, captured under the same per-exposure flag and byte ceiling as every other capture and, for ESRA, after the capability's own governance (masked fields masked, restricted fields absent).

The hot-path rule

Audit must never add latency or a failure mode to retrieval. Payload capture is conditional on a per-exposure flag, writes are asynchronous, and a failed audit write never fails an invocation.

Never captured: connection strings, resolved secrets, generated SQL, raw provider errors. Prompts and result fragments are captured only under an explicit per-capability retention classification; a hash or redacted form is the default.

Warning messages carry a fixed string and, at most, a source name — never an id-to-host mapping and never error text.


Metrics

Metric Type Dimension highlights
esra_invocations_total counter tenant, client, tool, outcome
esra_invocation_duration_ms histogram (ms) tenant, client, tool, outcome
esra_stage_duration_ms histogram (ms) tenant, stage, outcome
esra_provider_queries_total counter tenant, source, provider, outcome
esra_provider_query_duration_ms histogram (ms, bucketed 5ms-30s, giving p50/p95/p99) tenant, source, provider, outcome
esra_provider_query_results histogram tenant, source, provider, outcome
esra_llm_tokens_total counter tenant, task, model, token kind (prompt/completion)
esra_stage_fallbacks_total counter tenant, stage, fallback trigger
esra_fragments_total counter (returned records) tenant, source, provider, fragment outcome: match (cut around the match), leading (no searched word in the snippet field, so the start of it), native (the engine's snippet function), none (empty snippet field)

Every metric carries the tenant dimension. Tenant is never omitted, including on failures and denials.

These are all the metrics ESRA emits. Selected-source count, query fan-out, deduplication ratio, rerank candidate count, per-source retry and timeout rates and circuit-breaker openings are not metrics; the per-stage detail of the invocation trace shows them for each run.

What the model has cost

A durable running total per capability — input tokens, output tokens, invocation count, model-call count — is tracked separately from the point-in-time metrics above. It answers a question neither the metrics nor the invocation trace can: the metric counters report current spend and are aggregated away, and the trace is a read model over an audit trail that is scanned in a bounded window and purged on a retention schedule, so it can say what one run cost and never what a capability has cost in total.

It is reported on the Portal's capability list and detail screens, and summed across every capability — retired ones included — on the overview, since a retired capability's spend is still spent. Counting happens at the one point every model call passes through on its way out, so a call that timed out or was retried is billed exactly like one that succeeded. Where a connector reports no usage the count falls back to the platform's four-characters-per-token estimate, and the total says how much of it was estimated rather than presenting the two as the same kind of number. Accrual is off the hot path — buffered in memory and flushed by a background writer that coalesces by capability — on the same terms as audit.


Tracing

One span per stage, plus one per provider query, as children of the MCP invocation span. A single distributed trace therefore covers MCP invocation → policy evaluation → orchestration → selection → planning → each provider query → aggregation → reranking → audit dispatch.

ESRA's spans are on the platform activity source, CodedProjects.AI.ApiMapper.Platform, so any host exporting traces (an OTLP endpoint configured under Observability:OtlpEndpoint) exports them with nothing to add. Each stage span carries tenant.id, esra.invocation.id and esra.exposure.id.


Health

ESRA adds no check of its own to the Runtime host's health endpoints: provider and source problems are reported per source, as below, rather than failing the host.

Source connectivity is probed on a schedule, not on the readiness path. A failing optional source degrades a retrieval; it does not fail readiness. The four-state model — healthy, degraded, unhealthy, disabled — is surfaced per source in the Portal.

The sweep runs as a scheduled background job and probes every published, enabled source. Scope resolution excludes an unhealthy source, so a database that went away overnight stops being selected without an operator probing it by hand.

Situation Behavior
A probe throws that source is recorded unhealthy; the sweep continues
A source is Degraded it stays in scope — searchable, slower or less accurate — and says so
The source is a draft not probed; nothing depends on a draft's health
No provider serves it in this host its recorded health is left untouched — a composition problem is not the source's fault
Nothing changed recorded, not reported. A five-minute sweep that logged every pass would bury the pass that matters

The sweep is configurable and can be switched off for a deployment whose sources sit behind a connection-rate-limiting gateway. The Portal then shows when the probe last actually ran, rather than implying the recorded value is current.

Circuit breaking

A separate signal from health above, and a faster one: health is a scheduled probe's opinion, checked every few minutes; circuit state is the live resilience pipeline's view, updated the moment a source starts or stops failing. A source can be Healthy by the last probe while its circuit is open, because it started failing seconds after the probe ran. The Portal shows health, not circuit state.

Each source has its own circuit breaker: under a real outage, the breaker turns what would otherwise be every concurrent query burning its own retry budget and timing out independently into fast, immediate failures after an initial run of errors — until a single probing query decides the source has recovered. Breaker behavior is configurable per source on the Ceilings tab and defaults to on.

Result caching

Off by default, per source, on the same Ceilings tab: "Allow result caching" and a cache TTL (default 30 seconds, kept short: it collapses a burst of near-identical queries against a slow-changing source, not a data warehouse). Turning it on for a source whose content changes continuously just serves stale rows for no benefit; it is a setting for a reference catalog, not a ticketing system.

Results are cache-isolated per tenant, source, and caller, which is what makes this safe to turn on even for a source using a claim-narrowed record filter — two callers who are entitled to see the same data may share a cache entry, but a caller entitled to different data structurally cannot receive it, cache or not. Only raw, pre-mask rows are ever cached — masking re-applies on every read, cache hit or not, so a masking-policy change takes effect immediately rather than waiting out the TTL. Only Results-mode queries are eligible; a grounded answer always regenerates from current evidence, never from a cached result.

A cache hit still writes the invocation's audit record and stage trace — a cached answer is still a served answer for audit purposes, marked so in the esra.provider.query record's cacheHit dimension. Only the round-trip to the source itself was skipped.

Index and schema advisories

The scheduled health probe also flags conditions that make a mapping searchable but suboptimal, never conditions that make it unsearchable — those already surface as Degraded/Unhealthy above. Three closed-set advisory findings: a PostgreSQL index that exists but is a plain column rather than an expression matching the mapping's computed search vector, so it cannot actually accelerate the query; a matching expression index that was built against a text-search configuration the mapping no longer names; and, on PostgreSQL, SQL Server, MySQL/MariaDB and Oracle, a claim-narrowed record filter's column with no index covering it. A PostgreSQL entity that names a stored document vector column gets a fourth instead of the first two: the column has no GIN or GiST index.

Advisory means exactly that: never a blocker, never a contributor to a source's health state, never a reason a source drops out of scope. The source grid's Findings column shows a count of these findings as an amber dot, distinct from the health badge, since a source can be perfectly Healthy and still carry one — "reachable but suboptimal" is not a state the health badge alone can express. Each finding, shown on the entity it concerns on the source page's Searchable entities tab, names the affected relation and column and states the concrete remediation as text an operator can hand to their DBA; ESRA never runs the DDL itself.


Errors and Warnings

Closed sets. Nothing outside them reaches a caller.

Connection failures name a remedy

Four failures happen before the driver is involved — an unallowlisted host, an unresolvable secret, an unparseable template, and a source configured for an isolation level its database forbids. Each carries its own classification rather than falling through to UNKNOWN, and the Portal's connection test states what to change:

Classification What to do
HOST_NOT_ALLOWED add the host to the tenant's outbound allowlist; the database was never contacted
SECRET_UNRESOLVED re-bind the username or password secret — SECURITY_MANAGE work
CONNECTION_TEMPLATE_INVALID fix the template; it could not be parsed, or names no server
SNAPSHOT_ISOLATION_UNAVAILABLE enable ALLOW_SNAPSHOT_ISOLATION on the database, or set the source to read committed

Anything else unrecognized reports UNKNOWN.

A fifth, CIRCUIT_OPEN, is not a connection failure at all: it means the query never reached the driver — the source's circuit breaker was already open from prior failures and failed the call fast. It is permanently excluded from the retryable set, since retrying around an open circuit would defeat the point of tripping it; the remedy is to look at what opened the circuit, not to retry.

Errors — the invocation fails:

Code Meaning
ESRA_INVALID_REQUEST prompt missing or empty, filter malformed
ESRA_RESPONSE_MODE_NOT_PERMITTED mode outside the effective set
ESRA_FILTER_NOT_PERMITTED a caller filter names a field callers cannot filter on, or an operator that field does not permit; refused before any model call, with a message naming what is accepted
ESRA_FILTER_VALUE_INVALID a caller filter's value is not a value of its field's type (a date, a number, true/false); refused before any model call, with a message saying what the field takes
ESRA_CAPABILITY_UNAVAILABLE exposure unpublished or configuration invalid at invocation
ESRA_NO_SOURCES_AVAILABLE effective source set empty after resolution
ESRA_MANDATORY_SOURCE_FAILED a mandatory source failed and policy is fail-closed
ESRA_TIMEOUT total budget exhausted before any result
ESRA_CANCELLED caller or host canceled
ESRA_DOCUMENT_NOT_FOUND fetch: ref invalid, expired, replayed, or no longer authorized
ESRA_FETCH_NOT_PERMITTED fetch called on an exposure with fetch disabled
ESRA_FETCH_QUOTA_EXCEEDED caller exceeded the hourly fetch character quota
ESRA_INTERNAL anything unclassified

Warnings — the invocation succeeds with status: degraded:

Code Meaning
ESRA_SOURCE_UNAVAILABLE an optional source could not be reached
ESRA_SOURCE_TIMEOUT a source exceeded its command timeout
ESRA_SOURCE_PARTIAL a source held more matching rows than its row cap let through
ESRA_PLAN_REJECTED one or more generated queries failed validation
ESRA_SELECTION_FALLBACK source selection fell back to mandatory-only
ESRA_PLANNING_FALLBACK planning fell back to the default template
ESRA_RERANK_FALLBACK reranking failed; deterministic ordering used
ESRA_RERANK_PARTIAL a decision model rated only some results in time; the rest follow in search order
ESRA_ANSWER_UNAVAILABLE answer generation failed or is not permitted
ESRA_RESULTS_TRUNCATED the requested top-K exceeded the effective cap
ESRA_BUDGET_EXCEEDED a stage hit its deadline and degraded
ESRA_CONFIGURATION_DRIFT a bound source disappeared since publication

Diagnostics

Try a query

On an exposure's Try & trace tab, an administrator runs one real retrieval and sees every stage of it. It is not a simulation: the same orchestrator, the same configuration and the same providers a caller reaches, running as one of the exposure's own client applications — so narrowing, audience and tool policy all apply. A preview that returns nothing says something true about the configuration.

Beside the question, choose the Response mode — only the modes the exposure's effective scope permits are offered, Results first — and, if you want, a Top-K: empty runs with the capability's default, and it cannot exceed the exposure's result ceiling. A mode the capability does not permit is answered as unavailable, as it would be for a caller.

What it changes is the audit disposition, not the execution. The stage records are captured and returned instead of being written, and the preview writes one esra.preview operator-action record carrying the prompt, the status, the result count and the duration — never the results. An administrator testing a query must never appear in the trail as a caller having retrieved data: that trail answers "who read this record", and it is the one question it has to answer truthfully.

It requires ESRA_DATA_MANAGE, not the exposure role. Previewing returns real records from a real source, so the authority it needs is the authority to see that data — not the authority to decide who else may.

The response shows what a caller never sees: the resolved effective scope with narrowing notes, the generated plans, each query's rendered parameter metadata, per-source timings and result counts, all four per-result scores — provider, normalized, semantic and final — the deduplication merge, and every fallback taken.

An exposure that is not published, or has no client application bound, reports why it cannot run rather than reporting no results. The two need different responses from the operator: one is a configuration change, the other is a fact about the corpus.

Invocation traces

The same tab lists recent invocations and opens any one of them as a stage trace. This is a read model over the governance audit records ESRA already writes, not a second store, so it never disagrees with the audit trail. Preview records are excluded from the listing, for the same reason they are not invocations.

The timestamp in the When column expands that run's stages inside its own row — stage, outcome, duration and detail — and clicking it again collapses them. Both the listing and the trace read a tenant's audit trail, so both take the exposure under inspection: it names the tenant for a platform administrator, whose session pins none. When either cannot be read, the panel says why — an empty listing means the exposure has never been called, and it must not be shown for a request that simply failed.

The trace is what separates four situations that look identical from an empty result set: the corpus has no answer, the selector skipped every source, the plan was rejected, or a provider query timed out. Each calls for a different response, and the results alone tell them apart not at all.

Outcomes are shown as OK, Partial, Failed and Not run, each explaining what it means for the answer. Partial is the one worth knowing: the step produced a result but not its best one, and its commonest cause is that no model is configured for the tenant, so the deterministic path ran — a setting rather than a fault. The audit trail keeps the pipeline's own words (Success, Degraded, Failed, Skipped); the screens do not.

Each row carries an outcome — succeeded, degraded or failed, rolled up from the stages, worst wins — and a failed one names the stage that broke, the class of failure, and the reason that stage recorded. It names the first failure rather than the last: a stage that fails usually makes the ones after it fail too, and what an operator needs is the cause. Degraded is reported as degraded rather than as success, which matters most when it is a model stage that quietly fell back to the deterministic path.

Callers get status and warnings. Everything else is administrator-only.

What each step records

With Capture request and response payloads on for the exposure, the call flow carries the caller's tool arguments — the prompt among them — and the response they received, on the MCP Call step. The response is captured after governance: masked fields are masked and restricted fields are absent, exactly as the caller saw them.

The retrieval steps carry their own detail whether or not capture is on, because none of it is caller content: which sources were in effective scope, which of them were selected and which were passed over, how many queries were planned and how many rejected, and per provider query the source, the entity, the number of records and whether the result was truncated.

The terms a query searched for follow the capture setting, since they are the caller's own words. They are recorded as ESRA planned them: the concepts that all had to match, each with its alternatives, then exact phrases, then what was excluded. For example, concepts: [car, automobile] AND [insurance, policy] · phrases: "no claims" · excluding: rental. Excluded terms are worth reading first: they are the usual reason a record somebody expected is missing.

With capture on, each provider query also records executed: the full-text condition the engine actually ran, such as SQL Server's CONTAINSTABLE condition, PostgreSQL's tsquery or Elasticsearch's text clauses. It is the search condition alone. Filters and the record filter are never in it, since their values can come from the caller's claims. Neither the generated SQL nor an entity's underlying table is ever recorded: the trail carries no database structure.

The planning step says what ESRA changed in the model's plan, and why:

  • normalized: how many changes there were.
  • normalizationReasons: the reasons, for example legacy_fields=3, term_too_long=1.
  • With capture on: the terms affected, and each source's raw planning output.
  • With capture on, a rejected query also names its terms.

The reasons:

Reason Meaning
term_too_long A term over 64 characters (128 for a phrase) was dropped
term_unsafe A term carrying ;, --, /* or a control character was dropped
item_cap An item over the query's limits was dropped
empty_concept A concept with no usable alternative was dropped
concepts_merged The concepts were merged into one, for MongoDB
legacy_fields The query used the older required/optional term lists, which were read as concepts
legacy_fields_ignored The older term lists appeared beside concepts and were ignored
required_widened Of the older required terms, all but the first were made alternatives
duplicate A query that would match the same records as an earlier one was dropped
query_cap A query beyond the source's query ceiling was dropped
unknown_strategy, unknown_mapping, empty_query The whole query was dropped: an unknown strategy, an entity the planner was not given, or nothing left to search for

The wider call flow

Governance → Call Flow shows an execution end to end, and a retrieval call appears there in full: the governance check, then every ESRA stage — effective scope, source selection, planning, each provider query, aggregation, reranking, the answer — each as its own node with its own timing, followed by the response. Repeated stages are repeated nodes, because a call that fanned out to two sources and had one time out is not the same call as one that queried once.


Configurability

The operational limits — fan-out, row caps, timeouts, budgets, fetch quotas and the like — are set on the entities themselves, each starting from a shipped default, and narrow in the same order the pipeline does:

source        per-source ceilings (the Ceilings tab)
      ↓
capability    retrieval behavior and budgets
      ↓
exposure      overrides that may only narrow

An exposure override above its capability's value is a publication error, never a silent clamp — the narrowing-only rule for exposures. A source that permits less than its capability narrows the invocation for itself, and the effective scope notes it.

A few bounds are fixed rather than configured: how much of each result's fragments the reranking and answer models read (600 and 1,200 characters), and the shape a planned query may take (at most 4 concepts of at most 12 alternatives, terms of at most 64 characters and phrases of at most 128).