Skip to content

Commit 761a2bd

Browse files
cursoragentmorluto
andcommitted
chore: restack environment fidelity onto main
Keep probe comparison, paging, and tied-create behavior on main after morluto#5600. Capture parsing keeps field-path errors and records whether a probe kept request and response bodies. Co-authored-by: morluto <morluto@users.noreply.github.com>
1 parent 538017d commit 761a2bd

38 files changed

Lines changed: 4337 additions & 168 deletions

‎docs/agent-environments.md‎

Lines changed: 70 additions & 7 deletions
Large diffs are not rendered by default.

‎docs/cli.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,22 @@ of the serve command's stopped document. See
471471
[agent environments](agent-environments.md#export-a-bundle) for the folder
472472
layout and what the smoke task checks.
473473

474+
## Compare an environment with its application
475+
476+
`rea environment-compare <manifest.json> --evidence <capture.json> --probe <probe.json> [--probe <probe.json> ...]`
477+
compares the environment the pair serves with probe captures of the application it came from. Each probe is capture
478+
Evidence of one call sequence recorded against the application after a reset; the environment's state is reset before
479+
each probe, every request to the application's origin is answered as the served environment answers it, and the
480+
answer is compared with the application's after ids are mapped and clocks and generated values are normalised. The command reads files only and
481+
makes no network call. It prints the report and exits `0`, or prints a structured `invalid_request` error and exits `1`
482+
for the same pair refusals as `environment-serve`, a probe that is not capture Evidence, or a browser probe captured
483+
without response bodies, or without the request bodies its writes need. See
484+
[agent environments](agent-environments.md#measure-fidelity-against-the-application) for the report.
485+
486+
```sh
487+
rea environment-compare manifest.json --evidence capture.json --probe probe.json --json
488+
```
489+
474490
## Output and exit status
475491

476492
`rea mcp doctor --json` checks production MCP startup and reports child logs in
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Plan
2+
3+
1. Export the capture parser from `environmentSource.ts` so a probe loads like a capture.
4+
2. `environmentCompareMatch.ts`: a probe request to a tool and its arguments.
5+
3. `environmentCompareIds.ts`: the id map, natural-key pairing, learning from two answers, translating arguments.
6+
4. `environmentCompareDiff.ts`: normalisation and categorised differences.
7+
5. `environmentCompare.ts`: per probe, reset the state, answer each request, compare and learn; the report.
8+
6. `rea environment-compare` in `src/cli/environmentCommands.ts`, documented in `docs/agent-environments.md` and
9+
`docs/cli.md`.
10+
7. Tests: matching, pairing, normalisation and categories as unit tests; the command over a fixture capture and probes.
11+
8. Verification on VMs: six applications brought up and seeded as for their capture, reset from a snapshot per sequence,
12+
driven by a script that records each sequence as a HAR; baseline reports per environment.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Compare an environment with the application it came from
2+
3+
Issue: https://github.com/morluto/rea/issues/4933
4+
5+
## Outcome
6+
7+
An environment is only as useful as it is faithful: an agent trained or graded on it should meet the behaviour of the
8+
application it was captured from. REA checks an environment only against its own capture, so nothing says how far it
9+
drifts from the application on calls the capture did not make, after writes, or on errors.
10+
11+
`rea environment-compare` measures that. It takes an environment (a manifest and its capture Evidence) and one or more
12+
**probe captures**, each a recording of one call sequence made against the live application, and reports how many of the
13+
probe's calls the environment answers as the application did, which tools disagree and how.
14+
15+
The command only reads Evidence: it makes no network call. Whoever records the probes drives the application with its own
16+
credentials and resets it between sequences.
17+
18+
## Requirements
19+
20+
- Inputs: the manifest Evidence, its capture Evidence (`--evidence`), and one or more probe capture Evidence files
21+
(`--probe`, repeatable), each `inspect-web-network-capture` or `capture-browser-scenario` Evidence of one sequence.
22+
- Each probe is one sequence run against a freshly reset application. Before each probe the environment's state is reset,
23+
so sequences are independent on both sides.
24+
- Requests are taken in the probe's order (start time, then ordinal; ordinal alone when any record lacks a start
25+
time, as state extraction orders them). A request is matched to the manifest tool of the
26+
same method whose path template it fits with the most literal segments; format-rule parameters must fit their format
27+
once percent-decoded, as replay reads them.
28+
Query values the tool takes and a JSON body become the tool's arguments. A path argument is the raw segment: the
29+
environment decodes it once, so a segment encoded twice is not read as a second decoding. Replay matches that raw
30+
argument against a recorded segment that equals it, equals its one decoding, or decodes once to it.
31+
- A record without a usable request line (a redacted URL, a transaction the capture cannot attribute, an unparseable
32+
URL or no method) is not replayed, nor is a request to another origin than the probe's application (`other-origin`),
33+
which is the origin with the most JSON-like records, as the manifest chooses its own. A request with no recorded
34+
answer is made, since it may have changed the application, but not compared. Each is listed per probe with its
35+
reason and left out of agreement.
36+
- A request no tool matches is reported `no-tool`; a matched tool the environment does not offer, such as a write it
37+
withholds, is reported `not-served`. Neither is answered.
38+
- Ids differ between a re-seeded application and the capture. The comparison maps them:
39+
- seeded entities pair across the two answers by a natural key: a field present on every element of both arrays whose
40+
string values are unique on each side and shared between them;
41+
- identifier fields (`id`, `uuid`, `guid`, and names ending in `_id`, `Id`, `ID`, `_uuid` or `Uuid`) of paired objects,
42+
and of the two answers to the same call, map the live value to the environment's value; a create's two answers map
43+
the new ids, including a response that is only that id at the write plan's identity location. The `id`, `uuid` or
44+
`guid` of the answer's own entities (at the read view's entity or list location, a write's response location, or
45+
else the root) also maps within the collection the call names, since two collections can reuse a live id for
46+
different entities. An equal pair is kept in that collection, so another collection's mapping of the same live id
47+
does not replace it. A collection's map is a bijection: the first pairing of either side wins. Outside identifier
48+
fields, a string maps when the environment's state holds it as an id, and the keys of two objects keyed by ids map
49+
when their values pair (keys that partly overlap only when they are digits, UUIDs or their entries' identities, and
50+
every value pairs);
51+
- ids are learned only from an answer the environment gave this call, from its state or from a recording of exactly
52+
this call, its whole request line and its request body: a recording of another call that replay answers with
53+
instead holds other entities. A tool that takes a body does not match a recording whose body the probe did not send;
54+
- path, query and body values equal to a mapped live id are translated before the environment answers, a path
55+
parameter by the collection it names, except query values that page a list (`limit`, `offset`, `page` and the
56+
like), which count items rather than name one. A literal route segment is not translated. A nested collection is
57+
the live path's concrete parent values, each parameter decoded once, so two parents do not share one child map and
58+
spellings replay treats as equal name one. A second encoding stays a different parent. Learning and translation use
59+
that same live path.
60+
A path value the map does not know, and the environment's state does not hold, is reported `unmapped-id`.
61+
- A call is checked against the served tool's input schema first, as the MCP server checks it; a call it refuses is
62+
reported `refused`. A browser probe keeps its request bodies; one captured without response bodies is refused, since
63+
only statuses would compare, and so is one that makes POST, PUT or PATCH calls without recorded request bodies, since
64+
those calls would be made empty.
65+
- Answers compare after normalisation: empty response text equals no body (a JSON empty string stays one); mapped ids
66+
compare equal, in scalar sets as well, an entity's own identity within the call's collection and any other id by the
67+
probe's mapping, and an entity's own identity both sides hold verbatim differs when its collection's mapping gives it
68+
another environment value (a reference keeps raw equality, as the probe's mapping cannot tell which collection it
69+
names); two clock values (ISO-8601 strings, or epoch numbers under
70+
time-named fields) compare by format only; two different generated values (both UUIDs, or both of one length and the
71+
same character classes with a digit) that neither side maps compare equal and are counted. A body over the replay
72+
limit, text or binary, compares by status only, as does a live body the probe did not record, unless the answer has
73+
none by definition (204, 205, 304, or an answer to `HEAD`). Both are counted.
74+
- A step agrees when the statuses are equal and the normalised bodies are. Differences are categorised: `status`,
75+
`missing-field` (the application had it), `extra-field`, `value`, `length`, `order`, `clock-format`, `refused` (the
76+
environment refused the call), `not-served`, `no-tool` and `unmapped-id`, each with a JSON pointer and short values.
77+
- The report gives agreement overall, per probe and per tool, agreement ignoring item order beside it, the counts per
78+
category, the ids mapped and the values normalised, the records left uncompared, and each step's differences (at most
79+
20 per step).
80+
81+
## Non-goals
82+
83+
- No network access, no credentials, no reset of the application: probes are recorded outside REA.
84+
- No generation of call sequences; a later change generates them where the environment disagrees.
85+
- No change to how environments serve.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Tasks
2+
3+
- [x] Record the outcome, requirements and non-goals.
4+
- [x] Load probes as captures.
5+
- [x] Match probe requests to tools.
6+
- [x] Map ids and translate arguments.
7+
- [x] Normalise and categorise differences.
8+
- [x] Compare per probe and report.
9+
- [x] Add the command and its documentation.
10+
- [x] Add unit and command tests.
11+
- [x] Run the gates.
12+
- [x] Measure six environments against their live applications and record the results.

0 commit comments

Comments
 (0)