Skip to content

Layer 1 for agents: the replica's databases through agent PSBs

Crate oliviadb-enterprise/crates/oliviadb-agent (proprietary), on top of the open layer-1 view (oliviadb_memory::operational, see mcp.md). Tests: cargo test -p oliviadb-agent (tests/layer1.rs) and cargo test -p oliviadb-memory --test operational.

What an agent gets

The IMS databases replicated into OliviaDB (initial load from an HD unload, then the data capture log applied, integration.md) are served read-only through the MCP server:

catalog oliviadb_path CATALOG, resource oliviadb://<tenant>/CATALOG: databases, segment types, their parent, key field, fields with types, meanings and conditions, programs that read or change them (when a semantic catalog is loaded)
navigation oliviadb_path CUSTDB/CUST (roots, paged), CUSTDB/CUST=C001 (a segment and its child types), CUSTDB/CUST=C001/ACCT (children), .../NOTE[2] (unkeyed twins by position), ?as_of=<source store-clock time> (as the source had it then, from the version window), ?page=<cursor>&limit=n
search data_recall (query, budget): the best segments as compact lines with their paths
watch data_watch (path prefixes): a watch resource updated through subscriptions/listen when the capture applier commits changes the agent can see; its cursor is a source time (the IMS log time of the last unit seen), the same on every copy of the replica, so a watch survives a failover to the standby

Values are decoded: character fields as text (EBCDIC converted), packed and zoned decimal and binary as numbers with their sign (and scale, from a semantic catalog), other bytes as x: hexadecimal. Keys appear in paths as decoded text when that text encodes back to the same bytes, else in x: form.

Binary: oliviadb-agent-mcp --replica DIR --library DIR --agent-psb FILE --dir DIR --tenant T --principal P [--user branch=NORTH,...] [--profiles read,memory] (stdio).

Agent PSBs

An agent PSB is PSBGEN source plus three OliviaDB statements in the same format:

         PCB   TYPE=DB,DBDNAME=CUSTDB,PROCOPT=G,KEYLEN=8
         SENSEG NAME=CUST,PARENT=0
         SENFLD NAME=CNO,START=1
         SENFLD NAME=NAME,START=5
         SENFLD NAME=TAXID,START=15
         SENSEG NAME=ACCT,PARENT=CUST
         PSBGEN LANG=COBOL,PSBNAME=AGTKYC
         ROWS  DBDNAME=CUSTDB,SEGMENT=CUST,FIELD=BRANCH,OP=EQ,VALUE=$USER.BRANCH
         MASK  DBDNAME=CUSTDB,SEGMENT=CUST,FIELD=TAXID,HOW=REDACT
         MASK  DBDNAME=CUSTDB,SEGMENT=CUST,FIELD=NAME,HOW=(PARTIAL,3)
         PDATA DBDNAME=CUSTDB
         END
  • SENSEG / SENFLD: the segment types and fields the agent sees. A field of the segment's layout is visible when its bytes lie within the sensitive fields; PROCOPT=K on a SENSEG shows its key only. Only reading: PROCOPT may hold G, O and P (K on SENSEG); I, R, D, A, L are refused. PROCSEQ, logical and index databases, DEDB, MSDB and GSAM PCBs are refused for now.
  • ROWS: row predicates (OP=EQ, NE, IN; VALUE a value, a list, or $USER.<attribute> of the acting user, from the exchanged token's claims). A predicate is on a segment with a unique sequence field (the root, typically) and guards it and everything below it; all predicates of a database must hold; the fields may be outside SENFLD (a branch code the agent is not shown). A database without ROWS is refused unless it says ROWS DBDNAME=..,ALL=YES. A user without the attribute sees nothing (fail closed).
  • MASK: REDACT, TOKEN (a keyed pseudonym: equal values, equal tokens), (PARTIAL,n) (the last n characters). In IMS, SENFLD only includes or excludes a field; masking is OliviaDB's extension.
  • PDATA: character fields pass through the personal-data masker the host gives the view (oliviadb_memory::text::TextMasker); refused without one (the oliviadb-agent-mcp binary has none yet).

The statements compile to the open part's policy model: one Policy per database, types SEG, fields SEG.FIELD, the same predicates, visibility and masks as agent memory uses.

What does not leak (tested)

tests/layer1.rs checks, for agents of two branches and an operations agent:

  • a segment outside the row predicate, its dependents, a database or type outside the PSB give the same "not found" as a key that does not exist;
  • masked values are not in any result, and searching for them (tax ids, full names partly shown, the branch that drives the predicate, other branches' customers and their notes) finds nothing: the search index is built from what the agent sees, per agent view, never from raw data;
  • a segment whose key is masked or not visible is addressed by an opaque sealed name (CUST=~...); its raw key is refused as an address (no "does this number exist" test); names are bound to database, type and the server's key;
  • derived values (an 88-level meaning) are shown only when their source field is, are redacted when it is masked, and the catalog drops the source's value list then;
  • page cursors are sealed (no count of hidden segments) and bound to their listing;
  • watches report a change only when what the agent sees changed: a replace of a masked field only is not reported, a segment entering or leaving the predicate is reported as an insert or a delete, other branches' changes are not reported;
  • completion offers database and segment names, never values.

Lag

The replica measures how far it is behind its source from the change stream itself. Each unit of work applied records its source time (the commit time in the data capture record) and the time it was applied here; every read of the feed records the time it was read, whether it brought units or not (System::replica_lag, oliviadb_dli::capture::Lag):

  • the delay of the newest unit is its applied time minus its source time;
  • the lag is that delay while the feed was read within the feed timeout (a live feed that brings nothing new means the source had nothing new), and unknown before the first unit and while the feed is silent for longer than the timeout.

Source times are converted to Unix time by the configured clock: "source_clock": "store-clock" (the default; bit 51 counts microseconds since 1900-01-01, with "source_clock_offset_ms" for a source clock that runs ahead of UTC), "unix-ms" or "unix-us"; "feed_timeout_ms" (default 10000). The measurement is only as good as the agreement of the two clocks; a negative delay (the clocks disagree) counts as no lag.

Access profiles use it (spec/schema.md 6): the replica is a follower, so consistency strong is refused (503), follower max_lag d is served while the lag is known and at most d (503 otherwise), follower without a bound always. Operators see each database's lag, the newest unit's delay, when it was applied and when the feed was last read in GET /v1/admin/stats (replica_lag) and on the console's statistics tab. Test: oliviadb-enterprise/crates/oliviadb-agent-server/tests/lag.rs.

Open

  • The search index lives in process memory per agent view (rebuilt at start by a scan, then kept current from the change journal); lexical (BM25) only.
  • A change of a twin without a unique key is reported at the listing path of its type (the data capture record does not say which twin); ancestors with non-unique keys are taken as the first twin with that key.
  • Reads as of a source time use the version window (System::retain_versions_from); the search index is current only.
  • Notifications go out when the stdio server handles a message (Server::poll); a host that embeds the server calls poll after applying changes.
  • Opaque names are deterministic per server key (AgentView::set_key; the binary derives it from the master key): equal keys give equal names, by design, as for TOKEN masks.