RFC-003: Quotas, metering & porcelain

Give a world a quota, and Plurics charges its CPU time, the bytes it writes, and its egress traffic against it. When the quota runs out, the world freezes instead of dying, and a grant resumes it with no lost work. This RFC specifies the quota tree and its conservation rules, the declarative meter that turns a response stream into units, and the userland tools built on them.

$ plsh world fork job --compute-ms 60000 --units 5000000
forked job from main (id a1bb11354781, quota node 2)
$ plsh quota ls
ID  NAME  STATE    REASON  COMPUTE_MS  COW_BYTES  EGRESS_BYTES  UNITS
1   root  RUNNING  -       2/-         0/-        0/-           0/-
2   job   RUNNING  -       2/60000     0/-        0/-           0/5000000
$ plsh quota grant job --units 1000000
granted {"units":1000000} to job (node 2): RUNNING

Quotas#

Plurics keeps one tree of quota nodes. In the session above, job gets node 2 under the root, node 1. Every node holds a QuotaVector of four generic dimensions:

DimensionCountsCharged by
compute_msCPU time in millisecondsEach execution: a 1 ms hold before it starts, settled at the CPU time of its process tree
cow_bytesCopy-on-write bytes writtenWriteFile, reserved and settled before the write lands; the files a running process or a verification creates or changes, settled when it ends
egress_bytesBytes moved through the egress doorThe gateway's meter, in both directions
unitsAn opaque counter: requests, rows, pages, or tokensThe gateway's meter, as a route's meter spec defines it

The core gives units no meaning. A userland tool decides what one unit is worth.

A process writes straight into its working copy, so the daemon meters cow_bytes by comparison. When a process first starts in a metered world, the daemon records every regular file of the working copy by inode, so a hard link counts once. When the process ends, and before a fork, seal, merge, rewind, or discard, it charges each new or changed file its allocated bytes. Deleting files earns no credit. An overrun freezes the node with QuotaExhausted(cow_bytes).

  • Limits hold. For every node and every dimension, limit ≥ settled + held + leased, and available = limit − settled − held − leased.
  • All-or-nothing holds. reserve and extend are vector transactions against the node and every ancestor: either the whole vector is held everywhere, or nothing is.
  • Reservations move through Held, Streaming, Settling, and one of Settled, SettledConservative, or Released. settle refunds held − actual and is idempotent. A denied extend moves the hold to Settling, and the work stops at its next boundary.
  • Descent. A world without a node of its own draws on its nearest ancestor's, and a new node is carved under that same ancestor. No fork, however deep, escapes the quota of the world it came from. Escrow leases fund remote nodes and count as leased in every ancestor.
  • Restarts. Each broker start bumps a BrokerEpoch. Holds from an older epoch settle conservatively, at the amount held, and reconcile later.
  • Conservation. Every call writes balanced double-entry records against a system account in the ledger, and the audit balances after every call. plsh status reports it.

Freeze and thaw#

A node is Running, WrapUp, or Frozen. Past its soft watermark, 80% of its limit by default, it enters WrapUp. There, only a pre-reserved wrap-up allowance, 5% of its compute_ms and units stock, remains for small calls. A frozen node refuses every new hold: an execution does not start, a write fails with Quota, and the egress gateway answers 402.

FreezeReasonCauseLifted by
QuotaExhausted(dim)A dimension hit its limitQuotaGrant that covers the shortfall
ThrashDetected(detector)A loop breaker reached its last stageQuotaThaw
RevokedThe parent reclaimed the subtreeQuotaThaw
EmergencyFreezeAn operator stopQuotaThaw

Freezing kills nothing. A frozen world keeps its state, and a top-up such as the plsh quota grant in the opening session resumes it with no lost work.

Loop breakers. A program can also burn its quota without making progress, by repeating one failing call or by forking without end. Five deterministic detectors watch a node's step signals for such loops. Each detector is a pure function of its window, so replaying the same signals yields the same verdicts.

BreakerTrips on
D1IdenticalCallThe same deterministic call, against the same world root, 3 times in 16 calls
D2ZeroProgressUnits spent with no progress event reaching min(20_000, available / 10)
D3TreeOscillationThe world tree flipping between two hashes, A B A B, within 16 commits
D4ErrorStormThe same error from the same method 5 times in a row; a backoff warns at 2
D6SpawnFanOutMore than 16 active descendants, or delegation deeper than 4

A firing breaker escalates through four stages:

  1. Annotate the next step.
  2. Throttle with a backoff of 250, 1,000, then 4,000 ms.
  3. Restrict the offending call for 4 steps.
  4. Freeze the node with ThrashDetected.

A progress event (a non-empty diff, a new output, a flipped verdict, or a new outbox intent) resets D2.

Response metering#

Counting bytes is easy; counting what a response is worth is not. A model provider reports tokens in a usage field, a database reports rows, and a crawler counts pages. A route may carry a JsonFieldMeterSpec: rules that read unsigned integer fields out of a response and turn them into units. Whoever writes the route decides which fields count and what each is worth.

{
  "reserve_units": 2000000,
  "rules": [
    {"pointer": "/message/usage/input_tokens", "weight": 3000, "counter": "input"},
    {"pointer": "/usage/input_tokens", "weight": 3000, "counter": "input"},
    {"pointer": "/usage/output_tokens", "weight": 15000, "counter": "output"}
  ],
  "fallback_units_per_byte": 500
}
  • Pointers are RFC 6901 JSON pointers. JsonFieldTally applies them to every complete line of the decoded body, whether an event stream's data: line or an NDJSON line. If no line parses, it applies them to the whole body as one JSON document.
  • Weights are fixed-point integers: a match adds value × weight units. Arithmetic saturates. Negative and non-integer values never match.
  • Repeats. When a pointer matches in several events of one response, the largest value counts by default, so a cumulative counter that later events repeat is not counted twice. With accumulate, every match is summed.
  • Counters. Rules that name the same counter measure one quantity reported at different places. The counter costs the largest value × weight among its rules, not their sum.
  • Reserve and fallback. The gateway holds reserve_units before it forwards the request. A 2xx response that matched no rule costs fallback_units_per_byte per byte: lenient when parsing fails, conservative on the quota.
  • Bounds. At most 64 rules (METER_RULES_MAX) and 256-byte pointers (METER_POINTER_MAX). The meter skips lines over 1 MiB (METER_LINE_MAX) and parses a whole body only up to 256 KiB (METER_BODY_MAX).

The meter reads bytes and never rewrites them. A route without a spec uses the gateway's default meter: one unit per request or tunnel, plus the bytes it moved. The same spec meters rows for a database migration, pages for a crawler, and compile jobs for a build farm.

Userland tools#

These programs ship with Plurics. Each depends only on plurics-core and reaches the daemon through its socket, as any other program could.

plsh is the shell and CLI. The same binary runs on the host and inside a world, where it reaches the daemon through the world's port and every command is checked against that port's grants. Inside a world, self names the caller, and world fork --from defaults to it. plsh exits 0 on success, 1 when the daemon refuses a request, and 2 on a usage or connection error. exec, shell, exec-attach, and exec-wait exit with the program's own status instead: 124 if it timed out, 137 if it was killed. plsh help lists every command.

plurics-tui is the terminal review console, built on OpenTUI. It observes the daemon and merges on a person's behalf: views of worlds, triage, and quotas, a diff drawer, and live merge, discard, and quota top-up. Pressing e on a world with staged effects opens a ReleaseOutbox card that shows the staged calls and the bundle's approval digest; approving it calls EffectRelease with that digest. A newly shown control ignores activation for 200 ms, so a stray keypress cannot approve what the person did not see. --once prints one frame and exits. Like plsh, it connects over TCP with --addr and --key.

plurics-agent, from plurics-porcelain, runs coding agents in worlds. It turns what it knows about each provider into the generic pieces above:

  • Presets. --provider anthropic, openai, or openai-responses becomes an egress route to the provider. The route carries the vault credential that the gateway injects and a meter spec over the provider's usage fields, priced in nano-dollar units: one dollar is 1,000,000,000 units. The world sees ANTHROPIC_BASE_URL or OPENAI_BASE_URL at its own egress door and a placeholder key; the real key never enters it.
  • run runs an agent in a world, forked if needed and capped by --budget-usd. spawn --n <count> forks count worlds, runs the agent in all of them in parallel, then reports each world's status, spend, and state. A world out of budget gets 402 until plsh quota grant tops it up.
  • mcp serves the Model Context Protocol on standard input and output as newline-delimited JSON-RPC 2.0. An agent that speaks it gets tools that each make one pluricsd call: fork, list, diff, seal, verify, and discard worlds; stage an outbound call; read and bundle an outbox; and release a bundle. Inside a world, the server connects to $PLURICS_PORT first, so every tool call is confined to that port's grants and subtree. A release through effect_release passes the same daemon checks as any other: a reviewer world releases only a strict descendant's clean outbox (RFC-002). Host-only methods such as VaultStore, InitRepo, and Shutdown are not tools.
  • export-git commits a world's tree onto refs/heads/<branch> of a real Git repository with the real git binary. It parents the commit on the commit the world was imported at, or on --base. It never touches the repository's working trees or indexes, and it refuses a branch that is checked out.