Skip to main content

Module proc

Module proc 

Source
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:

TierWhereWhat
Ledger and live aggregatesthe kernel, feature procone append-only table of LedgerEntry rows; the live ps/top view and the OTel GenAI histograms are the process table’s (ProcessView)
Statisticsadk-eval’s ledger module, pure functionsrolling 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 observationsthe kernel’s Maintenance process, feature proc-baselinesthe 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.

WriterThroughRows
The kernelits event bus: every KernelEvent but Health (activity_for_event)process, wake, held, decided, rule_hit, spend, governance, observation
The harnessa 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).
LateLedgerSink
A LedgerSink bound later (spec 3.2 §7.10): what a hosted runtime writes through before the kernel that owns the ledger has started. Until bind it drops activity; clones share the binding.
Ledger
The ledger writer (spec 3.2 §7.10): checks, hashes and stamps each Activity and appends the LedgerEntry to its LedgerStore. Cloning shares it.
LedgerAuditTap
An AuditRecorder that 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.
LedgerEntry
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’s seq.
LedgerKey
The per-kernel key the subject hashes are HMACs under (spec 3.2 §7.10).
LedgerQuery
Which ledger rows LedgerStore::list returns (spec 3.2 §7.10, §7.11 GET /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).
ObservationQuery
Which observations LedgerStore::observations returns (spec 3.2 §7.11 GET /kernel/proc/observations).
ObservedDimension
One dimension an observation names (spec 3.2 §7.10).
PassState
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).
LedgerKind
What a ledger row records (spec 3.2 §7.10).
LedgerOffset
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 meta holds (spec 3.2 §7.10: small, schema-checked).

Traits§

LedgerSink
Where activity goes (spec 3.2 §7.10): the Ledger, or a LateLedgerSink a runtime the kernel hosts writes through before the kernel exists. The harness writes its tool events and audit records through one.
LedgerStore
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 None when another source writes it: an allowed tool call (the harness writes its tool_call row with the duration) and the kernel’s own kernel.* and governance.* records (its events write those).
activity_for_event
The row a KernelEvent becomes (spec 3.2 §7.10), or None for a Health report.
is_neutral_question
Whether text is 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 to max characters. 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.