Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
95c8c9d
feat(environment): render more read tools from the state and describe…
cursoragent Oct 21, 2026
ad8f674
feat(environment): apply evidence-gated write effects to the served s…
cursoragent Oct 21, 2026
733833e
feat(environment): model bodiless writes, omitted fields, projected r…
earakely-scale Oct 21, 2026
6f67a11
feat(environment): test and document wider write coverage
earakely-scale Oct 21, 2026
e44adb5
docs(environment): record the write-coverage checks on the current wr…
earakely-scale Oct 21, 2026
a4c4a23
docs(environment): record the re-recorded and end-to-end write-covera…
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
067f0fa
fix(environment): keep projected and partial reads out of the write g…
earakely-scale Oct 21, 2026
717ac2c
chore: merge main (8413ec08) into environment state writes
earakely-scale Oct 21, 2026
1074355
chore: merge environment state writes (717ac2c4) into environment wri…
earakely-scale Oct 22, 2026
0061234
chore: merge main (2451e187) into environment write coverage
earakely-scale Oct 22, 2026
70249b3
fix(environment): check the absence a projected read answers, and rea…
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
9517260
chore: merge environment state writes (2a125b71) into environment wri…
earakely-scale Oct 22, 2026
11e3f01
refactor(environment): keep the observing view helpers with the obser…
earakely-scale Oct 22, 2026
cfc43a7
chore: merge environment state writes (11e3f016) into environment wri…
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
54f7d85
fix(environment): note omitted fields only from reads the gate checks
earakely-scale Oct 22, 2026
3ac1136
chore: merge environment state writes (90d90227) into environment wri…
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
caf2acf
chore: merge environment state writes (3f1f825e) into environment wri…
earakely-scale Oct 22, 2026
613048a
chore: merge main (b8c1b453) into environment write coverage
earakely-scale Oct 22, 2026
e21f6c5
chore: merge main (538017d1, #5600 squashed) into environment write c…
earakely-scale Oct 22, 2026
06ec0d4
fix(merge): preserve write coverage with query-aware validation
morluto Oct 22, 2026
f5162bb
fix(environment): align write inference with resolved state facts
morluto Oct 22, 2026
17c5a44
chore: integrate write coverage with current main
gensokyo-dev Oct 22, 2026
8b6e35b
chore: sync write coverage with latest main
N0zoM1z0 Oct 22, 2026
6f726ef
fix(environment): preserve projection and omission evidence across wr…
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
fix(environment): name unmodelled writes as modelled ones, count fiel…
…ds updates write, and keep later members' types

An unmodelled write below an item path names its entity through itemTarget,
and one at or above a collection resolves the held collection, as modelled
writes do, so an encoded spelling no longer hides the entity it changed.
An update's answer counts the fields its rules write, other than increments,
as available, so a field only the update writes no longer makes it
incomplete-entities. A member a later call first stores keeps that call's
JSON type in the body's kinds, which the body check falls back to.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Loading branch information
earakely-scale and claude committed Oct 22, 2026
commit 90d9022741f7a55a7c0d7f3f742a2f27fedd991f
17 changes: 13 additions & 4 deletions docs/specs/agent-environments/state-writes/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ calls use a member both as the identity and as a fixed member, or fix it at
different values, is `unexplained-change`, as serving could not take every
recorded call. So is an update a later read shows dropped a field the
entity held, since serving keeps every field an update does not write; a write's
own response may leave fields out.
own response may leave fields out. A member a later call is the first to store,
which the plan's observation does not show, keeps the JSON type that call stored
it as (the body's `kinds`), as an exemplar's member keeps the observation's.
`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:
Expand Down Expand Up @@ -188,6 +190,11 @@ depends on where its path lies relative to each type's collection paths
- **At a collection path:** that collection is not checked again.
- **Above collection paths:** everything under the path is not checked again.

The path names its entity as an update's does and its collection as a create's
does, so a plain spelling reaches a collection held under an encoded one; a
path above collections covers each collection whose segments are its own
verbatim or once percent-decoded.

An item read of an unknown entity shows it again: the copy takes its recorded
values. A failed read that is no absence shows nothing, and the entity stays
unknown. Writes that changed it since its last check are checked only on the
Expand Down Expand Up @@ -280,7 +287,9 @@ contradicts it. Otherwise the reason, in this precedence, is:
when no initial entity holds every field its recorded answer shows (for
example a delete that answers with an edit view of the entity the reads
never showed), so it could answer only for entities the environment itself
created.
created. An update's answer renders the entity it wrote, so a field one of
its rules writes counts as held, except an increment's, which adds only to
a held value.

`checked_record_ordinals` lists the confirming reads.

Expand All @@ -305,8 +314,8 @@ changes it atomically, so every MCP session and `data/get` see one state.
- 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, for documents as well as
entities;
- a value of another JSON type than the exemplar's (for a member only a later
update stored, that call's), for documents as well as entities;
- 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 document write at a path other than the one the state holds it at;
Expand Down
2 changes: 1 addition & 1 deletion docs/web-network-captures.md
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ checked only on the members they sent; a mismatch no write explains marks the re
`side-effect`. A plan is `served` when a read confirmed it and none
contradicted it; otherwise its `reason` is the first of its build reason
(`no-call`, `body-unusable`, `no-observation`, `unexplained-change`),
`contradicted` (with `contradicted_by`), `side-effect`, `unconfirmed` and `incomplete-entities` (an update or delete that answers with the entity, when no initial entity holds every field its recorded answer shows, so it could answer only for entities the environment created).
`contradicted` (with `contradicted_by`), `side-effect`, `unconfirmed` and `incomplete-entities` (an update or delete that answers with the entity, when no initial entity holds every field its recorded answer shows, counting for an update the fields its rules write, so it could answer only for entities the environment created).
`checked_record_ordinals` lists the confirming reads, `insert` places created
entities (sorted by a field the collection's recorded order shows, else last),
and `write_clock` is the end of the last timed record, to the next second.
Expand Down
29 changes: 29 additions & 0 deletions src/application/environment/environmentStateWriteAnswer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,35 @@ describe("refusals", () => {
).toMatchObject({ id: 3, name: "Hard", format: "HARDCOVER" });
});

it("holds a member a later update first stored to the JSON type it stored", () => {
const shelved = { ...SECOND_BOOK, tags: ["a"] };
const renamed = renamedBook(FIRST_BOOK, "Renamed Book", 3);
const retagged = { ...shelved, tags: ["x"], updated_at: bookClock(5) };
// The rename the plan was built from shows no tags, which the first book never had.
const books = servedFrom([
["GET", "/api/books", [FIRST_BOOK, shelved]],
["GET", "/api/books/1", FIRST_BOOK],
["GET", "/api/books/2", shelved],
["PATCH", "/api/books/1", renamed, 200, { name: "Renamed Book" }],
["GET", "/api/books/1", renamed],
["PATCH", "/api/books/2", retagged, 200, { tags: ["x"] }],
["GET", "/api/books/2", retagged],
]);
expect(books.state.writes.get("patch_books_by_id")).toMatchObject({
served: true,
body: { kinds: [{ member: "tags", kind: "array" }] },
});
const before = books.snapshot();
expect(
books.refusal("patch_books_by_id", { id: "1", body: { tags: "x" } }),
).toMatchObject({
message: expect.stringContaining("Member tags must be a JSON array"),
});
expect(books.snapshot()).toBe(before);
books.answer("patch_books_by_id", { id: "1", body: { tags: ["y"] } });
expect(entityOf(books, "1")?.fields).toMatchObject({ tags: ["y"] });
});

it("generates the same values after a refused call as without it", () => {
const refusedFirst = servedFrom();
refusedFirst.refusal("post_books", { body: {} });
Expand Down
121 changes: 121 additions & 0 deletions src/domain/analysisView/EnvironmentStateWriteSimulation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,127 @@ describe("reads named as serving names them", () => {
});
});

describe("writes named as serving names them", () => {
const orgBook = (
id: number,
org: string,
name: string,
archived = false,
) => ({
id,
org,
name,
archived,
});
const ALPHA = orgBook(1, "acme1", "Alpha");
const BETA = orgBook(2, "beta2", "Beta");
const RENAMED_BETA = orgBook(2, "beta2", "Renamed Beta");
const INIT_ROWS: readonly TimedCaptureRow[] = [
["GET", "/api/orgs/%61cme1/books", [ALPHA]],
["GET", "/api/orgs/beta2/books", [BETA]],
["GET", "/api/orgs/%61cme1/books/1", ALPHA],
["GET", "/api/orgs/beta2/books/2", BETA],
];
const RENAME_BETA: readonly TimedCaptureRow[] = [
[
"PATCH",
"/api/orgs/beta2/books/2",
RENAMED_BETA,
200,
{ name: "Renamed Beta" },
],
["GET", "/api/orgs/beta2/books/2", RENAMED_BETA],
];
const CREATE_DELTA: readonly TimedCaptureRow[] = [
[
"POST",
"/api/orgs/beta2/books",
orgBook(4, "beta2", "Delta"),
201,
{ name: "Delta" },
],
];
const planned = (rows: readonly TimedCaptureRow[], effect: string) =>
environmentStateViewOf(timedCaptureEvidence(rows), [
"sibling-variance",
]).writes.find((plan) => plan.effect === effect);

it("contradicts a create named plainly by a list of the encoded collection it went to that omits it", () => {
const gamma = orgBook(3, "acme1", "Gamma");
const rows: TimedCaptureRow[] = [
...INIT_ROWS,
["POST", "/api/orgs/acme1/books", gamma, 201, { name: "Gamma" }],
["GET", "/api/orgs/acme1/books/3", gamma],
// Serving lists the create in the encoded collection, which the recording shows without it.
["GET", "/api/orgs/%61cme1/books", [ALPHA]],
...CREATE_DELTA,
];
expect(planned(rows, "create")).toMatchObject({
served: false,
contradicted_by: 6,
});
});

it("leaves unknown the entity a plainly named action changed under the encoded collection", () => {
const archived = orgBook(1, "acme1", "Alpha", true);
const rows: TimedCaptureRow[] = [
...INIT_ROWS,
["POST", "/api/orgs/acme1/books/1/archive", archived, 200],
// The rename's answer also shows the archive, which no rule of the rename explains.
[
"PATCH",
"/api/orgs/acme1/books/1",
orgBook(1, "acme1", "Renamed", true),
200,
{ name: "Renamed" },
],
...RENAME_BETA,
];
expect(planned(rows, "update")).toMatchObject({
served: true,
reason: null,
});
});

it("checks no list of the encoded collection after a plainly named write at the collection", () => {
const gamma = orgBook(3, "acme1", "Gamma");
const rows: TimedCaptureRow[] = [
...INIT_ROWS,
["DELETE", "/api/orgs/acme1/books", "", 204],
["POST", "/api/orgs/acme1/books", gamma, 201, { name: "Gamma" }],
["GET", "/api/orgs/acme1/books/3", gamma],
// The cleared collection now lists only the create, which the state alone cannot show.
["GET", "/api/orgs/%61cme1/books", [gamma]],
...CREATE_DELTA,
];
expect(planned(rows, "create")).toMatchObject({
served: true,
contradicted_by: null,
});
});

it("checks no read under the encoded collection after a plainly named write above it", () => {
const rows: TimedCaptureRow[] = [
...INIT_ROWS,
[
"PATCH",
"/api/orgs/%61cme1/books/1",
orgBook(1, "acme1", "Renamed"),
200,
{ name: "Renamed" },
],
["DELETE", "/api/orgs/acme1", "", 204],
// The organisation's books went with it, which the state alone cannot show.
["GET", "/api/orgs/%61cme1/books/1", BOOK_NOT_FOUND, 404],
...RENAME_BETA,
];
expect(planned(rows, "update")).toMatchObject({
served: true,
contradicted_by: null,
});
});
});

describe("resolved encoded item observations", () => {
it("matches the resolved raw ID when the collection alias and response ID are encoded", () => {
const collection = "/api/orgs/%61cme1/books";
Expand Down
3 changes: 1 addition & 2 deletions src/domain/analysisView/EnvironmentStateWriteSimulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ export class EnvironmentStateWriteSimulation {
new Map(
input.documents.map((document) => [document.tool, document.path]),
),
(type, collection, id) =>
this.#state.entity(type, collection, id) !== undefined,
this.#state,
);
}

Expand Down
8 changes: 7 additions & 1 deletion src/domain/analysisView/environmentStateView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,16 @@ const writePlanSchema = z.strictObject({
),
required: z.array(z.string()),
identity: z.string().nullable(),
kinds: z.array(
z.strictObject({
member: z.string(),
kind: z.enum(["array", "boolean", "number", "object", "string"]),
}),
),
})
.nullable()
.describe(
"Body members the application stored as sent (accepted), members accepted only with their recorded value (fixed), and members every call sends (required).",
"Body members the application stored as sent (accepted), members accepted only with their recorded value (fixed), members every call sends (required), and the JSON type a later call stored an accepted member as when the observation does not show it (kinds).",
),
rules: z
.array(fieldRuleSchema)
Expand Down
3 changes: 3 additions & 0 deletions src/domain/analysisView/environmentStateWriteApply.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const CONTRACT: WriteBody = {
],
required: ["title"],
identity: "id",
kinds: [],
};
const RECORDED = { title: "A", tags: ["x"], meta: null, priority: "high" };
const LISTED =
Expand Down Expand Up @@ -163,6 +164,7 @@ const CREATE_PLAN: Plan = {
fixed: [],
required: ["title", "meta"],
identity: null,
kinds: [],
},
};
const CREATE_OBSERVED: JsonObject = {
Expand Down Expand Up @@ -257,6 +259,7 @@ const UPDATE_PLAN: Plan = {
fixed: [{ member: "status", sent: "CLOSED" }],
required: [],
identity: "id",
kinds: [],
},
};
const BEFORE: JsonObject = {
Expand Down
31 changes: 24 additions & 7 deletions src/domain/analysisView/environmentStateWriteApply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import type {
FieldRule,
GeneratedRule,
JsonKind,
StateWritePlan,
WriteBody,
WriteCall,
Expand All @@ -36,6 +37,21 @@ export type GenerateValue = (
const kindOf = (value: JsonValue | undefined): string =>
value === null ? "null" : Array.isArray(value) ? "array" : typeof value;

/** The JSON types `stored` holds members in, for those `observed` shows no value of. */
export const storedKinds = (
members: readonly string[],
observed: JsonObject,
stored: JsonObject,
): WriteBody["kinds"] =>
members.flatMap((member) => {
const value = stored[member];
return (observed[member] ?? null) === null &&
value !== undefined &&
value !== null
? [{ member, kind: kindOf(value) as JsonKind }]
: [];
});

/** Members a refusal names, each cut to `LISTED_NAME_CHARS`; the plan in the state Evidence holds every one whole. */
const LISTED_MEMBERS = 12;
const LISTED_NAME_CHARS = 120;
Expand All @@ -62,14 +78,15 @@ const listed = (members: readonly string[]): string => {
const bodyContract = (body: WriteBody): string =>
`accepted members: ${listed(body.accepted)}; members accepted only with their recorded value: ${listed(body.fixed.map(({ member }) => member))}; required: ${listed(body.required)}`;

/** Why a call's body does not fit the members the capture showed, if it does not; `shapes` gives each accepted member's JSON type. */
/** Why a call's body does not fit the members the capture showed, if it does not; `shapes` gives each accepted member's JSON type, else the body's recorded kind. */
export const bodyProblem = (
body: WriteBody,
call: WriteCall,
shapes: { readonly entity: JsonObject; readonly id?: string },
): string | undefined => {
const sent = call.body ?? {};
const fixed = new Map(body.fixed.map((entry) => [entry.member, entry.sent]));
const kinds = new Map(body.kinds.map((entry) => [entry.member, entry.kind]));
for (const [member, value] of Object.entries(sent)) {
if (member === body.identity) {
if (scalarText(value) !== shapes.id)
Expand All @@ -84,12 +101,12 @@ export const bodyProblem = (
if (!body.accepted.includes(member))
return `Member ${member} is not one the capture showed stored (${bodyContract(body)}).`;
const recorded = shapes.entity[member];
if (
recorded !== undefined &&
recorded !== null &&
kindOf(recorded) !== kindOf(value)
)
return `Member ${member} must be a JSON ${kindOf(recorded)}, as the capture stored it.`;
const kind =
recorded === undefined || recorded === null
? kinds.get(member)
: kindOf(recorded);
if (kind !== undefined && kind !== kindOf(value))
return `Member ${member} must be a JSON ${kind}, as the capture stored it.`;
}
const missing = body.required.filter(
(member) => !Object.hasOwn(sent, member),
Expand Down
1 change: 1 addition & 0 deletions src/domain/analysisView/environmentStateWriteDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const buildDocument = (
fixed: [],
required: [],
identity: null,
kinds: [],
},
});
};
Expand Down
Loading