Files
aevolution/docs/adr/0092-m10-intentions-and-durable-outcomes.md
T
dingoandClaude Opus 5.5 07d12a4d82
Foundation / checks (deploy) (push) Successful in 3m27s
Foundation / checks (ecs) (push) Successful in 1m57s
Foundation / checks (client) (push) Successful in 12m41s
Foundation / checks (network) (push) Successful in 13m33s
Foundation / checks (tsan) (push) Successful in 7m54s
Foundation / checks (checks) (push) Successful in 32m56s
Foundation / checks (postgres) (push) Successful in 46m10s
Foundation / postgres-tools (push) Successful in 18s
Foundation / image (push) Successful in 2m33s
Foundation / server-image (push) Successful in 4m24s
M10.9d: batch durable action lookups (one per poll, one per commit)
The fourth dev drill showed a synchronous PostgreSQL round trip per action on the
simulation thread: at admission (uniqueness) and again at commit (first-record rule).
About 12 lookups landed on each commit tick (commit ticks 58-70 ms, session p99 30-39 ms).

- ActionLedger::find_all; persistence::find_region_actions applies the schema v11
  find_region_action to many pairs in one statement (no migration).
- IntentAdmission::admit/verify: actions only the ledger can refuse wait for one verify
  per poll; receipts still go out in the same poll. committed() asks once per commit.
- Tests: deferred_actions (network_control), find_region_actions and find_all (Postgres).
- ADR-0097 fourth run, ADR-0092 amendment, VALIDATION; refresh the dev session window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 21:35:43 -04:00

149 lines
10 KiB
Markdown

[Reviewed]
# ADR-0092: M10 intentions, actions and durable outcomes
## Status
Accepted for M10.4 (2026-10-03). Decisions confirmed with the maintainer on 2026-10-03:
intentions and actions have no biological effect yet (durable no-effect); stable action
ids and final outcomes are made durable in PostgreSQL in the same transaction as the
checkpoint; 10.4 wires M10 sessions into evo-server with a headless client (the GUI
client switches later). Delivery: 10.4a protocol and admission (this text), 10.4b durable
action records (migration v11) and host integration, 10.4c evo-server listener, headless
client and process kill tests. Each segment amends this ADR.
## Context
ADR-0089 fixed the scheduling window (server_tick + 1 ..= + 8), one intention per tick,
per-session u64 sequences, at most 256 unresolved intentions and 1.5 s final outcomes.
ADR-0090 put superseding intentions on QUIC DATAGRAMs and reliable actions on the stream.
ADR-0091 binds sessions to accounts. No controllable organism or movement rule exists
(10.6 movement experiment, M11 organisms), so nothing an intention names can change
authoritative state yet. Committed batch traces record host inputs only, not request ids.
## Decision (10.4a)
**Two kinds of client input, three distinct answers.**
- *Intentions* (datagram): session, epoch, sequence, tick, bounded move vector; never any
state claim (position, energy): the message has no such fields and any extra bytes make
it invalid. Answers: an `IntentionReceipt` (admitted = scheduled for its tick, or a
refusal) and a cumulative `SimulatedThrough` watermark (every admitted intention up to a
sequence whose tick has been simulated in the epoch), sent to every session on every
simulated tick (sequence 0 before its first), so a lost datagram is covered and clients
always know the server tick (until 10.5 snapshots carry it). Intentions are superseding: there is no per-intention durable record.
- *Actions* (stream): a client-chosen action id, unique per account and stable across
retries and reconnects, a kind and a tick. Answers: an `ActionReceipt` (scheduled, or a
refusal) and a final `ActionOutcome`: `committed_no_effect` with its commit sequence once
the commit covering its tick is durable, or `not_committed`. `ActionQuery` resolves an id
at any time (`pending`, `unknown`, or the final outcome). The only kind is `probe`.
- A receipt is never a final outcome, and the watermark is never durability.
**Admission** (`IntentAdmission`, transport-neutral, single owner), in order: the message
must name the connection's own session; rate (every attempt counts: 8 intentions and 4
actions per 8-tick window); authority ready; epoch; vector norm <= 1000 or a known action
kind and nonzero id; strictly increasing sequence; tick inside the window and, for
intentions, after the previous admitted intention's tick; duplicates (an action id already
pending or final for the account is never admitted again: `duplicate`, followed by its
outcome when final); at most 256 unresolved intentions plus actions per session.
Actions belong to the account: a takeover or reconnect sees the same pending and final
actions. The host takes scheduled actions with `carry(tick)` for the batch that simulates
that tick and reports durable commits with `committed(end_tick, sequence)`. When the epoch
advances, actions never carried are final `not_committed`; carried ones stay pending until
their durable record decides them (10.4b). Recent final outcomes (2,048) are kept for
duplicates and queries; older ones are resolved from the durable record (10.4b).
**Protocol.** Session protocol v1 gains message types 6-12 and Welcome gains the server
tick (schemas/network/session-v1.md). v1 has never been deployed, so it is amended in
place, as ADR-0083 did for M9 v1; after its first deployment, changes need a new version.
v1 was deployed in evolution-dev on 2026-10-05 and is frozen from then on.
The action kind is a raw u16 on the wire and validated by admission (an enum narrower than
the wire field must never be cast from it).
## Consequences and limits (10.4a)
- Durable resolution of carried actions after a crash, and of final outcomes evicted from
memory, needs the v11 records (10.4b). Until then a carried action of a lost epoch
answers `pending`.
- The simulated watermark says the targeted tick ran while the intention was scheduled;
with no movement rule it changed nothing. 10.6 gives intentions an effect.
- Nothing is wired into evo-server yet (10.4c); nothing deploys M10 sessions.
## M10.4b durable action records (2026-10-03)
Schema v11 (`migrations/0011_region_actions.sql`, [region-actions-v1](../../schemas/region-actions-v1.md)):
- **Same transaction as the checkpoint.** The region host attaches each submitted action to
the first simulated tick at or after its scheduled tick and publishes the batch's action
block with the three-argument `publish_region_checkpoint`; the records exist exactly when
the checkpoint does. Committed history stays immutable: blocks live in their own
append-only table, and an exact retry or resolution must repeat the block.
- **Outcomes come from the record.** `find_region_action` (under the caller's exact region
lease) returns the committed record of (world, account, action id). Found: final
`committed_no_effect` with that record's tick and commit. Absent once this authority is
recovered and ready: never committed by any earlier epoch (its commits are final).
- **One record per id, without stalling a region.** Found during testing: an account that
moves regions while its action is pending in the old one can have the same id admitted by
the new region (the record does not exist yet). Refusing the second commit would have
quarantined a healthy region. The database instead keeps the first record and lets the
later batch commit; `IntentAdmission::committed` reports each outcome from the record, so
every region answers the same tick and commit for an id.
- **Host semantics.** `submit_action` (bounded: 256 queued plus riding), `ActionAck` per
committed action, `DroppedAction` with `final` = certainly never committed. Actions of a
batch whose publication outcome was unknown when authority was lost are not final; the
session layer keeps them pending until the record decides.
- **Session layer.** `ActionLedger` (interface) with `PostgresActionLedger`; admission
checks the record before admitting an id not in memory (`duplicate` with its outcome, or
`not_ready` when the record cannot be read); queries resolve unknown-outcome and evicted
actions from the record once ready. `RegionSessions::committed/dropped` take the host's
reports.
- Limits: action rows are retained (no pruning policy yet); clones (ADR-0067) do not copy
them; the two-argument publication of a commit that has an action block would still
return its receipt (the adapter never does this).
## M10.4c evo-server listener and headless client (2026-10-04)
- **evo-server** (`--m10-listen ADDRESS:PORT --m10-cert F --m10-key F --m10-issuer F
--m10-environment dev|stage|world0`, builds with EVO_BUILD_QUIC and PostgreSQL only;
opt-in, development and test, nothing deploys it): `RegionSessions` with
`PostgresControlLedger` and `PostgresActionLedger` on their own connection slot (reconnects
after store failures) under the host's current lease (`RegionHost::authority()`). After
each host step the sessions see the host's authority; actions scheduled up to 8 ticks
ahead go to the host (`submit_action`; a refusal is final `not_committed`); the host's
action acknowledgements and drops become outcomes. Draining closes sessions with
`shutdown`. The issuer public key is a 65-byte file (key id 1).
- **evo-session-probe** (dev only): generates a dev issuer key pair, signs a grant for a
given account and serial, logs in, sends intentions and probe actions, queries ids and
prints one machine-readable line per answer.
- **After a restart, `unknown` means "not on record"**: a new process cannot tell an id it
never saw from one admitted by a dead process. Both were never committed (the old epoch
is fenced and its commits are final), so retrying the same id is safe and commits once.
- **Found with real processes: clients need the server tick every tick.** A client that sent
only actions learned the server tick from receipts and from watermarks repeated every 20
ticks, so after waiting about a second for an outcome its next action named a past tick
(`outside_window`). `SimulatedThrough` is now sent to every established session on every
simulated tick (sequence 0 before its first intention): 24 bytes per tick on the datagram
channel, and the client's clock for the server tick until 10.5 snapshots carry it.
- Process evidence: actions survive SIGKILL after their commit (the outcome is answered from
the record by the next process, and a retry is a duplicate with the same outcome); an
action whose tick had not run at SIGKILL has no record, answers `unknown`, and commits
exactly once when retried.
## Amendment (2026-10-08, M10.9d, ADR-0097): watermark cadence
Snapshots carry the server tick every tick (10.5), so the watermark no longer has to be
every client's clock. In evo-server, an advancing `SimulatedThrough` goes to a session at
most every 4 ticks, and idle sessions get one every 4 ticks
(`IntentLimits::watermark_coalesce` and `watermark_every`; the library defaults stay 1).
It is cumulative, so no admitted intention is ever missing from a later watermark; a client
learns "simulated" up to 3 ticks (150 ms) later. Receipts are unchanged: one per intention.
Reason: on the reference worker, datagram sends dominated the session layer, and the
per-tick watermark was a quarter of them.
## Amendment (2026-10-09, M10.9d, ADR-0097): batched durable lookups
The durable checks are unchanged; only how many store round trips they cost changes.
- **Admission.** In evo-server, an action that passes every in-memory check waits for the
poll's single `verify`, which asks the ledger about all waiting actions at once and
sends their receipts in the same poll.
- While it waits, the action counts toward the unresolved limit.
- A repeat of it is a `duplicate`.
- It is never carried.
- A store failure, lost readiness or a new epoch before `verify` refuses it as
admission would (`not_ready`, `stale_epoch`).
- **Commit.** A commit's outcomes come from one request for all of its actions. The
first-record rule still decides each one.
- **API.** `IntentAdmission::action` keeps the immediate single lookup for callers that
want it.
- **Reason:** one round trip per action on the simulation thread dominated the session
layer on the reference worker (ADR-0097, fourth run).