Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
155 commits
Select commit Hold shift + click to select a range
ad439bd
feat(environment): extract the initial state a capture's reads observed
earakely-scale Oct 20, 2026
7a668b7
Merge main into feat/environment-state-view
earakely-scale Oct 20, 2026
f2c9a2e
fix(environment): bound state at redacted writes; infer identity only…
earakely-scale Oct 20, 2026
2999128
fix(environment): keep first sightings, one list pointer and linear f…
earakely-scale Oct 20, 2026
a5c7b92
fix(environment): keep post-write values and partial lists out of the…
kaoru0822-kitauji Oct 20, 2026
4e93547
docs(environment): scope item-shaped and deleted written paths out of…
kaoru0822-kitauji Oct 20, 2026
aba9cb1
fix(environment): count writes in flight when a value changes between…
kaoru0822-kitauji Oct 20, 2026
856c8c0
Merge main into feat/environment-state-view
kaoru0822-kitauji Oct 20, 2026
55480bd
chore: merge main (5fa4defc) into environment state view
earakely-scale Oct 20, 2026
9fee36d
fix(environment): catch cross-tool changes across writes; read only i…
earakely-scale Oct 20, 2026
3c64cbe
chore: merge the branch's own main merge (856c8c0b), identical to 554…
earakely-scale Oct 20, 2026
47f8a27
chore: merge main (f93a0335, rich captures) into environment state view
earakely-scale Oct 20, 2026
32fbaa5
chore: merge main into environment state view
gensokyo-dev Oct 20, 2026
04e2c56
fix(environment): keep post-write observations out of initial state
gensokyo-dev Oct 20, 2026
3daeebb
chore: retain author main integration in environment state view
gensokyo-dev Oct 20, 2026
25923c3
chore: sync environment state view with latest main
gensokyo-dev Oct 20, 2026
6ad63bc
fix(environment): retain field provenance and bound state inference work
gensokyo-dev Oct 20, 2026
2bd0b3c
feat(environment): serve tool calls from the environment state
earakely-scale Oct 20, 2026
35aee7c
feat(environment): render more read tools from the state and describe…
earakely-scale Oct 20, 2026
9f60e54
Merge the environment state view's review fixes into feat/environment…
earakely-scale Oct 20, 2026
62708a8
Merge the environment state view's review fixes into feat/environment…
earakely-scale Oct 20, 2026
cb04dcd
docs(environment): record verification after merging the state view's…
earakely-scale Oct 20, 2026
9dfc05f
docs(environment): record verification after merging the state view's…
earakely-scale Oct 20, 2026
aa48c74
Merge main (#5319 squashed, #5349) into feat/environment-state-coverage
earakely-scale Oct 20, 2026
e96484b
Merge main (#5319 squashed, #5349) into feat/environment-state-serve
earakely-scale Oct 20, 2026
5bb7ca4
fix(environment): stop identity checks at the first missing or repeat…
earakely-scale Oct 20, 2026
6676582
feat(environment)!: serve the environment state by default
earakely-scale Oct 20, 2026
83fcc73
fix(environment): bound data-plane replies, keep batch order, cancel …
earakely-scale Oct 20, 2026
d9c0357
fix(environment): keep bodies too deep for the state's nesting out of…
earakely-scale Oct 20, 2026
d9a717e
Merge main (#5350 write cutoffs, #5031 protobuf bodies) into feat/env…
earakely-scale Oct 20, 2026
57b1168
fix(environment): measure data-plane replies before building them
earakely-scale Oct 20, 2026
5956e00
chore: merge main (d2a3269d) into environment state serve
earakely-scale Oct 20, 2026
bf0dd92
chore: merge environment state coverage into the state writes branch
earakely-scale Oct 20, 2026
a98df6c
chore: merge main (d2a3269d) into environment state coverage
earakely-scale Oct 20, 2026
ef49dca
fix(environment): keep changed documents out of the state; mark OPTIO…
earakely-scale Oct 20, 2026
306c3da
docs(specs): plan evidence-gated write effects on the served state
earakely-scale Oct 20, 2026
5a61853
fix(environment): release batch replies as they are encoded; judge ex…
earakely-scale Oct 20, 2026
b4b7ebc
perf(environment): intersect list identity candidates through a set
earakely-scale Oct 20, 2026
b9fbcd7
feat(environment): apply the write effects a capture confirms to the …
earakely-scale Oct 20, 2026
84291a0
fix(environment): count only applied writes and serve writes the held…
earakely-scale Oct 20, 2026
cbb7b61
test(environment): cover write plans, the write gate and served writes
earakely-scale Oct 20, 2026
e7bd24b
docs(specs): record the write effects verification
earakely-scale Oct 20, 2026
a0b3c55
Merge remote-tracking branch 'fork/feat/environment-state-serve' into…
earakely-scale Oct 20, 2026
0864bac
Merge remote-tracking branch 'fork/feat/environment-state-coverage' i…
earakely-scale Oct 20, 2026
2e89a39
Merge remote-tracking branch 'origin/main' into feat/environment-stat…
earakely-scale Oct 20, 2026
82dfd94
docs(specs): record the write effects checks after merging the base b…
earakely-scale Oct 20, 2026
ce12615
Merge remote-tracking branch 'origin/main' into feat/environment-stat…
earakely-scale Oct 20, 2026
52b6b78
docs(specs): record the checks after merging main again
earakely-scale Oct 20, 2026
dbd0dce
chore: merge main (1629266e) into environment state coverage
earakely-scale Oct 20, 2026
f6c756a
fix(environment): quote captured names in response summaries
earakely-scale Oct 20, 2026
370b9be
docs(specs): correct the showcase capture count to 50
earakely-scale Oct 20, 2026
c00fde4
fix(environment): keep room for refusals and framing in the reply budget
earakely-scale Oct 20, 2026
61c8e3e
chore: merge environment state serve (c00fde41) into environment stat…
earakely-scale Oct 20, 2026
862c88c
chore: merge environment state coverage (f6c756aa) into environment s…
earakely-scale Oct 20, 2026
b068b09
chore: merge main (1629266e) into environment state writes
earakely-scale Oct 20, 2026
82556cd
fix(environment): answer unfiltered lists from their own parent; desc…
earakely-scale Oct 20, 2026
138ea4b
fix(environment): judge writes by the full served response; model onl…
earakely-scale Oct 20, 2026
6d21b62
fix(environment): refuse writes the state could not hold or reload
earakely-scale Oct 20, 2026
f1b00f5
docs(environment): specify the write refusals, 2xx-only modelling and…
earakely-scale Oct 20, 2026
df2bded
test(environment): pin the replay card with quoted summary names; rec…
earakely-scale Oct 20, 2026
2086da6
fix(environment): make the write gate and serving agree on lines, rul…
earakely-scale Oct 20, 2026
7056f5f
docs(environment): record the second review round's verification
earakely-scale Oct 20, 2026
db8df45
fix(environment): keep checked lines' path spellings; check later slu…
earakely-scale Oct 20, 2026
5327e59
fix(environment): choose a read's checked line as replay chooses the …
earakely-scale Oct 20, 2026
b6c3b16
fix(environment): match document write paths, verbatim create collect…
earakely-scale Oct 20, 2026
f2b9535
fix(environment): answer a missing entity with a 2xx null only for reads
earakely-scale Oct 20, 2026
25b6622
chore: merge main (335c042d) into environment state serve
earakely-scale Oct 21, 2026
54d3d5e
feat(environment): decide a list's whole-collection membership per line
earakely-scale Oct 21, 2026
19ef539
chore: merge main (335c042d) into environment state coverage
earakely-scale Oct 21, 2026
87e94d1
test(environment): cover per-line list membership; document it
earakely-scale Oct 21, 2026
665112e
fix(environment): quote the prefix of a member name too long to show …
earakely-scale Oct 21, 2026
4aeefd9
chore: merge environment state serve (25b6622d) into environment stat…
earakely-scale Oct 21, 2026
9edbabe
chore: merge environment state coverage (665112e9) into environment s…
earakely-scale Oct 21, 2026
111556a
docs(specs): record per-line list membership measured on six environm…
earakely-scale Oct 21, 2026
6b8db19
fix(environment): refuse a loaded state that data/get would write pas…
earakely-scale Oct 21, 2026
fc403d9
chore: merge environment state serve (6b8db198) into environment stat…
earakely-scale Oct 21, 2026
1d1c478
fix(environment): confirm a write only by reads that still see it, an…
earakely-scale Oct 21, 2026
dc5e2aa
fix(environment): weigh an update's derived changes when a later writ…
earakely-scale Oct 21, 2026
8a374b6
Merge remote-tracking branch 'fork/feat/environment-state-writes' int…
earakely-scale Oct 21, 2026
4080063
fix(environment): count no write for a collection once a read shows i…
earakely-scale Oct 21, 2026
847b093
docs(specs): record per-line list membership over fifty captures and …
earakely-scale Oct 21, 2026
fe8ab58
fix(environment): erase overwritten fields from earlier write effects…
earakely-scale Oct 21, 2026
edc09db
Merge remote-tracking branch 'fork/feat/environment-state-writes' int…
earakely-scale Oct 21, 2026
73c0e9b
fix(environment): create in a held collection when an Evidence spelli…
earakely-scale Oct 21, 2026
b224462
chore: merge main into environment state writes
morluto Oct 21, 2026
19118fe
chore: merge environment state writes (73c0e9b5) into environment lis…
earakely-scale Oct 21, 2026
0a46f89
chore: merge main (4dfa1c67) into environment list lines
earakely-scale Oct 21, 2026
9f513d0
fix(environment): check reads on the lines serving answers, and refus…
earakely-scale Oct 21, 2026
6d28aa7
chore: merge the remote environment state writes (b2244622) into the …
earakely-scale Oct 21, 2026
2eb7be0
chore: merge environment state writes (6d28aa78) into environment lis…
earakely-scale Oct 21, 2026
7ffd077
fix(environment): take list counters from whole lines, per line, and …
earakely-scale Oct 21, 2026
bec65b3
chore: merge main (d8a9673f) into environment state writes
earakely-scale Oct 21, 2026
3580d85
fix(environment): confirm only the writes a read shows, and name and …
earakely-scale Oct 21, 2026
43d98ea
fix(environment): pin a create's observation to the id it answered, a…
earakely-scale Oct 21, 2026
3e18322
chore: merge environment state writes (43d98ea9) into environment lis…
earakely-scale Oct 21, 2026
de13b0c
docs(specs): record the list-lines re-run after the write-plan merge
earakely-scale Oct 21, 2026
264ce41
fix(environment): keep unseen writes pending, and hold later calls to…
earakely-scale Oct 21, 2026
2807278
chore: merge environment state writes (264ce410) into environment lis…
earakely-scale Oct 21, 2026
7d2587c
docs(specs): record the list-lines re-run after the third write-plan …
earakely-scale Oct 21, 2026
0ae6440
fix(environment): never rule an entity's identity, and read a zero pa…
earakely-scale Oct 21, 2026
34cbdd6
chore: merge environment state writes (0ae64400) into environment lis…
earakely-scale Oct 21, 2026
6257de9
refactor(environment): move the paging rules to environmentStatePagin…
earakely-scale Oct 21, 2026
4f40bff
chore: merge environment state writes (6257de93) into environment lis…
earakely-scale Oct 21, 2026
c68c63b
docs(specs): record the list-lines re-run after the later write-plan …
earakely-scale Oct 21, 2026
466ed8b
fix(environment): name entities and weigh interference per write as s…
earakely-scale Oct 21, 2026
f239fa3
chore: merge environment state writes (466ed8b4) into environment lis…
earakely-scale Oct 21, 2026
ed4b6db
docs(specs): record the list-lines re-run after the fourth write-plan…
earakely-scale Oct 21, 2026
7cef2fb
fix(environment): bound pages per size, refuse only read-observed rem…
earakely-scale Oct 21, 2026
8eea9f6
chore: merge environment state writes (7cef2fb2) into environment lis…
earakely-scale Oct 21, 2026
734786e
docs(specs): record the list-lines re-run after the 7cef2fb2 merge
earakely-scale Oct 21, 2026
45a5c8b
fix(environment): count interference on any target a read covers, and…
earakely-scale Oct 21, 2026
27dd606
chore: merge environment state writes (45a5c8b9) into environment lis…
earakely-scale Oct 21, 2026
325c128
fix(environment): weigh interference only where a tool's effect survives
earakely-scale Oct 21, 2026
9b868c0
chore: merge environment state writes (325c128f) into environment lis…
earakely-scale Oct 21, 2026
6c8f4f7
feat(environment): render more read tools from the state and describe…
cursoragent Oct 21, 2026
378a109
fix(environment): keep rendered documents and quoted samples inside t…
cursoragent Oct 21, 2026
cfb42dd
feat(environment): apply evidence-gated write effects to the served s…
cursoragent Oct 21, 2026
5d0e096
fix(environment): bound and validate write state history
morluto Oct 21, 2026
5b42469
feat(environment): render more read tools from the state and describe…
cursoragent Oct 21, 2026
54c8934
fix(environment): keep rendered documents and quoted samples inside t…
cursoragent Oct 21, 2026
19b50ea
feat(environment): apply evidence-gated write effects to the served s…
cursoragent Oct 21, 2026
a057ea9
fix(environment): bound and validate write state history
morluto Oct 21, 2026
f79f1e1
fix(environment): bound additional collection history
morluto Oct 21, 2026
4a678f1
Merge remote-tracking branch 'live-5600/feat/environment-state-writes…
morluto Oct 21, 2026
7de20bc
fix(environment): credit sent fields, negative sequences, and encoded…
cursoragent Oct 21, 2026
a1076ca
Merge live environment write verification fixes
morluto Oct 21, 2026
d3015d2
test(environment): cover resolved encoded update identities
morluto Oct 21, 2026
cddd3e6
fix: validate timed update observations
morluto Oct 21, 2026
fb6785d
fix(environment): share write overlap and check clocks on earlier calls
cursoragent Oct 21, 2026
d7c5c62
merge: restack environment state writes onto main after #5352
cursoragent Oct 21, 2026
3b34bbd
fix: preserve partial update evidence
morluto Oct 21, 2026
5d00ff3
Merge remote-tracking branch 'live-5600/feat/environment-state-writes…
morluto Oct 21, 2026
717ac2c
chore: merge main (8413ec08) into environment state writes
earakely-scale Oct 21, 2026
891f35e
chore: merge environment state writes (717ac2c4) into environment lis…
earakely-scale Oct 22, 2026
2013511
chore: merge main (2451e187) into environment list lines
earakely-scale Oct 22, 2026
e923fc7
fix(environment): let an unmodelled write explain only the list membe…
earakely-scale Oct 21, 2026
75d7bb0
fix(environment): explain added fields, tie creates to serving's coll…
earakely-scale Oct 21, 2026
cd26a76
docs(environment): state how list reads weigh unmodelled writes, adde…
earakely-scale Oct 22, 2026
2a125b7
chore: merge main (4a4bbab3) into environment state writes
earakely-scale Oct 22, 2026
ddab0a9
chore: merge environment state writes (2a125b71) into environment lis…
earakely-scale Oct 22, 2026
11e3f01
refactor(environment): keep the observing view helpers with the obser…
earakely-scale Oct 22, 2026
6685b37
chore: merge environment state writes (11e3f016) into environment lis…
earakely-scale Oct 22, 2026
53a7866
fix(environment): resolve unmodelled writes onto the held collection
cursoragent Oct 22, 2026
329aeed
fix(environment): confirm no write through volatile fields or overwri…
earakely-scale Oct 22, 2026
ccdf091
fix(environment): leave unknown entities unchecked by failed reads, v…
earakely-scale Oct 22, 2026
1c97933
fix(environment): fill a create's path fields from the collection ser…
earakely-scale Oct 22, 2026
90d9022
fix(environment): name unmodelled writes as modelled ones, count fiel…
earakely-scale Oct 22, 2026
ca88b5e
chore: merge environment state writes (90d90227) into environment lis…
earakely-scale Oct 22, 2026
0fe1738
refactor(environment): keep the written-field checks with the attribu…
earakely-scale Oct 22, 2026
756c631
fix(environment): let a document replacement overwrite everything und…
earakely-scale Oct 22, 2026
3f1f825
chore: merge the published environment state writes (756c6312)
earakely-scale Oct 22, 2026
79f0560
chore: merge environment state writes (3f1f825e) into environment lis…
earakely-scale Oct 22, 2026
1802e41
chore: merge main (b8c1b453) into environment list lines
earakely-scale Oct 22, 2026
0499ed1
chore: merge main (538017d1, #5600 squashed) into environment list lines
earakely-scale Oct 22, 2026
36571c4
fix(environment): preserve whole-list semantics when integrating late…
gensokyo-dev Oct 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs(specs): plan evidence-gated write effects on the served state
Adds the state-writes spec folder: write plans per write tool (create,
update, delete, document) learned from the first successful recorded call,
the gate that replays the capture's timeline on the initial state and serves
a write tool only when a later read confirms its effect and none contradicts
it, deterministic generated values, the serving contract and what stays
unmodelled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Loading branch information
earakely-scale and claude committed Oct 20, 2026
commit 306c3da915099463d7616ae2242f9d73527b988f
45 changes: 45 additions & 0 deletions docs/specs/agent-environments/state-writes/plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Implementation plan

The branch builds on the state-serving and coverage branches (merged into it).

1. **Write plan types and request bodies.** Add the plan, rule and reason types
beside the state rules, and have the state accumulator lend extraction
parsed request bodies under the same budget, admitted like response bodies.
2. **Field rules.** Add a module that explains an observed entity against the
call that wrote it (echo, copy, path, slug, clock, sequence, unique,
template and constant) and that recognises and formats clock values,
UUIDs and tokens.
3. **Effects.** Add one apply module that both the gate and the server use. It
applies a create, update, delete or document write to a writable state
interface from a plan, a call and a value source: the recorded values in
the gate, the store's generators when served.
4. **Gate.** Add a simulation that:
- classifies every write tool;
- builds each plan from its exemplar;
- walks the timeline over a copy of the initial state;
- checks state-answered reads;
- attributes passes and mismatches;
- learns the insert rule;
- records verdicts.

Extraction runs it after the read gate and returns `writes` and
`write_clock`; the view schema and its unknowns state the write model.

5. **Serving.**
- The loaded state carries the plans and the clock.
- The store gains atomic mutations, the clock and the counter (all reset by
`data/reset` and `data/add`).
- A write answer module validates the body, applies the effect and renders
the response.
- Item reads of missing entities answer recorded 404s.
- The served catalog adds served write tools, with descriptions charged to
the discovery budget.
6. **Export.** Count served write tools in the bundle plan and README.
7. **Tests.** Domain, services, adapters and MCP-boundary coverage as the
spec's acceptance lists.
8. **Documentation.** Document the write model in the environment-state and
serving sections, and record the real-capture results, the AgentEnv run
and the live comparison in `verification.md`.

There are no dependency, provider or REA tool contract changes beyond the
`environment-state` result members, and no new network activity.
271 changes: 271 additions & 0 deletions docs/specs/agent-environments/state-writes/spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
# Apply write effects to the served state

Issue: https://github.com/morluto/rea/issues/4933

## Outcome

An environment served from its state also serves the write tools whose effects
the capture itself confirms:

- a create adds an entity;
- an update changes the fields the call sends;
- a delete removes the entity;
- a document write changes a document.

Later reads, list membership and `data/get` show the change, and `data/reset`
undoes it.

The `environment-state` view decides which write tools are served. It replays
the capture's own timeline on the extracted initial state: each recorded write
applies its modelled effect, and each later read that the state answers is
rendered and compared with the recorded response. A write tool is served only
when at least one later read reproduces after its effect and none contradicts
it. Every other write tool stays unserved, listed with the reason.

Values the application generates are deterministic: identities, sequences and
clock values follow the formats the capture recorded, so the same calls after
a reset give the same state.

## Write plans

The view adds two members to its result:

- `writes`: one plan per manifest tool whose method may change state
(`changesState`);
- `write_clock`: the instant the served clock starts from.

**Effects.** Each plan classifies its tool:

| Effect | Tool | Target |
| ---------- | --------------------------------------------------------------------- | ------------------------- |
| `create` | `POST` to a state type's `collection_template` | an entity of that type |
| `update` | `PUT`, `PATCH` or `POST` to that template plus one trailing parameter | the entity the path names |
| `delete` | `DELETE` to that same item template | the entity the path names |
| `document` | `PUT`, `PATCH` or `POST` to a document view's path | that document |
| `none` | anything else | reason `no-state-target` |

**Exemplar.** A plan is built from its first successful (2xx) recorded call,
the exemplar.

- **Request body.** The exemplar's request body must be a JSON object that
could enter the state: a JSON-like media type, complete UTF-8 text within
256 KiB, exact numbers, no `__proto__` member. Otherwise the reason is
`body-unusable`. A `DELETE` takes no body.
- **The written entity.** The entity is observed in the exemplar's response,
located by its identity value at the root, in one member, or in a
one-element array, as item views locate it. When the response does not carry
it, the entity is observed in the first later read that shows it: an item
read of that entity, or for a create, the one entity a collection read newly
lists. With neither, the reason is `no-observation`.

**Field rules for creates.** Each field of the observed entity gets the first
rule that explains its value:

1. **Identity.** The type's `id_field` is generated. A sequence when it is an
integer (or a string of digits); otherwise a UUID when it has the
`8-4-4-4-12` hex shape; otherwise a token of the same length and character
classes.
2. **Echo.** A body member of the same name with an equal value.
3. **Copy.** A body string of 8 or more characters, found at a JSON pointer of
the body.
4. **Path.** The value of a path parameter of the call.
5. **Slug.** The slug of an echoed string member: lower case, runs of other
characters joined by `-`.
6. **Clock.** A timestamp within 10 minutes of the exemplar's start time. The
format is kept: ISO-8601 with its separator, fraction digits and zone, or
epoch seconds or milliseconds.
7. **Sequence.** An integer one greater than the largest value of the field in
the collection, else in the type.
8. **Unique.** A UUID-shaped string that no other entity of the type shares.
9. **Template.** A string containing a generated value as a delimited token
(for example a URL that ends in the new id). It is rebuilt around the new
value.
10. **Constant.** Otherwise the exemplar's value.

When a constant contains a path value of the exemplar's call as a delimited
token, the create is served only for calls naming the exemplar's collection.

**Body members of a create.** A member is either accepted or not:

- **Accepted.** An echoed member, or the identity field's value. Every member
the exemplar sent is required.
- **Not accepted.** A member the application stored with a different value
(transformed), or one it did not show. A call that sends such a member is a
tool error naming the accepted members.

**Updates.** Body members follow the same accepted and not-accepted rules.
`PUT` requires every member the exemplar sent; `PATCH` and `POST` require at
least one. A field the exemplar's update changed without sending it is
explained as one of:

- clock;
- an increment by one;
- a slug of an echoed member.

Any other change is `unexplained-change`.

**Deletes.** A delete removes the entity. Its response is the exemplar's
response, with the entity re-rendered when the response carries it.

**Documents.** A document write merges the body's members (replaces them, for
`PUT`) into the document object that holds most of them: the root or one
member.

**Responses.** A write answers with the status and content type of one
recorded response:

| Response | Body |
| ---------- | --------------------------------------------------------------------------------------------------------- |
| `entity` | the written entity, rendered into the recorded envelope at the plan's pointer through the recorded fields |
| `identity` | the recorded body with the new identity at the plan's pointer |
| `empty` | no body |
| `recorded` | the recorded body |

A rendered body missing a field the recorded response carried is a tool error,
and the state is left unchanged.

**List position.** A create's `insert` rule places the new entity in its
collection's order: sorted by the identity field or a clock field (ascending
or descending), `first` or `last`. The rule is the first candidate consistent
with both the initial `all`-membership recordings and the position a later
recorded list shows. With no evidence, the rule is `last`.

## The gate

The view replays every primary-origin record in timeline order on a copy of
the initial state.

**Writes.** A modelled write applies its effect, using the values it recorded
for generated fields and the stored values for fields it transformed. Any
other successful write taints the types whose collection paths are
segment-prefix related to its path (parameters match any segment). Later
checks of a tainted type are skipped.

**Reads.** A read is checked when the served environment would answer it
from the state:

- an item read of a state-backed item view;
- a list or document read on one of its view's checked request lines.

**Comparison.** The read's answer is rendered from the copy and compared with
the recording, as the read gate compares, with volatile fields taking the
observed values. A recorded 404 or 410 for an entity the copy does not hold
agrees with it.

**Attribution.**

- A check exercises the write tools that changed its entity or collection
since the previous check of it. A pass confirms them and a mismatch
contradicts them.
- A mismatch on an entity or collection that no write changed contradicts,
as `side-effect`, the modelled writes since that previous check whose paths
are segment-prefix related to the read's path.
- After a check, the copy takes the recorded values of the checked entity
objects. A collection whose membership mismatched is not checked again.
- The read that supplied a create's observation does not check that create.

**Verdicts.** A plan is served when at least one check confirms it and none
contradicts it. Otherwise the reason, in this precedence, is:

1. the first build reason;
2. `contradicted`, with `contradicted_by` naming the first contradicting read;
3. `side-effect`;
4. `unconfirmed`.

`checked_record_ordinals` lists the confirming reads.

## Serving

**Catalog.** In state mode, the catalog adds the write tools whose plan is
served. Their descriptions say the tool:

- applies its effect to the served state;
- names its target type;
- lists its required and accepted body members.

The discovery budget charges them. `--replay-only` and the replay fallback are
unchanged.

**Calls.** A served write answers synchronously against the live store and
changes it atomically, so every MCP session and `data/get` see one state.

**Refusals.** These are tool errors that leave the state unchanged:

- a body that is not an object;
- a missing required member;
- a member that is not accepted;
- a value of another JSON type than the exemplar's;
- an update or delete of an entity the state does not hold;
- a create in another collection when the plan is tied to its own;
- a rendered response missing a recorded field.

When the tool, or the type's item view, recorded a 404 or 410 response, an
update or delete of a missing entity answers with that recording instead.

**Clock and generators.** The store's clock starts at `write_clock` and
advances one second before each served write; clock fields take its value in
their recorded format.

- **Sequences:** one more than the largest current value in their scope.
- **UUIDs and tokens:** derived from a SHA-256 of the state Evidence id, the
tool, the field and a write counter, skipping values the type already holds.

`data/reset` and `data/add` restart the clock and the counter.

**Missing entities.** An item read of an entity the state does not hold
answers with the tool's latest recorded 404 or 410 response when it has one,
labelled as a state answer for a missing entity. Otherwise it stays a tool
error.

**Provenance.** Write answers carry `state: {source: "state", view: "create" |
"update" | "delete" | "document", type, collection, id}`. The document variant
has `path` instead of `type`, `collection` and `id`.

**Data plane and export.**

- `data/get` reports written entities without record citations; they load
back through `data/add` unchanged.
- `environment-export` counts served write tools in the bundle's tool count
and README. Its check stays a read tool.

## Not modelled

These stay unserved, or are labelled in the description:

- side effects on counters, relations and copies of entities in other
collections;
- inputs the application transforms;
- members the capture never sent;
- reordering after an update;
- membership of filtered or paged lists, which answer their recorded members;
- write paths the manifest left literal;
- writes in `capture_browser_scenario` captures, which retain no request
bodies;
- authorization.

## Acceptance

- **Domain tests:** classification, every field rule, request-body admission,
observation from a later read, the insert rules, every verdict and reason,
attribution and resynchronisation, and taint by an unmodelled write.
- **Services tests:**
- store mutations and their atomicity;
- every refusal;
- generated values and their determinism across reset;
- `data/get` round trips of written entities;
- the recorded 404 for missing entities;
- the catalog and descriptions in each mode.
- **Boundary test:** a write tool changes the next read over MCP.

**Real captures.**

- The view runs over every showcase capture within its budget, and the
verification reports, per capture, the write tools served and the reasons
for the rest.
- One environment, chosen at random among those serving a write tool, is
exported, run in the AgentEnv framework, and graded from `data/get` after an
agent's create, update and delete.
- The served model is compared with that application running live on the same
calls.

No test reaches an external network.
17 changes: 17 additions & 0 deletions docs/specs/agent-environments/state-writes/tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Tasks

- [x] Record the write model, the gate and the serving contract.
- [ ] Admit request bodies and add the plan types.
- [ ] Explain created and updated entities with field rules.
- [ ] Apply create, update, delete and document effects in one shared module.
- [ ] Simulate the capture's timeline and decide each plan's verdict.
- [ ] Serve gated write tools from the live store with deterministic values.
- [ ] Answer recorded 404s for missing entities.
- [ ] Count served write tools in exports.
- [ ] Add domain, services, adapters and boundary coverage.
- [ ] Document the write model and serving.
- [ ] Run the view over every showcase capture and report per-capture verdicts.
- [ ] Export one randomly chosen environment, run write tasks in the AgentEnv
framework and grade them from `data/get`.
- [ ] Compare the served model with the live application on the same calls.
- [ ] Run static, formatting, duplication, documentation and test gates.
4 changes: 4 additions & 0 deletions docs/specs/agent-environments/state-writes/verification.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Verification

Pending: this file records the gates, the real-capture results, the AgentEnv
run and the live comparison once the implementation lands.