Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
61d3536
feat(analysis-view): project an environment manifest from web network…
earakely-scale Oct 18, 2026
2d95597
test(web-network): check the manifest refusal text like the api-surfa…
earakely-scale Oct 18, 2026
6cb38b5
docs(specs): record the hosted web-network lane run for the manifest …
earakely-scale Oct 18, 2026
b6d18d2
docs(specs): reconcile the manifest view verification scope note with…
earakely-scale Oct 18, 2026
44203ec
fix(analysis-view): bound body, route and name work in the environmen…
earakely-scale Oct 18, 2026
bfe5a36
fix(analysis-view): keep manifest folding, naming and media-type read…
earakely-scale Oct 18, 2026
71d7513
fix(analysis-view): charge the manifest group key before building it
earakely-scale Oct 18, 2026
2679323
fix(analysis-view): accept a +json suffix only on application media t…
earakely-scale Oct 18, 2026
692453b
chore: merge main into environment manifest review
gensokyo-dev Oct 18, 2026
f73af11
fix(analysis-view): require the capture parent's exact subject for a …
earakely-scale Oct 18, 2026
d6cb57e
fix(analysis-view): share truncated suffix allocation work
gensokyo-dev Oct 18, 2026
99be275
chore: incorporate environment manifest review updates
gensokyo-dev Oct 18, 2026
dd87f54
fix(analysis-view): merge only identifier-like siblings under sibling…
earakely-scale Oct 18, 2026
ef47ead
chore: update environment manifest review from main
gensokyo-dev Oct 18, 2026
252b55d
fix(analysis-view): combine qualifying sibling cohorts
gensokyo-dev Oct 18, 2026
f2c3456
chore: refresh environment manifest validation from main
gensokyo-dev Oct 18, 2026
adbbbe5
docs(analysis-view): clarify opt-in sibling folding
gensokyo-dev Oct 18, 2026
494e015
chore: merge main (d1adc607) into the environment manifest view branch
earakely-scale Oct 18, 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(analysis-view): bound body, route and name work in the environmen…
…t manifest

Addresses the automated review findings on the PR: read request bodies at the
top level only instead of walking nested values; admit every literal route
part before materializing it; compare at most 32 segments in sibling-variance
and say so; keep stop words literal after a uid literal; keep the next
collision suffix per tool-name base; preserve a templated exclusion when two
groups print the same row.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
  • Loading branch information
earakely-scale and claude committed Oct 18, 2026
commit 44203ecd73d93ff1076f4bcd471824565f58abaf
10 changes: 6 additions & 4 deletions docs/specs/agent-environments/manifest-view/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,22 @@ manifest are later increments.
listed, each at most once, in that order, folding literal siblings of an
opt-in templated position into observed values whichever was recorded first,
never folding a literal into a format-rule parameter and never templating a
stop word.
stop word; `sibling-variance` compares routes of at most 32 segments and the
manifest states when a route exceeded that.
- Derive tool names from the method and route literals deterministically, at
most 60 characters, unique within one manifest.
- Derive `body_shape` for `POST`, `PUT` and `PATCH` from the tool's earliest
record when it carries a JSON-typed request body, as top-level key types
only; copy no header, cookie, query or body value anywhere in the result.
only without walking nested values; copy no header, cookie, query or body
value anywhere in the result.
- List records as pointers (`ordinal`, `method`, `path`, `status`,
`content_type`) and excluded groups with reason `other-origin`,
`ui-page-or-asset` or `non-json`.
- Mark the Evidence inferred whenever any tool or excluded group is templated,
derived otherwise; keep the parent's authority.
- Admit the capture clone, the inline envelope, every retained pointer, group,
observed value, query name and body-shape key before allocation, and charge
body parsing as temporary bytes, within the existing 96 MiB budget.
route part, observed value, query name and body-shape key before allocation,
and charge body parsing as temporary bytes, within the existing 96 MiB budget.

## Acceptance and limits

Expand Down
41 changes: 41 additions & 0 deletions docs/specs/agent-environments/manifest-view/verification.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,44 @@ the `cli-boundary` project was executing, and the clean 18aa9af2 export's
`npm ci`, build and test preparation overlapped the `mcp-boundary` and
`acceptance` runs, so those elapsed figures include host contention. Token usage and full process-family peak are
unmeasured. Local real-tool verification ran on macOS arm64; the hosted Linux lane result is recorded above.

## Automated review findings on the PR (2026-10-18)

Codex and Greptile left seven inline findings on morluto/rea#4954 at
b6d18d23; each was checked against the code and addressed in one follow-up
commit, with a regression test where the behaviour is observable:

- Body shapes walked nested values (both reviewers, P1): `#bodyShape` passed
the text to `inferJsonShape`, whose per-node path copies grow with the square
of depth, so a small deeply nested body could exceed the budget it had
reserved. The reader now parses once and reads top-level key types from the
parsed object; a test feeds a 2,500-level nested body and gets the four
top-level types back.
- Literal route parts were not admitted (Codex, P2): a path of many short
literal segments materialized one part object per segment without a charge.
Every route part is now charged before the group is created; a test shows a
5,000-segment path refused under a 1 MiB budget while a 100-segment path is
retained.
- `sibling-variance` rebuilt a key over the whole route at every position
(Greptile, P1): routes longer than 32 segments are no longer compared, the
manifest states it in a limitation, and a test shows two 39-segment siblings
left unmerged beside a merged short pair.
- `after-uid-literal` templated stop words (Greptile, P1): the rule now skips
them; a test keeps `/api/items/uid/search` literal beside
`/api/items/uid/{uid}`.
- Tool-name suffixes restarted at 2 on every collision (Greptile, P2): the
registry keeps the next suffix per base; a test projects 300 dotted literals
into `get_item` and `get_item_2` through `get_item_300`.
- An exclusion row could lose its templated flag when two groups printed the
same row (Codex, P2): the flag is now the logical or of both. The scenario
needs a literal segment spelled `{numeric}`, which the WHATWG URL parser
percent-encodes in recorded paths, so no capture reaches it; the one-line
defence is kept without a test.

Checks after the change: `oxfmt --check .` clean; `tsc --noEmit` clean;
`npm run lint` and `verify:module-boundaries` clean (the complexity warnings
on `#append` predate the change); `npx knip` no findings; `npm run jscpd`
3.35 % duplicated lines; `scan:todos` none; `verify:test-discovery` 1,580
files once; `vitest run` over the view, accumulator, JSON-shape and contract
example tests 32 passed in 4 files; `vitest run` over the service, CLI and
MCP boundary tests for analysis views 73 passed in 3 files.
18 changes: 10 additions & 8 deletions docs/web-network-captures.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ in this order:

| Rule | Applies to | Parameter |
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- |
| `after-uid-literal` | The literal segment right after a literal `uid` | `uid` |
| `after-uid-literal` | The literal segment right after a literal `uid`, unless it is a stop word | `uid` |
| `opaque-token` | A lowercase alphanumeric segment of twelve or more characters mixing letters and digits that is not a `v1`-style version | `uid` |
| `sibling-variance` | Groups equal in method, origin and segment count that differ in one literal at index 2 or later whose values are identifier-like (a digit or `:`, or three or more hyphenated names under a plural literal) and never a stop word | singular previous literal plus `_id`, else `id` |

Expand All @@ -379,10 +379,12 @@ cut to their first label, `_by_<params>` appended when parameters exist,
sanitized to `[a-z0-9_]`, at most 60 characters and made unique with numeric
suffixes: `get_dashboards_by_uid`, `get_plugins_settings_by_plugin_id`.

`body_shape` is derived for `POST`, `PUT` and `PATCH` from the tool's earliest
record when it carries an `application/json` or `application/*+json` request
body: top-level keys and their JSON type names, never values; a body on a later
record adds nothing. `unknowns` always states three facts: the authorization model, response
`sibling-variance` compares routes of at most 32 segments; longer routes keep
their grouped templates and the manifest says so in a limitation. `body_shape`
is derived for `POST`, `PUT` and `PATCH` from the tool's earliest record when it
carries an `application/json` or `application/*+json` request body: top-level
keys and their JSON type names, never values and never nested structure; a body
on a later record adds nothing. `unknowns` always states three facts: the authorization model, response
semantics and state transitions are not established by a capture.
`templated_groups` counts tools and excluded groups with a templated segment;
whenever it is nonzero the Evidence is inferred, otherwise derived. The view
Expand All @@ -392,9 +394,9 @@ typed unsupported errors as the api-surface view, including the canonical
token `sensitive_values_unretained`.

The manifest accumulator shares the api-surface admission model: the capture
clone, the inline envelope, record pointers, groups, observed values, query
names and body-shape keys are admitted before allocation, and each recorded
body is charged as temporary bytes before it is parsed. Retained state and
clone, the inline envelope, record pointers, groups, every route part, observed
values, query names and body-shape keys are admitted before allocation, and each
recorded body is charged as temporary bytes before it is parsed. Retained state and
temporary work must fit together within the 96 MiB projection representation
budget; exceeding it returns `resource_constraint` without a partial manifest.

Expand Down
12 changes: 11 additions & 1 deletion src/domain/analysisView/EnvironmentManifestAccumulator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const finished = (accumulator: EnvironmentManifestAccumulator) => {
};

it("refuses a body parse that exceeds the budget without retaining a partial tool", () => {
const accumulator = new EnvironmentManifestAccumulator(16 * 1024);
const accumulator = new EnvironmentManifestAccumulator(32 * 1024);
expect(accumulator.add(sample(0, "/api/items")).ok).toBe(true);
const before = finished(accumulator);
const body = `{"name":"${"x".repeat(2_000)}"}`;
Expand Down Expand Up @@ -85,3 +85,13 @@ it("retains repeated observed values, statuses and query names once across many
expect(manifest.tools[0]?.record_ordinals).toHaveLength(1000);
expect(manifest.records).toHaveLength(1000);
});

it("charges every literal route part so a path of many short segments fails closed", () => {
const accumulator = new EnvironmentManifestAccumulator(1024 * 1024);
expect(accumulator.add(sample(0, "/a".repeat(100))).ok).toBe(true);
expect(accumulator.add(sample(1, "/a".repeat(5_000)))).toMatchObject({
ok: false,
error: { _tag: "AnalysisResourceConstraintError", resource: "memory" },
});
expect(finished(accumulator).tools).toHaveLength(1);
});
61 changes: 47 additions & 14 deletions src/domain/analysisView/EnvironmentManifestAccumulator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from "zod";
import type { AnalysisError } from "../analysisErrorBase.js";
import { inferJsonShape } from "../jsonShape.js";
import { jsonValueType } from "../jsonShape.js";
import { ok, type Result } from "../result.js";
import {
compareUnicodeCodePoints as compare,
Expand All @@ -18,7 +18,9 @@ import {
compareTools,
parameterNames,
pathTemplate,
SIBLING_VARIANCE_SEGMENT_LIMIT,
toolName,
toolNameRegistry,
type BodyShape,
type JsonTypeName,
type LiteralPart,
Expand Down Expand Up @@ -127,6 +129,26 @@ const UNKNOWNS: Manifest["unknowns"] = [
},
];

/** Parse text as a JSON object; anything else, including invalid JSON, is null. */
const parseJsonObject = (
text: string,
): Readonly<Record<string, unknown>> | null => {
let root: unknown;
try {
root = JSON.parse(text);
} catch {
return null;
}
return typeof root === "object" && root !== null && !Array.isArray(root)
? (root as Readonly<Record<string, unknown>>)
: null;
};
/** Route parts of a template: one more than its separators. */
const routePartCount = (template: string): number => {
let count = 1;
for (const character of template) if (character === "/") count += 1;
return count;
};
const isJson = (essence: string | null): boolean =>
essence === "application/json" || (essence?.endsWith("+json") ?? false);
Comment thread
gensokyo-dev marked this conversation as resolved.
Resolved

Expand Down Expand Up @@ -235,7 +257,7 @@ export class EnvironmentManifestAccumulator extends WebNetworkProjectionAccumula
}
}

/** Parse the group's first recorded JSON-typed request body into key types only; values are discarded. */
/** Read the top-level key types of the group's first recorded JSON-typed request body; nested values are never walked. */
#bodyShape(reported: unknown): Result<BodyShape | null, AnalysisError> {
const parsed = postDataSchema.safeParse(reported);
const body = parsed.success ? parsed.data.request.postData : undefined;
Expand All @@ -247,18 +269,16 @@ export class EnvironmentManifestAccumulator extends WebNetworkProjectionAccumula
!isJson(mediaTypeEssence(body.mimeType))
Comment thread
gensokyo-dev marked this conversation as resolved.
Resolved
)
return ok(null);
// The parsed value, the shape nodes and their paths coexist with the text.
// The parsed tree is linear in the text and coexists with it and the key entries.
if (!this.scratch(RECORD_SCRATCH_BYTES + textBytes(body.text.length) * 3))
return this.overBudget();
const shape = inferJsonShape(body.text);
if (shape === null || shape.root_type !== "object") return ok(null);
const root = parseJsonObject(body.text);
if (root === null) return ok(null);
const entries: [string, JsonTypeName][] = [];
for (const property of shape.properties) {
const [segment] = property.path;
if (property.path.length !== 1 || segment?.kind !== "property") continue;
for (const [name, value] of Object.entries(root)) {
// JSON parsers and schema clones drop a __proto__ own property; omit it explicitly.
if (segment.name === "__proto__") this.#unrepresentableBodyKey = true;
else entries.push([segment.name, property.types[0] ?? "null"]);
if (name === "__proto__") this.#unrepresentableBodyKey = true;
else entries.push([name, jsonValueType(value)]);
}
return ok({ type: "object", properties: Object.fromEntries(entries) });
}
Expand Down Expand Up @@ -289,6 +309,8 @@ export class EnvironmentManifestAccumulator extends WebNetworkProjectionAccumula
textBytes(line.origin.length) +
textBytes(route.template.length) * 2 +
textBytes(route.rules.length);
// Every part, literal or templated, is one object in the group and in each rule, template and name pass.
bytes += ENTRY_BYTES * 4 * routePartCount(route.template);
for (const segment of route.segments)
bytes += SEGMENT_BYTES + ENTRY_BYTES + textBytes(segment.value.length);
if (bodyShape !== null)
Expand Down Expand Up @@ -371,7 +393,7 @@ export class EnvironmentManifestAccumulator extends WebNetworkProjectionAccumula
}

#tools(groups: readonly ToolGroup[]): Tool[] {
const used = new Set<string>();
const registry = toolNameRegistry();
return applyTemplateRules(groups, this.#rules)
.map((group) => {
const names = parameterNames(group.parts);
Expand All @@ -386,7 +408,7 @@ export class EnvironmentManifestAccumulator extends WebNetworkProjectionAccumula
.map(({ group, names, template }): Tool => {
let next = 0;
return {
name: toolName(group.method, group.parts, names, used),
name: toolName(group.method, group.parts, names, registry),
method: group.method,
path_template: template,
api_surface_template: group.api_surface_template,
Expand Down Expand Up @@ -439,9 +461,12 @@ export class EnvironmentManifestAccumulator extends WebNetworkProjectionAccumula
path_template: group.api_surface_template,
reason,
};
exclusions.set(compositeKey(Object.values(exclusion)), {
// Distinct groups can print the same exclusion row; a templated one keeps the row inferred.
const key = compositeKey(Object.values(exclusion));
exclusions.set(key, {
...exclusion,
templated: hasParam(group.parts),
templated:
(exclusions.get(key)?.templated ?? false) || hasParam(group.parts),
});
}
const tools = this.#tools(toolGroups);
Expand All @@ -467,6 +492,14 @@ export class EnvironmentManifestAccumulator extends WebNetworkProjectionAccumula
"A top-level __proto__ key in a recorded JSON body is omitted from body_shape; it cannot be an own property of the published object.",
]
: []),
...(this.#rules.has("sibling-variance") &&
toolGroups.some(
(group) => group.parts.length > SIBLING_VARIANCE_SEGMENT_LIMIT,
)
? [
`Routes with more than ${String(SIBLING_VARIANCE_SEGMENT_LIMIT)} segments are not compared by sibling-variance; they keep their grouped templates.`,
]
: []),
...(this.#unrepresented > 0
? [
`${String(this.#unrepresented)} retained records without a usable request line are not represented in the manifest.`,
Expand Down
40 changes: 31 additions & 9 deletions src/domain/analysisView/environmentManifestRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ const STOP_WORDS = new Set([
]);
const DROPPED_NAME_LITERALS = new Set(["api", "apis", "namespaces", "default"]);
const TOOL_NAME_LIMIT = 60;
/** Longest route sibling-variance compares; every position rebuilds a key over the whole route. */
export const SIBLING_VARIANCE_SEGMENT_LIMIT = 32;
const BASE_RULES: ReadonlySet<string> = new Set(ROUTE_RULES);
const OPT_IN_RULES: ReadonlySet<string> = new Set(TEMPLATE_RULES);

Expand Down Expand Up @@ -152,7 +154,8 @@ const templateAfterUidLiteral = (parts: readonly RoutePart[]): RoutePart[] =>
const previous = parts[index - 1];
return part.kind === "literal" &&
previous?.kind === "literal" &&
previous.value === "uid"
previous.value === "uid" &&
!STOP_WORDS.has(part.value)
? param("after-uid-literal", [part.value])
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
: part;
});
Expand Down Expand Up @@ -244,8 +247,13 @@ const mergeSiblings = (

/** Merge groups that differ in exactly one identifier-like segment at index two or later. */
const mergeSiblingVariance = (groups: readonly ToolGroup[]): ToolGroup[] => {
let current = [...groups];
const longest = Math.max(0, ...groups.map((group) => group.parts.length));
const beyondLimit = groups.filter(
(group) => group.parts.length > SIBLING_VARIANCE_SEGMENT_LIMIT,
);
let current = groups.filter(
(group) => group.parts.length <= SIBLING_VARIANCE_SEGMENT_LIMIT,
);
const longest = Math.max(0, ...current.map((group) => group.parts.length));
for (let position = 2; position < longest; position += 1) {
const buckets = new Map<string, ToolGroup[]>();
const output: ToolGroup[] = [];
Expand All @@ -270,7 +278,7 @@ const mergeSiblingVariance = (groups: readonly ToolGroup[]): ToolGroup[] => {
output.push(...mergeSiblings(bucket, position));
current = output;
}
return current;
return [...current, ...beyondLimit];
};

/** Apply the selected opt-in rules in fixed order; every merge is an inference. */
Expand Down Expand Up @@ -360,12 +368,21 @@ export const pathTemplate = (
.join("/")}`;
};

/** Names assigned in one manifest and the next suffix to try for each colliding base. */
export interface ToolNameRegistry {
readonly used: Set<string>;
readonly nextSuffix: Map<string, number>;
}
export const toolNameRegistry = (): ToolNameRegistry => ({
used: new Set(),
nextSuffix: new Map(),
});
/** Deterministic tool name from the method and route literals, unique within a manifest. */
export const toolName = (
method: string,
parts: readonly RoutePart[],
names: readonly string[],
used: Set<string>,
registry: ToolNameRegistry,
): string => {
const literals = parts.flatMap((part, index) => {
if (part.kind !== "literal") return [];
Expand All @@ -390,11 +407,16 @@ export const toolName = (
const truncate = (text: string, limit: number): string =>
text.slice(0, limit).replace(/_+$/u, "");
let candidate = truncate(base, TOOL_NAME_LIMIT);
for (let suffix = 2; used.has(candidate); suffix += 1) {
const tail = `_${String(suffix)}`;
candidate = `${truncate(base, TOOL_NAME_LIMIT - tail.length)}${tail}`;
if (registry.used.has(candidate)) {
let suffix = registry.nextSuffix.get(base) ?? 2;
Comment thread
gensokyo-dev marked this conversation as resolved.
Resolved
for (; ; suffix += 1) {
const tail = `_${String(suffix)}`;
candidate = `${truncate(base, TOOL_NAME_LIMIT - tail.length)}${tail}`;
if (!registry.used.has(candidate)) break;
}
registry.nextSuffix.set(base, suffix + 1);
}
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
used.add(candidate);
registry.used.add(candidate);
return candidate;
};

Expand Down
Loading