Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 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
9f60e54
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
e96484b
Merge main (#5319 squashed, #5349) into feat/environment-state-serve
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
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
5a61853
fix(environment): release batch replies as they are encoded; judge ex…
earakely-scale Oct 20, 2026
c00fde4
fix(environment): keep room for refusals and framing in the reply budget
earakely-scale Oct 20, 2026
25b6622
chore: merge main (335c042d) into environment state serve
earakely-scale Oct 21, 2026
6b8db19
fix(environment): refuse a loaded state that data/get would write pas…
earakely-scale Oct 21, 2026
31a618e
chore: merge main (d9767eb4) into environment state serve
cursoragent Oct 21, 2026
96ce6c6
fix(environment): keep merged export checks on the shared test graph
cursoragent Oct 21, 2026
bfe9d4b
chore: merge main into environment state serve
morluto Oct 21, 2026
0da8e23
fix(environment): keep a state file whose close failed owned until it…
earakely-scale Oct 21, 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 bodies too deep for the state's nesting out of…
… the state

A recorded body at the JSON depth limit was accepted by extraction, then
nested a few levels deeper as a document or entity value, so sealing the
state Evidence threw and environment-serve and environment-export stopped
instead of falling back. stateBodyJson, the one rule extraction and
serving share, now treats a body nesting deeper than the limit minus 16
levels as unusable, so its tool stays a recorded view.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Loading branch information
earakely-scale and claude committed Oct 20, 2026
commit d9c0357b2a5a0c50fa9a7955edfc54895fa847ca
9 changes: 9 additions & 0 deletions docs/specs/agent-environments/state-serve/verification.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,12 @@ any path conversion on every platform), a real `https://` download (tests
inject the fetcher), the memory and time of a budgeted batch (not measured),
agent token usage, a real AgentEnv framework run, a real-world capture, and
write effects, which are a later increment.

After refusing bodies too deep for the state's own nesting (a recorded body
must nest at most the JSON depth limit minus 16 levels to enter the state):
`npm run check:fast`, `npm run format:check`, `npx knip`, `npm run scan:todos`
passed; `npm run jscpd`: 3.37% over 3373 files; `npx vitest run --project
domain --project services`: 347 files, 5950 tests passed, 5 pre-existing
skips; `npm run build:cached`, then `npm run test:focused --` the serve CLI,
MCP and process boundaries, the export CLI boundary and the two serve adapter
tests: 6 files, 48 tests passed.
23 changes: 23 additions & 0 deletions src/application/environment/environmentState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from "../../../tests/fixtures/environmentServe.js";
import { AnalysisInputError } from "../../domain/analysisErrorCore.js";
import { projectAnalysisError } from "../../domain/analysisErrorProjection.js";
import type { JsonValue } from "../../domain/jsonValue.js";
import {
inspectAnalysisView,
inspectAnalysisViewValidated,
Expand Down Expand Up @@ -226,6 +227,28 @@ describe("prepareServedState", () => {
});
});

it("derives a state when a body leaves no room for the state's own nesting", () => {
let deep: JsonValue = { theme: "dark" };
for (let level = 0; level < 995; level += 1) deep = { nested: deep };
const deepFixture = environmentStateServeFixture(
timedCaptureEvidence([
["GET", "/api/settings", deep],
["PUT", "/api/settings", { theme: "light" }],
]),
);
const deepSource = loadEnvironmentSource(
deepFixture.manifest,
deepFixture.capture,
);
if (!deepSource.ok) throw deepSource.error;
expect(
prepareServedState(deepSource.value, deepFixture.capture).report,
).toEqual({
served: true,
evidence_id: deepFixture.state.evidence_id,
});
});

it("serves replay and reports the code and message when the capture yields a manifest but no state", () => {
const headerOnly = scenarioServeFixture(
scenarioHeaderOnlyCaptureEvidence(),
Expand Down
16 changes: 14 additions & 2 deletions src/domain/analysisView/EnvironmentStateAccumulator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from "zod";
import type { AnalysisError } from "../analysisErrorBase.js";
import { parseExactJson } from "../exactJsonNumber.js";
import type { JsonValue } from "../jsonValue.js";
import { MAX_JSON_DEPTH, type JsonValue } from "../jsonValue.js";
import { ok, type Result } from "../result.js";
import {
WEB_NETWORK_CAPTURE_LIMITS,
Expand All @@ -15,6 +15,7 @@ import {
import { EnvironmentStateExtraction } from "./EnvironmentStateExtraction.js";
import type { TemplateRule } from "./environmentManifestRules.js";
import {
deeperThan,
hasPrototypeKey,
isStateWrite,
type ParsedBody,
Expand Down Expand Up @@ -52,6 +53,13 @@ type StateFields = Pick<
/** Bodies beyond this many UTF-8 bytes are not parsed into state; their views stay recorded. */
export const STATE_BODY_LIMIT_BYTES = 256 * 1024;

/**
* Levels the state's own nesting adds above a recorded value: Evidence, a `data/get` reply and a
* JSON-RPC response hold a body's members about ten levels down, so a body must leave this much
* room under the JSON depth limit to be sealed and served.
*/
const STATE_NESTING_DEPTH = 16;

/** A recorded response body as state JSON: a JSON-like media type, complete UTF-8 text within the state body limit, exact numbers and no `__proto__` member; otherwise undefined. */
export const stateBodyJson = (
contentType: string | null,
Expand All @@ -67,7 +75,11 @@ export const stateBodyJson = (
)
return undefined;
const value = parseExactJson(body.bodyText);
return value === undefined || hasPrototypeKey(value) ? undefined : value;
return value === undefined ||
hasPrototypeKey(value) ||
deeperThan(value, MAX_JSON_DEPTH - STATE_NESTING_DEPTH)
? undefined
: value;
};

const timingSchema = z.object({
Expand Down
18 changes: 18 additions & 0 deletions src/domain/analysisView/environmentStateRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,24 @@ export const jsonBytes = (value: JsonValue): number => {
return ENTRY_BYTES;
};

/** Whether a JSON value nests more than `limit` levels below its root. */
export const deeperThan = (value: JsonValue, limit: number): boolean => {
const pending: { readonly value: JsonValue; readonly depth: number }[] = [
{ value, depth: 0 },
];
for (let next = pending.pop(); next !== undefined; next = pending.pop()) {
if (next.depth > limit) return true;
const children = Array.isArray(next.value)
? next.value
: isObject(next.value)
? Object.values(next.value)
: [];
for (const child of children)
pending.push({ value: child, depth: next.depth + 1 });
}
return false;
};

/** JSON parsers keep a `__proto__` member that plain object construction would turn into a prototype. */
export const hasPrototypeKey = (value: JsonValue): boolean =>
Array.isArray(value)
Expand Down
17 changes: 17 additions & 0 deletions src/domain/analysisView/environmentStateView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,23 @@ it("leaves recorded the views it cannot reproduce, with the reason", () => {
expect(state.entities).toEqual([]);
});

it("leaves a body too deep for the state's own nesting recorded instead of failing to seal", () => {
let deep: JsonValue = { theme: "dark" };
for (let level = 0; level < 995; level += 1) deep = { nested: deep };
const state = stateOf(
captureOf([
["GET", "/api/settings", deep],
["PUT", "/api/settings", { theme: "light" }],
]),
);
expect(state.documents).toEqual([]);
expect(viewOf(state, "get_settings")).toEqual({
tool: "get_settings",
shape: "recorded",
reason: "body-unusable",
});
});

it("holds a written path's non-entity read as a document", () => {
const state = stateOf(
captureOf([
Expand Down
Loading