> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# System tables

> Read the host's own facts through sys: grants (identity trusts, bindings and sessions included), tasks, branches, pins, legal holds, disclosures, erasures, member registrations, the organization registry and the program a frame runs.

`sys`, from `@bijectionhq/bijection`, holds the host's own tables. They are
read with the same five reads and addresses as an app's tables, and they are
**read-only** to the six writes: a write to a `sys` table is a type error. Each
changes only through its grave acts, which `bijection check` lists per
function. The kernel lowers each act to an existing host verb.

| Table | Fact | Indexes | Written by |
| - | - | - | - |
| `sys.grants` | `{ id, holder, rights, parent, roleChain, label, expiresAtMs }` | `["label", "holder"]`, `["label", "parent"]` | `ctx.grant`, `ctx.revoke` and the Sessions app for issuer trusts, identity bindings and sessions |
| `sys.grantTransitions` | `{ id, grant, sequence, kind, previous, assertion, as, asFor, chain, survivors, digest, version, at }` | `["grant", "sequence"]`, `["version"]` (the audit order) | the host, on every issue and revocation |
| `sys.tasks` | `{ id, task, once, target, args, state, result, due, until, claim, replyTo, survivors }` | `["target", "once"]`, `["target", "state"]`, `["state", "due"]` | `ctx.submit`, `ctx.answer`, `ctx.withdraw` |
| `sys.branches` | `{ id, from, until }` (`until` moves while a pin field holds the branch) | `["from"]`, `["until"]` | `ctx.branch`, `ctx.land`, `ctx.discard`, a pin field |
| `sys.pins` | `{ id, version, branch, holder, until }` (a version pin or a pin field's version or branch with its table as `holder`) | `["version"]`, `["until"]` | `ctx.pin`, `ctx.unpin`, a write of a pin field |
| `sys.holds` | `{ id, unit, message, as, at }` | `["unit"]`, `["at"]` | `ctx.hold`, `ctx.lift` |
| `sys.disclosures` | `{ id, release, shared, unique, index, judgement, as, asFor, chain, survivors, at, from, to, removed, member, members, atSource, sequence, previous, digest }` (fields vary by record) | `["release", "at"]`, `["release", "member", "at"]`, `["as", "at"]` | Each use of a release, including `ctx.open(sealed, { release })` and a release applied by an import, and host audits for a `shared: true` limit’s judgement (`"admitted"` or `"refused"`) or a unique key judged `across` a cover |
| `sys.erasures` | `{ id, unit, at }` | `["at"]`, `["unit"]` | `ctx.erase` |
| `sys.destructions` | `{ id, unit, erasure, at, evidence }` | `["unit"]`, `["at"]` | the host custody collector (when `erasable.custody` is declared) |
| `sys.members` | `{ id, family, key? }` | `["family"]` | `ctx.register(family)`, `ctx.retire(tag)` |
| `sys.organizationRegistry` | `{ id, generation, registry }` | none (one fact, the installation's) | the installation steward |
| `sys.programs` | `{ id, at, over, as?, message? }` | `["at"]` | a deploy |
| `sys.logs` | `{ id, stream, execution, line, site, function, on, level, message, code, reason, at, version }` | `["site", "at"]`, `["site", "version"]` for app reads | the host, for application logs and platform audit events |

An app selection binds the declaration that its rows describe in the
index prefix. For example, grants bind a label and a holder or parent,
tasks a target, and logs a site. An unbounded or out-of-reach selection refuses with
`GrantRequired`. A principal's own identity binding and sessions are read
under the principal's own member, and they take the same site reach as any
relation: the root app's functions reach them as they reach
`sys.installation`, and a mounted component does not. A table's `writers`
gives a site no read reach.

A task's lifecycle state is `pending`, `blocked` or `settled`. A task is
`blocked` when the grants recorded at submit are no longer live when it is
claimed.
`survivors` holds the ids of the submitter's surviving grants at submit, per
position (`credential`, `actor`, `code`): a claim decides only through those
that are still live. `replyTo` is where the claim may write, fixed at
submit, and `claim` is the claim record (claimant and instant) that consumed
the task; a second claim refuses. A settled task carries its `Result`. A read below the task's run label
can see `withheld`, which describes visibility.

A grant's `id` and `parent` are `{ label, key }`. The opaque `key` names the
original issuance, and `parent` is the grant it was issued from. `holder` is `{ kind, id }`: a
`principal`, a `class` (`anyone` or `signedIn`) or an invitation `bearer`
(the token's digest). `rights` lists its `{ verb, object, scope }` rights.
`roleChain` is its role's path, then the roles of the grants above it: the
grant binds the role by name, so a release that replaces the role keeps it.
`label` is where the grant is observed, and `expiresAtMs` its end (null until
revoked). A grant lives only while its parent lives. Revoking a grant is a
later assertion of the same grant that expires at the revoking instant;
nothing is retracted. A grant carries no other attribute: a session's or an
installation key's details live in the platform's sessions and keys
records, keyed by the grant's id.

| Selection | Selects |
| - | - |
| `sys.grants.where({ label, role })` | Grants of one role at an exact label. Add `holder` or `parent` to narrow the results. |
| `sys.grants.where({ label, issuer })` | Trust grants of one issuer declaration at an exact label. Add `holder` or `parent` to narrow the results. |
| `sys.grants.mine()` | The caller's own live grants, from a function under `label.principals`. |
| `sys.grants.invitation({ token })` | The bearer holder of an invitation, from its token (or `{ tokenDigest }`), to pass as `ctx.grant`'s `to`. |

Pass a `where` selection to `ctx.revoke` to revoke the visible grants it
names in one bounded append.

Identities are grants too. Trusting an issuer issues a grant to the issuer
that carries `attest` for it. Each identity that signs in through the issuer
is bound to its principal by a grant under that trust, which carries `speak`
for the principal, and each session is a grant under the binding, held by the
session's credential (`credential:<id>`). Revoking the trust ends every
binding and session under it, and revoking a binding ends its sessions (see
[Authenticate callers](https://docs.bijection.com/access/authentication#trust-verified-email-for-invitations)).
Service keys, export secrets and development keys speak for their principals
the same way, through grants held by their credentials (see
[Installation credentials](https://docs.bijection.com/operate/installations/credentials.md)).

A member of a dynamic label family holds its own accounts only once
registered. `ctx.register(family)` registers one: the host
mints a random, opaque tag `<family>:<id>` (32 lowercase hex) and answers
it. An admitted retry of the same act occurrence returns its retained
receipt's original tag, including after erasure.

* Founding needs the `register` right for the family from both the caller's
  and the code's grants ([Found a family member](https://docs.bijection.com/access/grants.md#found-a-family-member)).
  It runs at the public label, registers the member in its own step and
  charges the public `members` account. Past the family's `members: n` it
  refuses `Limit` (`MemberEntitlementExhausted`). Your plan's
  member place capacity is a host-only shared limit: it reveals no member
  count. Each returned judgement records `sys.disclosures` at the asking
  label and the release's source label.
* The member's place is funded with the family's quotas.
* A family declared `keyed: true` takes `ctx.register(family, { key })`. The tag is still
  random; a keyed index at the family's stem finds it, and erasing the member
  deletes the index entry. A fresh registration of a taken key refuses
  `Exists`. A fresh registration can reuse an erased member's key and
  receives a new opaque tag.

`sys.members` is keyed by the member's tag, and `family` is the family declaration.
For a current keyed member, read `ctx.get(sys.members({ family, key }))` in
the live world.
The point answers `{ id, family, key }` when the member is live and `null`
when the key is absent. The keyed lookup can refuse while the index is
rebuilding. See [Family tables](https://docs.bijection.com/database/family-tables.md#register-and-look-up-a-member).
`ctx.retire(tag)` retires a live member and answers its point.
It refuses `Absent` if the member is missing or already retired. The
family recovers its slot at the retirement horizon. Retiring from above
the public label takes a declared release.

`sys.organizationRegistry` is the platform's fact, and no app act writes
it. The organization registry is one fact, the installation's own, and
`sys.organizationRegistry` is itself its point: `ctx.get(sys.organizationRegistry)`
reads it, with no key, and answers null until management delivers a registry.
Its `id` is the installation, and it holds the `generation` and the verified
registry that management delivered.

`sys.programs(program)` reads the first deployment of the content-addressed Program.
The public fact gives its id, publication time and previous Program. Reads
that clear the operator label `sys.host` also return the deployer and push
message. Change reactions receive the public fields. `ctx.get(sys.programs.current)`
answers `{ id, program }` for the program installed in the frame’s world at
its version. A branch reads its candidate, or the program installed at its fork.
Use `sys.programs.current.in(world)` to select a world explicitly. Both fields carry
the same `program:<64 hex>` reference. A live read joins the read set for that world,
so a deploy into the same world can conflict with a mutation that read it.

`sys.logs` holds every execution's log lines (`console.debug`, `info`,
`log`, `warn` and `error`), committed or refused, as labelled facts. Each
line carries its execution's label, so a frame reads only the lines its
label clears. `stream` is `"app"` for application executions, or an audit
stream such as `"sys.sessions"` or `"sys.recovery"`. In app code, select
a site with `sys.logs.where({ site: "orders.place" }).by("version")`.
`execution` names the run, `line` orders its lines, `function`
is the full tree path that ran, `code` is the refusal code it ended with (null when it ended ok),
`reason` is that refusal's reason (when it has one), and `version` is the
line's commit-order cursor. Read the newest lines for one site with
`ctx.list(sys.logs.where({ site: "orders.place" }).by("at").descending().first(50))`.
Lines are kept for 14 days.
`on` holds the triggering task, obligation, source or branch point. Direct
calls have `on: null`. An operator's direct read can select logs by their
triggering task.
`bijection list sys.logs` reads the same table.

Execution measurements leave the host through telemetry. See
[Monitoring and profiling](https://docs.bijection.com/functions/monitoring.md).

`sys.grantTransitions` records each grant's append-only audit chain at the
grant's label: its `issue`, then at most one `revoke`, each entry carrying
its predecessor's `digest`, who acted (`as`), the person they acted for
(`asFor`), the call `chain` and the `survivors` that admitted the act. Read one
grant's chain in order with `ctx.list(sys.grantTransitions.where({ grant }))`.
Each committed transition carries its commit instant (`at`) and an audit
cursor (`version`) that combines the commit position and transition id.
The platform's telemetry export uses
`ctx.page(sys.grantTransitions.by("version"), { size, cursor })` to read
the transitions its frame clears in commit order. It ships them through
the installation's telemetry slot.

`sys.logs` also holds the host's span of each top-level mutation run, as the
`sys.traces` stream. Only a read of that stream shows them
(`sys.logs.where({ stream: "sys.traces" })`), and the telemetry export sends
them as OTLP traces.

Operator read acts (`POST /api/world/act`, CLI `bijection list` / `page` /
`get`) use the same catalog. The operator's inventory includes secret
metadata, completed landings, and program rollout history.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { label, query, role, sys, t, type AnyTarget } from "@bijectionhq/bijection";

export const staff = label();
export const admin = role({ clear: [staff] });
export const clerk = role({ clear: [staff] });

/** One page of a principal's live clerk grants at staff. */
export const grantsOf = query(
  { under: staff, allow: [admin], args: { person: t.principal, cursor: t.cursor } },
  async (ctx, { person, cursor }) => {
    const page = await ctx.page(sys.grants.where({ label: staff, role: clerk, holder: sys.grants.holder(person) }), { size: 50, cursor });
    return { ...page, facts: page.facts.map(({ id, roleChain, expiresAtMs }) => ({ id, role: roleChain[0] ?? null, expiresAtMs })) };
  },
);

/** How many tasks of a target are still pending. */
export const pendingCharges = (charge: AnyTarget) => query({ allow: [admin] }, (ctx) =>
  ctx.count(sys.tasks.where({ target: charge, state: "pending" })),
);
```

A `where` on `target` takes the target value itself. A task is also the
point of its own state: `ctx.get(task)` reads a `TaskState`, by `state`:
`{ state: "pending", target, due, until, claim }`,
`{ state: "blocked", target, reason, since, due, until }`,
`{ state: "settled", target, result }`, or `{ state: "withheld" }` when the
task runs under a label your function does not clear.
When a settled reply closes, its task remains settled and `result` reads
as `null`.

Reading a `sys` fact joins the read set like any read: a mutation that read a
grant conflicts with a revocation of it. A rule about who holds what, such as
separation of duties, is a guard that reads `sys.grants`: see
[Guards](https://docs.bijection.com/access/guards.md).

## Disclosure chain coverage

Release records and the asker-side records of shared judgements form a
hash chain at each exact label in a world. `sequence` is a decimal string
starting at one. `previous` is the preceding digest or `null` at the start.
`digest` commits to the stored record and its predecessor. A branch extends
the chain it sees at its fork. A landing links its covered records into the
Root chain in its own append.

The same ordered decision records the source-side copy of a shared bound
or cross-cover unique judgement, including a refusal. The source copy is
a blind append at `from` with `atSource: true` and omits `sequence`,
`previous` and `digest`. It carries the release, endpoints, acting principal,
time and judgement. A chain check against a trusted head covers the linked
rows through that head. A complete census of source-side rows would require
separate evidence at the source label and an exact Store position.

`ctx.get`, `ctx.list`, and `ctx.page` decode the visible records of the
requested selection. The remote SDK client decodes application replies
without checking disclosure hashes or verifying the source census. An app
selection must bind the release and the frame must be able to read the
records' labels. A page cursor continues that selection. Fetching its last
page gives no source census attestation.

## Host functions

`sys` also holds one group of functions the host serves itself. You enter
them with `ctx.call`, or with `ctx.try` to get a refusal back as a `Result`.
They take no `{ in, at }`, and you never place them in an app:

| Functions | What they do | Library |
| - | - | - |
| `sys.lake.issue`, `.handoff`, `.shred` | Issue a custodied lake file key, hand it off under a lease, or request reclamation. Each runs in a mutation at head. | `@bijectionhq/library-lake` |

Apps use the library, which adds lease bounds and named types on top of these
functions. Kept decisions need no host function: `@bijectionhq/library-decisions`
records each one as a fact of its own table and judges it by replay.

## Files

`sys.files` is the host's file inventory. Select from it to list stored files
or call `sys.files(id)` to recover the point from a raw key. Use
`ctx.get(file)` for its metadata and `ctx.get(file.bytes)` for its bytes.
See [Files](https://docs.bijection.com/files).

## The grave acts

The act verbs are described with the functions that use them:
[grants](https://docs.bijection.com/access/grants.md), [tasks](https://docs.bijection.com/functions/effects.md),
[branches and landing](https://docs.bijection.com/branches), [pins](https://docs.bijection.com/database/history-and-lifetime.md#pins),
[disclosures](https://docs.bijection.com/access/disclosure.md) and [erasure](https://docs.bijection.com/database/history-and-lifetime.md#erasure).

Each `then` creates a `sys.obligations` fact with its task, name, state,
attempts and `since`. States are `waiting`, `due`, `stuck`, `delivered`,
`withdrawn` and `disposed`. A stuck obligation carries a `Refusal`.
A withdrawn obligation carries the supplied `message`. A disposed
obligation carries a `DisposeReason`, such as `MemberErased`.
The terminal states are `delivered`, `withdrawn` and `disposed`.
Read the fact at its delivery label. Use `bijection list sys.obligations --where state=stuck --first 50`
to find obligations that need intervention.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.