Expand description
/proc: the kernel’s self-observation (spec 3.2 §7.10, §13 Q4; feature proc).
The kernel keeps a content-free activity ledger and, behind proc-baselines, learns a
per-partition baseline from it, in three tiers:
| Tier | Where | What |
|---|---|---|
| Ledger and live aggregates | the kernel, feature proc | one append-only table of LedgerEntry rows; the live ps/top view and the OTel GenAI histograms are the process table’s (ProcessView) |
| Statistics | adk-eval’s ledger module, pure functions | rolling 28-day median and MAD per dimension and day class, the 14-day warm-up, the windowed deviation test; cargo adk eval --ledger <export.jsonl> runs them in CI |
| Baselines and observations | the kernel’s Maintenance process, feature proc-baselines | the daily pass (baselines) calls the statistics, applies the “meaningful” rule and the seven-day cooldown, and offers each observation as a neutral question |
§The ledger
A row is ts, partition, agent, kind, effect, duration_ms, subject_hash, meta, trace_id
(LedgerEntry): never a payload, a prompt, a file’s content or a secret (K-I19). A
writer submits an Activity; the Ledger checks that every field is a label, a
count or a duration, stores what the activity was about only as an HMAC under the
kernel’s LedgerKey, and stamps the user’s local offset.
| Writer | Through | Rows |
|---|---|---|
| The kernel | its event bus: every KernelEvent but Health (activity_for_event) | process, wake, held, decided, rule_hit, spend, governance, observation |
| The harness | a LedgerSink the kernel hands its ProgressSource at start (ProgressSource::attach_ledger) | intent and tool_call from its runs; approval, rejection, denial, held, turn, loop_guard and audit from its audit records (LedgerAuditTap, activity_for_audit) |
LedgerStore holds the rows, the observations and the pass state on every backend the
ProcessStore has: in-memory, SQLite, PostgreSQL and Redis, with
one conformance suite (ledger_store_conformance_tests!). The ledger never leaves the
host unless its user exports it: GET /api/kernel/proc/ledger?format=jsonl, an operator
route, writes the JSONL cargo adk eval --ledger reads.
§Example
use std::sync::Arc;
use std::time::Duration;
use adk_kernel::proc::{Activity, InMemoryLedgerStore, Ledger, LedgerKey, LedgerKind, LedgerQuery, LedgerSink};
let ledger = Ledger::new(Arc::new(InMemoryLedgerStore::new()), LedgerKey::from_bytes([9; 32]));
ledger
.record(
Activity::new(LedgerKind::ToolCall, "urn:adk:agent:adk-rust/harness")
.with_effect("read_only")
.with_duration(Duration::from_millis(140))
.with_subject("read_file\u{1f}{\"path\":\"notes/salary.md\"}"),
)
.await?;
let rows = ledger.store().list(&LedgerQuery::default().kind("tool_call")).await?;
let line = rows[0].to_jsonl()?;
assert!(line.contains("\"durationMs\":140") && !line.contains("salary"));Re-exports§
pub use crate::stores::FirestoreLedgerStore;pub use crate::stores::InMemoryLedgerStore;pub use crate::stores::MongoLedgerStore;pub use crate::stores::Neo4jLedgerStore;pub use crate::stores::PostgresLedgerStore;pub use crate::stores::RedisLedgerStore;pub use crate::stores::SqliteLedgerStore;pub use ledger::Activity;pub use ledger::KERNEL_AGENT;pub use ledger::LEDGER_INVALID_CODE;pub use ledger::LateLedgerSink;pub use ledger::Ledger;pub use ledger::LedgerEntry;pub use ledger::LedgerKey;pub use ledger::LedgerKind;pub use ledger::LedgerOffset;pub use ledger::LedgerSink;pub use ledger::MAX_META_ENTRIES;pub use ledger::label;
Modules§
- baselines
- The daily baseline pass (spec 3.2 §7.10, §9.2 K-I20, §13 Q4; feature
proc-baselines).
Structs§
- Activity
- What a writer tells the ledger happened (spec 3.2 §7.10).
- Late
Ledger Sink - A
LedgerSinkbound later (spec 3.2 §7.10): what a hosted runtime writes through before the kernel that owns the ledger has started. Untilbindit drops activity; clones share the binding. - Ledger
- The ledger writer (spec 3.2 §7.10): checks, hashes and stamps each
Activityand appends theLedgerEntryto itsLedgerStore. Cloning shares it. - Ledger
Audit Tap - An
AuditRecorderthat also writes each record’s ledger row (spec 3.2 §7.10): the harness wraps its audit log in one, so its spend, loop-guard, approval and other audit records feed the ledger. The record is written first; a ledger failure is logged and never fails the record. - Ledger
Entry - One row of the ledger as stored and exported (spec 3.2 §7.10):
ts, partition, agent, kind, effect, duration_ms, subject_hash, meta, trace_id, plus the store’sseq. - Ledger
Key - The per-kernel key the subject hashes are HMACs under (spec 3.2 §7.10).
- Ledger
Query - Which ledger rows
LedgerStore::listreturns (spec 3.2 §7.10, §7.11GET /kernel/proc/ledger). An empty field matches every row. - Observation
- A change in a partition’s routine the kernel noticed, offered as a question (spec 3.2 §7.10, K-I20).
- Observation
Query - Which observations
LedgerStore::observationsreturns (spec 3.2 §7.11GET /kernel/proc/observations). - Observed
Dimension - One dimension an observation names (spec 3.2 §7.10).
- Pass
State - What a baseline pass carries for a partition from one day to the next (spec 3.2 §7.10): the last day it tested, the drift state (each deviating dimension’s run and each dimension’s cooldown) and the baselines it last computed.
Enums§
- Direction
- Which way a dimension moved from its baseline (spec 3.2 §7.10).
- Ledger
Kind - What a ledger row records (spec 3.2 §7.10).
- Ledger
Offset - How the ledger stamps a row’s local offset (spec 3.2 §7.10): the day and time of day the baselines read are the user’s.
- Phrasing
- Who worded an observation’s question (spec 3.2 §7.10): the model phrases only what the deterministic detection found, and the kernel’s template words it when the model is unavailable, over budget, or answers with anything but a neutral question.
Constants§
- KERNEL_
AGENT - The agent label of the rows the kernel writes about its own work (spec 3.2 §7.10).
- MAX_
META_ ENTRIES - Most entries a row’s
metaholds (spec 3.2 §7.10: small, schema-checked).
Traits§
- Ledger
Sink - Where activity goes (spec 3.2 §7.10): the
Ledger, or aLateLedgerSinka runtime the kernel hosts writes through before the kernel exists. The harness writes its tool events and audit records through one. - Ledger
Store - The kernel’s ledger, observations and baseline pass state (spec 3.2 §7.10, §13 Q8).
Functions§
- activity_
for_ audit - The row an audit record becomes (spec 3.2 §7.10), or
Nonewhen another source writes it: an allowed tool call (the harness writes itstool_callrow with the duration) and the kernel’s ownkernel.*andgovernance.*records (its events write those). - activity_
for_ event - The row a
KernelEventbecomes (spec 3.2 §7.10), orNonefor aHealthreport. - is_
neutral_ question - Whether
textis a question in neutral language (spec 3.2 §7.10, K-I20): one line of 20 to 400 characters ending in?, with no diagnosing, judging or instructing word. - label
- An identifier as a label the ledger accepts (spec 3.2 §7.10): every character a label
may not hold replaced with
_, shortened tomaxcharacters. For identifiers a writer copies into a row, such as an agent’s id or a run’s target — never for content, which belongs in an activity’s subject. - template_
question - The kernel’s own wording of an observation (spec 3.2 §7.10): a neutral question built from the dimension names and directions alone.