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): share write overlap and check clocks on earlier calls
Observation search skips a read begun before the write ended. That
comparison now uses the same overlap as the check path.

A clock learned on a later call was not checked against earlier calls
that kept the field. Serving would stamp those calls too, so the plan
stays unserved. A clock learned earlier is still refused when a later
call does not advance it.

Regression tests cover an overlapping empty update and a published_at
clock that one recorded call leaves unchanged.

Co-authored-by: morluto <morluto@users.noreply.github.com>
  • Loading branch information
cursoragent and morluto committed Oct 21, 2026
commit fb6785dcafe5d4ab59eaabf503801d8e8a9767fa
115 changes: 115 additions & 0 deletions src/domain/analysisView/EnvironmentStateWriteSimulation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,97 @@ describe("slug rules learned from a later call", () => {
});
});

describe("clock rules learned across calls", () => {
it("serves a clock only when every recorded call changed that field", () => {
const oldFirst = "2026-10-01T09:00:00Z";
const oldSecond = "2026-10-01T10:00:00Z";
const described = (
entry: Book,
description: string,
publishedAt: string,
): Book => ({ ...entry, description, published_at: publishedAt });
const first = described(FIRST_BOOK, "original", oldFirst);
const second = described(SECOND_BOOK, "other", oldSecond);
const published = described(
renamedBook(FIRST_BOOK, "Renamed Book", 3),
"original",
bookClock(3),
);
/** The first call stamps `published_at`; `later` is the second call's answer. */
const rows = (later: Book, sent: Book): TimedCaptureRow[] => [
["GET", "/api/books", [first, second]],
["GET", "/api/books/1", first],
["GET", "/api/books/2", second],
["PATCH", "/api/books/1", published, 200, { name: "Renamed Book" }],
["GET", "/api/books/1", published],
["PATCH", "/api/books/2", later, 200, sent],
["GET", "/api/books/2", later],
];
// The description edit stamps `updated_at` and leaves `published_at` as it was.
const edited = described(
{ ...SECOND_BOOK, updated_at: bookClock(5) },
"revised",
oldSecond,
);
expect(
gated(rows(edited, { description: "revised" }), "patch_books_by_id"),
).toMatchObject({ served: false, reason: "unexplained-change" });
const stamped = described(
renamedBook(SECOND_BOOK, "Second Edition", 5),
"other",
bookClock(5),
);
const plan = gated(
rows(stamped, { name: "Second Edition" }),
"patch_books_by_id",
);
expect(plan).toMatchObject({
served: true,
checked_record_ordinals: [4, 6],
});
expect(plan.rules).toContainEqual({
field: "published_at",
rule: "clock",
format: { kind: "iso", separator: "T", fraction: 0, zone: "Z" },
});
});

it("leaves a clock unserved when an earlier call kept the field a later call stamped", () => {
const oldFirst = "2026-10-01T09:00:00Z";
const oldSecond = "2026-10-01T10:00:00Z";
const described = (
entry: Book,
description: string,
publishedAt: string,
): Book => ({ ...entry, description, published_at: publishedAt });
const first = described(FIRST_BOOK, "original", oldFirst);
const second = described(SECOND_BOOK, "other", oldSecond);
const edited = described(
{ ...SECOND_BOOK, updated_at: bookClock(3) },
"revised",
oldSecond,
);
const published = described(
renamedBook(FIRST_BOOK, "Renamed Book", 5),
"original",
bookClock(5),
);
const rows: TimedCaptureRow[] = [
["GET", "/api/books", [first, second]],
["GET", "/api/books/1", first],
["GET", "/api/books/2", second],
["PATCH", "/api/books/2", edited, 200, { description: "revised" }],
["GET", "/api/books/2", edited],
["PATCH", "/api/books/1", published, 200, { name: "Renamed Book" }],
["GET", "/api/books/1", published],
];
expect(gated(rows, "patch_books_by_id")).toMatchObject({
served: false,
reason: "unexplained-change",
});
});
});

describe("checked lines", () => {
/** A list page that echoes its own request path, as some APIs do. */
const page = (path: string, items: JsonValue[]): JsonValue => ({
Expand Down Expand Up @@ -1057,6 +1148,30 @@ describe("what a check leaves pending", () => {
});
});

it("learns an update from a read begun after the write, not from one that overlapped it", () => {
const named = (name: string) => ({ id: 1, name });
const other = { id: 2, name: "B" };
const rows: TimedCaptureRow[] = [
["GET", "/api/books", [named("A"), other]],
["GET", "/api/books/1", named("A")],
["GET", "/api/books/2", other],
// The patch runs from second 3 to 5.5 and returns no entity. A read begun while it still runs shows the old name.
["PATCH", "/api/books/1", "", 204, { name: "Z" }, 2500],
["GET", "/api/books/1", named("A")],
["GET", "/api/books/1", named("A")],
["GET", "/api/books/1", named("Z")],
["GET", "/api/books", [named("Z"), other]],
];
expect(gated(rows, "patch_books_by_id")).toMatchObject({
served: true,
observation: { ordinal: 6, pointer: "" },
body: { accepted: ["name"], fixed: [] },
rules: [{ field: "name", rule: "echo" }],
checked_record_ordinals: [7],
contradicted_by: null,
});
});

it("checks nothing by a range read the collection has outgrown", () => {
const rows: TimedCaptureRow[] = [
["GET", "/api/books?_start=0&_end=2", [FIRST_BOOK, SECOND_BOOK]],
Expand Down
6 changes: 5 additions & 1 deletion src/domain/analysisView/environmentStateWriteAttribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ export type PendingTargets = Map<
{ until: number; readonly at: Map<string, number> }
>;

/** Whether a write that ended at `until` was still running when a read began at `start`, so the read may show either state. */
export const overlapsWrite = (until: number, start: number): boolean =>
until > start;

/** Whether a modelled write to the target was still running when a read began at `start`, so the read may show either state. */
export const runningAt = (
pending: PendingTargets,
key: string,
start: number,
): boolean => (pending.get(key)?.until ?? -Infinity) > start;
): boolean => overlapsWrite(pending.get(key)?.until ?? -Infinity, start);

/** The tools whose writes a read exercises: those that changed its targets since they were last checked, less those that borrowed the read to learn their effect. */
export const exercisedBy = (
Expand Down
4 changes: 3 additions & 1 deletion src/domain/analysisView/environmentStateWriteEffects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,15 @@ const contradictsEarlierCalls = (
const ruled = new Set(draft.plan.rules.map((rule) => rule.field));
return rules.some(
(rule) =>
unsentChange(rule) &&
(unsentChange(rule) || rule.rule === "clock") &&
!ruled.has(rule.field) &&
draft.updates.some(({ shown, sent }) => {
// An unruled field an earlier call showed is one it left as it was.
const value = shown.get(rule.field);
if (value === undefined) return false;
if (rule.rule === "increment") return integerOf(value) !== undefined;
// Serving stamps a clock on every call, so a field an earlier call kept contradicts it.
if (rule.rule === "clock") return true;
const from = rule.rule === "slug" ? sent.get(rule.from) : undefined;
return typeof from === "string" && slugOf(from) !== value;
}),
Expand Down
8 changes: 6 additions & 2 deletions src/domain/analysisView/environmentStateWriteObserve.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { JsonValue } from "../jsonValue.js";
import { overlapsWrite } from "./environmentStateWriteAttribution.js";
import {
collectionPathOf,
isObject,
Expand Down Expand Up @@ -62,7 +63,7 @@ export const newEntityIn = (
export interface ObservationSearch {
readonly records: readonly StateRecordFacts[];
readonly from: number;
/** A timed write's completion; reads begun before it cannot observe its effect. */
/** A timed write's completion. A read begun while it still ran may show the prior state. */
readonly after?: number;
readonly viewOf: (ordinal: number) => StateView | undefined;
readonly withBody: <T>(
Expand All @@ -77,6 +78,7 @@ const succeeded = (record: StateRecordFacts): boolean =>
/**
* The first later read, before the next write, that shows a written entity: an item read of
* `id` when given, else an item read of an unheld id or a collection read listing exactly one.
* A read begun while the write still ran may show the earlier state, so it is not chosen.
*/
export const laterObservation = (
search: ObservationSearch,
Expand All @@ -93,7 +95,9 @@ export const laterObservation = (
): Observed | undefined => {
for (const record of search.records.slice(search.from + 1)) {
if (target.isWrite(record)) return undefined;
if (search.after !== undefined && record.start < search.after) continue;
// The same overlap the check path ignores: the write was still running when this read began.
if (search.after !== undefined && overlapsWrite(search.after, record.start))
continue;
const view = search.viewOf(record.ordinal);
if (
!succeeded(record) ||
Expand Down
Loading