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): keep rendered documents and quoted samples inside t…
…heir budgets

A recorded body of exponential numbers can render past 256 KiB and turn a
working read into a state size error, so that document stays a recorded replay.
Description samples are measured after JSON quoting, and the replay-fallback
catalog check uses a tool count the longer response descriptions still separate.

Co-authored-by: morluto <morluto@users.noreply.github.com>
  • Loading branch information
cursoragent and morluto committed Oct 21, 2026
commit 378a109cc62edda924510c24122386ee69b06917
4 changes: 3 additions & 1 deletion docs/agent-environments.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,9 @@ naming the entity, collection or document path, or `{"source": "recording",
"reason": …}` with the view's reason, `no-view` or `unrecorded-request`. A
state answer carries the base record's status, content type and `replay`
provenance with `truncated: false`; one whose JSON would exceed 256 KiB is
refused as a `resource_constraint` tool error rather than cut. Serving is
refused as a `resource_constraint` tool error rather than cut. Extraction does
not state-back a document whose rendered JSON exceeds 256 KiB; that read stays
recorded (`rendered-oversize`) and replays the captured body. Serving is
read-only: `POST`, `PUT`, `PATCH` and `DELETE` tools, other than query `POST`s,
are not served, so nothing a call does changes the state. Query `POST`s stay
served and answer from their recordings with the reason `query-body`.
Expand Down
17 changes: 11 additions & 6 deletions docs/specs/agent-environments/state-coverage/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ tool, view kind, provider, network activity or write effect.
item or list plan holds its latest initial value as a `document` when its
initial reads have one request line, whether or not the capture writes its
path, unless its value changed between two of those reads across any
recorded write (even under another root), which leaves it `fields-differ`. More request lines give `path-varies` when they differ by path (a
template with a parameter before its end) and `query-varies` when they share
one path. With every such read now a document, `path-varies`, `query-varies`
or `body-unusable`, the unreachable `not-entity` reason leaves the result
recorded write (even under another root), which leaves it `fields-differ`. A
value whose rendered JSON exceeds 256 KiB stays `rendered-oversize` and is
replayed from the recorded body, which itself fit. More request lines give
`path-varies` when they differ by path (a template with a parameter before
its end) and `query-varies` when they share one path. With every such read
now a document, `path-varies`, `query-varies`, `body-unusable` or
`rendered-oversize`, the unreachable `not-entity` reason leaves the result
schema, and `no-identity` names item tools only. A document holds the value
of its one `path`.
- When no path parameter proves an identity and no identity name identifies
Expand Down Expand Up @@ -80,8 +83,10 @@ Grafana-shaped fixture covers documents for its read-only paths (its one-member
team list among them) and object, array and enveloped-list descriptions;
synthetic sources cover the `2xx` preference over an earlier error body, the
first of several JSON records, the labelled fallback, the manifest's statuses,
empty, scalar and fieldless bodies, a truncated member name, non-JSON bodies
and the catalog budget; the in-process and compiled MCP servers advertise the
empty, scalar and fieldless bodies, a truncated member name, a name whose
JSON quoting exceeds the sample, a recorded body under 256 KiB whose rendered
JSON exceeds it, non-JSON bodies and the catalog budget; the in-process and
compiled MCP servers advertise the
hints. A filtered list may still answer with one element whose identity name
repeats the requested value; list filters, pagination, lossless big integers
and cross-endpoint entity linking remain out of scope. Documents inline whole
Expand Down
9 changes: 5 additions & 4 deletions docs/web-network-captures.md
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,9 @@ with reason `envelope-varies`, `fields-differ` or `list-differs`; the other
reasons are `query-body` (a query `POST`), `no-init-recording`,
`body-unusable`, `no-identity` (an item read without a proved identity),
`path-varies` (another read under more than one path, as a template with a
parameter before its end) and `query-varies` (another read of one path under
more than one query). A document holds the value of its one `path`, so for such
parameter before its end), `query-varies` (another read of one path under
more than one query) and `rendered-oversize` (a document value whose JSON
renders to more than 256 KiB). A document holds the value of its one `path`, so for such
a template it says nothing about the template's other paths. A body is usable
when its content type is
JSON-like, it is UTF-8 text of at most 256 KiB, every number survives native
Expand All @@ -626,8 +627,8 @@ computes responses or derived values, and no effects of writes. The state
accumulator charges the manifest's admission and grouping, every record line,
each body as temporary bytes before it is decoded and parsed, and every value
it keeps, within the same 96 MiB budget. Documents hold whole recorded response
values of up to 256 KiB each, so a capture with many read-only paths yields a
correspondingly larger state result. The view performs no network activity
values whose recorded text and rendered JSON are each at most 256 KiB, so a
capture with many read-only paths yields a correspondingly larger state result. The view performs no network activity
and serves nothing; `rea environment-serve` derives it from the capture at
startup, serves read tools from it and loads replacement states through the
AgentEnv data plane, as
Expand Down
5 changes: 3 additions & 2 deletions src/application/environment/environmentBundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,11 @@ describe("planEnvironmentBundle without a state", () => {

it("serves and predicts replay when the state's catalog exceeds the discovery budget that replay's fits", () => {
// Read tools only, so leaving out write tools saves nothing while each state description is longer.
// 300 sits between the two catalogs on this fixture: replay still fits and the state catalog does not.
const reads = servedSource.manifest.tools.filter(
({ method }) => method === "GET",
);
const tools = Array.from({ length: 350 }, (_, index) => {
const tools = Array.from({ length: 300 }, (_, index) => {
const tool = reads[index % reads.length]!;
return index < reads.length
? tool
Expand All @@ -416,7 +417,7 @@ describe("planEnvironmentBundle without a state", () => {
served: false,
code: "resource_constraint",
});
expect(planned.value.toolCount).toBe(350);
expect(planned.value.toolCount).toBe(300);
expect(planned.value.check).toEqual({
tool: "get_annotations",
recordOrdinal: 25,
Expand Down
6 changes: 3 additions & 3 deletions src/application/environment/environmentState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,12 +485,12 @@ describe("rea-state/v1 validation", () => {
"a document for a tool that is not a document view",
(document: Editable) => {
document.rea_state.documents.push({
tool: "get_org",
path: "/api/org",
tool: "get_folders",
path: "/api/folders",
value: {},
});
},
"rea_state/documents/0/tool",
`rea_state/documents/${String(state.documents.length)}/tool`,
],
[
"a member the format does not define",
Expand Down
11 changes: 11 additions & 0 deletions src/application/environment/environmentStateAnswer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,17 @@ describe("recorded and document answers", () => {
});
});

it("replays a read whose rendered document exceeds the body limit", () => {
const values = Array.from({ length: 60_000 }, () => "1e3").join(",");
const body = `{"values":[${values}]}`;
const serving = servingFrom([["GET", "/api/config", body]]);
expect(serving.store.state.documents).toEqual([]);
expect(answer(serving, "get_config", {})).toMatchObject({
replay: { record_ordinal: 0 },
state: { source: "recording", reason: "rendered-oversize" },
});
});

it("answers a document's recorded line with the state's value for it", () => {
const capture = timedCaptureEvidence([
["GET", "/api/settings", { theme: "dark", density: "compact" }],
Expand Down
15 changes: 14 additions & 1 deletion src/application/environment/environmentTools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ describe("environment tool response shapes", () => {
{ bodyText: JSON.stringify({ [member]: [{ id: 1 }, { id: 2 }] }) },
]),
).toContain(
`{numeric}; returns a JSON object whose "${"m".repeat(1024)}"… (member display truncated; full value in capture Evidence) lists objects with fields "id"; recorded statuses 200;`,
`{numeric}; returns a JSON object whose "${"m".repeat(1022)}"… (member display truncated; full value in capture Evidence) lists objects with fields "id"; recorded statuses 200;`,
);
});

Expand Down Expand Up @@ -219,6 +219,19 @@ describe("environment tool response shapes", () => {
expect(shown).toContain('whose "items; recorded statuses 500\\nmmm');
expect(shown).not.toContain("items; recorded statuses 500\n");
});

it("applies the sample budget after JSON escaping", () => {
const member = "\u0000".repeat(1024);
const description = usersAnswering([
{ bodyText: JSON.stringify({ [member]: [{ id: 1 }] }) },
]);
const shown = /whose (?<name>"(?:\\u0000)*")/u.exec(description ?? "")
?.groups?.name;
expect(shown).toBeDefined();
expect(Buffer.byteLength(shown ?? "")).toBeLessThanOrEqual(1024);
expect(description).toContain("member display truncated");
expect(description).not.toContain("\u0000");
});
});

describe("environment tool response summaries", () => {
Expand Down
38 changes: 30 additions & 8 deletions src/application/environment/environmentTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,16 @@ const environmentToolAnnotations = ({
/** Agent-context budget for each captured display sample, excluding its provenance notice. */
const DESCRIPTION_SAMPLE_BYTES = 1024;

/** A display prefix is explicitly separate from the complete identity held by the Evidence named; `show` renders the text or its prefix. */
/** Whether a rendered sample fits the display budget. Callers' `show` never shortens its input. */
const sampleFits = (shown: string): boolean =>
shown.length <= DESCRIPTION_SAMPLE_BYTES &&
Buffer.byteLength(shown, "utf8") <= DESCRIPTION_SAMPLE_BYTES;

/**
* A display prefix is explicitly separate from the complete identity held by the Evidence named.
* `show` renders the text or its prefix. The budget applies to that rendering, so JSON quoting of a
* name full of NULs or newlines cannot outgrow the sample.
*/
const describeText = (
text: string,
label: string,
Expand All @@ -93,13 +102,26 @@ const describeText = (
if (
text.length <= DESCRIPTION_SAMPLE_BYTES &&
Buffer.byteLength(text, "utf8") <= DESCRIPTION_SAMPLE_BYTES
)
return show(text);
const { read } = new TextEncoder().encodeInto(
text,
new Uint8Array(DESCRIPTION_SAMPLE_BYTES),
);
return `${show(text.slice(0, read))}… (${label} display truncated; full value in ${holder})`;
) {
const shown = show(text);
if (sampleFits(shown)) return shown;
}
let low = 0;
let high = Math.min(text.length, DESCRIPTION_SAMPLE_BYTES);
let best = 0;
while (low <= high) {
const mid = (low + high) >> 1;
if (sampleFits(show(text.slice(0, mid)))) {
best = mid;
low = mid + 1;
} else high = mid - 1;
}
// A lone surrogate is not a character. Step off a high surrogate so the prefix stays whole.
if (best > 0 && best < text.length) {
const unit = text.charCodeAt(best - 1);
if (unit >= 0xd8_00 && unit <= 0xdb_ff) best -= 1;
}
return `${show(text.slice(0, best))}… (${label} display truncated; full value in ${holder})`;
};

/** Sample whole values before joining; keep full lists in the Evidence that owns them. */
Expand Down
4 changes: 2 additions & 2 deletions src/domain/analysisView/EnvironmentStateAccumulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
deeperThan,
hasPrototypeKey,
isStateWrite,
STATE_BODY_LIMIT_BYTES,
type ParsedBody,
type StateRecordFacts,
type StateTimeline,
Expand Down Expand Up @@ -50,8 +51,7 @@ type StateFields = Pick<
| "limitations"
>;

/** Bodies beyond this many UTF-8 bytes are not parsed into state; their views stay recorded. */
export const STATE_BODY_LIMIT_BYTES = 256 * 1024;
export { STATE_BODY_LIMIT_BYTES };

/**
* Levels the state's own nesting adds above a recorded value: Evidence, a `data/get` reply and a
Expand Down
11 changes: 11 additions & 0 deletions src/domain/analysisView/EnvironmentStateExtraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
isStateWrite,
jsonBytes,
lastSegmentValue,
STATE_BODY_LIMIT_BYTES,
listItems,
locateItem,
locateList,
Expand Down Expand Up @@ -553,6 +554,16 @@ export class EnvironmentStateExtraction {
this.#recorded(tool, "body-unusable");
continue;
}
// Parsing can lengthen a body that was admitted under the recorded-text limit:
// `1e3` is four bytes once rendered as `1000`. Serving refuses that rendering,
// so an oversized document stays the recorded replay instead of a failing read.
if (
Buffer.byteLength(JSON.stringify(value), "utf8") >
STATE_BODY_LIMIT_BYTES
) {
this.#recorded(tool, "rendered-oversize");
continue;
}
this.#retain(
ENTRY_BYTES + jsonBytes(value) + textBytes(record.path.length),
);
Expand Down
10 changes: 9 additions & 1 deletion src/domain/analysisView/environmentStateRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ export type RecordedViewReason =
| "query-varies"
| "fields-differ"
| "envelope-varies"
| "list-differs";
| "list-differs"
| "rendered-oversize";

/**
* Recorded response text, and a document value rendered back to JSON, stay within this many UTF-8
* bytes. A larger recorded body is not parsed; a parsed value whose JSON rendering exceeds it stays
* a recorded replay (`rendered-oversize`) rather than a document the server would have to refuse.
*/
export const STATE_BODY_LIMIT_BYTES = 256 * 1024;

export interface StateType {
readonly collection_template: string;
Expand Down
19 changes: 19 additions & 0 deletions src/domain/analysisView/environmentStateView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,25 @@ it("holds a read-only non-entity read as a document unless it varies by request
expect(state.types).toEqual([]);
});

it("leaves a document recorded when rendering it exceeds the body limit", () => {
const small = stateOf(
captureOf([["GET", "/api/config", '{"values":[1e3]}']]),
);
expect(viewOf(small, "get_config")).toMatchObject({ shape: "document" });
expect(small.documents[0]?.value).toEqual({ values: [1000] });
// 60,000 `1e3` tokens are 240,012 recorded bytes and 300,012 once rendered as `1000`.
const values = Array.from({ length: 60_000 }, () => "1e3").join(",");
const body = `{"values":[${values}]}`;
expect(Buffer.byteLength(body, "utf8")).toBe(240_012);
const state = stateOf(captureOf([["GET", "/api/config", body]]));
expect(state.documents).toEqual([]);
expect(viewOf(state, "get_config")).toEqual({
tool: "get_config",
shape: "recorded",
reason: "rendered-oversize",
});
});

it("infers a suffix-named identity only when no identity name identifies the listed items", () => {
const state = stateOf(
captureOf([
Expand Down
1 change: 1 addition & 0 deletions src/domain/analysisView/environmentStateView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const viewSchema = z.discriminatedUnion("shape", [
"fields-differ",
"envelope-varies",
"list-differs",
"rendered-oversize",
]),
}),
]);
Expand Down