Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 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
98a7511
fix(environment): attempt all state cleanup on close
morluto Oct 21, 2026
d681bfd
fix(environment): bound wide state JSON traversal
morluto Oct 21, 2026
e4a0fc6
chore: merge current main into state server fixes
morluto Oct 21, 2026
467828e
fix(environment): scope cached state reply sizes to requests
morluto Oct 21, 2026
05deae3
fix(domain): preserve JSON depth diagnostic guidance
morluto Oct 21, 2026
7c3d0e9
chore: merge current main into state server fixes
morluto 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): bound state at redacted writes; infer identity only…
… from items

A scenario write whose URL was redacted has no request line, so it was
dropped and reads after it counted as initial state. Such a successful
write now joins the timeline with an empty path, whose root relates to
every type, so it ends every type's state; a limitation counts them.

A list whose recordings were all empty passed the "every listed item
carries it" check vacuously and published an identity field nothing
showed; it now needs at least one item, else the view stays recorded
as no-identity.

A value that differed between two request lines of one item tool, such
as a query variant, was called volatile, and the gate then substituted
each recording's own value; only repeats of one request line now show
volatility, so differing lines go through fields-differ.

List membership is compared only while a list can still be the whole
collection, and merged entities are indexed by type and collection once,
so paged captures no longer cost pages times entities (8,000 pages of
40,000 entities: 5.7 s to 0.23 s).

Docs and the tool contract say scenario state keeps the capture's
redaction markers and how redacted writes bound it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Loading branch information
earakely-scale and claude committed Oct 20, 2026
commit f2c9a2e4462a7162224bec209f21dfa2622abe39
11 changes: 6 additions & 5 deletions docs/specs/agent-environments/state-view/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ later increments.
- Order primary-origin records by recorded start time, or by record order when
any start time is missing, and say which. Bound each type's state by the first
write under its root (API base, version segments, one segment); a query
`POST` is not a write, and a read overlapping the write is left out.
`POST` is not a write, a read overlapping the write is left out, and a write
whose URL was redacted bounds every type, with a limitation counting it.
- Prove an item type's identity field from the requested path value its
responses repeat; otherwise infer it from a fixed list of identity names that
every listed item carries distinctly. Never treat an envelope that is itself
an entity as a list.
every listed item carries distinctly, which needs at least one listed item.
Never treat an envelope that is itself an entity as a list.
- Merge observations into one entity per collection and identity: item views'
latest values win over list views', differing views keep their own values,
and a value that changed with no related write is volatile and keeps the
latest.
and a value that changed between repeats of one request line with no related
write is volatile and keeps the latest.
- Keep an item or list plan only when it reproduces each request line's latest
initial recording from the state, comparing JSON values without regard to
member order; otherwise record the tool with a reason. Parse bodies only when
Expand Down
6 changes: 5 additions & 1 deletion docs/web-network-captures.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,11 @@ path has a segment such as `search`, `query`, `list`, `find`, `fuzzy`,
successful reads that finished before the first such write under the same root:
the path's API base (the literal segments every tool sharing its first segment
has), any `v1`-style version segments, then one more segment. A read that
overlaps that write in time is left out.
overlaps that write in time is left out. A write whose URL a scenario redacted
has an unknown target, so it ends the state of every type, and a limitation
counts such writes. Values from a `capture_browser_scenario` parent keep the
capture's redaction markers in place of declared secrets; the state is not
refused for them, as the manifest is not.

Each `GET` tool whose template ends in a parameter is an item tool, and its
type's `collection_template` is the template without that parameter; any other
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/analysisViewToolContracts.ts

Large diffs are not rendered by default.

69 changes: 61 additions & 8 deletions src/domain/analysisView/EnvironmentStateAccumulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import {
} from "./EnvironmentManifestAccumulator.js";
import { EnvironmentStateExtraction } from "./EnvironmentStateExtraction.js";
import type { TemplateRule } from "./environmentManifestRules.js";
import type {
ParsedBody,
StateRecordFacts,
StateTimeline,
import {
isStateWrite,
type ParsedBody,
type StateRecordFacts,
type StateTimeline,
} from "./environmentStateRules.js";
import {
base64PrefixChars,
Expand Down Expand Up @@ -52,13 +53,18 @@ const timingSchema = z.object({
startedDateTime: z.string(),
time: z.number().nonnegative(),
});
const redactedWriteSchema = z.object({
request: z.object({ method: z.string() }),
response: z.object({ status: z.number() }).optional(),
});
const contentSchema = z.object({
response: z.object({ content: z.object({ text: z.string() }) }),
});

interface RecordEntry {
readonly facts: StateRecordFacts;
readonly origin: string;
/** Null for a write whose URL was redacted: its target is unknown, so it bounds every type. */
readonly origin: string | null;
readonly contentType: string;
readonly timed: boolean;
readonly record: WebNetworkCaptureRecord;
Expand Down Expand Up @@ -104,11 +110,20 @@ export class EnvironmentStateAccumulator extends EnvironmentManifestAccumulator
try {
const line = readRecordedRequestLine(record.reported, true, this.scratch);
if (line === null) return this.overBudget();
if (line.kind === "excluded") return ok(undefined);
const timing = timingSchema.safeParse(record.reported);
const start = timing.success
? Date.parse(timing.data.startedDateTime)
: Number.NaN;
const timed = timing.success && Number.isFinite(start);
if (line.kind === "excluded")
return line.reason === "url-redacted"
? this.#redactedWrite(
record,
timing.success && timed
? { start, end: start + timing.data.time }
: undefined,
)
: ok(undefined);
// The entry keeps the line's strings and a reference to the already admitted record.
if (
!this.retain(
Expand All @@ -123,7 +138,6 @@ export class EnvironmentStateAccumulator extends EnvironmentManifestAccumulator
)
)
return this.overBudget();
const timed = timing.success && Number.isFinite(start);
this.#entries.set(record.ordinal, {
facts: {
ordinal: record.ordinal,
Expand All @@ -145,6 +159,36 @@ export class EnvironmentStateAccumulator extends EnvironmentManifestAccumulator
}
}

/** Keep a successful write whose URL was redacted, with an empty path whose root relates to every type. */
#redactedWrite(
record: WebNetworkCaptureRecord,
timing: { readonly start: number; readonly end: number } | undefined,
): Result<void, AnalysisError> {
const parsed = redactedWriteSchema.safeParse(record.reported);
if (!parsed.success) return ok(undefined);
const status = parsed.data.response?.status ?? 0;
const facts: StateRecordFacts = {
ordinal: record.ordinal,
method: parsed.data.request.method,
path: "",
query: undefined,
status: status > 0 ? status : null,
start: timing?.start ?? record.ordinal,
end: timing?.end ?? record.ordinal,
};
if (!isStateWrite(facts)) return ok(undefined);
if (!this.retain(ENTRY_BYTES * 8 + textBytes(facts.method.length)))
return this.overBudget();
this.#entries.set(record.ordinal, {
facts,
origin: null,
contentType: "",
timed: timing !== undefined,
record,
});
return ok(undefined);
}

/** Parse one retained response body as exact JSON, charging its decoding and tree as temporary work. */
#body(ordinal: number): ParsedBody | null {
const entry = this.#entries.get(ordinal);
Expand Down Expand Up @@ -175,8 +219,12 @@ export class EnvironmentStateAccumulator extends EnvironmentManifestAccumulator
const manifest = this.finish();
if (!manifest.ok) return manifest;
const entries = [...this.#entries.values()].filter(
(entry) => entry.origin === manifest.value.origin,
(entry) =>
entry.origin === manifest.value.origin || entry.origin === null,
);
const redactedWrites = entries.filter(
(entry) => entry.origin === null,
).length;
const timeline: StateTimeline =
entries.length > 0 && entries.every((entry) => entry.timed)
? "recorded-start-time"
Expand Down Expand Up @@ -205,6 +253,11 @@ export class EnvironmentStateAccumulator extends EnvironmentManifestAccumulator
}).run();
if (state === null) return this.overBudget();
const limitations = this.addLimitations([
...(redactedWrites > 0
? [
`${String(redactedWrites)} of the recorded writes had a redacted URL; each ends the initial state of every type, since its target is unknown.`,
]
: []),
...(timeline === "record-order"
? [
"Some records carry no start time, so the state's timeline is record order and overlapping requests are not detected.",
Expand Down
31 changes: 26 additions & 5 deletions src/domain/analysisView/EnvironmentStateExtraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export class EnvironmentStateExtraction {
readonly #entities = new Map<string, ObservedEntity>();
readonly #volatile = new Map<string, Set<string>>();
readonly #merged = new Map<string, StateEntity>();
/** Merged entities by type and collection, built once on first use after merging. */
#collections: Map<string, StateEntity[]> | undefined;

constructor(input: {
readonly tools: readonly StateToolFacts[];
Expand Down Expand Up @@ -280,6 +282,7 @@ export class EnvironmentStateExtraction {
const proved = this.#identity.get(type)?.field;
let pointer: string | undefined;
let names: readonly string[] | undefined;
let sawItems = false;
for (const record of recordings) {
const found = this.#withBody(record.ordinal, (body) => {
if (body === undefined) return null;
Expand All @@ -288,6 +291,7 @@ export class EnvironmentStateExtraction {
located === undefined ? undefined : listItems(body, located);
if (items === undefined) return undefined;
pointer = located;
if (items.length > 0) sawItems = true;
return items.length === 0
? (names ?? (proved === undefined ? IDENTITY_NAMES : [proved]))
: (proved === undefined ? IDENTITY_NAMES : [proved]).filter((name) =>
Expand All @@ -301,7 +305,12 @@ export class EnvironmentStateExtraction {
names = (names ?? found).filter((name) => found.includes(name));
}
const field = names?.[0];
if (field === undefined || pointer === undefined) {
// An identity name is only inferred from items that carry it; empty lists prove none.
if (
field === undefined ||
pointer === undefined ||
(proved === undefined && !sawItems)
) {
this.#recorded(tool, "no-identity");
return;
}
Expand Down Expand Up @@ -351,8 +360,12 @@ export class EnvironmentStateExtraction {
};
this.#entities.set(key, entity);
}
// Only a repeated request line shows a value changing; other lines may differ by query.
const line = requestLine(record);
const earlier = entity.observations.findLast(
(observation) => observation.tool === plan.tool.name,
(observation) =>
observation.tool === plan.tool.name &&
requestLine(this.#byOrdinal.get(observation.ordinal)!) === line,
);
for (const name of Object.keys(object))
if (
Expand Down Expand Up @@ -400,9 +413,17 @@ export class EnvironmentStateExtraction {
}

#inCollection(type: string, collection: string): StateEntity[] {
return [...this.#merged.values()].filter(
(entity) => entity.type === type && entity.collection === collection,
);
if (this.#collections === undefined) {
this.#retain(ENTRY_BYTES * (this.#merged.size + 1));
this.#collections = new Map();
for (const entity of this.#merged.values()) {
const key = JSON.stringify([entity.type, entity.collection]);
const members = this.#collections.get(key);
if (members === undefined) this.#collections.set(key, [entity]);
else members.push(entity);
}
}
return this.#collections.get(JSON.stringify([type, collection])) ?? [];
}

/** A written path whose read is not an entity holds one document value: its latest init recording. */
Expand Down
13 changes: 8 additions & 5 deletions src/domain/analysisView/environmentStateGate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,14 @@ const listFacts = (
body === undefined ? undefined : listItems(body, plan.pointer);
if (body === undefined || items === undefined) return;
items.forEach((item) => union.add(item));
const ids = items.map((item) => scalarText(item[field]) ?? "");
const expected = context
.inCollection(plan.type, collectionPathOf(record, false))
.map((entity) => entity.id);
if (record.query !== undefined || !same(ids, expected)) all = false;
// Once a list cannot be the whole collection, its membership is not compared again.
if (all && record.query === undefined) {
const ids = items.map((item) => scalarText(item[field]) ?? "");
const expected = context
.inCollection(plan.type, collectionPathOf(record, false))
.map((entity) => entity.id);
if (!same(ids, expected)) all = false;
} else all = false;
const parent = plan.pointer === "" || !isObject(body) ? {} : body;
const names = Object.keys(parent).filter(
(name) => /total|count/iu.test(name) && parent[name] === items.length,
Expand Down
44 changes: 44 additions & 0 deletions src/domain/analysisView/environmentStateView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,47 @@ it("refuses when extraction would exceed the projection budget", () => {
},
});
});

it("ends every type's state at a write whose URL was redacted, and says so", () => {
const parent = captureOf([
["GET", "/api/items/1", { id: 1, title: "Granite Ledger" }],
["PUT", "/api/items/1", { id: 1 }],
["GET", "/api/items/1", { id: 1, title: "Saltmarsh Depot" }],
]);
const result = structuredClone(parent.normalizedResult) as {
records: { reported: { request: { url: string | null } } }[];
};
// A scenario keeps a redacted URL as null, so the write's target is unknown.
result.records[1]!.reported.request.url = null;
const state = stateOf({ ...parent, normalizedResult: result });
expect(state.types).toMatchObject([{ init_before_ordinal: 1 }]);
expect(state.entities).toMatchObject([
{ fields: { title: "Granite Ledger" }, record_ordinals: [0] },
]);
expect(state.limitations).toContain(
"1 of the recorded writes had a redacted URL; each ends the initial state of every type, since its target is unknown.",
);
});

it("infers no identity for a list whose recordings held no items", () => {
const state = stateOf(captureOf([["GET", "/api/widgets", []]]));
expect(state.types).toEqual([]);
expect(state.views).toEqual([
{ tool: "get_widgets", shape: "recorded", reason: "no-identity" },
]);
});

it("does not call a value volatile when it differs between request lines", () => {
const state = stateOf(
captureOf([
["GET", "/api/items/1?lang=fr", { id: 1, name: "Bonjour" }],
["GET", "/api/items/1", { id: 1, name: "Hello" }],
]),
);
expect(state.types).toEqual([]);
expect(
state.views.map((view) =>
view.shape === "recorded" ? [view.tool, view.reason] : view.tool,
),
).toEqual([["get_items_by_id", "fields-differ"]]);
});
Loading