Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
143 changes: 143 additions & 0 deletions src/domain/analysisView/EnvironmentStateWriteSimulation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,67 @@ describe("what a read shows of a write", () => {
});
});

describe("document writes later writes overwrite", () => {
it("confirms no document replacement a later merge overwrote", () => {
const rows: TimedCaptureRow[] = [
["GET", "/api/settings", { theme: "light", lang: "en" }],
[
"PUT",
"/api/settings",
{ theme: "dark", lang: "fr" },
200,
{ theme: "dark", lang: "fr" },
],
[
"PATCH",
"/api/settings",
{ theme: "blue", lang: "de" },
200,
{ theme: "blue", lang: "de" },
],
["GET", "/api/settings", { theme: "blue", lang: "de" }],
];
expect(gated(rows, "put_settings")).toMatchObject({
served: false,
checked_record_ordinals: [],
});
expect(gated(rows, "patch_settings")).toMatchObject({
served: true,
checked_record_ordinals: [3],
});
});

it("confirms no document merge a later replacement of its object overwrote", () => {
const rows: TimedCaptureRow[] = [
["GET", "/api/settings", { prefs: { lang: "en" }, theme: "light" }],
[
"PATCH",
"/api/settings",
{ prefs: { lang: "fr" }, theme: "light" },
200,
{ prefs: { lang: "fr" } },
],
// The replacement holds `lang`, so it replaces all of `prefs`, which the merge wrote.
[
"PUT",
"/api/settings",
{ prefs: { lang: "de" }, theme: "light" },
200,
{ lang: "de" },
],
["GET", "/api/settings", { prefs: { lang: "de" }, theme: "light" }],
];
expect(gated(rows, "patch_settings")).toMatchObject({
served: false,
checked_record_ordinals: [],
});
expect(gated(rows, "put_settings")).toMatchObject({
served: true,
checked_record_ordinals: [3],
});
});
});

describe("reads named as serving names them", () => {
const orgBook = (id: number, org: string, name: string): Book => ({
id,
Expand Down Expand Up @@ -1848,6 +1909,88 @@ describe("reads and calls on an entity an unmodelled write left unknown", () =>
});
});

describe("volatile fields", () => {
it("confirms no write through a volatile field a read renders from itself", () => {
const seen = (id: number, name: string, at: string) => ({
id,
name,
seen: at,
});
const rows: TimedCaptureRow[] = [
["GET", "/api/books", [seen(1, "A", "t1"), seen(2, "B", "t1")]],
["GET", "/api/books/1", seen(1, "A", "t1")],
// A repeated read with no write between shows `seen` changing on its own, so it is volatile.
["GET", "/api/books/1", seen(1, "A", "t2")],
["GET", "/api/books/2", seen(2, "B", "t1")],
["PATCH", "/api/books/1", seen(1, "A", "t3"), 200, { seen: "t3" }],
["POST", "/api/exports", { queued: true }, 202, { format: "csv" }],
// The export may explain the new name, and `seen` renders from the read, so nothing shows the patch.
["GET", "/api/books/1", seen(1, "Z", "t9")],
];
expect(gated(rows, "patch_books_by_id")).toMatchObject({
served: false,
checked_record_ordinals: [],
});
});
});

describe("an unmodelled write under another collection spelling", () => {
it("keeps a confirmed update when the write spells the held collection plainly", () => {
const acme = (name: string, status: string) => ({
id: 1,
org: "acme1",
name,
status,
});
const beta = (name: string) => ({
id: 2,
org: "beta2",
name,
status: "open",
});
const rows: TimedCaptureRow[] = [
["GET", "/api/orgs/%61cme1/books", [acme("Alpha", "open")]],
["GET", "/api/orgs/beta2/books", [beta("Beta")]],
["GET", "/api/orgs/%61cme1/books/1", acme("Alpha", "open")],
["GET", "/api/orgs/beta2/books/2", beta("Beta")],
[
"PATCH",
"/api/orgs/acme1/books/1",
acme("Renamed", "open"),
200,
{ name: "Renamed" },
],
[
"PATCH",
"/api/orgs/beta2/books/2",
beta("Renamed Beta"),
200,
{ name: "Renamed Beta" },
],
["GET", "/api/orgs/%61cme1/books/1", acme("Renamed", "open")],
["GET", "/api/orgs/beta2/books/2", beta("Renamed Beta")],
// Book 1 is held under the encoded collection. This archive spells it plainly.
["POST", "/api/orgs/acme1/books/1/archive", null, 204, {}],
// The response shows the status the archive changed. The patch sent only the name.
[
"PATCH",
"/api/orgs/%61cme1/books/1",
acme("Retitled", "archived"),
200,
{ name: "Retitled" },
],
];
const { writes } = environmentStateViewOf(timedCaptureEvidence(rows), [
"sibling-variance",
]);
expect(writes.find((plan) => plan.effect === "update")).toMatchObject({
served: true,
reason: null,
checked_record_ordinals: [6, 7],
});
});
});

describe("timed write observations and generated clocks", () => {
it("does not learn an update from a read that began before the write completed", () => {
const changed = { ...FIRST_BOOK, name: "Changed", slug: "changed" };
Expand Down
4 changes: 3 additions & 1 deletion src/domain/analysisView/environmentStateWriteAttribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ export class WriteEffects {
};
/** Set when the fields are a document's pointers. */
readonly pointers?: boolean;
/** What the write overwrites of earlier effects, when more than the fields it claims. */
readonly overwrites?: readonly string[];
},
): void {
const [entity, collection] = effect.targets as [string, string?];
Expand All @@ -219,7 +221,7 @@ export class WriteEffects {
{
whole,
fields: new Set(
changed.filter(
(effect.overwrites ?? changed).filter(
(field) => !effect.changed?.accumulated.includes(field),
),
),
Expand Down
26 changes: 23 additions & 3 deletions src/domain/analysisView/environmentStateWriteDocument.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { JsonValue } from "../jsonValue.js";
import {
at as valueAt,
decodedSegment,
isObject,
pointerTo,
same,
segmentsOf,
Expand Down Expand Up @@ -49,15 +51,26 @@ const writePointer = (
? draft.plan.observation?.pointer
: documentPointerOf(value, body);

/** The fields a document write changed, as pointers: a merge the members it sent at its object, a replacement all under it (undefined: the whole document). */
/**
* The fields a document write changed, as pointers: a merge the members it sent at its object, a replacement every
* member it wrote or removed there, so later writes can overwrite its effect (undefined: the whole document).
*/
const writtenPointers = (
draft: WriteDraft,
body: JsonObject,
values: { readonly before: JsonValue; readonly after: JsonValue },
): readonly string[] | undefined => {
const at = draft.plan.observation?.pointer ?? "";
if (draft.plan.merge === "merge")
return Object.keys(body).map((member) => `${at}${pointerTo(member)}`);
return at === "" ? undefined : [at];
const members = new Set(
[values.before, values.after].flatMap((value) => {
const object = valueAt(value, at);
return isObject(object) ? Object.keys(object) : [];
}),
);
if (members.size === 0) return at === "" ? undefined : [at];
return [...members].map((member) => `${at}${pointerTo(member)}`);
};

/** Build a document plan from its exemplar: its object, merge or replacement by method, and the members it sent. */
Expand Down Expand Up @@ -131,10 +144,17 @@ export const applyDocument = (
}));
context.io.retain(64 + JSON.stringify(written.value).length * 2);
context.state.setDocument(tool, written.value);
const fields = writtenPointers(draft, body!);
const fields = writtenPointers(draft, body!, {
before: value!,
after: written.value,
});
const replaced = draft.plan.merge === "merge" ? undefined : pointer;
return {
kind: "applied",
targets: [documentTarget(tool)],
...(fields === undefined ? {} : { fields, pointers: true }),
...(fields === undefined || replaced === undefined
? {}
: { overwrites: [replaced] }),
};
};
2 changes: 2 additions & 0 deletions src/domain/analysisView/environmentStateWriteEffects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ export type EffectResult =
readonly fields?: readonly string[];
/** Set when the fields are a document's pointers, each covering the members under it. */
readonly pointers?: boolean;
/** A document replacement's object, as a pointer: it overwrites every earlier effect under it, though it claims only its members. */
readonly overwrites?: readonly string[];
/** The fields an update sent or changed, derived ones included, and those of them its increments add to. */
readonly changed?: {
readonly fields: readonly string[];
Expand Down
16 changes: 16 additions & 0 deletions src/domain/analysisView/environmentStateWrites.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,22 @@ describe("served write plans", () => {
});
});

it("starts no clock when a recorded time lies past the range of a date", () => {
const state = stateOf([
["GET", "/api/books", [FIRST_BOOK]],
["GET", "/api/books/1", FIRST_BOOK],
[
"PATCH",
"/api/books/1",
RENAMED_AT_3,
200,
{ name: "Renamed Book" },
9_000_000_000_000_000,
],
]);
expect(state.write_clock).toBeNull();
});

it("starts no clock on a record-order timeline, where no value is generated by a clock", () => {
const state = environmentStateViewOf(
rawCaptureEvidence(
Expand Down
7 changes: 4 additions & 3 deletions src/domain/analysisView/environmentStateWrites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ const clockStart = (
(latest, record) => Math.max(latest, record.end),
Number.NEGATIVE_INFINITY,
);
return Number.isFinite(end)
? new Date(Math.ceil(end / 1000) * 1000).toISOString()
: null;
if (!Number.isFinite(end)) return null;
const start = new Date(Math.ceil(end / 1000) * 1000);
// A recorded time past the range a date can hold gives no served clock.
return Number.isNaN(start.getTime()) ? null : start.toISOString();
};

/** The write plans a capture's own timeline confirms against an extracted state, and the served clock's start. */
Expand Down
Loading