Stability¶
A harness built on gvn keeps its runs in a journal: one record per event, plus snapshots (saved copies of each actor's state). A run can wait for days, so the data it stored must still load after you upgrade gvn. Your code also calls gvn's classes and functions, so you need to know how a change to them is made and recorded. This page says what gvn promises about each, and each promise is backed by a test that fails when it is broken.
The short version¶
This table needs no prior reading.
| Promise | How it is checked |
|---|---|
| Every journal record and snapshot says which form (version of its shape) it was written in. | The Governor, the runtime object that writes the journal, stamps it. A test reads every record and snapshot of a run and checks the stamp. |
| Data in an older form is upgraded, one step per version, before anything is built from it. Data in a newer form, or with a gap in the upgrades, is refused with a named error, and nothing is half-loaded. | Tests read older, newer and gapped data and check the upgrade or the named refusal. |
| A stored form cannot change by accident. | A test drives a small run of every kind of actor and compares what it stores with a frozen copy kept in the repository. |
| Data written in every earlier form gvn has frozen still loads. | The same test loads every frozen form through the upgrades. |
| The identity of a tool gvn ships cannot change by accident: stored runs and rules refer to tools by it. | A test compares every shipped tool's identity with a frozen list. |
A change to the public API is deliberate and is recorded in the changelog (CHANGELOG.md at the root of the repository). |
A test compares every public signature with a frozen copy. |
| Every durable class (one whose objects can be saved) refuses state that belongs to another class. | A test finds every such class by itself and hands each one other classes' saved state. |
The tests are in the repository under packages/gvn/tests/runtime and
packages/gvn/tests/architecture, and run in the default test suite. The rest of this page
explains each line.
What you will learn below: how stored data is versioned and upgraded, with runnable examples; how your own stored shapes are versioned; and how a change to the public API is recorded.
For the sections below, read first: Crash and resume, so you know what a journal and a snapshot are, and The Governor for who writes them.
Time: about 2 minutes for the short version, about 15 for the page.
Where this sits¶
Two things in the big picture outlive one version of gvn: what the Governor writes to the journal (records and snapshots), and the classes and functions your code calls.
The shape of it¶
flowchart LR
governor["Governor"] -- "writes, stamped with a form number" --> journal[("journal:<br/>records and snapshots")]
journal -- "read through Forms:<br/>upgrade older, refuse newer" --> readers["Recovery · Replay"]
yourcode(["your code"]) -- "calls" --> api["public API<br/>(frozen signatures)"]
- Stored data carries a version number, its form. Older forms are upgraded one step at a time as they are read; newer or unknown ones are refused, and nothing is half-loaded.
- The public API is written down, name by name, in a frozen copy; a change fails a test until it is made on purpose and recorded in the changelog.
- Durable classes refuse saved state that belongs to another class.
The page goes on to how stored forms and upgrades work (with runnable examples), then the public API, shipped tool identities and durable classes.
Stored forms¶
A stored form is the shape of something gvn writes to a journal. There are two kinds:
- a journal record:
{"form": 4, "sequence": 0, "at": 0.0, "event": {...}}, one per event; - a snapshot: the plain form of an actor's
Dto(its saved state), plus"form": 4.
The "form" number is the version of that shape. gvn writes form 4. A class called
Forms (in gvn.runtime.forms) writes the number and reads it back. You rarely touch it:
the Governor uses it to write, and Recovery (which rebuilds a run from its journal after a
crash; see The Governor) and Replay (which reads a recorded run
back; see Replay and evaluation) use it to read.
Here is what writing and reading look like on their own, with a hand-made record:
import typing
from gvn.runtime.forms import JOURNAL_RECORD, Forms
forms = Forms()
stored = forms.stored(kind=JOURNAL_RECORD, body={"sequence": 0, "at": 0.0, "event": {}})
print(stored) # {'form': 4, 'sequence': 0, 'at': 0.0, 'event': {}}
body = forms.read(kind=JOURNAL_RECORD, stored=stored)
print(body) # {'sequence': 0, 'at': 0.0, 'event': {}}
stored adds the current form; read checks it and hands back the body without it. Reading
data in the current form changes nothing.
Data in a form this build does not know¶
If a newer build of gvn wrote the data, its form is higher than this build reads. gvn refuses it rather than guess:
from gvn.runtime.forms import NewerForm
try:
forms.read(kind=JOURNAL_RECORD, stored={"form": 5, "sequence": 0})
except NewerForm as refused:
print(type(refused).__name__) # NewerForm
The message says what was found (form 5) and what is read (form 4 and older). Recovery and
Replay add which run and which record, and they read every record before building the
actor, so a refused journal loads nothing.
Upgrades¶
An upgrade is a plain function: it takes the body of one stored record in form n (plain
JSON, without "form") and returns it in form n + 1. It must be pure: no I/O, no clock, the
same answer every time. You register it with Forms.upgrade, which returns a new registry and
leaves the old one alone. A record or snapshot with no "form" at all is read as form 0, so an
upgrade from form 0 is how you bring such data in.
Say your old records kept the event under "input" instead of "event":
def input_becomes_event(body: dict[str, typing.Any]) -> dict[str, typing.Any]:
body["event"] = body.pop("input")
return body
upgrading = Forms().upgrade(kind=JOURNAL_RECORD, from_version=0, function=input_becomes_event)
old_record = {"sequence": 0, "at": 0.0, "input": {"name": "started", "payload": None, "to": None}}
print(upgrading.read(kind=JOURNAL_RECORD, stored=old_record)["event"]["name"]) # started
Pass the registry to whatever reads the journal:
Recovery(journal=journal, forms=upgrading) or Replay(journal=journal, forms=upgrading).
Each step runs once, in order (0 to 1, 1 to 2, ...). If any step is missing, NoUpgrade is
raised before any of them runs. What an upgrade returns is checked by the same code that checks
any stored data: Event.Dto.from_plain for a record and the actor's Dto.from_plain for a
snapshot. An upgrade that returns nonsense is refused there, not loaded.
Snapshots work the same way with kind=SNAPSHOT. A snapshot upgrade sees whatever actor the
run used, including actors hosted inside a workflow's state, so it must recognise the shape it
changes.
When gvn changes a stored form¶
gvn's own forms are frozen by a test that drives a small run of every actor kind (Agent,
Conversation, Errand, Inquiry, Timer, Approval, Choice, and a Workflow in a Host, a
FanOut, a ForEach with a retried item and a Parallel stage, and one with a Compensate
declaration) and keeps one record per event name and one snapshot per actor. Some runs use
the optional parts of a payload: an agent's structured answer, attachments, citations, a
model call that was retried, and a failure with retry_after and usage. They must equal
a frozen copy kept in the repository, one directory per form. So a change to a stored shape
fails the test until the current form is raised by one, an upgrade from the previous form
is registered for each kind, and the change is recorded in the changelog.
Every frozen directory is kept for good, and the same test loads each of its records and snapshots through the upgrades. So data in the shapes gvn has frozen keeps loading. Shapes that a harness of your own adds are versioned by your deployment, as the next section shows.
Form 2: tools are stored by identity¶
Form 1 stored each tool by its short name, the name the model sees. Form 2 stores the
tool identity instead, the namespace and the short name
(shop.orders.look_up_order), so that two tools of one short name from different packages
are never confused (see Tools). The snapshots changed: an agent's and
a conversation's offered tools hold identities, an errand holds the identity of each fixed
call, every attempt and every "tools" entry of an outcome holds "identity", and a
conversation counts calls by identity. Journal records kept their shape; the upgrade from
form 1 changes nothing in them.
A form-1 snapshot says "look_up_order" and nothing in it says which tool that meant, so
the upgrade needs the tools the deployment offered: build the registry with
Forms(tools=...), the tools themselves or the deployment's Toolbox. Each short name is
then replaced by the identity of the one given tool of that name. Without them, a form-1
snapshot that names a tool is refused, before anything is built:
from gvn.harness.agent import Agent
from gvn.kernel.schema import Record, Text
from gvn.runtime.forms import SNAPSHOT
from gvn.testing.fakes import StubTool
look_up_order = StubTool("look_up_order", Record({"order_id": Text()}), namespace="shop.orders")
snapshot = Agent(name="helpdesk", instructions="Help.", tools=[look_up_order]).to_dto().to_plain()
form_1 = {**snapshot, "form": 1, "tools": ["look_up_order"]} # as form 1 stored it
try:
Forms().read(kind=SNAPSHOT, stored=form_1)
except ValueError as refused:
print(refused)
print(Forms(tools=[look_up_order]).read(kind=SNAPSHOT, stored=form_1)["tools"])
a form-1 snapshot names the tool 'look_up_order' (the tools offered), and no tool of that short name was given to qualify it (given: []). Read it with Forms(tools=<the tools the run was offered>).
['shop.orders.look_up_order']
Pass that registry to Recovery(journal=journal, forms=Forms(tools=toolbox)) and
Replay(journal=journal, forms=Forms(tools=toolbox)) when a journal may hold runs written in
form 1. The tools given must include a tool for each short name the old runs used. When two of the
tools given share a short name that an old record holds, the upgrade stops and names both:
the short name is all form 1 kept, so give Forms only the tools the old data was written
with.
Form 3: actors carry their sensors¶
Form 3 gives the Agent and the Conversation sensors: each actor's
snapshot holds "sensors" (its sensors, the readings owed, the counts and each sensor's
latest reading), and both machines gained the states checking_sensors and sensing. A
form-2 snapshot has no sensors, so the upgrade from form 2 needs nothing from you: it gives
every agent and conversation an empty "sensors" and moves its machine position onto the
form-3 machine, keeping its state and step count (every form-2 state is still there, with the
same meaning). Journal records kept their shape. Forms() registers both steps, so a journal
holding form-2 runs is read as it is:
FORM_2_AGENT_MACHINE = "c52ff945c979e51a7eaa549ed2488ca3f11e3b33cd8f0102bc4ef5feb122d316"
form_2 = {**snapshot, "form": 2}
del form_2["sensors"]
form_2["machine"] = {**form_2["machine"], "fingerprint": FORM_2_AGENT_MACHINE}
upgraded = Forms().read(kind=SNAPSHOT, stored=form_2)
print(Agent.from_dto(Agent.Dto.from_plain(upgraded)).sensors()) # ()
The fingerprint is the one the form-2 agent machine had; the upgrade knows the form-2 fingerprints of the agent, the agent with an answer schema and the conversation.
Form 4: what the model read and who answered¶
Form 4 records an actor's exposure and who answered a request
(Trust), each under a key that is present only when used. An agent's
and a conversation's snapshot hold "untrusted" (the identities of their untrusted tools) and
"exposure" (the untrusted sources their model has read), and a conversation's
"thread_exposure"; an event holds "by" (the principal that
answered), and an approval's and an inquiry's snapshot "answered_by"; a model_replied or
model_failed payload, and each of its retries, holds "provider". Data written in form 3
has none of these keys and means the same in form 4, so both upgrades from form 3 change
nothing, and Forms() reads form-3 runs as they are.
When your own stored shapes change¶
Your actors' Dtos are stored forms too. If you change one, give your deployment its own
current form and the upgrade:
def add_priority(body: dict[str, typing.Any]) -> dict[str, typing.Any]:
return {**body, "priority": "normal"}
mine = (
Forms(current=5)
.upgrade(kind=JOURNAL_RECORD, from_version=4, function=lambda body: body)
.upgrade(kind=SNAPSHOT, from_version=4, function=add_priority)
)
print(mine.current()) # 5
Your form numbers continue gvn's: gvn writes form 4, so your first change is form 5, with
upgrades from form 4. gvn's own upgrades from the forms below are registered already. Pass
it to every Governor(..., forms=mine), Recovery and Replay of that deployment (with
tools= as well when the journal may hold form-1 runs:
Forms(current=5, tools=toolbox)). The Governor then stamps form 5. A gvn release that changes its own forms will say so in the
changelog and name its upgrade functions, so you can chain them into your registry.
The public API¶
The interface contract map identifies the main application and extension boundaries and links to their behavior. This section describes how changes to the wider public surface are recorded and checked.
The public API is every class, function and constant in a module of gvn, gvn_tools or
gvn_domains whose name, and whose module's name, does not start with an underscore. A test
writes down each of them with its signature (parameter names, kinds and default values) and
each class's public methods, and compares that with a frozen copy kept in the repository,
one file per package.
So no public name or signature changes without that test failing. When one changes on purpose, the change is recorded in the changelog (under Added, Changed or Removed) in the same change as the new frozen copy. The test checks names and signatures only. What a function does is covered by the ordinary tests, not by this one. The changelog lists every such change, so read it when you upgrade.
Shipped tool identities¶
Stored runs, policies and evaluation checks refer to a tool by its
identity, its namespace and its short name, and the namespace is
by default the module that defines the tool's class. So moving a tool class to another
module, or renaming a tool, changes what every journal written before means. A test writes
down, for every concrete tool class in gvn, gvn_tools and gvn_domains, the identity it
answers, as <module>.<Class>: <namespace>.<name> (<configured> for the part a tool takes
when it is built, as FunctionTool and the MCP tools take their namespace), and compares
it with a frozen list kept in the repository. A deliberate change
is recorded in the changelog with the stored-form upgrade that renames the tool in old runs.
Durable classes check whose state they are given¶
Every class that can be saved has an inner Dto and a from_dto that rebuilds it. Rebuilding
an object from another class's state would be wrong in ways nothing else catches, so every
from_dto must raise TypeError for anything but its own kind of Dto. The check is exact:
an instance of a subclass of the class's own Dto is refused too, since it may carry fields
the class does not know and would drop. Every class makes the check with one shared function,
gvn.kernel.durable.require_own_dto(owner, dto), which your own durable classes can call
first thing in their from_dto. A test finds every such class in the three packages by
itself (no list to forget to update) and hands each one other classes' Dtos, a subclass of
its own Dto, a plain dict and None.
Changing a frozen copy¶
The frozen copies change only with a deliberate change to gvn itself. CONTRIBUTING.md, at
the root of the repository, gives the steps for contributors and the checks that run on
every change.
Recap¶
- Every record and snapshot carries its form; older forms are upgraded one step at a time, newer ones and gaps are refused, and nothing is half-loaded.
- Frozen copies make a change to a stored form, to a shipped tool's identity or to the public API fail a test until it is made on purpose and recorded.
- Form 2 stores tools by identity; reading form-1 runs needs the tools they were offered,
Forms(tools=toolbox). Form 3 adds the actors' sensors; form-2 runs upgrade with nothing to give. Form 4 adds exposure, who answered and the provider, under optional keys; form-3 runs read as they are. - Every durable class refuses saved state that belongs to another class.
Next: back to Architecture, which shows how the layers that make these promises fit together, or the glossary for any term.