Repository navigation
feat(environment): compare an environment with probe captures of its application - #5699
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Medium impact] The PR appears safe to merge, with non-blocking fixes for a dropped query name and slow ID learning on large lists. FindingsFix with agent prompt### Issue 1
src/application/environment/environmentCompareMatch.ts:170-171
A query named `__proto__` disappears because `args` is a plain object. Assigning its string value calls the inherited setter instead of adding an own member. `environmentArguments` then omits it, so replay can choose the first recording instead of the one matching the probe’s query. These query names are allowed and advertised.
Build `args` with `Object.create(null)` or `Object.fromEntries` so the comparison keeps the supplied value.
### Issue 2
src/application/environment/environmentCompareIds.ts:69-74
`#pairScoped` scans every earlier value for each new ID. A 20,000-item list containing only `id` fields fits under the replay body limit but causes about 200 million checks, even when comparing unchanged IDs against their own capture. Large list probes pay this cost each time they run.
Keep a reverse set or map per collection, as the probe-wide `#toLive` map already does.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryAdds offline
DiagramsequenceDiagram
participant Input as Evidence files
participant Compare as Comparison
participant State as Fresh probe state
participant IDs as ID map
participant Report as Report
Input->>Compare: Authenticate manifest, capture, and probes
loop Each probe
Compare->>State: Start from captured state
loop Each usable request
Compare->>IDs: Translate known IDs
Compare->>State: Check arguments and answer
State-->>Compare: Recorded or state-backed answer
Compare->>IDs: Learn matching IDs
Compare->>Report: Compare status and body
end
end
Reviews (29) · Last reviewed commit: "fix(merge): reconcile environment compar..." · Reviewed by Greptile |
|
Maintainer thread pass (inventory):
|
…application Add environment-compare against probe captures of the served application, keeping the rebased write effects and main's state-file ownership. Squashed rebase of morluto#5699 onto the rebased morluto#5600 tip.
6c13ef7 to
12d2bc3
Compare
This comment has been minimized.
This comment has been minimized.
…application Add environment-compare against probe captures of the served application, keeping the rebased write effects and main's state-file ownership. Squashed rebase of morluto#5699 onto the rebased morluto#5600 tip.
12d2bc3 to
b1c6875
Compare
…application Add environment-compare against probe captures of the served application, keeping the rebased write effects and main's state-file ownership. Squashed rebase of morluto#5699 onto the rebased morluto#5600 tip.
b1c6875 to
14b474c
Compare
|
Fixed in b8154e9 — a nonzero |
|
Fixed two open Greptile P1s. Tip
|
…application Add environment-compare against probe captures of the served application, keeping the rebased write effects and main's state-file ownership. Squashed rebase of morluto#5699 onto the rebased morluto#5600 tip.
ae52ae9 to
98fa616
Compare
|
Restacked onto #5600 tip The five fidelity commits replayed with no conflict files. Offset/page handling, child-id scope decoding, and the tied-collection create guard are still on the branch. Typecheck passed, and 402 focused environment tests passed. |
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>
The tied-create collection order lives with the checks that match encoded parents. The write simulation reads field checks from that attribution, and taint uses the same segment match. Co-authored-by: morluto <morluto@users.noreply.github.com>
b1fecee to
1874b20
Compare
|
Restacked onto main The only content conflict was |
… learned ids Differ.object mapped every key through the probe's id map, so a field named like a learned id was compared with another field, and a real rename could pass as a mapped key. Keys now translate only for an object keyed by learned ids as learning reads one: a key both sides share needs every key evidently an id, and otherwise each entry is an entity or each key evidently an id. Any other object compares field by field. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Preserve main's per-line list membership and query-aware serving while retaining shared encoded-path matching and stable collection order. Update paging regressions and docs for the current behavior, and remove the unused APK input type that blocked Knip. Validation: 993 source tests and 26 CLI/MCP/process boundary tests passed. npm run check and npm run docs:check passed. Live application probes and the full repository suite were not rerun.
| else if (!Object.hasOwn(args, name)) { | ||
| args[name] = value; |
There was a problem hiding this comment.
A query named __proto__ disappears because args is a plain object. Assigning its string value calls the inherited setter instead of adding an own member. environmentArguments then omits it, so replay can choose the first recording instead of the one matching the probe’s query. These query names are allowed and advertised.
Build args with Object.create(null) or Object.fromEntries so the comparison keeps the supplied value.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/application/environment/environmentCompareMatch.ts
Line: 170-171
Comment:
**A query value disappears**
A query named `__proto__` disappears because `args` is a plain object. Assigning its string value calls the inherited setter instead of adding an own member. `environmentArguments` then omits it, so replay can choose the first recording instead of the one matching the probe’s query. These query names are allowed and advertised.
Build `args` with `Object.create(null)` or `Object.fromEntries` so the comparison keeps the supplied value.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| for (const value of scoped.values()) { | ||
| if (String(value) === envKey) { | ||
| this.#conflicts += 1; | ||
| return false; | ||
| } | ||
| } |
There was a problem hiding this comment.
#pairScoped scans every earlier value for each new ID. A 20,000-item list containing only id fields fits under the replay body limit but causes about 200 million checks, even when comparing unchanged IDs against their own capture. Large list probes pay this cost each time they run.
Keep a reverse set or map per collection, as the probe-wide #toLive map already does.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/application/environment/environmentCompareIds.ts
Line: 69-74
Comment:
**Large lists learn IDs slowly**
`#pairScoped` scans every earlier value for each new ID. A 20,000-item list containing only `id` fields fits under the replay body limit but causes about 200 million checks, even when comparing unchanged IDs against their own capture. Large list probes pay this cost each time they run.
Keep a reverse set or map per collection, as the probe-wide `#toLive` map already does.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Summary
An environment is only as useful as it is faithful: an agent graded or trained on it should meet the behaviour of the application it was captured from. REA checks an environment only against its own capture, so nothing measured how far it drifts from the application on calls the capture did not make, after writes, or on errors. Every important gap found so far came from ad hoc replays against live applications.
This PR adds
rea environment-compare, which measures that. It compares an environment with probe captures: recordings of call sequences made against the live application, each after a reset. It reports how many calls the environment answers as the application did, which tools disagree and how. The command only reads Evidence and makes no network call.Part of #4933. Stacked on #5600, which carries #5351 and #5352; it is merged in at
5327e598. Until #5600 lands, the diff against main includes it. The new work is:src/application/environment/environmentCompare*.tsand their tests;src/cli/environmentCommands.tsandsrc/cliCommandNames.ts;tests/boundary/cli/environmentCompareCli.test.ts;docs/specs/agent-environments/fidelity-compare/.Problem and expected behavior
Each
--probeisinspect-web-network-captureorcapture-browser-scenarioEvidence of one sequence, recorded against the application after a reset. For each probe, the comparison:Id mapping. A re-seeded application holds the same entities under other ids, so the comparison maps them:
Normalisation. After mapping:
The report counts each kind.
Report. Agreement overall, per probe and per tool, plus agreement ignoring order for applications that return sets in no fixed order. Differences are categorised as
status,missing-field,extra-field,value,length,order,clock-format,refused,not-served,no-toolandunmapped-id, each with a JSON pointer.Change and scope
environmentToolAnswerwith a fresh state store per probe), so it measures exactly what an agent meets. Probes load with the capture parser, now exported.Contract and boundary impact
src/application/environment/) and the CLI.environment-comparewith a repeatable--probe; no MCP tool, so the catalog is unchanged.environment-servedoes; the report cites every Evidence id and is not itself Evidence.docs/public/product-catalog.json), package, or installation impact: none.Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.
Evidence and regression coverage
Tests added.
Executed evidence: six environments against their live applications. The same images were seeded by the same scripts and restored from a snapshot before every sequence (7 to 80 s).
A driver outside REA recorded three kinds of sequence:
The environments' manifests use
prefix-variance, so the comparison ran on a local build with #5664 merged.Environment gaps the runs found, which are the next things to fix:
domainparameter;"<scrubbed>".Differences not caused by the environment:
The six runs also found six ways the comparison itself was wrong. Each was fixed with a test before the next run:
Details are in
docs/specs/agent-environments/fidelity-compare/verification.md.User-visible output. The summary for Komga:
{"probes": 3, "steps": 356, "equal": 334, "agreement": 0.938, "agreement_ignoring_order": 0.938, "unobserved": 0, "categories": {"status": 6, "missing-field": 4, "extra-field": 4, "value": 10, "length": 2, "not-served": 8, "unmapped-id": 6, "...": 0}, "normalised": {"ids": 926, "clocks": 1550, "generated": 17, "large_bodies": 0, "unobserved_bodies": 0}}Remaining proof gaps:
For evidence-bearing changes:
Validation performed
Run on macOS with Node v22.23.1 at 235b22f (verification commit 20ad661), then again after merging #5600's head into 64b4994.
At 235b22f:
npm run build:cached,npm run check:fast,npm run format:check,npx knip,npm run scan:todos,npm run docs:check,npm run verify:test-discovery,npm run mcp-catalog:check— passed.npm run jscpd— 3.46% over 3609 files.npx vitest run --project domain --project services— 7487 passed, 5 pre-existing skips.npm run test:prepare, thennpm run test:focused --the environment-compare, export and serve CLI boundaries, the serve MCP boundary and tool schema validity — 5 files, 30 passed.At 64b4994:
npm run build:cached,check:fast,format:check,knip,mcp-catalog:checkanddocs:checkpassed;jscpdat 3.46%;Review round (head 473d03c): fixed the 11 Greptile threads and two findings of my own.
check:fast, format, knip, todos, docs, test discovery, module boundaries and catalog; domain and services 7504 (5 pre-existing skips); focused boundaries 80; conformance;jscpd3.46%.Review round 2 (head c63bcb7): merged feat(environment): apply evidence-gated write effects to the served state #5600's f2b9535 (a write of a missing entity never answers with a 2xx), then fixed Greptile's four follow-ups in 736bf38.
jscpd3.46%), and the six environments still compare exactly as in the table.Review round 3 (head 5604d55): entities inside an envelope keep their collection's mapping: the answer's own entities are found at the view's entity or list pointer, or the write's response pointer (8ef9257). Its test fails on c63bcb7; domain and services 7509 passed, boundaries 80, and the six environments are unchanged.
Review round 4 (head 7e26d99): no new findings; merged the write-plan branch at 9edbabe and fc403d9 (main 335c042 and the base branches' review fixes). Gates passed (domain and services 7637, 5 pre-existing skips; boundaries 80; conformance;
jscpd3.44%; the environment application tests 189 after the last merge).Review round 5 (head 71a50f0): merged feat(environment): apply evidence-gated write effects to the served state #5600's 1d1c478 in 9622c5d, then fixed Greptile's three findings. The required-field finding was feat(environment): apply evidence-gated write effects to the served state #5600 code, fixed there. The other two are fixed in 71a50f0.
unobservedwith their reason, and left out of agreement.unobserved_bodies.check:fast, format, knip, todos, docs, discovery, module boundaries, catalog, no oxlint warnings; domain and services 7647 (5 pre-existing skips); the compare, export, serve and analysis-view boundaries 69; conformance 279;jscpd3.44%.Review round 6 (head bacafc5): merged feat(environment): apply evidence-gated write effects to the served state #5600's dc5e2aa in 8996fbf. That fixes the two findings Greptile raised on both PRs: derived update changes are weighed, and a reset or load resets collection spellings.
jscpd3.44%, no oxlint warnings.Review round 7 (head ac3ca8a): Greptile's two findings on round 6 were in feat(environment): apply evidence-gated write effects to the served state #5600's code, fixed there in fe8ab58 and merged here in d58c9ab. Gates passed: domain and services 7653 (5 pre-existing skips), boundaries 69, conformance,
jscpd3.44%. The six environments compare exactly as in the table.Review round 8 (head 779910e): Greptile's finding on round 7 was in feat(environment): apply evidence-gated write effects to the served state #5600's store, fixed there in 73c0e9b and merged here. Gates passed: domain and services 7654, boundaries,
jscpd3.44%. The six environments compare exactly as in the table.Review round 9 (head ce49169): fixed Greptile's two findings on round 8 in 5020a83: a probe with any undated record keeps its recorded order, as state extraction does, and a browser probe that makes POST, PUT or PATCH calls without recorded request bodies is refused. It also merged morluto's a36cdf4 and feat(environment): apply evidence-gated write effects to the served state #5600 at 3580d85 and 43d98ea, whose gate fix settles the finding Greptile raised here about overwritten document writes. Both new tests fail on the previous head, and the six environments compare exactly as before, on the probes and against their own captures.
Review round 10 (head 6c13ef7):
other-origin. The origin choice moved toenvironmentManifestOrigin.ts, shared by the manifest and the comparison.isPagingParameter, moved toenvironmentStatePaging.ts.check:fast, format, knip, todos, docs, discovery, module boundaries and catalog, with no oxlint warnings in the changed files; domain and services 7789 (5 pre-existing skips); environment boundaries 65; conformance 265;jscpd3.43%.Review round 11 (head ea72e29):
format:checkfailed on two docs tables and three test files; they are formatted in 6c1e5a8 and ea72e29.check:fast, format, knip, todos, docs, discovery, module boundaries and catalog; domain and services 7912 (5 pre-existing skips); environment boundaries 65;jscpd3.47%.Review round 12 (head 5a09aae):
project.idand user ids, and agreement fell from 23.9% to 20.9%. That thread stays open.src/main/deferredRuntime.tsinside a conflicted merge.check:fast, format, knip, todos, docs, discovery, module boundaries and catalog; domain and services 7969 (5 pre-existing skips); environment boundaries 67;jscpd3.40%.state, comes from feat(environment): apply evidence-gated write effects to the served state #5600. The smoke ran 31/31.Review round 13 (head 9549f74): fixed Greptile's finding on 1874b20, the Cursor agent's restack onto main after feat(environment): apply evidence-gated write effects to the served state #5600 landed.
Differ.objecttranslates keys only for an object keyed by learned ids, read as learning reads one, so ordinary fields compare by name and a real rename shows. The new test fails on 1874b20.check:fast, format, knip, todos, docs, discovery, module boundaries and catalog; domain and services 7982 (5 pre-existing skips); environment boundaries 67;jscpd3.39%.Merge resolution validation
At
462434c03, mergedmain(293832baf) while preserving its per-line whole-list membership, query-aware list serving, and extracted helper owners alongside this PR's shared encoded-path matching and stable collection ordering. Paging regressions now distinguish learned offset queries from unproved whole lines, use an explicit page size for later-page fixtures, and retain positive-page-base uncertainty. Removed the unreferencedInspectApkSignatureInputtype after confirming the Knip finding also on clean main.npm run check— exit 0, including typecheck, lint, formatting, Knip, metadata, module boundaries, and architecture guards.npm run check:fast— exit 0.npm run docs:generateandnpm run docs:check— exit 0, including 9 README consistency tests.Compatibility, safety, and release
Author readiness
Human owner: @earakely-scale
Before merge
type(scope): outcome.🤖 Generated with Claude Code